Port to the new Awesome widget system

This commit fix most issues introduced by the new widget system. It
is not production ready and will require multiple commits to fix
individual issues.

The new widget system is better suited for modules like Radical than
the previous one. Over time, this breakage will probably end up being
a good thing. However, for now, expect multiple errors.

The changes:

 * The draw "wibox" argument is now a "context". "context.wibox" is
   the equivalent. This will allow passing the Radical structure to
   the draw method without storing it in the widgets.
 * "fit" now have a new required "context" argument for the DPI, this
   will allow removing the "default_height" variable Radical is using
   to scale the UI on HIDPI systems. This will allow size policies to
   be passed to the fit method
 * "draw" has been splitted into "draw", "draw_before_children",
   "draw_after_children" and "layout". This simplify the overlay
   system and will allow cleaner code
 * Drawing outside of the widget clip is no longer supported, this
   break multiple Radical item.style. This will allow better
   performance and less redraw once the new system issues have been
   fixed
This commit is contained in:
Emmanuel Lepage Vallee 2015-12-29 05:19:23 -05:00
parent dba05f5774
commit cf9bb87b36
34 changed files with 200 additions and 156 deletions

View File

@ -25,13 +25,12 @@ local function set_position(self)
end end
-- Draw the menu background -- Draw the menu background
local function bg_draw(self, w, cr, width, height) local function bg_draw(self, context, cr, width, height)--w, cr, width, height)
cr:save() cr:save()
cr:set_source(color(self._data.bg)) cr:set_source(color(self._data.bg))
cr:rectangle(0,0,width,height) cr:rectangle(0,0,width,height)
cr:fill() cr:fill()
cr:restore() cr:restore()
self._draw(self, w, cr, width, height)
end end
local function proxy_draw(_,...) local function proxy_draw(_,...)
@ -49,8 +48,9 @@ local function setup_drawable(data)
local private_data = internal.private_data local private_data = internal.private_data
internal.layout = internal.layout_func or wibox.layout.fixed.horizontal() internal.layout = internal.layout_func or wibox.layout.fixed.horizontal()
internal.layout._draw = internal.layout.draw
internal.layout.draw = bg_draw --internal.layout.draw = bg_draw --TODO Dead code?
internal.layout._data = data internal.layout._data = data
if internal.layout.set_spacing and data.spacing then if internal.layout.set_spacing and data.spacing then

View File

