diff --git a/README.md b/README.md index 4d9d858..43dacde 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,13 @@ Multiple items can have multiple sets of options. | filter_string | Default filter string | string | | fkeys_prefix | Display F1-F12 indicators for easy navigation | boolean | | underlay_alpha | Underlay (see item options) opacity | 0-1 | +| underlay_style | Underlay (see item options) opacity | | +| underlay_align | Underlay alignment | "left" or "center" | +| underlay_bg | Fallback background color for missing states | color/gradient/pattern | +| overlay_alpha | Overlay (see item options) opacity | 0-1 | +| overlay_style | Overlay (see item options) opacity | | +| overlay_align | Overlay alignment | "left" or "center" | +| overlay_bg | Fallback background color for missing states | color/gradient/pattern | | filter_prefix | Text to be shown at begenning of the filter string | string | | max_items | Maximum number of items before showing scrollbar | number | | enable_keyboard | Enable or disable keyboard navigation / hooks | boolean | @@ -210,28 +217,35 @@ Multiple items can have multiple sets of options. ###Item options -| Name | Description | Type | -| -------------- | -------------------------------------------- | ----------------- | -| text | The item text | string | -| height | The item height | number | -| icon | The item icon | string or pattern | -| sub_menu | Add a submenu to this item | menu or function | -| selected | Select this item | boolean | -| checkable | Is the item dual state (a checkbox) | boolean | -| checked | Is the item checked or not | boolean | -| underlay | Text to render at the far-right of the item | [array of] string | -| prefix_widget | Widget to append at the begenning of the item| widget | -| suffix_widget | Widget to append at the end of the item | widget | -| style | Custom item_style for this item | item_style | -| layout | Custom item_layout for this item | item_layout | -| tooltip | A tooltip shown on the side or bottom | string | -| button1 | Left mouse button action | function | -| button2 | Mid mouse button action | function | -| button3 | Right mouse button action | function | -| button4 | Scroll up action | function | -| button5 | Scroll down action | function | -| overlay | See menu.overlay | function | -| margins | Read/Write table (left,right,top and bottom) | dynamic table | +| Name | Description | Type | +| -------------- | -------------------------------------------- | ------------------ | +| text | The item text | string | +| height | The item height | number | +| icon | The item icon | string or pattern | +| sub_menu | Add a submenu to this item | menu or function | +| selected | Select this item | boolean | +| checkable | Is the item dual state (a checkbox) | boolean | +| checked | Is the item checked or not | boolean | +| underlay | Text to render at the far-right of the item | [array of] string | +| prefix_widget | Widget to append at the begenning of the item| widget | +| suffix_widget | Widget to append at the end of the item | widget | +| style | Custom item_style for this item | item_style | +| layout | Custom item_layout for this item | item_layout | +| tooltip | A tooltip shown on the side or bottom | string | +| button1 | Left mouse button action | function | +| button2 | Mid mouse button action | function | +| button3 | Right mouse button action | function | +| button4 | Scroll up action | function | +| button5 | Scroll down action | function | +| overlay | See menu.overlay | function | +| margins | Read/Write table (left,right,top and bottom) | dynamic table | +| underlay_alpha | Underlay (see item options) opacity | 0-1 | +| underlay_style | Underlay (see item options) opacity | | +| underlay_align | Underlay alignment | "left" or "center" | +| overlay_alpha | Overlay (see item options) opacity | 0-1 | +| overlay_style | Overlay (see item options) opacity | | +| overlay_align | Overlay alignment | "left" or "center" | +| overlay_draw | Draw a custom painter on top of the item | draw function | ###Colors options diff --git a/base.lua b/base.lua index 8c8b8a7..f4d5fde 100644 --- a/base.lua +++ b/base.lua @@ -303,7 +303,7 @@ local function new(args) local internal = args.internal or {} if not internal.items then internal.items = {} end if not internal.widgets then internal.widgets = {} end -print(beautiful.menu_border_color) + -- All the magic in the universe local data,private_data = object({ private_data = { @@ -341,6 +341,13 @@ print(beautiful.menu_border_color) fkeys_prefix = args.fkeys_prefix or false, underlay_alpha = args.underlay_alpha or beautiful.underlay_alpha or 0.7, underlay_style = args.underlay_style or nil, + underlay_align = args.underlay_align or nil, + underlay_bg = args.underlay_bg or nil, + overlay_alpha = args.overlay_alpha or beautiful.overlay_alpha or 0.7, + overlay_style = args.overlay_style or nil, + overlay_align = args.overlay_align or nil, + overlay_draw = args.overlay_draw or nil, + overlay_bg = args.overlay_bg or nil, filter_underlay = args.filter_underlay or nil, filter_prefix = args.filter_prefix or "Filter:", enable_keyboard = (args.enable_keyboard ~= false), @@ -351,6 +358,7 @@ print(beautiful.menu_border_color) sub_menu_on = args.sub_menu_on or module.event.SELECTED, select_on = args.select_on or module.event.HOVER, overlay = args.overlay or nil, + overlay_draw = args.overlay_draw or nil, opacity = args.opacity or beautiful.menu_opacity or 1, spacing = args.spacing or nil, --TODO add to README once merged upstream default_margins = args.default_margins or {}, diff --git a/impl/common/tag.lua b/impl/common/tag.lua index 67e93f5..75a66fd 100644 --- a/impl/common/tag.lua +++ b/impl/common/tag.lua @@ -65,13 +65,14 @@ function module.layouts(menu,layouts) local layouts = layouts or awful.layout.layouts or fallback_layouts for i, layout_real in ipairs(layouts) do local layout2 = awful.layout.getname(layout_real) + local is_current = cur and ((layout_real == cur) or (layout_real.name == cur.name)) if layout2 and beautiful["layout_" ..layout2] then screenSelect:add_item({icon=beautiful["layout_" ..layout2],button1 = function(_,mod) if mod then screenSelect[mod[1] == "Shift" and "previous_item" or "next_item"].selected = true end awful.layout.set(layouts[screenSelect.current_index] or layouts[1],awful.tag.selected(capi.client.focus and capi.client.focus.screen)) - end, selected = (layout_real == cur), item_layout = radical.item.layout.icon}) + end, selected = is_current, item_layout = radical.item.layout.icon}) end end return screenSelect @@ -85,7 +86,7 @@ function module.layout_item(menu,args) local ib = wibox.widget.imagebox() local screen = args.screen or 1 local sub_menu = nil - + local function toggle() if not sub_menu then sub_menu = radical.context{ @@ -100,10 +101,10 @@ function module.layout_item(menu,args) end sub_menu.visible = not sub_menu.visible end - + --TODO button 4 and 5 local item = menu:add_item{text=args.text,button1=toggle,tooltip=args.tooltip} - + local function update() local layout = awful.layout.getname(awful.layout.get(screen)) local ic = beautiful["layout_small_" ..layout] or beautiful["layout_" ..layout] diff --git a/impl/tasklist/init.lua b/impl/tasklist/init.lua index 920f097..5f64e27 100644 --- a/impl/tasklist/init.lua +++ b/impl/tasklist/init.lua @@ -156,7 +156,20 @@ local function create_client_item(c,screen) -- Too bad, let's create a new one local suf_w = wibox.layout.fixed.horizontal() - item = menu:add_item{text=c.name,icon=(not beautiful.tasklist_disable_icon) and surface(c.icon),suffix_widget=suf_w} + + item = menu:add_item{ + text=c.name, + icon=(not beautiful.tasklist_disable_icon) and surface(c.icon), + suffix_widget=suf_w + } + + item:connect_signal("mouse::enter", function() + item.overlay = {"1:23:45", c.pid} + end) + item:connect_signal("mouse::leave", function() + item.overlay = nil + end) + item.add_suffix = function(w,w2) suf_w:add(w2) end @@ -248,6 +261,9 @@ local function new(screen) fg = beautiful.tasklist_fg or beautiful.fg_normal , bg = beautiful.tasklist_bg or beautiful.bg_normal , underlay_style = beautiful.tasklist_underlay_style or radical.widgets.underlay.draw_arrow, + overlay_align = "center" , + overlay_alpha = 1 , + overlay_bg = beautiful.tasklist_bg_overlay , icon_transformation = beautiful.tasklist_icon_transformation , default_item_margins = beautiful.tasklist_default_item_margins , default_margins = beautiful.tasklist_default_margins , diff --git a/item/init.lua b/item/init.lua index a756275..597f841 100644 --- a/item/init.lua +++ b/item/init.lua @@ -114,11 +114,10 @@ local function new_item(data,args) sub_menu_f = (args.sub_menu and type(args.sub_menu) == "function") and args.sub_menu or nil , checkable = args.checkable or (args.checked ~= nil) or false , checked = args.checked or false , - underlay = args.underlay or nil , tooltip = args.tooltip or nil , style = args.style or data.item_style , layout = args.layout or args.item_layout or nil , - overlay = args.overlay or data.overlay or nil , + overlay_draw= args.overlay_draw or data.overlay_draw , item_border_color = args.item_border_color or data.item_border_color or nil , }, force_private = { @@ -146,19 +145,27 @@ local function new_item(data,args) return data.fg end - item.set_underlay = function(item,underlay) - if not item._internal.underlay_init then - data:add_colors_group("underlay") - item._internal.underlay_init = true - end + -- Setup underlay and overlay + for k, name in ipairs {"underlay", "overlay"} do + item["set_"..name] = function(item,underlay) + if not item._internal.underlay_init then + data:add_colors_group(name) + item._internal.underlay_init = true + end - item._internal.underlay_content = underlay - end - item.get_underlay = function(item) - return item._internal.underlay_content + item._internal[name.."_content"] = underlay + end + item.get_underlay = function(item) + return item._internal.underlay_content + end + item[name.."_alpha"] = args[name.."_alpha"] + item[name.."_style"] = args[name.."_style"] + item[name.."_align"] = args[name.."_align"] end + item.state = theme.init_state(item) item.underlay = args.underlay + item.overlay = args.overlay for i=1,10 do item["button"..i] = args["button"..i] diff --git a/item/layout/horizontal.lua b/item/layout/horizontal.lua index 23262bb..2f3704d 100644 --- a/item/layout/horizontal.lua +++ b/item/layout/horizontal.lua @@ -28,17 +28,40 @@ function module:setup_fkey(item,data) end -- Like an overlay, but under -function module.paint_underlay(data,item,cr,width,height) +function module.paint_underlay(data,item,cr,width,height, name) + name = name or "underlay" cr:save() local state = item.state or {} local current_state = state._current_key or nil local state_name = theme.colors_by_id[current_state] or "" - local udl = underlay.draw(item.underlay,{style=data.underlay_style,height=height,bg=data["underlay_bg_"..state_name]}) - cr:set_source_surface(udl,width-udl:get_width()-3) - cr:paint_with_alpha(data.underlay_alpha) + + local bg_color = item[name.."_bg_"..state_name] or data[name.."_bg_"..state_name] or data[name.."_bg"] + local style = item[name.."_style" ] or data[name.."_style" ] + local alpha = item[name.."_alpha" ] or data[name.."_alpha" ] + local align = item[name.."_align" ] or data[name.."_align" ] + + local udl = underlay.draw(item[name],{style=data.underlay_style,height=height,bg=bg_color, style = style}) + + if align == "center" then + local offset = (width-udl:get_width()-6)/2 + cr:set_source_surface(udl,3 + offset) + else + cr:set_source_surface(udl,width-udl:get_width()-3) + end + cr:paint_with_alpha(data[name.."_alpha"]) cr:restore() end +function module.after_draw_children(self, context, cr, width, height) + if self._item.overlay then + module.paint_underlay(self._data, self._item, cr, width, height, "overlay") + end + + if self._item.overlay_draw then + self._item.overlay_draw(context,self._item,cr,width,height) + end +end + -- Apply icon transformation function module.set_icon(self,image) if self._data.icon_transformation then @@ -267,6 +290,7 @@ local function create_item(item,data,args) -- Set widget item.widget = bg bg._item = item + bg._data = data -- Tooltip item.widget:set_tooltip(item.tooltip) @@ -299,6 +323,8 @@ local function create_item(item,data,args) -- bg:buttons(item.buttons) -- end + bg.after_draw_children = module.after_draw_children + return bg end diff --git a/item/layout/icon.lua b/item/layout/icon.lua index 7b90152..e5f299c 100644 --- a/item/layout/icon.lua +++ b/item/layout/icon.lua @@ -19,7 +19,13 @@ local function icon_fit(data,...) else return w,data.icon_size or h end - + +end + +local function after_draw_children(self, context, cr, width, height) + if self._item.overlay_draw then + self._item.overlay_draw(context,self._item,cr,width,height) + end end local function icon_draw(self, context, cr, width, height) @@ -119,9 +125,12 @@ local function create_item(item,data,args) -- Setup events horizontal.setup_event(data,item,bg) - + item.widget = bg + bg._item = item + bg.after_draw_children = horizontal.after_draw_children + return bg end diff --git a/item/layout/notification.lua b/item/layout/notification.lua index b47a91a..95db371 100644 --- a/item/layout/notification.lua +++ b/item/layout/notification.lua @@ -27,18 +27,6 @@ function module:setup_fkey(item,data) item.get_f_key = function() return item._internal.f_key end end --- Like an overlay, but under -function module.paint_underlay(data,item,cr,width,height) - cr:save() - local state = item.state or {} - local current_state = state._current_key or nil - local state_name = theme.colors_by_id[current_state] or "" - local udl = underlay.draw(item.underlay,{style=data.underlay_style,height=height,bg=data["underlay_bg_"..state_name]}) - cr:set_source_surface(udl,width-udl:get_width()-3) - cr:paint_with_alpha(data.underlay_alpha) - cr:restore() -end - -- Show the checkbox function module:setup_checked(item,data) if item.checkable then @@ -209,7 +197,7 @@ local function create_item(item,data,args) local tb4 = wibox.widget.textbox() tb4.draw = function(self, context, cr, width, height) if item.underlay then - module.paint_underlay(data,item,cr,width,height) + horizontal.paint_underlay(data,item,cr,width,height) end wibox.widget.textbox.draw(self, context, cr, width, height) end diff --git a/item/style/arrow_3d.lua b/item/style/arrow_3d.lua index 87fd64b..0f1ca26 100644 --- a/item/style/arrow_3d.lua +++ b/item/style/arrow_3d.lua @@ -30,10 +30,6 @@ local padding = 1 local p2 = 2 local function widget_draw23(self, context, cr, width, height) - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end cr:save() cr:reset_clip() cr:set_line_width(1) diff --git a/item/style/arrow_alt.lua b/item/style/arrow_alt.lua index 3a5f4d3..d197e9e 100644 --- a/item/style/arrow_alt.lua +++ b/item/style/arrow_alt.lua @@ -103,11 +103,6 @@ local function draw_real(self, context, cr, width, height) if self.widget.draw then self.widget:draw(context, cr, width, height) end - - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/item/style/arrow_prefix.lua b/item/style/arrow_prefix.lua index 8d27236..cca6ad1 100644 --- a/item/style/arrow_prefix.lua +++ b/item/style/arrow_prefix.lua @@ -50,10 +50,6 @@ end local function widget_draw(self, context, cr, width, height) self:_drawprefix(context, cr, width, height) - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/item/style/arrow_single.lua b/item/style/arrow_single.lua index 686841e..615df1b 100644 --- a/item/style/arrow_single.lua +++ b/item/style/arrow_single.lua @@ -32,10 +32,6 @@ local function suffix_draw(self, context, cr, width, height) wibox.widget.background.draw(self, context, cr, width, height) end - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end cr:restore() end diff --git a/item/style/basic.lua b/item/style/basic.lua index e411fd7..5a825e9 100644 --- a/item/style/basic.lua +++ b/item/style/basic.lua @@ -17,11 +17,6 @@ local function widget_draw23(self, context, 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 - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/item/style/classic.lua b/item/style/classic.lua index c5422c8..753d280 100644 --- a/item/style/classic.lua +++ b/item/style/classic.lua @@ -33,11 +33,6 @@ local function widget_draw(self, context, 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 - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/item/style/holo.lua b/item/style/holo.lua index 0b8de9b..cd854cd 100644 --- a/item/style/holo.lua +++ b/item/style/holo.lua @@ -59,11 +59,6 @@ local function widget_draw(self, context, cr, width, height) if self._drawrounded then self:_drawrounded(context, cr, width, height) end - - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/item/style/line_3d.lua b/item/style/line_3d.lua index eec359b..bc06e4a 100644 --- a/item/style/line_3d.lua +++ b/item/style/line_3d.lua @@ -23,10 +23,6 @@ local function widget_draw(self, context, cr, width, height) cr:set_source(self.col2) cr:rectangle(width-1,3,1,height-6) cr:fill() - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/item/style/rounded.lua b/item/style/rounded.lua index e651dcc..555bc0a 100644 --- a/item/style/rounded.lua +++ b/item/style/rounded.lua @@ -73,11 +73,6 @@ local function widget_draw(self, context, cr, width, height,shadow) if wibox.widget.background.draw then wibox.widget.background.draw(self, context, cr, width, height) end - - local overlay = item and item.overlay - if overlay then - overlay(item._menu,item,cr,width,height) - end end local function draw_width_shadow(self, context, cr, width, height) diff --git a/item/style/slice_prefix.lua b/item/style/slice_prefix.lua index fcd2f5e..c5856c9 100644 --- a/item/style/slice_prefix.lua +++ b/item/style/slice_prefix.lua @@ -51,11 +51,6 @@ local function widget_draw(self, context, cr, width, height) if self._drawprefix then self:_drawprefix(context, cr, width, height) end - - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/item/style/subtle.lua b/item/style/subtle.lua index 970411b..8600e6b 100644 --- a/item/style/subtle.lua +++ b/item/style/subtle.lua @@ -66,11 +66,6 @@ local function widget_draw(self, context, cr, width, height) if self._drawrounded then self:_drawrounded(context, cr, width, height) end - - local overlay = self._item and self._item.overlay - if overlay then - overlay(self._item._menu,self._item,cr,width,height) - end end local function draw(item,args) diff --git a/theme/init.lua b/theme/init.lua index 94dc857..dd24a50 100644 --- a/theme/init.lua +++ b/theme/init.lua @@ -101,7 +101,6 @@ function module.add_colors_from_namespace(data,namespace) priv["fg"] = beautiful[namespace.."_fg"] or priv["fg"] priv["bg"] = beautiful[namespace.."_bg"] or priv["bg"] priv["border_color"] = beautiful[namespace.."_border_color"] or priv["border_color"] - print("ICI",namespace,namespace.."_item_border_color",beautiful[namespace.."_item_border_color"]) priv["item_border_color"] = beautiful[namespace.."_item_border_color"] or priv["item_border_color"] priv.namespace = priv.namespace or {} priv.namespace[#priv.namespace+1] = namespace