awful.menu: add menu_toggle parameter

This commit is contained in:
Damien Leone 2008-10-30 12:46:49 +01:00 committed by Julien Danjou
parent 17a6d2283e
commit d8aef41795
1 changed files with 15 additions and 8 deletions

View File

@ -89,7 +89,9 @@ end
local function exec(data, action, num) local function exec(data, action, num)
if type(action[2]) == "table" then if type(action[2]) == "table" then
destroy(data.child) if data.child and data.child.id ~= action[1] then
destroy(data.child)
end
data.child = new({ id=action[1], items=action[2] }, data, num) data.child = new({ id=action[1], items=action[2] }, data, num)
elseif type(action[2]) == "string" then elseif type(action[2]) == "string" then
destroy(get_parents(data)) destroy(get_parents(data))
@ -228,18 +230,23 @@ local function set_coords(data)
end end
--- Open a menu popup. --- Open a menu popup.
-- @param menu Table containing the menu informations. Element id: string naming your menu, only one menu with the same id can be displayed on screen at the same time. Element items: Table containing the displayed items, each element is a tab containing: item name, tiggered action, submenu table or function, item icon (optional). Elements [fg|bg]_[focus|normal], border, border_width, submenu_icon, height and width override the default display for your menu, each of them are optional -- @param menu Table containing the menu informations. Key id: string naming your menu, only one menu with the same id can be displayed on screen at the same time. Key items: Table containing the displayed items, each element is a tab containing: item name, tiggered action, submenu table or function, item icon (optional). Key menu_toggle (optional, false by default): boolean setting wether the menu should be re-opened or toggle its opened/closed state when mouse button 1 is pressed. Keys [fg|bg]_[focus|normal], border, border_width, submenu_icon, height and width override the default display for your menu, each of them are optional
-- @param parent Specify the parent menu if we want to open a submenu, this value should never be set by the user. -- @param parent Specify the parent menu if we want to open a submenu, this value should never be set by the user.
-- @param num Specify the parent's clicked item number if we want to open a submenu, this value should never be set by the user. -- @param num Specify the parent's clicked item number if we want to open a submenu, this value should never be set by the user.
function new(menu, parent, num) function new(menu, parent, num)
-- Close the menu if it was already opened
if menus[menu.id] then
destroy(menus[menu.id])
end
-- Create a table to store our menu informations -- Create a table to store our menu informations
local data = {} local data = {}
data.id = menu.id data.id = menu.id
data.menu_toggle = (parent and parent.menu_toggle) or menu.menu_toggle or false
-- Close the menu if it was already opened
if menus[data.id] then
destroy(menus[data.id])
if data.menu_toggle then
return
end
end
data.screen = capi.mouse.screen data.screen = capi.mouse.screen
data.items = {} data.items = {}
data.child = nil data.child = nil
@ -258,7 +265,7 @@ function new(menu, parent, num)
end end
-- Add menu to menus table -- Add menu to menus table
menus[menu.id] = data menus[data.id] = data
return data return data
end end