@ -213,8 +213,8 @@ local function add_widget(data,widget,args)
args = args or {} args = args or {}
data._internal.has_widget = true data._internal.has_widget = true
widget._fit = widget.fit widget._fit = widget.fit
widget.fit = function(self,width,height) widget.fit = function(self,context,width,height)
local w,h = widget._fit(self,width or 1, height or 1) local w,h = widget._fit(self, context, width or 1, height or 1)
return args.width or w,args.height or h return args.width or w,args.height or h
end end
@ -239,7 +239,7 @@ local function add_widget(data,widget,args)
data._internal.items[#data._internal.items+1] = item data._internal.items[#data._internal.items+1] = item
data:emit_signal("widget::added",item,widget) data:emit_signal("widget::added",item,widget)
if data.visible then if data.visible then
local fit_w,fit_h = data._internal.layout:fit(9999,9999) local fit_w,fit_h = data._internal.layout:fit({dpi=96}, 9999,9999)
data.width = data._internal.width or fit_w data.width = data._internal.width or fit_w
data.height = fit_h data.height = fit_h
end end
@ -262,18 +262,21 @@ end
-- Sum all widgets height and width -- Sum all widgets height and width
local function get_widget_fit_sum(data) local function get_widget_fit_sum(data)
local h,w = 0,0 local h,w = 0,0
-- TODO query this from the layout itself
for k,v in ipairs(data._internal.widgets) do for k,v in ipairs(data._internal.widgets) do
local fw,fh = v.widget:fit(9999,9999) local fw,fh = v.widget:fit({dpi=96},9999,9999)
w,h = w + fw,h + fh w,h = w + fw,h + fh
end end
return w,h return w,h
end end
local function get_widget_fit_width_sum(data) local function get_widget_fit_width_sum(data)
-- TODO query this from the layout itself
return get_widget_fit_sum(data) return get_widget_fit_sum(data)
end end
local function get_widget_fit_height_sum(data) local function get_widget_fit_height_sum(data)
-- TODO query this from the layout itself
local w,h = get_widget_fit_sum(data) local w,h = get_widget_fit_sum(data)
return h return h
end end
@ -406,7 +409,7 @@ print(beautiful.menu_border_color)
data.set_visible = function(_,value) data.set_visible = function(_,value)
private_data.visible = value private_data.visible = value
if value then if value then
local fit_w,fit_h = data._internal.layout:fit(9999,9999) local fit_w,fit_h = data._internal.layout:fit({dpi=96}, 9999,9999)
data.width = internal.width or fit_w data.width = internal.width or fit_w
data.height = fit_h data.height = fit_h
elseif data._tmp_menu and data._current_item then elseif data._tmp_menu and data._current_item then

View File

@ -7,8 +7,8 @@ local function set_position(data)
local s = data.screen or capi.mouse.screen local s = data.screen or capi.mouse.screen
s = s > capi.screen.count() and 1 or s s = s > capi.screen.count() and 1 or s
local geom = capi.screen[s].geometry local geom = capi.screen[s].geometry
data.wibox.x = geom.x + (geom.width/2) - data.width/2 data.wibox.x = math.ceil(geom.x + (geom.width/2) - data.width/2)
data.wibox.y = geom.y + (geom.height/2) - data.height/2 data.wibox.y = math.ceil(geom.y + (geom.height/2) - data.height/2)
end end
local function new(args) local function new(args)

View File

@ -43,7 +43,7 @@ local function set_geometry_real(data)
local geo = data._internal._next_geometry local geo = data._internal._next_geometry
if geo then if geo then
for k,v in pairs(geo) do for k,v in pairs(geo) do
data.wibox[k] = v data.wibox[k] = math.ceil(v)
end end
end end
data._internal._next_geometry = nil data._internal._next_geometry = nil

View File

@ -78,7 +78,9 @@ local function mask(rotate,width,height,radius,offset,anti,bg,fg)
end end
-- Do not draw over the boder, ever -- Do not draw over the boder, ever
local function dock_draw(self, w, cr, width, height) local function dock_draw(self, context, cr, width, height)
local w = context.wibox
-- Generate the border surface -- Generate the border surface
if not self.mask or self.mask_hash ~= width*1000+height then if not self.mask or self.mask_hash ~= width*1000+height then
@ -89,7 +91,7 @@ local function dock_draw(self, w, cr, width, height)
cr:save() cr:save()
--Draw the border --Draw the border
self.__draw(self, w, cr, width, height) --self.__draw(self, context, cr, width, height)
cr:set_source_surface(self.mask) cr:set_source_surface(self.mask)
cr:paint() cr:paint()
cr:restore() cr:restore()
@ -103,15 +105,15 @@ local function align_wibox(w,direction,screen)
local src_geom = capi.screen[screen].geometry local src_geom = capi.screen[screen].geometry
local scr_size = src_geom[offset] + (src_geom[axis] - w[axis]) /2 local scr_size = src_geom[offset] + (src_geom[axis] - w[axis]) /2
w[offset] = scr_size w[offset] = math.ceil(scr_size)
if direction == "left" then if direction == "left" then
w.x = src_geom.x w.x = math.ceil(src_geom.x)
elseif direction == "right" then elseif direction == "right" then
w.x = src_geom.x + src_geom.width - w.width w.x = math.ceil(src_geom.x + src_geom.width - w.width)
elseif direction == "bottom" then elseif direction == "bottom" then
w.y = src_geom.y+src_geom.height-w.height w.y = math.ceil(src_geom.y+src_geom.height-w.height)
else else
w.y = src_geom.y w.y = math.ceil(src_geom.y)
end end
end end
@ -163,7 +165,7 @@ local function adapt_size(data,w,h,screen)
local max = get_max_size(data,screen) local max = get_max_size(data,screen)
-- Get the current size, then compare and ajust -- Get the current size, then compare and ajust
local fit_w,fit_h = data._internal.layout:fit(20,9999,true) local fit_w,fit_h = data._internal.layout:fit({dpi=96},20,9999,true)
-- Get the number of items minus the number of widgets -- Get the number of items minus the number of widgets
-- This can be used to approximate the number of pixel to remove -- This can be used to approximate the number of pixel to remove
@ -323,13 +325,13 @@ local function setup_drawable(data)
data.get_x = function() return 0 end data.get_x = function() return 0 end
data.get_y = function() return 0 end data.get_y = function() return 0 end
data.get_width = function() data.get_width = function()
return internal.w and internal.w.width or data._internal.layout:fit(9999,9999,true) return internal.w and internal.w.width or data._internal.layout:fit({dpi=96},9999,9999,true)
end end
data.get_height = function() data.get_height = function()
if internal.orientation == "horizontal" then if internal.orientation == "horizontal" then
return beautiful.default_height return beautiful.default_height
else else
local w,h = internal.layout.fit(internal.layout,9999,9999) local w,h = internal.layout.fit(internal.layout,{dpi=96},9999,9999)
return h return h
end end
end end
@ -355,7 +357,7 @@ end
local function setup_item(data,item,args) local function setup_item(data,item,args)
-- Add widgets -- Add widgets
local f = (data._internal.layout.setup_item) or (layout.vertical.setup_item) local f = (data._internal.layout.setup_item) or (vertical.setup_item)
f(data._internal.layout,data,item,args) f(data._internal.layout,data,item,args)
-- Buttons -- Buttons
@ -397,7 +399,7 @@ local function new(args)
args.internal.layout_func = orientation == "vertical" and vertical or horizontal args.internal.layout_func = orientation == "vertical" and vertical or horizontal
args.layout = args.layout or args.internal.layout_func args.layout = args.layout or args.internal.layout_func
args.item_style = args.item_style or item.style args.item_style = args.item_style or item.style
args.item_layout = args.item_layout or item_layout -- args.item_layout = args.item_layout or item_layout
args[length_inv] = args[length_inv] or 40 args[length_inv] = args[length_inv] or 40
-- Create the dock -- Create the dock

View File

@ -126,8 +126,8 @@ local function new(args)
if not auto_release then if not auto_release then
local pref_bg = wibox.widget.background() local pref_bg = wibox.widget.background()
local pref_l = wibox.layout.align.horizontal() local pref_l = wibox.layout.align.horizontal()
pref_bg.fit = function(s,w,h) pref_bg.fit = function(s,c,w,h)
local w2,h2 = wibox.widget.background.fit(s,w,h) local w2,h2 = wibox.widget.background.fit(s,c,w,h)
return w2,currentMenu.item_height return w2,currentMenu.item_height
end end
pref_bg:set_bg(currentMenu.bg_alternate) pref_bg:set_bg(currentMenu.bg_alternate)
@ -136,13 +136,13 @@ local function new(args)
pref_l:set_first(tb2) pref_l:set_first(tb2)
pref_bg:set_widget(pref_l) pref_bg:set_widget(pref_l)
local pref_menu,pref_menu_l = radical.bar{item_style=radical.item.style.basic} local pref_menu,pref_menu_l = radical.bar{item_style=radical.item.style.basic}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL)) -- pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_menu:add_item{text="Exclusive"} pref_menu:add_item{text="Exclusive"}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL)) -- pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_menu:add_item{text="12 clients"} pref_menu:add_item{text="12 clients"}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL)) -- pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_menu:add_item{text="All Screens"} pref_menu:add_item{text="All Screens"}
pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL)) -- pref_menu:add_widget(radical.widgets.separator(pref_menu,radical.widgets.separator.VERTICAL))
pref_l:set_third(pref_menu_l) pref_l:set_third(pref_menu_l)
currentMenu:add_prefix_widget(pref_bg) currentMenu:add_prefix_widget(pref_bg)
@ -186,7 +186,7 @@ local function new(args)
l:add( button_group({client = v, field = "sticky" , focus = false, checked = function() return v.sticky end, onclick = function() v.sticky = not v.sticky end })) l:add( button_group({client = v, field = "sticky" , focus = false, checked = function() return v.sticky end, onclick = function() v.sticky = not v.sticky end }))
l:add( button_group({client = v, field = "ontop" , focus = false, checked = function() return v.ontop end, onclick = function() v.ontop = not v.ontop end })) l:add( button_group({client = v, field = "ontop" , focus = false, checked = function() return v.ontop end, onclick = function() v.ontop = not v.ontop end }))
l:add( button_group({client = v, field = "close" , focus = false, checked = function() return false end, onclick = function() v:kill() end })) l:add( button_group({client = v, field = "close" , focus = false, checked = function() return false end, onclick = function() v:kill() end }))
l.fit = function (s,w,h) return 5*h,h end l.fit = function (s,c,w,h) return 5*h,h end
end end
local underlays = reload_underlay(v) local underlays = reload_underlay(v)

View File

