awful.menu: change menu parameters to use a table, add height and width parameters
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
3005196d64
commit
75e6f4cb9e
|
@ -115,7 +115,7 @@ mymainmenu = {
|
||||||
|
|
||||||
mylauncher = awful.widget.launcher({ name = "mylauncher",
|
mylauncher = awful.widget.launcher({ name = "mylauncher",
|
||||||
image = "@AWESOME_ICON_PATH@/awesome16.png",
|
image = "@AWESOME_ICON_PATH@/awesome16.png",
|
||||||
menu = { "mymainmenu", mymainmenu } })
|
menu = { id="mymainmenu", items=mymainmenu } })
|
||||||
|
|
||||||
-- Create a systray
|
-- Create a systray
|
||||||
mysystray = widget({ type = "systray", name = "mysystray", align = "right" })
|
mysystray = widget({ type = "systray", name = "mysystray", align = "right" })
|
||||||
|
@ -172,7 +172,7 @@ end
|
||||||
|
|
||||||
-- {{{ Mouse bindings
|
-- {{{ Mouse bindings
|
||||||
awesome.buttons({
|
awesome.buttons({
|
||||||
button({ }, 3, function () awful.menu.new("mymainmenu", mymainmenu) end),
|
button({ }, 3, function () awful.menu.new({ id="mymainmenu", items=mymainmenu }) end),
|
||||||
button({ }, 4, awful.tag.viewnext),
|
button({ }, 4, awful.tag.viewnext),
|
||||||
button({ }, 5, awful.tag.viewprev)
|
button({ }, 5, awful.tag.viewprev)
|
||||||
})
|
})
|
||||||
|
|
|
@ -90,7 +90,7 @@ 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)
|
destroy(data.child)
|
||||||
data.child = new(action[1], 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))
|
||||||
util.spawn(action[2])
|
util.spawn(action[2])
|
||||||
|
@ -127,7 +127,7 @@ local function add_item(data, num, item_info)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
icon = widget({ type = "textbox", name = "icon", align = "left" })
|
icon = widget({ type = "textbox", name = "icon", align = "left" })
|
||||||
icon.width = theme.menu_height
|
icon.width = data.h
|
||||||
end
|
end
|
||||||
|
|
||||||
icon:buttons(bindings)
|
icon:buttons(bindings)
|
||||||
|
@ -162,10 +162,10 @@ local function add_item(data, num, item_info)
|
||||||
item.widgets = { icon, label, submenu }
|
item.widgets = { icon, label, submenu }
|
||||||
|
|
||||||
item:geometry({
|
item:geometry({
|
||||||
width = theme.menu_width,
|
width = data.w,
|
||||||
height = theme.menu_height,
|
height = data.h,
|
||||||
x = data.x,
|
x = data.x,
|
||||||
y = data.y + theme.menu_height*(num - 1)
|
y = data.y + data.h*(num - 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
item.ontop = true
|
item.ontop = true
|
||||||
|
@ -188,37 +188,42 @@ function clients()
|
||||||
end,
|
end,
|
||||||
c.icon }
|
c.icon }
|
||||||
end
|
end
|
||||||
return new("Clients", cls_t)
|
return new({ id="Clients", items=cls_t })
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Open a menu popup.
|
--- Open a menu popup.
|
||||||
-- @param id Menu id, string naming your menu, only one menu with the same id can be displayed on screen at the same time.
|
-- @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 or submenu table, item icon (optional). Elements width and height: force the geometry of your menu, if one (or both) of these elements is not specified, the default values will be used.
|
||||||
-- @param items Table containing the displayed items, each element is a tab containing: item name, tiggered action or submenu table, item icon (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(id, items, parent, num)
|
function new(menu, parent, num)
|
||||||
-- Load config only one time
|
-- Load config only one time
|
||||||
if not theme then
|
if not theme then
|
||||||
load_theme()
|
load_theme()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Close the menu if it was already opened
|
-- Close the menu if it was already opened
|
||||||
if menus[id] then
|
if menus[menu.id] then
|
||||||
destroy(menus[id])
|
destroy(menus[menu.id])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create a table to store our menu informations
|
-- Create a table to store our menu informations
|
||||||
local data = {}
|
local data = {}
|
||||||
data.id = id
|
data.id = menu.id
|
||||||
data.screen = capi.mouse.screen
|
data.screen = capi.mouse.screen
|
||||||
data.items = {}
|
data.items = {}
|
||||||
data.child = nil
|
data.child = nil
|
||||||
|
|
||||||
if parent then
|
if parent then
|
||||||
data.x = parent.x + theme.menu_width + theme.border_width
|
data.h = parent.h
|
||||||
data.y = parent.y + theme.menu_height*(num - 1)
|
data.w = parent.w
|
||||||
|
|
||||||
|
data.x = parent.x + data.w + theme.border_width
|
||||||
|
data.y = parent.y + data.h*(num - 1)
|
||||||
data.parent = parent
|
data.parent = parent
|
||||||
else
|
else
|
||||||
|
data.h = menu.height and menu.height or theme.menu_height
|
||||||
|
data.w = menu.width and menu.width or theme.menu_width
|
||||||
|
|
||||||
local m_coords = capi.mouse.coords()
|
local m_coords = capi.mouse.coords()
|
||||||
data.x = m_coords.x
|
data.x = m_coords.x
|
||||||
data.y = m_coords.y
|
data.y = m_coords.y
|
||||||
|
@ -226,12 +231,12 @@ function new(id, items, parent, num)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create items
|
-- Create items
|
||||||
for k, v in pairs(items) do
|
for k, v in pairs(menu.items) do
|
||||||
table.insert(data.items, add_item(data, k, v))
|
table.insert(data.items, add_item(data, k, v))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add menu to menus table
|
-- Add menu to menus table
|
||||||
menus[id] = data
|
menus[menu.id] = data
|
||||||
|
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
|
@ -388,7 +388,7 @@ function launcher(args)
|
||||||
if args.command then
|
if args.command then
|
||||||
b[#b + 1] = capi.button({}, 1, nil, function () util.spawn(args.command) end)
|
b[#b + 1] = capi.button({}, 1, nil, function () util.spawn(args.command) end)
|
||||||
elseif args.menu then
|
elseif args.menu then
|
||||||
b[#b + 1] = capi.button({}, 1, nil, function () menu.new(args.menu[1], args.menu[2]) end)
|
b[#b + 1] = capi.button({}, 1, nil, function () menu.new(args.menu) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
w:buttons(b)
|
w:buttons(b)
|
||||||
|
|
Loading…
Reference in New Issue