overlay: Re-write for the new widget system

**WARNING**: this break the API
menu.overlay -> menu.draw_overlay

The new "overlay" behave like underlay, but is on top

This commit also add underlay/overlay "align" option and document
the feature properly.
This commit is contained in:
Emmanuel Lepage Vallee 2016-01-12 03:33:38 -05:00
parent bd3591dae6
commit eab27bdd8c
20 changed files with 127 additions and 110 deletions

View File

@ -190,6 +190,13 @@ Multiple items can have multiple sets of options.
| filter_string | Default filter string | string | | filter_string | Default filter string | string |
| fkeys_prefix | Display F1-F12 indicators for easy navigation | boolean | | fkeys_prefix | Display F1-F12 indicators for easy navigation | boolean |
| underlay_alpha | Underlay (see item options) opacity | 0-1 | | 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 | | filter_prefix | Text to be shown at begenning of the filter string | string |
| max_items | Maximum number of items before showing scrollbar | number | | max_items | Maximum number of items before showing scrollbar | number |
| enable_keyboard | Enable or disable keyboard navigation / hooks | boolean | | enable_keyboard | Enable or disable keyboard navigation / hooks | boolean |
@ -210,28 +217,35 @@ Multiple items can have multiple sets of options.
###Item options ###Item options
| Name | Description | Type | | Name | Description | Type |
| -------------- | -------------------------------------------- | ----------------- | | -------------- | -------------------------------------------- | ------------------ |
| text | The item text | string | | text | The item text | string |
| height | The item height | number | | height | The item height | number |
| icon | The item icon | string or pattern | | icon | The item icon | string or pattern |
| sub_menu | Add a submenu to this item | menu or function | | sub_menu | Add a submenu to this item | menu or function |
| selected | Select this item | boolean | | selected | Select this item | boolean |
| checkable | Is the item dual state (a checkbox) | boolean | | checkable | Is the item dual state (a checkbox) | boolean |
| checked | Is the item checked or not | boolean | | checked | Is the item checked or not | boolean |
| underlay | Text to render at the far-right of the item | [array of] string | | 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 | | prefix_widget | Widget to append at the begenning of the item| widget |
| suffix_widget | Widget to append at the end 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 | | style | Custom item_style for this item | item_style |
| layout | Custom item_layout for this item | item_layout | | layout | Custom item_layout for this item | item_layout |
| tooltip | A tooltip shown on the side or bottom | string | | tooltip | A tooltip shown on the side or bottom | string |
| button1 | Left mouse button action | function | | button1 | Left mouse button action | function |
| button2 | Mid mouse button action | function | | button2 | Mid mouse button action | function |
| button3 | Right mouse button action | function | | button3 | Right mouse button action | function |
| button4 | Scroll up action | function | | button4 | Scroll up action | function |
| button5 | Scroll down action | function | | button5 | Scroll down action | function |
| overlay | See menu.overlay | function | | overlay | See menu.overlay | function |
| margins | Read/Write table (left,right,top and bottom) | dynamic table | | 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 ###Colors options

View File