@ -50,11 +50,13 @@ module.buttons = { [1] = awful.tag.viewonly,
local function index_draw(self,w, cr, width, height) local function index_draw(self, context, cr, width, height)
cr:save() cr:save()
cr:set_source(color(self._color or beautiful.taglist_fg_prefix or beautiful.fg_normal)) cr:set_source(color(self._color or beautiful.taglist_fg_prefix or beautiful.fg_normal))
local d = wibox.widget.textbox._draw or wibox.widget.textbox.draw local d = wibox.widget.textbox._draw or wibox.widget.textbox.draw
d(self,wibox, cr, width, height) if d then
d(self,context, cr, width, height)
end
cr:restore() cr:restore()
end end

View File

@ -35,13 +35,13 @@ local function set_menu(self,menu,button)
return bt return bt
end end
local function _underlay_draw(self,w, cr, width, height) local function _underlay_draw(self, context, cr, width, height)
cr:save() cr:save()
local udl = underlay.draw(self._underlay,{height=height,style = self._underlay_style,bg=self._underlay_color}) local udl = underlay.draw(self._underlay,{height=height,style = self._underlay_style,bg=self._underlay_color})
cr:set_source_surface(udl,width-udl:get_width()-3) cr:set_source_surface(udl,width-udl:get_width()-3)
cr:paint_with_alpha(self._underlay_alpha or beautiful.underlay_alpha or 0.7) cr:paint_with_alpha(self._underlay_alpha or beautiful.underlay_alpha or 0.7)
cr:restore() cr:restore()
self._draw_underlay(self,w, cr, width, height) self._draw_underlay(self, context, cr, width, height)
end end
local function set_underlay(self,udl,args) local function set_underlay(self,udl,args)

View File

@ -100,7 +100,7 @@ function module:setup_sub_menu_arrow(item,data)
if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) and not data.disable_submenu_icon then if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) and not data.disable_submenu_icon then
if not sub_arrow then if not sub_arrow then
sub_arrow = wibox.widget.imagebox() --TODO, make global sub_arrow = wibox.widget.imagebox() --TODO, make global
sub_arrow.fit = function(box, w, h) return (sub_arrow._image and sub_arrow._image:get_width() or 0),item.height end sub_arrow.fit = function(box, context,w, h) return (sub_arrow._image and sub_arrow._image:get_width() or 0),item.height end
sub_arrow:set_image( beautiful.menu_submenu_icon ) sub_arrow:set_image( beautiful.menu_submenu_icon )
end end
return sub_arrow return sub_arrow
@ -157,15 +157,15 @@ function module.setup_event(data,item,widget)
end end
-- Use all the space, let "align_fit" compute the right size -- Use all the space, let "align_fit" compute the right size
local function textbox_fit(box,w,h) local function textbox_fit(box,context,w,h)
return w,h return w,h
end end
-- Force the width or compute the minimum space -- Force the width or compute the minimum space
local function align_fit(box,w,h) local function align_fit(box,context,w,h)
local mar = util.table.join(box._data.item_style.margins,box._data.default_item_margins) local mar = util.table.join(box._data.item_style.margins,box._data.default_item_margins)
if box._item.width then return box._item.width - box._data.item_style.margins.LEFT - box._data.item_style.margins.RIGHT,h end if box._item.width then return box._item.width - box._data.item_style.margins.LEFT - box._data.item_style.margins.RIGHT,h end
return box.first:fit(w,h)+wibox.widget.textbox.fit(box.second,w,h)+box.third:fit(w,h),h return box.first:fit(context,w,h)+wibox.widget.textbox.fit(box.second,context,w,h)+box.third:fit(context,w,h),h
end end
-- Create the actual widget -- Create the actual widget
@ -217,11 +217,11 @@ local function create_item(item,data,args)
-- Text -- Text
local tb = wibox.widget.textbox() local tb = wibox.widget.textbox()
tb.fit = data._internal.text_fit or textbox_fit tb.fit = data._internal.text_fit or textbox_fit
tb.draw = function(self,w, cr, width, height) tb.draw = function(self, context, cr, width, height)
if item.underlay then if item.underlay then
module.paint_underlay(data,item,cr,width,height) module.paint_underlay(data,item,cr,width,height)
end end
wibox.widget.textbox.draw(self,w, cr, width, height) wibox.widget.textbox.draw(self, context, cr, width, height)
end end
tb:set_text(item.text) tb:set_text(item.text)
item.set_text = function (_,value) item.set_text = function (_,value)

View File

@ -22,11 +22,11 @@ local function icon_fit(data,...)
end end
local function icon_draw(self,w, cr, width, height) local function icon_draw(self, context, cr, width, height)
local w,h = wibox.widget.imagebox.fit(self,width,height) local w,h = wibox.widget.imagebox.fit(self,context,width,height)
cr:save() cr:save()
cr:translate((width-w)/2,0) cr:translate((width-w)/2,0)
wibox.widget.imagebox.draw(self,w, cr, width, height) wibox.widget.imagebox.draw(self, context, cr, width, height)
cr:restore() cr:restore()
end end
@ -57,10 +57,10 @@ local function create_item(item,data,args)
if data.fkeys_prefix == true then if data.fkeys_prefix == true then
local pref = wibox.widget.textbox() local pref = wibox.widget.textbox()
pref.draw = function(self,w, cr, width, height) pref.draw = function(self, context, cr, width, height)
cr:set_source(color(beautiful.fg_normal)) cr:set_source(color(beautiful.fg_normal))
cr:paint() cr:paint()
wibox.widget.textbox.draw(self,w, cr, width, height) wibox.widget.textbox.draw(self, context, cr, width, height)
end end
l:add(pref) l:add(pref)
m:set_left ( 0 ) m:set_left ( 0 )
@ -78,16 +78,16 @@ local function create_item(item,data,args)
l:add(text_w) l:add(text_w)
if item._private_data.sub_menu_f or item._private_data.sub_menu_m then if item._private_data.sub_menu_f or item._private_data.sub_menu_m then
local subArrow = wibox.widget.imagebox() --TODO, make global local subArrow = wibox.widget.imagebox() --TODO, make global
subArrow.fit = function(box, w, h) return subArrow._image:get_width(),item.height end subArrow.fit = function(box, context, w, h) return subArrow._image:get_width(),item.height end
subArrow:set_image( beautiful.menu_submenu_icon ) subArrow:set_image( beautiful.menu_submenu_icon )
lr:add(subArrow) lr:add(subArrow)
end end
bg.fit = function(box,w,h) bg.fit = function(box, context, w,h)
-- args.y = data.height-h-data.margins.top --TODO dead code? -- args.y = data.height-h-data.margins.top --TODO dead code?
if data._internal.layout.item_fit then if data._internal.layout.item_fit then
return data._internal.layout.item_fit(data,item,box,w,h) return data._internal.layout.item_fit(data,item,box,contextw,h)
else else
return wibox.widget.background.fit(box,w,h) return wibox.widget.background.fit(box,context, w,h)
end end
return 0,0 return 0,0
end end

