Add partial dynamic overlay support
This will require a better event API to be useful, including issue #10
This commit is contained in:
parent
76623695e6
commit
9205d9f27a
|
@ -184,6 +184,7 @@ Multiple items can have multiple sets of options.
|
||||||
| y | Y position (absolute) | number |
|
| y | Y position (absolute) | number |
|
||||||
| sub_menu_on | Show submenu on selection or when clicking | see "event" enum |
|
| sub_menu_on | Show submenu on selection or when clicking | see "event" enum |
|
||||||
| select_on | The event used to trigger item selection | see "event" enum |
|
| select_on | The event used to trigger item selection | see "event" enum |
|
||||||
|
| overlay | A layer on top of the item | function(data,item,cr,w,h) |
|
||||||
|
|
||||||
###Item options
|
###Item options
|
||||||
|
|
||||||
|
@ -211,6 +212,7 @@ Multiple items can have multiple sets of options.
|
||||||
| 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 |
|
||||||
|
|
||||||
###Common methods
|
###Common methods
|
||||||
|
|
||||||
|
|
23
base.lua
23
base.lua
|
@ -27,14 +27,17 @@ local module = {
|
||||||
LEAVE = 1001,
|
LEAVE = 1001,
|
||||||
},
|
},
|
||||||
item_flags = {
|
item_flags = {
|
||||||
NONE = 0,
|
NONE = 0 ,
|
||||||
SELECTED = 1, -- Single item selected
|
SELECTED = 1 , -- Single item selected [[FOCUS]]
|
||||||
HOVERED = 2, -- Mouse hover
|
HOVERED = 2 , -- Mouse hover
|
||||||
PRESSED = 3, -- Mouse pressed
|
PRESSED = 3 , -- Mouse pressed
|
||||||
URGENT = 4, -- Need attention
|
URGENT = 4 , -- Need attention
|
||||||
USED = 5, -- Common flag
|
USED = 5 , -- Common flag
|
||||||
DISABLED = 6, -- Cannot be interacted with
|
DISABLED = 6 , -- Cannot be interacted with
|
||||||
CHECKED = 7, -- When checkbox isn't enough
|
CHECKED = 7 , -- When checkbox isn't enough
|
||||||
|
ALTERNATE = 8 ,
|
||||||
|
HIGHLIGHT = 9 ,
|
||||||
|
HEADER = 10,
|
||||||
|
|
||||||
-- Implementation defined flags
|
-- Implementation defined flags
|
||||||
USR1 = 101,
|
USR1 = 101,
|
||||||
|
@ -167,7 +170,8 @@ local function add_item(data,args)
|
||||||
tooltip = args.tooltip or nil ,
|
tooltip = args.tooltip or nil ,
|
||||||
item_style = args.item_style or nil ,
|
item_style = args.item_style or nil ,
|
||||||
item_layout = args.item_layout or nil ,
|
item_layout = args.item_layout or nil ,
|
||||||
selected = false,
|
selected = false ,
|
||||||
|
overlay = args.overlay or data.overlay or nil ,
|
||||||
},
|
},
|
||||||
force_private = {
|
force_private = {
|
||||||
visible = true,
|
visible = true,
|
||||||
|
@ -336,6 +340,7 @@ local function new(args)
|
||||||
y = args.y or 0,
|
y = args.y or 0,
|
||||||
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,
|
||||||
},
|
},
|
||||||
get_map = {
|
get_map = {
|
||||||
is_menu = function() return true end,
|
is_menu = function() return true end,
|
||||||
|
|
|
@ -28,12 +28,14 @@ local state = {
|
||||||
local cache = setmetatable({}, { __mode = 'k' })
|
local cache = setmetatable({}, { __mode = 'k' })
|
||||||
|
|
||||||
local function create_item(t,s)
|
local function create_item(t,s)
|
||||||
local item = instances[s]:add_item { text = t.name, icon = tag.geticon(t), button1 = function()
|
local menu = instances[s]
|
||||||
|
if not menu then return end
|
||||||
|
local item = menu:add_item { text = t.name, icon = tag.geticon(t), button1 = function()
|
||||||
tag.viewonly(t)
|
tag.viewonly(t)
|
||||||
end}
|
end}
|
||||||
item._internal.set_map.used = function(value)
|
item._internal.set_map.used = function(value)
|
||||||
local item_style = item.item_style or instances[s].item_style
|
local item_style = item.item_style or menu.item_style
|
||||||
item_style(instances[s],item,{value and radical.base.item_flags.USED or nil,item.selected and 1 or nil})
|
item_style(menu,item,{value and radical.base.item_flags.USED or nil,item.selected and 1 or nil})
|
||||||
end
|
end
|
||||||
item._internal.screen = s
|
item._internal.screen = s
|
||||||
cache[t] = item
|
cache[t] = item
|
||||||
|
@ -96,6 +98,7 @@ local function init()
|
||||||
item.icon = tag.geticon(t)
|
item.icon = tag.geticon(t)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
is_init = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function new(s)
|
local function new(s)
|
||||||
|
|
|
@ -119,7 +119,10 @@ local function new(screen)
|
||||||
fg = beautiful.fg_normal,
|
fg = beautiful.fg_normal,
|
||||||
bg_focus = beautiful.taglist_bg_image_selected2 or beautiful.bg_focus,
|
bg_focus = beautiful.taglist_bg_image_selected2 or beautiful.bg_focus,
|
||||||
bg_hover = beautiful.menu_bg_focus,
|
bg_hover = beautiful.menu_bg_focus,
|
||||||
disable_markup = true
|
disable_markup = true,
|
||||||
|
overlay = function(data,item,cd,w,h)
|
||||||
|
print("foo!")
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Clear the menu and repopulate it
|
-- Clear the menu and repopulate it
|
||||||
|
|
|
@ -196,10 +196,17 @@ local function create_item(item,data,args)
|
||||||
|
|
||||||
-- Set widget
|
-- Set widget
|
||||||
item.widget = bg
|
item.widget = bg
|
||||||
|
bg._item = item
|
||||||
|
|
||||||
-- Tooltip
|
-- Tooltip
|
||||||
item.widget:set_tooltip(item.tooltip)
|
item.widget:set_tooltip(item.tooltip)
|
||||||
|
|
||||||
|
-- Overlay
|
||||||
|
item._internal.set_map.overlay = function(value)
|
||||||
|
item._private_data.overlay = value
|
||||||
|
item.widget:emit_signal("widget::updated")
|
||||||
|
end
|
||||||
|
|
||||||
-- Draw
|
-- Draw
|
||||||
local item_style = item.item_style or data.item_style
|
local item_style = item.item_style or data.item_style
|
||||||
item_style(data,item,{})
|
item_style(data,item,{})
|
||||||
|
|
|
@ -28,6 +28,10 @@ local function suffix_draw(self, w, cr, width, height)
|
||||||
cr:close_path()
|
cr:close_path()
|
||||||
cr:clip()
|
cr:clip()
|
||||||
wibox.widget.background.draw(self, w, cr, width, height)
|
wibox.widget.background.draw(self, w, 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:restore()
|
cr:restore()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue