Wibox: Use the "refresh" signal for redrawing

Previously, we used a timer with a timeout of 0 for redrawing the wibox. I had
the visual impression that the wibox was black for a moment. With strace I was
able to measure a latency of 10ms until the wibox was finally redrawn.

This now uses the "refresh" signal. With this, we get our latency down to
something like 0.15ms which sounds a lot better. :)

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-10-15 18:57:50 +02:00
parent ab3674ec13
commit 1beb274944
1 changed files with 11 additions and 10 deletions

View File

@ -10,7 +10,7 @@ require("wibox.widget")
local capi = { local capi = {
drawin = drawin, drawin = drawin,
oocairo = oocairo, oocairo = oocairo,
timer = timer awesome = awesome
} }
local setmetatable = setmetatable local setmetatable = setmetatable
local pairs = pairs local pairs = pairs
@ -257,19 +257,20 @@ local function new(args)
end end
end end
-- We use a timer with timeout 0, this makes sure that the wibox will only -- This is to make sure that the wibox will only be redrawn once even when
-- redrawn once even if there are multiple widget::updated events -- we receive multiple widget::updated signals.
local t = capi.timer({ timeout = 0 }) ret._redraw_pending = false
local function update_wibox() ret._do_redraw = function()
t:stop() ret._redraw_pending = false
capi.awesome.disconnect_signal("refresh", ret._do_redraw)
do_redraw(ret) do_redraw(ret)
end end
t:connect_signal("timeout", update_wibox)
-- Start our timer when the widget changed -- Connect our signal when we need a redraw
ret.draw = function() ret.draw = function()
if not t.started then if not ret._redraw_pending then
t:start() capi.awesome.connect_signal("refresh", ret._do_redraw)
ret._redraw_pending = true
end end
end end