diff --git a/README.md b/README.md index f1fe2b4..b5f41cf 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,7 @@ Multiple items can have multiple sets of options. | overlay | A layer on top of the item | function(data,item,cr,w,h) | | opacity | Make this menu translucent (require a compositor) | number (0 to 1) | | icon_transformation | Hijack the icon drawing function | function(icon,data,item) | +| disable_submenu_icon| Do not show the submenu icon (arrow) | boolean | ###Item options diff --git a/bar.lua b/bar.lua index 134e899..7956170 100644 --- a/bar.lua +++ b/bar.lua @@ -24,14 +24,14 @@ local function set_position(self) end -- Draw the menu background --- local function bg_draw(self, w, cr, width, height) --- cr:save() --- cr:set_source(color(self._data.bg)) --- cr:rectangle(0,0,width,height) --- cr:fill() --- cr:restore() --- wibox.layout.margin.draw(self, w, cr, width, height) --- end +local function bg_draw(self, w, cr, width, height) + cr:save() + cr:set_source(color(self._data.bg)) + cr:rectangle(0,0,width,height) + cr:fill() + cr:restore() + self._draw(self, w, cr, width, height) +end local function proxy_draw(_,...) local l = _._internal and _._internal.layout or _ @@ -48,7 +48,10 @@ local function setup_drawable(data) local private_data = internal.private_data internal.layout = internal.layout_func or wibox.layout.fixed.horizontal() - +internal.layout._draw = internal.layout.draw +internal.layout.draw = bg_draw +internal.layout._data = data + --Getters data.get_x = function() return 0 end data.get_y = function() return 0 end diff --git a/base.lua b/base.lua index e6e20e0..8542a73 100644 --- a/base.lua +++ b/base.lua @@ -305,6 +305,7 @@ local function new(args) filter_underlay_style = args.filter_underlay_style or nil, filter_underlay_color = args.filter_underlay_color, filter_placeholder = args.filter_placeholder or "", + disable_submenu_icon = args.disable_submenu_icon or false }, force_private = { parent = true, diff --git a/context.lua b/context.lua index 58740be..425244b 100644 --- a/context.lua +++ b/context.lua @@ -218,14 +218,7 @@ local function setup_buttons(data,item,args) --Hide on right click if not buttons[3] then buttons[3] = function() - data.visible = false - if data.parent_geometry and data.parent_geometry.is_menu then - local parent = data.parent_geometry - while parent do - parent.visible = false - parent = parent.parent_geometry and parent.parent_geometry.is_menu and parent.parent_geometry - end - end + data:hide() end end diff --git a/item/init.lua b/item/init.lua index 0f294fa..7f2b2a8 100644 --- a/item/init.lua +++ b/item/init.lua @@ -129,7 +129,7 @@ local function new_item(data,args) autogen_signals = true, }) item._private_data = private_data - item._internal = {} + item._internal = args._internal or {} theme.setup_item_colors(data,item,args) item.get_y = function() return (args.y and args.y >= 0) and args.y or data.height - (data.margins.top or data.border_width) - data.item_height --Hack around missing :fit call for last item @@ -174,6 +174,7 @@ local function new_item(data,args) local current_item = data._current_item if current_item and current_item ~= item or force then current_item.state[module.item_flags.SELECTED] = nil + current_item:emit_signal("selected::changed",false) hide_sub_menu(current_item,data) end diff --git a/item/layout/horizontal.lua b/item/layout/horizontal.lua index 5451218..5f73d6f 100644 --- a/item/layout/horizontal.lua +++ b/item/layout/horizontal.lua @@ -49,10 +49,6 @@ end -- Setup the item icon function module:setup_icon(item,data) local icon = wibox.widget.imagebox() - icon.fit = function(...) - local w,h = wibox.widget.imagebox.fit(...) - return w+3,h - end icon._data = data icon._item = item icon.set_image = module.set_icon @@ -99,7 +95,7 @@ end -- Create sub_menu arrows local sub_arrow = nil 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) and not data.disable_submenu_icon then if not sub_arrow then sub_arrow = wibox.widget.imagebox() --TODO, make global sub_arrow.fit = function(box, w, h) return sub_arrow._image:get_width(),item.height end @@ -197,6 +193,10 @@ local function create_item(item,data,args) -- Icon local icon = module:setup_icon(item,data) + icon.fit = function(...) + local w,h = wibox.widget.imagebox.fit(...) + return w+3,h + end layout:add(icon) -- Prefix diff --git a/item/layout/icon.lua b/item/layout/icon.lua index 8828db5..c6a5b94 100644 --- a/item/layout/icon.lua +++ b/item/layout/icon.lua @@ -68,14 +68,9 @@ local function create_item(item,data,args) l:add(args.prefix_widget) end - local icon = wibox.widget.imagebox() + local icon = horizontal.setup_icon(horizontal,item,data) icon.fit = function(...) return icon_fit(data,...) end icon.draw = icon_draw - icon._data = data - icon.set_image = horizontal.set_icon - if args.icon then - icon:set_image(args.icon) - end l:add(icon) l:add(text_w) diff --git a/item/layout/notification.lua b/item/layout/notification.lua index 1cac98d..b1a8b93 100644 --- a/item/layout/notification.lua +++ b/item/layout/notification.lua @@ -7,6 +7,7 @@ local checkbox = require( "radical.widgets.checkbox" ) local fkey = require( "radical.widgets.fkey" ) local underlay = require( "radical.widgets.underlay" ) local theme = require( "radical.theme" ) +local horizontal= require( "radical.item.layout.horizontal") local module = {} @@ -37,35 +38,6 @@ function module.paint_underlay(data,item,cr,width,height) cr:restore() end --- Apply icon transformation -function module.set_icon(self,image) - if self._data.icon_transformation then - self._item._original_icon = image - image = self._data.icon_transformation(image,self._data,self._item) - end - wibox.widget.imagebox.set_image(self,image) -end - --- Setup the item icon -function module:setup_icon(item,data) - local icon = wibox.widget.imagebox() - icon.fit = function(...) - local w,h = wibox.widget.imagebox.fit(...) - return w+3,h - end - icon._data = data - icon._item = item - icon.set_image = module.set_icon - if item.icon then - icon:set_image(item.icon) - end - - item.set_icon = function (_,value) - icon:set_image(value) - end - return icon -end - -- Show the checkbox function module:setup_checked(item,data) if item.checkable then @@ -197,7 +169,11 @@ local function create_item(item,data,args) end -- Icon - local icon = module:setup_icon(item,data) + local icon = horizontal.setup_icon(horizontal,item,data) + icon.fit = function(...) + local w,h = wibox.widget.imagebox.fit(...) + return w+3,h + end layout:add(icon) -- Prefix diff --git a/item/style/classic.lua b/item/style/classic.lua index a712c2b..f1babcb 100644 --- a/item/style/classic.lua +++ b/item/style/classic.lua @@ -61,7 +61,7 @@ local function draw(item,args) local state = item.state or {} local current_state = state._current_key or nil - local state_name = base.colors_by_id[current_state] + local state_name = current_state and base.colors_by_id[current_state] or "normal" if current_state == base.item_flags.SELECTED or (item._tmp_menu) then item.widget:set_bg(focussed[ih])