awful: automatize titlebar update
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
f48f26286e
commit
6c2c607759
|
@ -296,9 +296,6 @@ function hook_focus(c)
|
||||||
if not awful.client.ismarked(c) then
|
if not awful.client.ismarked(c) then
|
||||||
c.border_color = border_focus
|
c.border_color = border_focus
|
||||||
end
|
end
|
||||||
if use_titlebar then
|
|
||||||
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Hook function to execute when unfocusing a client.
|
-- Hook function to execute when unfocusing a client.
|
||||||
|
@ -306,9 +303,6 @@ function hook_unfocus(c)
|
||||||
if not awful.client.ismarked(c) then
|
if not awful.client.ismarked(c) then
|
||||||
c.border_color = border_normal
|
c.border_color = border_normal
|
||||||
end
|
end
|
||||||
if use_titlebar then
|
|
||||||
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Hook function to execute when marking a client
|
-- Hook function to execute when marking a client
|
||||||
|
@ -335,8 +329,11 @@ function hook_manage(c)
|
||||||
c.floating_placement = "smart"
|
c.floating_placement = "smart"
|
||||||
if use_titlebar then
|
if use_titlebar then
|
||||||
-- Add a titlebar
|
-- Add a titlebar
|
||||||
c.titlebar = awful.titlebar.new({ fg = fg, bg = bg, modkey = modkey })
|
awful.titlebar.add(c, { fg = fg_normal,
|
||||||
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
|
bg = bg_normal,
|
||||||
|
fg_focus = fg_focus,
|
||||||
|
bg_focus = bg_focus,
|
||||||
|
modkey = modkey })
|
||||||
end
|
end
|
||||||
-- Add mouse bindings
|
-- Add mouse bindings
|
||||||
c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end))
|
c:mouse_add(mouse({ }, 1, function (c) c:focus_set(); c:raise() end))
|
||||||
|
@ -391,13 +388,6 @@ function hook_timer ()
|
||||||
-- mytextbox.text = " " .. os.date() .. " "
|
-- mytextbox.text = " " .. os.date() .. " "
|
||||||
end
|
end
|
||||||
|
|
||||||
function hook_titleupdate (c)
|
|
||||||
if use_titlebar then
|
|
||||||
-- Update titlebar
|
|
||||||
awful.titlebar.update(c, bg_normal, fg_normal, bg_focus, fg_focus)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Set up some hooks
|
-- Set up some hooks
|
||||||
awful.hooks.focus(hook_focus)
|
awful.hooks.focus(hook_focus)
|
||||||
awful.hooks.unfocus(hook_unfocus)
|
awful.hooks.unfocus(hook_unfocus)
|
||||||
|
@ -407,5 +397,4 @@ awful.hooks.manage(hook_manage)
|
||||||
awful.hooks.mouseover(hook_mouseover)
|
awful.hooks.mouseover(hook_mouseover)
|
||||||
awful.hooks.arrange(hook_arrange)
|
awful.hooks.arrange(hook_arrange)
|
||||||
awful.hooks.timer(1, hook_timer)
|
awful.hooks.timer(1, hook_timer)
|
||||||
awful.hooks.titleupdate(hook_titleupdate)
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
|
@ -33,10 +33,30 @@ local table = table
|
||||||
local hooks = hooks
|
local hooks = hooks
|
||||||
local keygrabber = keygrabber
|
local keygrabber = keygrabber
|
||||||
local io = io
|
local io = io
|
||||||
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Reset env
|
-- Reset env
|
||||||
setfenv(1, P)
|
setfenv(1, P)
|
||||||
|
|
||||||
|
-- The ObjectTable class
|
||||||
|
ObjectTable = {}
|
||||||
|
ObjectTable.__index = ObjectTable
|
||||||
|
--- Lookup in a table indexed by objects
|
||||||
|
function ObjectTable.__index(self, key)
|
||||||
|
for k, v in pairs(self) do
|
||||||
|
if k == key then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function ObjectTable.new()
|
||||||
|
local o = {}
|
||||||
|
setmetatable(o, ObjectTable)
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Various structure
|
||||||
P.hooks = {}
|
P.hooks = {}
|
||||||
P.myhooks = {}
|
P.myhooks = {}
|
||||||
P.prompt = {}
|
P.prompt = {}
|
||||||
|
@ -53,12 +73,14 @@ P.tag.history.data = {}
|
||||||
P.tag.history.data.past = {}
|
P.tag.history.data.past = {}
|
||||||
P.tag.history.data.current = {}
|
P.tag.history.data.current = {}
|
||||||
P.titlebar = {}
|
P.titlebar = {}
|
||||||
|
P.titlebar.data = ObjectTable.new()
|
||||||
P.widget = {}
|
P.widget = {}
|
||||||
P.widget.taglist = {}
|
P.widget.taglist = {}
|
||||||
P.widget.taglist.label = {}
|
P.widget.taglist.label = {}
|
||||||
P.widget.tasklist = {}
|
P.widget.tasklist = {}
|
||||||
P.widget.tasklist.label = {}
|
P.widget.tasklist.label = {}
|
||||||
|
|
||||||
|
|
||||||
--- Create a new userhook (for external libs).
|
--- Create a new userhook (for external libs).
|
||||||
-- @param name Hook name.
|
-- @param name Hook name.
|
||||||
local function userhook_create(name)
|
local function userhook_create(name)
|
||||||
|
@ -983,47 +1005,59 @@ function P.widget.tasklist.label.currenttags(c, screen, bg_focus, fg_focus)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a standard titlebar.
|
--- Create a standard titlebar.
|
||||||
|
-- @param c The client.
|
||||||
-- @param args Arguments.
|
-- @param args Arguments.
|
||||||
-- fg: the foreground color,
|
-- fg: the foreground color.
|
||||||
-- bg: the background color.
|
-- bg: the background color.
|
||||||
-- @return A brand new titlebar.
|
-- fg_focus: the foreground color for focused window.
|
||||||
function P.titlebar.new(args)
|
-- fg_focus: the background color for focused window.
|
||||||
|
function P.titlebar.add(c, args)
|
||||||
|
-- Store colors
|
||||||
|
P.titlebar.data[c] = {}
|
||||||
|
P.titlebar.data[c].fg = args.fg
|
||||||
|
P.titlebar.data[c].bg = args.bg
|
||||||
|
P.titlebar.data[c].fg_focus = args.fg_focus
|
||||||
|
P.titlebar.data[c].bg_focus = args.bg_focus
|
||||||
|
|
||||||
|
-- Built args
|
||||||
local targs = {}
|
local targs = {}
|
||||||
if args.fg then targs.fg = args.fg end
|
if args.fg then targs.fg = args.fg end
|
||||||
if args.bg then targs.bg = args.bg end
|
if args.bg then targs.bg = args.bg end
|
||||||
local tb = titlebar(targs)
|
local tb = titlebar(targs)
|
||||||
|
|
||||||
tb:widget_add(widget({ type = "appicon", name = "appicon", align = "left" }))
|
tb:widget_add(widget({ type = "appicon", name = "appicon", align = "left" }))
|
||||||
|
|
||||||
local title = widget({ type = "textbox", name = "title", align = "flex" })
|
local title = widget({ type = "textbox", name = "title", align = "flex" })
|
||||||
title:mouse_add(mouse({ args.modkey }, 1, function (t) t:client_get():mouse_move() end))
|
title:mouse_add(mouse({ args.modkey }, 1, function (t) t:client_get():mouse_move() end))
|
||||||
title:mouse_add(mouse({ args.modkey }, 3, function (t) t:client_get():mouse_resize() end))
|
title:mouse_add(mouse({ args.modkey }, 3, function (t) t:client_get():mouse_resize() end))
|
||||||
tb:widget_add(title)
|
tb:widget_add(title)
|
||||||
|
|
||||||
local close_button= widget({ type = "textbox", name = "close", align = "right" })
|
local close_button= widget({ type = "textbox", name = "close", align = "right" })
|
||||||
close_button:mouse_add(mouse({ }, 1, function (t) t:client_get():kill() end))
|
close_button:mouse_add(mouse({ }, 1, function (t) t:client_get():kill() end))
|
||||||
tb:widget_add(close_button)
|
tb:widget_add(close_button)
|
||||||
return tb
|
|
||||||
|
P.titlebar.update(c)
|
||||||
|
|
||||||
|
c.titlebar = tb
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Update a titlebar. This should be called in some hooks.
|
--- Update a titlebar. This should be called in some hooks.
|
||||||
-- @param c The client to update.
|
-- @param c The client to update.
|
||||||
-- @param bg The background color for normal client.
|
function P.titlebar.update(c)
|
||||||
-- @param fg The foreground color for normal client.
|
if c.titlebar and P.titlebar.data[c] then
|
||||||
-- @param bg_focus The background color for focused client.
|
|
||||||
-- @param fg_focus The foreground color for focused client.
|
|
||||||
function P.titlebar.update(c, bg, fg, bg_focus, fg_focus)
|
|
||||||
if c.titlebar then
|
|
||||||
local widgets = c.titlebar:widget_get()
|
local widgets = c.titlebar:widget_get()
|
||||||
if widgets.title then
|
if widgets.title then
|
||||||
widgets.title.text = " " .. P.escape(c.name)
|
widgets.title.text = " " .. P.escape(c.name)
|
||||||
end
|
end
|
||||||
if client.focus_get() == c then
|
if client.focus_get() == c then
|
||||||
c.titlebar.bg = bg_focus
|
c.titlebar.fg = P.titlebar.data[c].fg_focus
|
||||||
c.titlebar.fg = fg_focus
|
c.titlebar.bg = P.titlebar.data[c].bg_focus
|
||||||
if widgets.close then
|
if widgets.close then
|
||||||
widgets.close.text = "<bg image=\"@AWESOME_ICON_PATH@/titlebar/closer.png\" resize=\"true\"/>"
|
widgets.close.text = "<bg image=\"@AWESOME_ICON_PATH@/titlebar/closer.png\" resize=\"true\"/>"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
c.titlebar.bg = bg
|
c.titlebar.fg = P.titlebar.data[c].fg
|
||||||
c.titlebar.fg = fg
|
c.titlebar.bg = P.titlebar.data[c].bg
|
||||||
if widgets.close then
|
if widgets.close then
|
||||||
widgets.close.text = "<bg image=\"@AWESOME_ICON_PATH@/titlebar/close.png\" resize=\"true\"/>"
|
widgets.close.text = "<bg image=\"@AWESOME_ICON_PATH@/titlebar/close.png\" resize=\"true\"/>"
|
||||||
end
|
end
|
||||||
|
@ -1031,9 +1065,22 @@ function P.titlebar.update(c, bg, fg, bg_focus, fg_focus)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Remove a titlebar from a client.
|
||||||
|
-- @param c The client.
|
||||||
|
function P.titlebar.remove(c)
|
||||||
|
c.titlebar = nil
|
||||||
|
P.titlebar.data[c] = nil
|
||||||
|
end
|
||||||
|
|
||||||
-- Register standards hooks
|
-- Register standards hooks
|
||||||
P.hooks.arrange(P.tag.history.update)
|
P.hooks.arrange(P.tag.history.update)
|
||||||
|
|
||||||
P.hooks.focus(P.client.focus.history.add)
|
P.hooks.focus(P.client.focus.history.add)
|
||||||
P.hooks.unmanage(P.client.focus.history.delete)
|
P.hooks.unmanage(P.client.focus.history.delete)
|
||||||
|
|
||||||
|
P.hooks.focus(P.titlebar.update)
|
||||||
|
P.hooks.unfocus(P.titlebar.update)
|
||||||
|
P.hooks.titleupdate(P.titlebar.update)
|
||||||
|
P.hooks.unmanage(P.titlebar.unmanage)
|
||||||
|
|
||||||
return P
|
return P
|
||||||
|
|
Loading…
Reference in New Issue