From e24c09e828bc15cc75a1eb340060fd1e666e866c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 29 Nov 2012 16:52:19 +0100 Subject: [PATCH] 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 a1918b8306f3a03. Signed-off-by: Uli Schlachter --- lib/awful/titlebar.lua.in | 17 +++++++++++------ lib/wibox/drawable.lua.in | 3 +-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/awful/titlebar.lua.in b/lib/awful/titlebar.lua.in index 2b00bbe71..b6e2ad390 100644 --- a/lib/awful/titlebar.lua.in +++ b/lib/awful/titlebar.lua.in @@ -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 diff --git a/lib/wibox/drawable.lua.in b/lib/wibox/drawable.lua.in index 8f019f593..6728f4e3d 100644 --- a/lib/wibox/drawable.lua.in +++ b/lib/wibox/drawable.lua.in @@ -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)