View File

@ -75,7 +75,7 @@ function module:setup_sub_menu_arrow(item,data)
if item._private_data.sub_menu_f or item._private_data.sub_menu_m then if item._private_data.sub_menu_f or item._private_data.sub_menu_m then
if not sub_arrow then if not sub_arrow then
sub_arrow = wibox.widget.imagebox() --TODO, make global sub_arrow = wibox.widget.imagebox() --TODO, make global
sub_arrow.fit = function(box, w, h) return sub_arrow._image:get_width(),item.height end sub_arrow.fit = function(box, context, w, h) return sub_arrow._image:get_width(),item.height end
sub_arrow:set_image( beautiful.menu_submenu_icon ) sub_arrow:set_image( beautiful.menu_submenu_icon )
end end
return sub_arrow return sub_arrow
@ -132,15 +132,15 @@ function module.setup_event(data,item,widget)
end end
-- Use all the space, let "align_fit" compute the right size -- Use all the space, let "align_fit" compute the right size
local function textbox_fit(box,w,h) local function textbox_fit(box,context,w,h)
local w2,h2 = wibox.widget.textbox.fit(box,w,h) local w2,h2 = wibox.widget.textbox.fit(box,context,w,h)
return w,h2 return w,h2
end end
-- Force the width or compute the minimum space -- Force the width or compute the minimum space
local function align_fit(box,w,h) local function align_fit(box,context,w,h)
if box._item.width then return box._item.width - box._data.item_style.margins.LEFT - box._data.item_style.margins.RIGHT,h end if box._item.width then return box._item.width - box._data.item_style.margins.LEFT - box._data.item_style.margins.RIGHT,h end
return box.first:fit(w,h)+wibox.widget.textbox.fit(box.second,w,h)+box.third:fit(w,h),h return box.first:fit(context,w,h)+wibox.widget.textbox.fit(box.second,context,w,h)+box.third:fit(context,w,h),h
end end
-- Create the actual widget -- Create the actual widget
@ -207,11 +207,11 @@ local function create_item(item,data,args)
-- Text -- Text
local tb4 = wibox.widget.textbox() local tb4 = wibox.widget.textbox()
tb4.draw = function(self,w, cr, width, height) tb4.draw = function(self, context, cr, width, height)
if item.underlay then if item.underlay then
module.paint_underlay(data,item,cr,width,height) module.paint_underlay(data,item,cr,width,height)
end end
wibox.widget.textbox.draw(self,w, cr, width, height) wibox.widget.textbox.draw(self, context, cr, width, height)
end end
item.set_text = function (_,value) item.set_text = function (_,value)
@ -225,7 +225,7 @@ local function create_item(item,data,args)
item:set_text(item.text or "") item:set_text(item.text or "")
local tb2 = wibox.widget.textbox() local tb2 = wibox.widget.textbox()
tb2:set_text("alternate") tb2:set_text("alternate")
tb2.fit = function(s,w,h) tb2.fit = function(s,context,w,h)
return w,h return w,h
end end

View File

@ -28,7 +28,7 @@ local c4 = color("#3b4249dd")
local padding = 1 local padding = 1
local p2 = 2 local p2 = 2
local function widget_draw23(self, w, cr, width, height) local function widget_draw23(self, context, cr, width, height)
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)
@ -62,7 +62,10 @@ local function widget_draw23(self, w, cr, width, height)
create_path(cr,1,height,1) create_path(cr,1,height,1)
cr:stroke() cr:stroke()
cr:restore() cr:restore()
self.__drawbasic(self,w, cr, width, height)
if self.__drawbasic then
self.__drawbasic(self, context, cr, width, height)
end
end end
local function new_set_bg(self,bg) local function new_set_bg(self,bg)

View File

@ -76,8 +76,8 @@ module.get_beg_arrow = function(args)
return img return img
end end
local function draw_real(self, w, cr, width, height) local function draw_real(self, context, cr, width, height)
-- wibox.widget.background.draw(self, w, cr, width, height) -- wibox.widget.background.draw(self, context, cr, width, height)
cr:save() cr:save()
-- This item style require negative padding, this is a little dangerous to -- This item style require negative padding, this is a little dangerous to
@ -94,9 +94,15 @@ local function draw_real(self, w, cr, width, height)
cr:reset_clip() cr:reset_clip()
cr:fill() cr:fill()
cr:restore() cr:restore()
self._draw(self, w, cr, width, height)
self.widget:draw(w, cr, width, height) if self._draw then
self._draw(self, context, cr, width, height)
end
if self.widget.draw then
self.widget:draw(context, cr, width, height)
end
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)

View File

@ -15,7 +15,7 @@ local module = {
} }
} }
local function prefix_draw(self, w, cr, width, height) local function prefix_draw(self, context, cr, width, height)
cr:save() cr:save()
-- This item style require negative padding, this is a little dangerous to -- This item style require negative padding, this is a little dangerous to
@ -32,21 +32,23 @@ local function prefix_draw(self, w, cr, width, height)
cr:reset_clip() cr:reset_clip()
cr:fill() cr:fill()
cr:restore() cr:restore()
self._draw(self, w, cr, width, height) if self._draw then
self._draw(self, context, cr, width, height)
end
end end
local function prefix_fit(box,w,h) local function prefix_fit(box,context,w,h)
local width,height = box._fit(box,w,h) local width,height = box._fit(box,context,w,h)
return width + h/2 + h/6,height return width + h/2 + h/6,height
end end
local function suffix_fit(box,w,h) local function suffix_fit(box,context,w,h)
local width,height = box._fit(box,w,h) local width,height = box._fit(box,context,w,h)
return width + h/2 + h/6,height return width + h/2 + h/6,height
end end
local function widget_draw(self, w, cr, width, height) local function widget_draw(self, context, cr, width, height)
self:_drawprefix(w, cr, width, height) self:_drawprefix(context, cr, width, height)
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)

View File

