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:
parent
c50d62749b
commit
e24c09e828
|
@ -70,24 +70,29 @@ local function new(c, args)
|
||||||
|
|
||||||
local ret
|
local ret
|
||||||
if not bars[position] then
|
if not bars[position] then
|
||||||
ret = drawable(d, nil, function()
|
ret = drawable(d, nil)
|
||||||
-- On redraw, update the fg and bg colors of the titlebar
|
local function update_colors()
|
||||||
local args = bars[position].args
|
local args = bars[position].args
|
||||||
ret:set_bg(get_color("bg", c, args))
|
ret:set_bg(get_color("bg", c, args))
|
||||||
ret:set_fg(get_color("fg", c, args))
|
ret:set_fg(get_color("fg", c, args))
|
||||||
end)
|
end
|
||||||
|
|
||||||
bars[position] = {
|
bars[position] = {
|
||||||
args = args,
|
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
|
else
|
||||||
bars[position].args = args
|
bars[position].args = args
|
||||||
ret = bars[position].drawable
|
ret = bars[position].drawable
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Make sure the titlebar is (re-)drawn
|
-- Make sure the titlebar has the right colors applied
|
||||||
ret.draw()
|
bars[position].update_colors()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
|
@ -198,7 +198,7 @@ local function setup_signals(_drawable)
|
||||||
clone_signal("property::y")
|
clone_signal("property::y")
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawable.new(d, widget_arg, redraw_hook)
|
function drawable.new(d, widget_arg)
|
||||||
local ret = object()
|
local ret = object()
|
||||||
ret.drawable = d
|
ret.drawable = d
|
||||||
ret.widget_arg = widget_arg or ret
|
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.
|
-- Only redraw a drawable once, even when we get told to do so multiple times.
|
||||||
ret._redraw_pending = false
|
ret._redraw_pending = false
|
||||||
ret._do_redraw = function()
|
ret._do_redraw = function()
|
||||||
if redraw_hook then redraw_hook(ret) end
|
|
||||||
ret._redraw_pending = false
|
ret._redraw_pending = false
|
||||||
capi.awesome.disconnect_signal("refresh", ret._do_redraw)
|
capi.awesome.disconnect_signal("refresh", ret._do_redraw)
|
||||||
do_redraw(ret)
|
do_redraw(ret)
|
||||||
|
|
Loading…
Reference in New Issue