diff --git a/bar.lua b/bar.lua index b6896b1..0b488ac 100644 --- a/bar.lua +++ b/bar.lua @@ -94,7 +94,9 @@ local function setup_drawable(data) end) data:connect_signal("item::removed",function(_,item,old_idx) table.remove(internal.layout.widgets,old_idx) - item.widget:disconnect_signal("widget::updated", internal.layout._emit_updated) + if internal.layout._emit_updated then + item.widget:disconnect_signal("widget::updated", internal.layout._emit_updated) + end internal.layout:emit_signal("widget::updated") end) data:connect_signal("item::appended",function(_,item) diff --git a/item/init.lua b/item/init.lua index 2eb9a3d..a756275 100644 --- a/item/init.lua +++ b/item/init.lua @@ -210,6 +210,13 @@ local function new_item(data,args) -- Listen to signals item:connect_signal("state::changed",function() item:style() + + -- Some item.style need full widget repaint + if item.style.need_full_repaint then + --TODO HACK HACK HACK for the repaint, this is really, really stupid + data._internal.layout:emit_signal("widget::redraw_needed") + --TODO END HACK + end end) -- Add support for long hover and press diff --git a/item/layout/icon.lua b/item/layout/icon.lua index 1366ec8..7b90152 100644 --- a/item/layout/icon.lua +++ b/item/layout/icon.lua @@ -85,7 +85,7 @@ local function create_item(item,data,args) bg.fit = function(box, context, w,h) -- args.y = data.height-h-data.margins.top --TODO dead code? if data._internal.layout.item_fit then - return data._internal.layout.item_fit(data,item,box,contextw,h) + return data._internal.layout.item_fit(data,item,box,context, w, h) else return wibox.widget.background.fit(box,context, w,h) end diff --git a/item/style/arrow_3d.lua b/item/style/arrow_3d.lua index b9b6723..87fd64b 100644 --- a/item/style/arrow_3d.lua +++ b/item/style/arrow_3d.lua @@ -10,7 +10,8 @@ local module = { BOTTOM = 2, RIGHT = 2, LEFT = 4 - } + }, + need_full_repaint = true } local function create_path(cr,x,height,padding) diff --git a/item/style/arrow_alt.lua b/item/style/arrow_alt.lua index f53c073..3a5f4d3 100644 --- a/item/style/arrow_alt.lua +++ b/item/style/arrow_alt.lua @@ -15,7 +15,8 @@ local module = { BOTTOM = 2, RIGHT = 20, LEFT = 3 - } + }, + need_full_repaint = true } local hcode = {"#7777ff","#ff7777","#77ff77","#77ffff","#ffff77"} diff --git a/item/style/arrow_prefix.lua b/item/style/arrow_prefix.lua index 481a249..8d27236 100644 --- a/item/style/arrow_prefix.lua +++ b/item/style/arrow_prefix.lua @@ -12,7 +12,8 @@ local module = { BOTTOM = 0, RIGHT = 0, LEFT = 0 - } + }, + need_full_repaint = true } local function prefix_draw(self, context, cr, width, height) diff --git a/item/style/slice_prefix.lua b/item/style/slice_prefix.lua index e3342d4..fcd2f5e 100644 --- a/item/style/slice_prefix.lua +++ b/item/style/slice_prefix.lua @@ -12,7 +12,8 @@ local module = { BOTTOM = 0, RIGHT = 0, LEFT = 0 - } + }, + need_full_repaint = true } local function prefix_draw(self, context, cr, width, height) diff --git a/layout/horizontal.lua b/layout/horizontal.lua index 40af97a..9a30938 100644 --- a/layout/horizontal.lua +++ b/layout/horizontal.lua @@ -133,9 +133,9 @@ function module:setup_item(data,item,args) end --Get preferred item geometry -local function item_fit(data,item,...) +local function item_fit(data,item,self, content, width, height) if not data.visible then return 1,1 end - local w, h = item._private_data._fit(...) + local w, h = item._private_data._fit(self,content,width,height) --TODO port to new context API return data.item_width or 70, item._private_data.height or h end @@ -144,8 +144,15 @@ local function new(data) base = require( "radical.base" ) end local l = wibox.layout.fixed.horizontal() - l.fit = function(self,context,w,h,force_values) --TODO use the context instead of extra argument - local result,r2 = wibox.layout.fixed:get_preferred_size(self,context, force_values and w, force_values and h) + l._fit = l.fit + local new_fit + new_fit = function(self,context,w,h,force_values) --TODO use the context instead of extra argument + + -- Get the original fit, the function need to be replaced to avoir a stack overflow + l.fit = l._fit + local result,r2 = self:get_preferred_size(context, force_values and w, force_values and h) + l.fit = new_fit + local w,h if data.auto_resize and data._internal.largest_item_h then w,h = data.rowcount*(data.item_width or data.default_width),data._internal.largest_item_h_v > data.item_height and data._internal.largest_item_h_v or data.item_height @@ -155,6 +162,7 @@ local function new(data) data:emit_signal("layout_size",w,h) return w,h end + l.fit = new_fit l.add = function(l,item) return wibox.layout.fixed.add(l,item.widget) end diff --git a/layout/vertical.lua b/layout/vertical.lua index 5396bad..df842d7 100644 --- a/layout/vertical.lua +++ b/layout/vertical.lua @@ -52,38 +52,16 @@ function module:setup_key_hooks(data) end --Get preferred item geometry -local function item_fit(data,item,self,width,height) +local function item_fit(data,item,self,context, width,height) local w, h = 0,0--item._internal.cache_w or 1,item._internal.cache_h or 1 if data.visible then - w, h = item._private_data._fit({},self,{},width,height) + w, h = item._private_data._fit({},self,context,width,height) item._internal.pix_cache = {} --Clear the pimap cache end return w, item.height or h end --- As of July 2013, LGI is too slow to redraw big menus at ok speed --- This do a pixmap cache to allow pre-rendering -local function cache_pixmap(item) - item._internal.pix_cache = {} - item.widget._draw = item.widget.draw - item.widget.draw = function(self, context, cr, width, height) - if not w.visible or item._hidden then return end - if item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)] then - cr:set_source_surface(item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)]) - cr:paint() - else - local img5 = cairo.ImageSurface.create(cairo.Format.ARGB32, width, height) - local cr5 = cairo.Context(img5) - item.widget._draw(self, context, cr5, width, height) - cr:set_source_surface(img5) - cr:paint() - item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)] = img5 - return - end - end -end - function module:setup_text(item,data,text_w) local text_w = item._internal.text_w @@ -113,8 +91,7 @@ function module:setup_item(data,item,args) end --Create the background local item_layout = item.layout or data.item_layout or horizontal_item_layout - item.widget = item_layout(item,data,args)--wibox.widget.background() - cache_pixmap(item) + item.widget = item_layout(item,data,args) --Event handling if data.select_on == base.event.HOVER then