@ -16,7 +16,7 @@ local module = {
} }
local function suffix_draw(self, w, cr, width, height) local function suffix_draw(self, context, cr, width, height)
cr:save() cr:save()
cr:move_to(height/2,0) cr:move_to(height/2,0)
cr:line_to(width-height/2,0) cr:line_to(width-height/2,0)
@ -27,7 +27,11 @@ local function suffix_draw(self, w, cr, width, height)
cr:line_to(height/2,0) cr:line_to(height/2,0)
cr:close_path() cr:close_path()
cr:clip() cr:clip()
wibox.widget.background.draw(self, w, cr, width, height)
if wibox.widget.background.draw then
wibox.widget.background.draw(self, context, cr, width, height)
end
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)

View File

@ -2,6 +2,7 @@ local setmetatable = setmetatable
local print = print local print = print
local pairs=pairs local pairs=pairs
local base = require( "radical.base" ) local base = require( "radical.base" )
local wibox = require("wibox" )
local module = { local module = {
margins = { margins = {
@ -12,8 +13,11 @@ local module = {
} }
} }
local function widget_draw23(self, w, cr, width, height) local function widget_draw23(self, context, cr, width, height)
self.__drawbasic(self,w, cr, width, height) if wibox.widget.background.draw then
wibox.widget.background.draw(self, context, cr, width, height)
end
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)
@ -23,11 +27,7 @@ end
local function draw(item,args) local function draw(item,args)
local args = args or {} local args = args or {}
if not item.widget._overlay_init and not item.widget._draw then
item.widget.__drawbasic = item.widget.draw
item.widget.draw = widget_draw23 item.widget.draw = widget_draw23
item.widget._overlay_init = true
end
local state = item.state or {} local state = item.state or {}
local current_state = state._current_key or nil local current_state = state._current_key or nil

View File

@ -3,6 +3,7 @@ local base = require( "radical.base" )
local color = require( "gears.color" ) local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo local cairo = require( "lgi" ).cairo
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
local wibox = require("wibox" )
local print = print local print = print
local module = { local module = {
@ -27,8 +28,12 @@ local function gen(item_height,bg_color,border_color)
return cairo.Pattern.create_for_surface(img) return cairo.Pattern.create_for_surface(img)
end end
local function widget_draw(self, w, cr, width, height) local function widget_draw(self, context, cr, width, height)
self:_draw2(w, cr, width, height)
if wibox.widget.background.draw then
wibox.widget.background.draw(self, context, cr, width, height)
end
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)
@ -39,11 +44,7 @@ local function draw(item,args)
local args = args or {} local args = args or {}
local col = args.color local col = args.color
if not item.widget._overlay_init then
item.widget._draw2 = item.widget.draw
item.widget.draw = widget_draw item.widget.draw = widget_draw
item.widget._overlay_init = true
end
local ih = item.height or 1 local ih = item.height or 1
if not focussed or not focussed[ih] then if not focussed or not focussed[ih] then

View File

@ -32,7 +32,7 @@ local function gen(width,height,bg_color,border_color, pos)
return cairo.Pattern.create_for_surface(img) return cairo.Pattern.create_for_surface(img)
end end
local function widget_draw(self, w, cr, width, height) local function widget_draw(self, context, cr, width, height)
local state = self._item.state or {} local state = self._item.state or {}
local current_state = state._current_key or "" local current_state = state._current_key or ""
@ -56,7 +56,10 @@ local function widget_draw(self, w, cr, width, height)
self._last_state = current_state self._last_state = current_state
end end
self:_drawrounded(w, cr, width, height) if self._drawrounded then
self:_drawrounded(context, cr, width, height)
end
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)

View File

@ -15,8 +15,8 @@ local module = {
} }
} }
local function widget_draw(self, w, cr, width, height) local function widget_draw(self, context, cr, width, height)
self.__drawbasic(self,w, cr, width, height) self.__drawbasic(self,context, cr, width, height)
cr:set_source(self.col1) cr:set_source(self.col1)
cr:rectangle(0,3,1,height-6) cr:rectangle(0,3,1,height-6)
cr:fill() cr:fill()

View File

@ -3,6 +3,7 @@ local math = math
local base = require( "radical.base" ) local base = require( "radical.base" )
local color = require( "gears.color" ) local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo local cairo = require( "lgi" ).cairo
local wibox = require("wibox" )
local print = print local print = print
local module = { local module = {
@ -45,7 +46,7 @@ local function gen(width,height,bg_color,border_color,item,shadow)
return cairo.Pattern.create_for_surface(img) return cairo.Pattern.create_for_surface(img)
end end
local function widget_draw(self, w, cr, width, height,shadow) local function widget_draw(self, context, cr, width, height,shadow)
local item = self._item local item = self._item
local state = item.state or {} local state = item.state or {}
local current_state = state._current_key or "" local current_state = state._current_key or ""
@ -69,14 +70,17 @@ local function widget_draw(self, w, cr, width, height,shadow)
self._last_state = current_state self._last_state = current_state
end end
self:_drawrounded(w, cr, width, height) if wibox.widget.background.draw then
wibox.widget.background.draw(self, context, cr, width, height)
end
local overlay = item and item.overlay local overlay = item and item.overlay
if overlay then if overlay then
overlay(item._menu,item,cr,width,height) overlay(item._menu,item,cr,width,height)
end end
end end
local function draw_width_shadow(self, w, cr, width, height) local function draw_width_shadow(self, context, cr, width, height)
cr:save() cr:save()
cr:reset_clip() cr:reset_clip()
@ -90,7 +94,7 @@ local function draw_width_shadow(self, w, cr, width, height)
end end
cr:restore() cr:restore()
widget_draw(self, w, cr, width, height,true) widget_draw(self, context, cr, width, height,true)
end end
local function common(item,args) local function common(item,args)
@ -110,9 +114,9 @@ end
local function draw(item,args) local function draw(item,args)
local args = args or {} local args = args or {}
if not item.widget._overlay_init then
item.widget._drawrounded = item.widget.draw
item.widget.draw = widget_draw item.widget.draw = widget_draw
if not item.widget._overlay_init then
item.widget._overlay_init = true item.widget._overlay_init = true
item.widget._item = item item.widget._item = item
end end
@ -124,9 +128,9 @@ end
local function shadow(item,args) local function shadow(item,args)
local args = args or {} local args = args or {}
if not item.widget._overlay_init then
item.widget._drawrounded = item.widget.draw
item.widget.draw = draw_width_shadow item.widget.draw = draw_width_shadow
if not item.widget._overlay_init then
item.widget._overlay_init = true item.widget._overlay_init = true
item.widget._item = item item.widget._item = item
end end

View File

@ -15,7 +15,7 @@ local module = {
} }
} }
local function prefix_draw(self, w, cr, width, height) local function prefix_draw(self, context, cr, width, height)
cr:save() cr:save()
-- This item style require negative padding, this is a little dangerous to -- This item style require negative padding, this is a little dangerous to
@ -30,21 +30,27 @@ local function prefix_draw(self, w, cr, width, height)
cr:reset_clip() cr:reset_clip()
cr:fill() cr:fill()
cr:restore() cr:restore()
self._draw(self, w, cr, width, height)
if self._draw then
self._draw(self, context, cr, width, height)
end
end end
local function prefix_fit(box,w,h) local function prefix_fit(box,context,w,h)
local width,height = box._fit(box,w,h) local width,height = box._fit(box,context,w,h)
return width + h/2,height return width + h/2,height
end end
local function suffix_fit(box,w,h) local function suffix_fit(box,context,w,h)
local width,height = box._fit(box,w,h) local width,height = box._fit(box,context,w,h)
return width + h/2 + h/6,height return width + h/2 + h/6,height
end end
local function widget_draw(self, w, cr, width, height) local function widget_draw(self, context, cr, width, height)
self:_drawprefix(w, cr, width, height) if self._drawprefix then
self:_drawprefix(context, cr, width, height)
end
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)

