From f746a8b347bf0ae1305aac768d905e685629d860 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 23 Mar 2014 19:00:43 -0400 Subject: [PATCH] Make async menu faster This may cause some visual artefacts, but is about 5 time faster than the old way. --- style/arrow.lua | 12 +++++++++++- widgets/separator.lua | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/style/arrow.lua b/style/arrow.lua index 2d3d7ce..f14889d 100644 --- a/style/arrow.lua +++ b/style/arrow.lua @@ -3,6 +3,7 @@ local beautiful = require( "beautiful" ) local color = require( "gears.color" ) local cairo = require( "lgi" ).cairo local base = require( "radical.base" ) +local glib = require("lgi").GLib local module = { margins = { @@ -51,7 +52,7 @@ local function do_gen_menu_top(data, width, height, radius,padding,args) return img end -local function set_direction(data,direction) +local function _set_direction(data,direction) local geometry = (direction == "left" or direction == "right") and {width = data.wibox.height, height = data.wibox.width} or {height = data.wibox.height, width = data.wibox.width} local top_clip_surface = do_gen_menu_top(data,geometry.width,geometry.height,10,data.border_width,{bg=beautiful.fg_normal or "#0000ff",fg=data.bg or "#00ffff"}) local top_bounding_surface = do_gen_menu_top(data,geometry.width,geometry.height,10,0,{bg="#00000000",fg="#ffffffff"}) @@ -70,6 +71,15 @@ local function set_direction(data,direction) end data.wibox.shape_bounding = top_bounding_surface._native data.wibox:set_bg(cairo.Pattern.create_for_surface(top_clip_surface)) + data._internal._need_direction_reload = false +end + +-- Try to avoid useless repaint, this function is heavy +local function set_direction(data,direction) + if not data._internal._need_direction_reload then + glib.idle_add(glib.PRIORITY_HIGH_IDLE, function() _set_direction(data,direction) end) + data._internal._need_direction_reload = true + end end local function draw(data,args) diff --git a/widgets/separator.lua b/widgets/separator.lua index 1ab17cf..6955681 100644 --- a/widgets/separator.lua +++ b/widgets/separator.lua @@ -20,7 +20,8 @@ local function draw(self, w, cr, width, height) end local function fit(box, w, h) - return box.direction == module.VERTICAL and 5 or w,box.direction == module.VERTICAL and h or 5 + local direction = box.direction or w > h and module.HORIZONTAL or module.VERTICAL + return direction == module.VERTICAL and 5 or w,direction == module.VERTICAL and h or 5 end local function new(menu,direction)