From 1beb274944d182104c5a6dd1343cf7d52876f491 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 15 Oct 2010 18:57:50 +0200 Subject: [PATCH] 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 --- lib/wibox/init.lua.in | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/wibox/init.lua.in b/lib/wibox/init.lua.in index ede40954..9b48c25d 100644 --- a/lib/wibox/init.lua.in +++ b/lib/wibox/init.lua.in @@ -10,7 +10,7 @@ require("wibox.widget") local capi = { drawin = drawin, oocairo = oocairo, - timer = timer + awesome = awesome } local setmetatable = setmetatable local pairs = pairs @@ -257,19 +257,20 @@ local function new(args) end end - -- We use a timer with timeout 0, this makes sure that the wibox will only - -- redrawn once even if there are multiple widget::updated events - local t = capi.timer({ timeout = 0 }) - local function update_wibox() - t:stop() + -- This is to make sure that the wibox will only be redrawn once even when + -- we receive multiple widget::updated signals. + ret._redraw_pending = false + ret._do_redraw = function() + ret._redraw_pending = false + capi.awesome.disconnect_signal("refresh", ret._do_redraw) do_redraw(ret) 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() - if not t.started then - t:start() + if not ret._redraw_pending then + capi.awesome.connect_signal("refresh", ret._do_redraw) + ret._redraw_pending = true end end