View File

@ -39,7 +39,7 @@ local function gen(w,h,bg_color,border_color)
return cairo.Pattern.create_for_surface(img) return cairo.Pattern.create_for_surface(img)
end end
local function widget_draw(self, w, cr, width, height) local function widget_draw(self, context, cr, width, height)
local state = self._item.state or {} local state = self._item.state or {}
local current_state = state._current_key or "" local current_state = state._current_key or ""
@ -63,7 +63,10 @@ local function widget_draw(self, w, cr, width, height)
self._last_state = current_state self._last_state = current_state
end end
self:_drawrounded(w, cr, width, height) if self._drawrounded then
self:_drawrounded(context, cr, width, height)
end
local overlay = self._item and self._item.overlay local overlay = self._item and self._item.overlay
if overlay then if overlay then
overlay(self._item._menu,self._item,cr,width,height) overlay(self._item._menu,self._item,cr,width,height)

View File

@ -109,7 +109,7 @@ function module:setup_item(data,item,args)
text_w:set_markup(value) text_w:set_markup(value)
end end
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({dpi=96},999,9999)
local is_largest = item == data._internal.largest_item_h local is_largest = item == data._internal.largest_item_h
--TODO find new largest is item is smaller --TODO find new largest is item is smaller
if not data._internal.largest_item_h_v or data._internal.largest_item_h_v < fit_h then if not data._internal.largest_item_h_v or data._internal.largest_item_h_v < fit_h then
@ -144,8 +144,8 @@ local function new(data)
base = require( "radical.base" ) base = require( "radical.base" )
end end
local l = wibox.layout.fixed.horizontal() local l = wibox.layout.fixed.horizontal()
l.fit = function(a1,a2,a3,force_values) l.fit = function(self,context,w,h,force_values) --TODO use the context instead of extra argument
local result,r2 = wibox.layout.fixed.fit(a1,force_values and a2 or 99999,force_values and a3 or 99999) local result,r2 = wibox.layout.fixed.fit(self,context,force_values and w or 99999,force_values and h or 99999)
local w,h local w,h
if data.auto_resize and data._internal.largest_item_h then 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 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

View File

