Update titlebar color when focus changes (FS#1056)

The current code relied on some widget to cause a redraw when the focus changes.
Obviously, this assumption is wrong.

Instead, the code now uses the proper "focus" and "unfocus" signals for setting
titlebar colors, but it also needs to set these colors when a new titlebar is
created (v1 of this patch forgot that). For this reason, update_colors has to be
saved for when a titlebar's colors are updated.

This commit also reverts the ugly redraw_hook hack from commit a1918b8306.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2012-11-29 16:52:19 +01:00
parent c50d62749b
commit e24c09e828
2 changed files with 12 additions and 8 deletions

View File

@ -70,24 +70,29 @@ local function new(c, args)
local ret
if not bars[position] then
ret = drawable(d, nil, function()
-- On redraw, update the fg and bg colors of the titlebar
ret = drawable(d, nil)
local function update_colors()
local args = bars[position].args
ret:set_bg(get_color("bg", c, args))
ret:set_fg(get_color("fg", c, args))
end)
end
bars[position] = {
args = args,
drawable = ret
drawable = ret,
update_colors = update_colors
}
-- Update the colors when focus changes
c:connect_signal("focus", update_colors)
c:connect_signal("unfocus", update_colors)
else
bars[position].args = args
ret = bars[position].drawable
end
-- Make sure the titlebar is (re-)drawn
ret.draw()
-- Make sure the titlebar has the right colors applied
bars[position].update_colors()
return ret
end

View File

@ -198,7 +198,7 @@ local function setup_signals(_drawable)
clone_signal("property::y")
end
function drawable.new(d, widget_arg, redraw_hook)
function drawable.new(d, widget_arg)
local ret = object()
ret.drawable = d
ret.widget_arg = widget_arg or ret
@ -213,7 +213,6 @@ function drawable.new(d, widget_arg, redraw_hook)
-- Only redraw a drawable once, even when we get told to do so multiple times.
ret._redraw_pending = false
ret._do_redraw = function()
if redraw_hook then redraw_hook(ret) end
ret._redraw_pending = false
capi.awesome.disconnect_signal("refresh", ret._do_redraw)
do_redraw(ret)