@ -303,7 +303,7 @@ local function new(args)
local internal = args.internal or {} local internal = args.internal or {}
if not internal.items then internal.items = {} end if not internal.items then internal.items = {} end
if not internal.widgets then internal.widgets = {} end if not internal.widgets then internal.widgets = {} end
print(beautiful.menu_border_color)
-- All the magic in the universe -- All the magic in the universe
local data,private_data = object({ local data,private_data = object({
private_data = { private_data = {
@ -341,6 +341,13 @@ print(beautiful.menu_border_color)
fkeys_prefix = args.fkeys_prefix or false, fkeys_prefix = args.fkeys_prefix or false,
underlay_alpha = args.underlay_alpha or beautiful.underlay_alpha or 0.7, underlay_alpha = args.underlay_alpha or beautiful.underlay_alpha or 0.7,
underlay_style = args.underlay_style or nil, 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_underlay = args.filter_underlay or nil,
filter_prefix = args.filter_prefix or "Filter:", filter_prefix = args.filter_prefix or "Filter:",
enable_keyboard = (args.enable_keyboard ~= false), 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, sub_menu_on = args.sub_menu_on or module.event.SELECTED,
select_on = args.select_on or module.event.HOVER, select_on = args.select_on or module.event.HOVER,
overlay = args.overlay or nil, overlay = args.overlay or nil,
overlay_draw = args.overlay_draw or nil,
opacity = args.opacity or beautiful.menu_opacity or 1, opacity = args.opacity or beautiful.menu_opacity or 1,
spacing = args.spacing or nil, --TODO add to README once merged upstream spacing = args.spacing or nil, --TODO add to README once merged upstream
default_margins = args.default_margins or {}, default_margins = args.default_margins or {},

View File

@ -65,13 +65,14 @@ function module.layouts(menu,layouts)
local layouts = layouts or awful.layout.layouts or fallback_layouts local layouts = layouts or awful.layout.layouts or fallback_layouts
for i, layout_real in ipairs(layouts) do for i, layout_real in ipairs(layouts) do
local layout2 = awful.layout.getname(layout_real) 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 if layout2 and beautiful["layout_" ..layout2] then
screenSelect:add_item({icon=beautiful["layout_" ..layout2],button1 = function(_,mod) screenSelect:add_item({icon=beautiful["layout_" ..layout2],button1 = function(_,mod)
if mod then if mod then
screenSelect[mod[1] == "Shift" and "previous_item" or "next_item"].selected = true screenSelect[mod[1] == "Shift" and "previous_item" or "next_item"].selected = true
end end
awful.layout.set(layouts[screenSelect.current_index] or layouts[1],awful.tag.selected(capi.client.focus and capi.client.focus.screen)) 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
end end
return screenSelect return screenSelect
@ -85,7 +86,7 @@ function module.layout_item(menu,args)
local ib = wibox.widget.imagebox() local ib = wibox.widget.imagebox()
local screen = args.screen or 1 local screen = args.screen or 1
local sub_menu = nil local sub_menu = nil
local function toggle() local function toggle()
if not sub_menu then if not sub_menu then
sub_menu = radical.context{ sub_menu = radical.context{
@ -100,10 +101,10 @@ function module.layout_item(menu,args)
end end
sub_menu.visible = not sub_menu.visible sub_menu.visible = not sub_menu.visible
end end
--TODO button 4 and 5 --TODO button 4 and 5
local item = menu:add_item{text=args.text,button1=toggle,tooltip=args.tooltip} local item = menu:add_item{text=args.text,button1=toggle,tooltip=args.tooltip}
local function update() local function update()
local layout = awful.layout.getname(awful.layout.get(screen)) local layout = awful.layout.getname(awful.layout.get(screen))
local ic = beautiful["layout_small_" ..layout] or beautiful["layout_" ..layout] local ic = beautiful["layout_small_" ..layout] or beautiful["layout_" ..layout]

View File

@ -156,7 +156,20 @@ local function create_client_item(c,screen)
-- Too bad, let's create a new one -- Too bad, let's create a new one
local suf_w = wibox.layout.fixed.horizontal() 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) item.add_suffix = function(w,w2)
suf_w:add(w2) suf_w:add(w2)
end end
@ -248,6 +261,9 @@ local function new(screen)
fg = beautiful.tasklist_fg or beautiful.fg_normal , fg = beautiful.tasklist_fg or beautiful.fg_normal ,
bg = beautiful.tasklist_bg or beautiful.bg_normal , bg = beautiful.tasklist_bg or beautiful.bg_normal ,
underlay_style = beautiful.tasklist_underlay_style or radical.widgets.underlay.draw_arrow, 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 , icon_transformation = beautiful.tasklist_icon_transformation ,
default_item_margins = beautiful.tasklist_default_item_margins , default_item_margins = beautiful.tasklist_default_item_margins ,
default_margins = beautiful.tasklist_default_margins , default_margins = beautiful.tasklist_default_margins ,

View File

@ -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 , 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 , checkable = args.checkable or (args.checked ~= nil) or false ,
checked = args.checked or false , checked = args.checked or false ,
underlay = args.underlay or nil ,
tooltip = args.tooltip or nil , tooltip = args.tooltip or nil ,
style = args.style or data.item_style , style = args.style or data.item_style ,
layout = args.layout or args.item_layout or nil , 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 , item_border_color = args.item_border_color or data.item_border_color or nil ,
}, },
force_private = { force_private = {
@ -146,19 +145,27 @@ local function new_item(data,args)
return data.fg return data.fg
end end
item.set_underlay = function(item,underlay) -- Setup underlay and overlay
if not item._internal.underlay_init then for k, name in ipairs {"underlay", "overlay"} do
data:add_colors_group("underlay") item["set_"..name] = function(item,underlay)
item._internal.underlay_init = true if not item._internal.underlay_init then
end data:add_colors_group(name)
item._internal.underlay_init = true
end
item._internal.underlay_content = underlay item._internal[name.."_content"] = underlay
end end
item.get_underlay = function(item) item.get_underlay = function(item)
return item._internal.underlay_content 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 end
item.state = theme.init_state(item) item.state = theme.init_state(item)
item.underlay = args.underlay item.underlay = args.underlay
item.overlay = args.overlay
for i=1,10 do for i=1,10 do
item["button"..i] = args["button"..i] item["button"..i] = args["button"..i]

View File

@ -28,17 +28,40 @@ function module:setup_fkey(item,data)
end end
-- Like an overlay, but under -- 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() cr:save()
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
local state_name = theme.colors_by_id[current_state] or "" 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) local bg_color = item[name.."_bg_"..state_name] or data[name.."_bg_"..state_name] or data[name.."_bg"]
cr:paint_with_alpha(data.underlay_alpha) 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() cr:restore()
end 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 -- Apply icon transformation
function module.set_icon(self,image) function module.set_icon(self,image)
if self._data.icon_transformation then if self._data.icon_transformation then
@ -267,6 +290,7 @@ local function create_item(item,data,args)
-- Set widget -- Set widget
item.widget = bg item.widget = bg
bg._item = item bg._item = item
bg._data = data
-- Tooltip -- Tooltip
item.widget:set_tooltip(item.tooltip) item.widget:set_tooltip(item.tooltip)
@ -299,6 +323,8 @@ local function create_item(item,data,args)
-- bg:buttons(item.buttons) -- bg:buttons(item.buttons)
-- end -- end
bg.after_draw_children = module.after_draw_children
return bg return bg
end end

View File

@ -19,7 +19,13 @@ local function icon_fit(data,...)
else else
return w,data.icon_size or h return w,data.icon_size or h
end 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 end
local function icon_draw(self, context, cr, width, height) local function icon_draw(self, context, cr, width, height)
@ -119,9 +125,12 @@ local function create_item(item,data,args)
-- Setup events -- Setup events
horizontal.setup_event(data,item,bg) horizontal.setup_event(data,item,bg)
item.widget = bg item.widget = bg
bg._item = item
bg.after_draw_children = horizontal.after_draw_children
return bg return bg
end end

View File

@ -27,18 +27,6 @@ function module:setup_fkey(item,data)
item.get_f_key = function() return item._internal.f_key end item.get_f_key = function() return item._internal.f_key end
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 -- Show the checkbox
function module:setup_checked(item,data) function module:setup_checked(item,data)
if item.checkable then if item.checkable then
@ -209,7 +197,7 @@ local function create_item(item,data,args)
local tb4 = wibox.widget.textbox() local tb4 = wibox.widget.textbox()
tb4.draw = function(self, context, 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) horizontal.paint_underlay(data,item,cr,width,height)
end end
wibox.widget.textbox.draw(self, context, cr, width, height) wibox.widget.textbox.draw(self, context, cr, width, height)
end end

View File

@ -30,10 +30,6 @@ local padding = 1
local p2 = 2 local p2 = 2
local function widget_draw23(self, context, cr, width, height) 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:save()
cr:reset_clip() cr:reset_clip()
cr:set_line_width(1) cr:set_line_width(1)

View File

@ -103,11 +103,6 @@ local function draw_real(self, context, cr, width, height)
if self.widget.draw then if self.widget.draw then
self.widget:draw(context, cr, width, height) self.widget:draw(context, cr, width, height)
end end
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end end
local function draw(item,args) local function draw(item,args)

View File

@ -50,10 +50,6 @@ end
local function widget_draw(self, context, cr, width, height) local function widget_draw(self, context, cr, width, height)
self:_drawprefix(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 end
local function draw(item,args) local function draw(item,args)

View File

@ -32,10 +32,6 @@ local function suffix_draw(self, context, cr, width, height)
wibox.widget.background.draw(self, context, cr, width, height) wibox.widget.background.draw(self, context, cr, width, height)
end end
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
cr:restore() cr:restore()
end end

View File

@ -17,11 +17,6 @@ local function widget_draw23(self, context, cr, width, height)
if wibox.widget.background.draw then if wibox.widget.background.draw then
wibox.widget.background.draw(self, context, cr, width, height) wibox.widget.background.draw(self, context, cr, width, height)
end end
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end end
local function draw(item,args) local function draw(item,args)

View File

@ -33,11 +33,6 @@ local function widget_draw(self, context, cr, width, height)
if wibox.widget.background.draw then if wibox.widget.background.draw then
wibox.widget.background.draw(self, context, cr, width, height) wibox.widget.background.draw(self, context, cr, width, height)
end end
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end end
local function draw(item,args) local function draw(item,args)

View File

@ -59,11 +59,6 @@ local function widget_draw(self, context, cr, width, height)
if self._drawrounded then if self._drawrounded then
self:_drawrounded(context, cr, width, height) self:_drawrounded(context, cr, width, height)
end end
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end end
local function draw(item,args) local function draw(item,args)

View File

@ -23,10 +23,6 @@ local function widget_draw(self, context, cr, width, height)
cr:set_source(self.col2) cr:set_source(self.col2)
cr:rectangle(width-1,3,1,height-6) cr:rectangle(width-1,3,1,height-6)
cr:fill() cr:fill()
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end end
local function draw(item,args) local function draw(item,args)

View File

@ -73,11 +73,6 @@ local function widget_draw(self, context, cr, width, height,shadow)
if wibox.widget.background.draw then if wibox.widget.background.draw then
wibox.widget.background.draw(self, context, cr, width, height) wibox.widget.background.draw(self, context, cr, width, height)
end end
local overlay = item and item.overlay
if overlay then
overlay(item._menu,item,cr,width,height)
end
end end
local function draw_width_shadow(self, context, cr, width, height) local function draw_width_shadow(self, context, cr, width, height)

View File

@ -51,11 +51,6 @@ local function widget_draw(self, context, cr, width, height)
if self._drawprefix then if self._drawprefix then
self:_drawprefix(context, cr, width, height) self:_drawprefix(context, cr, width, height)
end end
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end end
local function draw(item,args) local function draw(item,args)

View File

@ -66,11 +66,6 @@ local function widget_draw(self, context, cr, width, height)
if self._drawrounded then if self._drawrounded then
self:_drawrounded(context, cr, width, height) self:_drawrounded(context, cr, width, height)
end end
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
end end
local function draw(item,args) local function draw(item,args)

View File

@ -101,7 +101,6 @@ function module.add_colors_from_namespace(data,namespace)
priv["fg"] = beautiful[namespace.."_fg"] or priv["fg"] priv["fg"] = beautiful[namespace.."_fg"] or priv["fg"]
priv["bg"] = beautiful[namespace.."_bg"] or priv["bg"] priv["bg"] = beautiful[namespace.."_bg"] or priv["bg"]
priv["border_color"] = beautiful[namespace.."_border_color"] or priv["border_color"] 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["item_border_color"] = beautiful[namespace.."_item_border_color"] or priv["item_border_color"]
priv.namespace = priv.namespace or {} priv.namespace = priv.namespace or {}
priv.namespace[#priv.namespace+1] = namespace priv.namespace[#priv.namespace+1] = namespace