@ -55,7 +55,7 @@ end
local function item_fit(data,item,self,width,height) local function item_fit(data,item,self,width,height)
local w, h = 0,0--item._internal.cache_w or 1,item._internal.cache_h or 1 local w, h = 0,0--item._internal.cache_w or 1,item._internal.cache_h or 1
if data.visible then if data.visible then
w, h = item._private_data._fit(self,width,height) w, h = item._private_data._fit({},self,{},width,height)
item._internal.pix_cache = {} --Clear the pimap cache item._internal.pix_cache = {} --Clear the pimap cache
end end
@ -67,7 +67,7 @@ end
local function cache_pixmap(item) local function cache_pixmap(item)
item._internal.pix_cache = {} item._internal.pix_cache = {}
item.widget._draw = item.widget.draw item.widget._draw = item.widget.draw
item.widget.draw = function(self,w, cr, width, height) item.widget.draw = function(self, context, cr, width, height)
if not w.visible or item._hidden then return end 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 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:set_source_surface(item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)])
@ -75,7 +75,7 @@ local function cache_pixmap(item)
else else
local img5 = cairo.ImageSurface.create(cairo.Format.ARGB32, width, height) local img5 = cairo.ImageSurface.create(cairo.Format.ARGB32, width, height)
local cr5 = cairo.Context(img5) local cr5 = cairo.Context(img5)
item.widget._draw(self,w, cr5, width, height) item.widget._draw(self, context, cr5, width, height)
cr:set_source_surface(img5) cr:set_source_surface(img5)
cr:paint() cr:paint()
item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)] = img5 item._internal.pix_cache[10*width+7*height+(item.selected and 8888 or 999)] = img5
@ -87,13 +87,13 @@ end
function module:setup_text(item,data,text_w) function module:setup_text(item,data,text_w)
local text_w = item._internal.text_w local text_w = item._internal.text_w
text_w.draw = function(self,w, cr, width, height) text_w.draw = function(self,context, cr, width, height)
if item.underlay then if item.underlay then
horizontal_item_layout.paint_underlay(data,item,cr,width,height) horizontal_item_layout.paint_underlay(data,item,cr,width,height)
end end
wibox.widget.textbox.draw(self,w, cr, width, height) wibox.widget.textbox.draw(self, context, cr, width, height)
end end
text_w.fit = function(self,width,height) return width,height end text_w.fit = function(self,context,width,height) return width,height end
item.set_text = function (_,value) item.set_text = function (_,value)
if data.disable_markup then if data.disable_markup then
@ -183,7 +183,7 @@ function module:setup_item(data,item,args)
-- Compute the minimum width -- Compute the minimum width
if data.auto_resize and item._internal.margin_w then if data.auto_resize and item._internal.margin_w then
local fit_w,fit_h = wibox.layout.margin.fit(item._internal.margin_w,9999,9999) local fit_w = wibox.layout.margin.fit(item._internal.margin_w,{},9999,9999)
local is_largest = item == data._internal.largest_item_w local is_largest = item == data._internal.largest_item_w
if fit_w < 1000 and (not data._internal.largest_item_w_v or data._internal.largest_item_w_v < fit_w) then if fit_w < 1000 and (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
@ -202,8 +202,8 @@ local function compute_geo(data,width,height,force_values)
local visblerow = data.visible_row_count local visblerow = data.visible_row_count
local sw,sh = data._internal.suf_l:fit(9999,9999) local sw,sh = data._internal.suf_l:fit({dpi=96},9999,9999)
local pw,ph = data._internal.pref_l:fit(9999,9999) local pw,ph = data._internal.pref_l:fit({dpi=96},9999,9999)
if not data._internal.has_widget then if not data._internal.has_widget then
return w,(total and total > 0 and total or visblerow*data.item_height) + ph + sh return w,(total and total > 0 and total or visblerow*data.item_height) + ph + sh
else else
@ -217,8 +217,8 @@ local function new(data)
if not base then if not base then
base = require( "radical.base" ) base = require( "radical.base" )
end end
local l,real_l = wibox.layout.fixed.vertical(),nil local l = wibox.layout.fixed.vertical()
real_l = wibox.layout.fixed.vertical() local real_l = wibox.layout.fixed.vertical()
local pref_l,suf_l = wibox.layout.fixed.vertical(),wibox.layout.fixed.vertical() local pref_l,suf_l = wibox.layout.fixed.vertical(),wibox.layout.fixed.vertical()
real_l:add(pref_l) real_l:add(pref_l)
if data.max_items then if data.max_items then
@ -239,9 +239,9 @@ local function new(data)
suf_l:add(data._internal.scroll_w["down"]) suf_l:add(data._internal.scroll_w["down"])
end end
end end
real_l.fit = function(a1,a2,a3,force_values) real_l.fit = function(self,context,o_w,o_h,force_values)
if not data.visible then return 1,1 end if not data.visible then return 1,1 end
local w,h = compute_geo(data,a2,a3,force_values) local w,h = compute_geo(data,o_w,o_h,force_values)
data:emit_signal("layout_size",w,h) data:emit_signal("layout_size",w,h)
return w,h return w,h
end end
@ -287,7 +287,7 @@ local function new(data)
data:connect_signal("suffix_widget::added",function(_,widget,args) data:connect_signal("suffix_widget::added",function(_,widget,args)
suf_l:add(widget) suf_l:add(widget)
end) end)
data._internal.text_fit = function(self,width,height) return width,height end data._internal.text_fit = function(self,context,width,height) return width,height end
return real_l return real_l
end end

View File

@ -189,10 +189,10 @@ local function get_arrow_x(data)
return data._arrow_x return data._arrow_x
end end
-- Draw the border on top of items, prevent sharp corners from messing with the border -- As the menus have a rounded border, rectangle elements will draw over the
local function draw_border(self,w, cr, width, height) -- corner border. To fix this, this method re-draw the border on top of the
-- Draw the widget content -- content
self.__draw(self,w, cr, width, height) local function after_draw_children(self, context, cr, width, height)
local data = self._data local data = self._data
-- Create a matrix to rotate the border -- Create a matrix to rotate the border
@ -217,7 +217,7 @@ local function draw(data,args)
-- Prevent sharp corners from being over the border -- Prevent sharp corners from being over the border
if data._internal.margin then if data._internal.margin then
data._internal.margin.__draw = data._internal.margin.draw data._internal.margin.__draw = data._internal.margin.draw
data._internal.margin.draw = draw_border data._internal.margin.after_draw_children = after_draw_children
if not data._internal.margin._data then if not data._internal.margin._data then
data._internal.margin._data = data data._internal.margin._data = data
end end

View File

@ -23,20 +23,25 @@ local function rounded_rect(cr,x,y,w,h,radius)
cr:restore() cr:restore()
end end
local function draw2(self,w, cr, width, height) local function draw2(self, context, cr, width, height)
cr:save() cr:save()
local mx,my = self.left or 0, self.top or 0 local mx,my = self.left or 0, self.top or 0
local mw,mh = width - mx - (self.right or 0), height - my - (self.bottom or 0) local mw,mh = width - mx - (self.right or 0), height - my - (self.bottom or 0)
rounded_rect(cr,mx,my,mw,mh,6) rounded_rect(cr,mx,my,mw,mh,6)
local path = cr:copy_path() local path = cr:copy_path()
cr:clip() cr:clip()
self.___draw(self,w, cr, width, height)
if self.___draw then
self.___draw(self, context, cr, width, height)
end
cr:append_path(path) cr:append_path(path)
cr:set_source(color(self.data.border_color)) cr:set_source(color(self.data.border_color))
cr:stroke() cr:stroke()
cr:restore() cr:restore()
end end
--TODO unported
local function draw(data) local function draw(data)
if not data._internal then return end if not data._internal then return end

View File

@ -152,8 +152,8 @@ local function new(widget,text, args)
data.wibox:connect_signal("mouse::leave",hide_tooltip) data.wibox:connect_signal("mouse::leave",hide_tooltip)
local relative_to_parent = rel_parent(data.wibox,args2,args) local relative_to_parent = rel_parent(data.wibox,args2,args)
data.wibox.x = args2.x or args.x or relative_to_parent.x or capi.mouse.coords().x - data.wibox.width/2 -5 data.wibox.x = math.floor(args2.x or args.x or relative_to_parent.x or capi.mouse.coords().x - data.wibox.width/2 -5)
data.wibox.y = args2.y or args.y or relative_to_parent.y or ((not vertical) and capi.screen[capi.mouse.screen].geometry.height - 16 - 25 or 16) data.wibox.y = math.floor(args2.y or args.y or relative_to_parent.y or ((not vertical) and capi.screen[capi.mouse.screen].geometry.height - 16 - 25 or 16))
data.wibox.visible = true data.wibox.visible = true
if args2.parent and args2.parent.drawable and data.drawable ~= args2.parent.drawable then if args2.parent and args2.parent.drawable and data.drawable ~= args2.parent.drawable then
data.drawable = args2.parent.drawable data.drawable = args2.parent.drawable

View File

@ -14,7 +14,7 @@ local function new(data)
bg:set_bg(data.bg_highlight) bg:set_bg(data.bg_highlight)
bg:set_widget(filter_tb) bg:set_widget(filter_tb)
filter_tb:set_markup(" <b>".. data.filter_prefix .."</b> "..data.filter_placeholder) filter_tb:set_markup(" <b>".. data.filter_prefix .."</b> "..data.filter_placeholder)
filter_tb.fit = function(tb,width,height) filter_tb.fit = function(tb,context,width,height)
return width,data.item_height return width,data.item_height
end end
filter_tb:set_underlay(data.filter_underlay,{alpha=data.filter_underlay_alpha,color=data.filter_underlay_color}) filter_tb:set_underlay(data.filter_underlay,{alpha=data.filter_underlay_alpha,color=data.filter_underlay_color})

View File

@ -24,7 +24,7 @@ end
local function new(data,item) local function new(data,item)
local pref = wibox.widget.textbox() local pref = wibox.widget.textbox()
pref.draw = function(self,w, cr, width, height) pref.draw = function(self, context, cr, width, height)
local padding = height/4 local padding = height/4
local key = item._internal.f_key local key = item._internal.f_key
if not keys[height] then if not keys[height] then
@ -55,7 +55,7 @@ local function new(data,item)
cr:set_source_surface((key and key > 12 and keys[height][0]) and keys[height][0] or keys[height][key]) cr:set_source_surface((key and key > 12 and keys[height][0]) and keys[height][0] or keys[height][key])
cr:paint() cr:paint()
end end
pref.fit = function(self,width,height) pref.fit = function(self,context,width,height)
return max_width,data.item_height return max_width,data.item_height
end end
pref:set_markup("<span fgcolor='".. beautiful.bg_normal .."'><tt><b>F11</b></tt></span>") pref:set_markup("<span fgcolor='".. beautiful.bg_normal .."'><tt><b>F11</b></tt></span>")

View File

@ -38,7 +38,7 @@ local function compute_sum(data)
return ret return ret
end end
local function draw(self, w, cr, width, height) local function draw(self, context, cr, width, height)
if not self._data then return end if not self._data then return end
-- Load from cache -- Load from cache

View File

@ -50,13 +50,13 @@ local function new(data)
for k,v in ipairs({"up","down"}) do for k,v in ipairs({"up","down"}) do
local ib = wibox.widget.imagebox() local ib = wibox.widget.imagebox()
ib:set_image(module[v]()) ib:set_image(module[v]())
ib.fit = function(tb,width,height) ib.fit = function(tb,context,width,height)
if scroll_w.visible == false then if scroll_w.visible == false then
return 0,0 return 0,0
end end
return width,data.item_height return width,data.item_height
end end
ib.draw = function(self,wibox, cr, width, height) ib.draw = function(self, context, cr, width, height)
if width > 0 and height > 0 then if width > 0 and height > 0 then
cr:set_source_surface(self._image, width/2 - self._image:get_width()/2, 0) cr:set_source_surface(self._image, width/2 - self._image:get_width()/2, 0)
end end

View File

@ -7,7 +7,7 @@ local beautiful = require( "beautiful" )
local module = {HORIZONTAL=1,VERTICAL=2} local module = {HORIZONTAL=1,VERTICAL=2}
local function draw(self, w, cr, width, height) local function draw(self, context, cr, width, height)
cr:save() cr:save()
cr:set_source(self._color) cr:set_source(self._color)
if self.direction == module.VERTICAL then if self.direction == module.VERTICAL then
@ -19,7 +19,7 @@ local function draw(self, w, cr, width, height)
cr:restore() cr:restore()
end end
local function fit(box, w, h) local function fit(box, context, w, h)
local direction = box.direction or w > h and module.HORIZONTAL or module.VERTICAL 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 return direction == module.VERTICAL and 5 or w,direction == module.VERTICAL and h or 5
end end

View File

@ -4,7 +4,7 @@ local color = require("gears.color")
local ipairs = ipairs local ipairs = ipairs
local print = print local print = print
local function textbox_draw(self, w, cr, width, height) local function textbox_draw(self, context, cr, width, height)
cr:save() cr:save()
cr:set_source(color(beautiful.menu_border_color or beautiful.border_normal or beautiful.border_color)) cr:set_source(color(beautiful.menu_border_color or beautiful.border_normal or beautiful.border_color))
cr:rectangle(0,0,width,1) cr:rectangle(0,0,width,1)
@ -12,14 +12,14 @@ local function textbox_draw(self, w, cr, width, height)
cr:stroke() cr:stroke()
cr:restore() cr:restore()
cr:set_source(color(beautiful.menu_fg_normal or beautiful.fg_normal)) cr:set_source(color(beautiful.menu_fg_normal or beautiful.fg_normal))
wibox.widget.textbox.draw(self, w, cr, width, height) wibox.widget.textbox.draw(self, context, cr, width, height)
end end
local function create_textbox(w,col_c,col,has_v_header,row_height) local function create_textbox(context,col_c,col,has_v_header,row_height)
local t = wibox.widget.textbox() local t = wibox.widget.textbox()
t.fit = function(s,w2,h) t.fit = function(s,context,w2,h)
local fw,fh = wibox.widget.textbox.fit(s,w2,h) local fw,fh = wibox.widget.textbox.fit(s,context,w2,h)
return (w2/(col_c+2 - col)),row_height or fh return (w2/(col_c+2 - col)),row_height or fh
end end
t.draw = textbox_draw t.draw = textbox_draw
@ -27,19 +27,19 @@ local function create_textbox(w,col_c,col,has_v_header,row_height)
return t return t
end end
local function create_h_header(main_l,cols,w,args) local function create_h_header(main_l,cols,context,args)
if args.h_header then if args.h_header then
local bg = wibox.widget.background() local bg = wibox.widget.background()
local row_l = wibox.layout.fixed.horizontal() local row_l = wibox.layout.fixed.horizontal()
bg:set_bg(beautiful.menu_table_bg_header or beautiful.menu_bg_header or beautiful.fg_normal) bg:set_bg(beautiful.menu_table_bg_header or beautiful.menu_bg_header or beautiful.fg_normal)
bg:set_widget(row_l) bg:set_widget(row_l)
if args.v_header then if args.v_header then
local t = create_textbox(w,cols,1,args.v_header ~= nil,args.row_height) local t = create_textbox(context,cols,1,args.v_header ~= nil,args.row_height)
t:set_markup("<span color='".. beautiful.bg_normal .."'>--</span>") t:set_markup("<span color='".. beautiful.bg_normal .."'>--</span>")
row_l:add(t) row_l:add(t)
end end
for i=1,cols do for i=1,cols do
local t = create_textbox(w,cols,i+1,args.v_header ~= nil,args.row_height) local t = create_textbox(context,cols,i+1,args.v_header ~= nil,args.row_height)
t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.h_header[i] or "-") .."</span>") t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.h_header[i] or "-") .."</span>")
row_l:add(t) row_l:add(t)
end end
@ -58,9 +58,9 @@ local function new(content,args)
end end
local main_l = wibox.layout.fixed.vertical() local main_l = wibox.layout.fixed.vertical()
local w =200 local w =200
main_l.fit = function(self,width,height) main_l.fit = function(self,context,width,height)
w = width w = width
return wibox.layout.fixed.fit(self,width,height) return wibox.layout.fixed.fit(self,context,width,height)
end end
create_h_header(main_l,cols,w,args) create_h_header(main_l,cols,w,args)