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:
parent
bd3591dae6
commit
eab27bdd8c
58
README.md
58
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
|
||||
|
||||
|
|
10
base.lua
10
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 {},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ,
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -22,6 +22,12 @@ local function icon_fit(data,...)
|
|||
|
||||
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)
|
||||
local w,h = wibox.widget.imagebox.fit(self,context,width,height)
|
||||
cr:save()
|
||||
|
@ -122,6 +128,9 @@ local function create_item(item,data,args)
|
|||
|
||||
item.widget = bg
|
||||
|
||||
bg._item = item
|
||||
bg.after_draw_children = horizontal.after_draw_children
|
||||
|
||||
return bg
|
||||
end
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue