Improve menu loading speed with some caching

This commit is contained in:
Emmanuel Lepage Vallee 2013-07-04 01:51:01 -04:00
parent 42e12e297c
commit 3403fb56f3
4 changed files with 17 additions and 8 deletions

View File

@ -294,6 +294,7 @@ local function new(args)
end end
set_map.visible = function(value) set_map.visible = function(value)
private_data.visible = value
if value then if value then
local fit_w,fit_h = data._internal.layout:fit() local fit_w,fit_h = data._internal.layout:fit()
data.width = fit_w data.width = fit_w
@ -308,7 +309,6 @@ local function new(args)
if internal.set_visible then if internal.set_visible then
internal:set_visible(value) internal:set_visible(value)
end end
private_data.visible = value
if value and not capi.keygrabber.isrunning() then if value and not capi.keygrabber.isrunning() then
activateKeyboard(data) activateKeyboard(data)
elseif data.parent_geometry and not data.parent_geometry.is_menu then elseif data.parent_geometry and not data.parent_geometry.is_menu then

View File

@ -95,7 +95,7 @@ local function setup_drawable(data)
get_map.y = function() return internal.w.y end get_map.y = function() return internal.w.y end
get_map.width = function() return internal.w.width end get_map.width = function() return internal.w.width end
get_map.height = function() return internal.w.height end get_map.height = function() return internal.w.height end
get_map.visible = function() return internal.w.visible end get_map.visible = function() return private_data.visible end
get_map.direction = function() return private_data.direction end get_map.direction = function() return private_data.direction end
get_map.margins = function() get_map.margins = function()
local ret = {left=data.border_width,right=data.border_width,top=data.style.margins.TOP,bottom=data.style.margins.BOTTOM} local ret = {left=data.border_width,right=data.border_width,top=data.style.margins.TOP,bottom=data.style.margins.BOTTOM}

View File

@ -191,6 +191,7 @@ end
--Get preferred item geometry --Get preferred item geometry
local function item_fit(data,item,...) local function item_fit(data,item,...)
if not data.visible then return 1,1 end
local w, h = item._private_data._fit(...) local w, h = item._private_data._fit(...)
return data.item_width or 70, item._private_data.height or h return data.item_width or 70, item._private_data.height or h
end end

View File

@ -52,7 +52,11 @@ end
--Get preferred item geometry --Get preferred item geometry
local function item_fit(data,item,...) local function item_fit(data,item,...)
local w, h = item._private_data._fit(...) local w, h = item._internal.cache_w or 1,item._internal.cache_h or 1
if item._internal.has_changed and data.visible then
w, h = item._private_data._fit(...)
item._internal.has_changed = false
end
return w, item._private_data.height or h return w, item._private_data.height or h
end end
@ -61,6 +65,7 @@ function module:setup_item(data,item,args)
item.widget = wibox.widget.background() item.widget = wibox.widget.background()
data.item_style(data,item,false,false) data.item_style(data,item,false,false)
item.widget:set_fg(item._private_data.fg) item.widget:set_fg(item._private_data.fg)
item._internal.has_changed = true
--Event handling --Event handling
item.widget:connect_signal("mouse::enter", function() item.selected = true end) item.widget:connect_signal("mouse::enter", function() item.selected = true end)
@ -105,10 +110,10 @@ function module:setup_item(data,item,args)
local text_w = wibox.widget.textbox() local text_w = wibox.widget.textbox()
item._private_data._fit = wibox.widget.background.fit item._private_data._fit = wibox.widget.background.fit
m.fit = function(...) m.fit = function(...)
if item.visible == false or item._filter_out == true then if not data.visible or (item.visible == false or item._filter_out == true) then
return 0,0 return 1,1
end end
return data._internal.layout.item_fit(data,item,...) return data._internal.layout.item_fit(data,item,...)
end end
if data.fkeys_prefix == true then if data.fkeys_prefix == true then
@ -140,7 +145,7 @@ function module:setup_item(data,item,args)
lr:add(subArrow) lr:add(subArrow)
item.widget.fit = function(box,w,h,...) item.widget.fit = function(box,w,h,...)
args.y = data.height-h-data.margins.top args.y = data.height-h-data.margins.top
return wibox.widget.background.fit(box,w,h,...) return item._internal.cache_w,item._internal.cache_h
end end
end end
if item.checkable then if item.checkable then
@ -157,6 +162,7 @@ function module:setup_item(data,item,args)
item._internal.set_map.checked = function (value) item._internal.set_map.checked = function (value)
item._private_data.checked = value item._private_data.checked = value
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked()) ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
item._internal.has_changed = true
end end
end end
if args.suffix_widget then if args.suffix_widget then
@ -174,6 +180,7 @@ function module:setup_item(data,item,args)
if data.auto_resize then if data.auto_resize then
local fit_w,fit_h = text_w:fit(999,9999) local fit_w,fit_h = text_w:fit(999,9999)
local is_largest = item == data._internal.largest_item_w local is_largest = item == data._internal.largest_item_w
item._internal.has_changed = true
if not data._internal.largest_item_w_v or data._internal.largest_item_w_v < fit_w then if not data._internal.largest_item_w_v or data._internal.largest_item_w_v < fit_w then
data._internal.largest_item_w = item data._internal.largest_item_w = item
data._internal.largest_item_w_v = fit_w data._internal.largest_item_w_v = fit_w
@ -230,6 +237,7 @@ local function new(data)
real_l = l real_l = l
end end
real_l.fit = function(a1,a2,a3) real_l.fit = function(a1,a2,a3)
if not data.visible then return 1,1 end
local result,r2 = wibox.layout.fixed.fit(a1,99999,99999) local result,r2 = wibox.layout.fixed.fit(a1,99999,99999)
local total = data._total_item_height local total = data._total_item_height
return compute_geo(data) return compute_geo(data)