awful.menu: add a menu for listing clients

This also allows usage of images object as icons, and destroy menu on
function execution.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-10-23 11:19:46 +02:00
parent 598a50249e
commit dc58313eee
1 changed files with 34 additions and 11 deletions

View File

@ -5,6 +5,7 @@
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
-- Grab environment we need -- Grab environment we need
local pairs = pairs
local table = table local table = table
local type = type local type = type
local wibox = wibox local wibox = wibox
@ -12,8 +13,9 @@ local image = image
local string = string local string = string
local widget = widget local widget = widget
local button = button local button = button
local capi = { screen = screen, mouse = mouse } local capi = { screen = screen, mouse = mouse, client = client }
local util = require("awful.util") local util = require("awful.util")
local tags = require("awful.tag")
local awbeautiful = require("awful.beautiful") local awbeautiful = require("awful.beautiful")
--- Menu module for awful --- Menu module for awful
@ -93,6 +95,7 @@ local function exec(data, action, num)
destroy(get_parents(data)) destroy(get_parents(data))
util.spawn(action[2]) util.spawn(action[2])
elseif type(action[2]) == "function" then elseif type(action[2]) == "function" then
destroy(get_parents(data))
action[2]() action[2]()
end end
end end
@ -117,7 +120,11 @@ local function add_item(data, num, item_info)
local icon = nil local icon = nil
if item_info[3] then if item_info[3] then
icon = widget({ type = "imagebox", name = "icon", align = "left" }) icon = widget({ type = "imagebox", name = "icon", align = "left" })
if type(item_info[3]) == "string" then
icon.image = image(item_info[3]) icon.image = image(item_info[3])
else
icon.image = item_info[3]
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 = theme.menu_height
@ -152,7 +159,7 @@ local function add_item(data, num, item_info)
end end
-- Add widgets to the wibox -- Add widgets to the wibox
item.widgets = {icon, label, submenu} item.widgets = { icon, label, submenu }
item:geometry({ item:geometry({
width = theme.menu_width, width = theme.menu_width,
@ -167,11 +174,28 @@ local function add_item(data, num, item_info)
return item return item
end end
--- Open a menu popup --- Open a popup menu with running clients.
-- @param id Menu id, string naming your menu, only one menu with the same id can be displayed on screen at the same time function clients()
-- @param items Table containing the displayed items, each element is a tab containing: item name, tiggered action or submenu table, item icon (optional) local cls = capi.client.get()
-- @param parent Specify the parent menu if we want to open a submenu, this value should never be set by the user local cls_t = {}
-- @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 for k, c in pairs(cls) do
cls_t[#cls_t + 1] = { c.name,
function ()
if not c:isvisible() then
tags.viewmore(c:tags(), c.screen)
end
capi.client.focus = c
end,
c.icon }
end
return new("Clients", cls_t)
end
--- 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 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 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(id, items, parent, num)
-- Load config only one time -- Load config only one time
if not theme then if not theme then
@ -187,7 +211,6 @@ function new(id, items, parent, num)
local data = {} local data = {}
data.id = id data.id = id
data.screen = capi.mouse.screen data.screen = capi.mouse.screen
data.nb_items = #items
data.items = {} data.items = {}
data.child = nil data.child = nil
@ -203,8 +226,8 @@ function new(id, items, parent, num)
end end
-- Create items -- Create items
for i = 1, data.nb_items do for k, v in pairs(items) do
table.insert(data.items, add_item(data, i, items[i])) table.insert(data.items, add_item(data, k, v))
end end
-- Add menu to menus table -- Add menu to menus table