awful.menu: Move code from rc.lua to awful.menu

Fixes: #2524
This commit is contained in:
Sorky 2019-01-27 04:19:05 +11:00 committed by Emmanuel Lepage Vallée
parent e8bf75ef3c
commit bf62695f76
2 changed files with 25 additions and 16 deletions

View File

@ -85,21 +85,6 @@ awful.layout.layouts = {
}
-- }}}
-- {{{ Helper functions
local function client_menu_toggle_fn()
local instance = nil
return function ()
if instance and instance.wibox.visible then
instance:hide()
instance = nil
else
instance = awful.menu.clients({ theme = { width = 250 } })
end
end
end
-- }}}
-- {{{ Menu
-- @DOC_MENU@
-- Create a launcher widget and a main menu
@ -162,7 +147,9 @@ local tasklist_buttons = gears.table.join(
)
end
end),
awful.button({ }, 3, client_menu_toggle_fn()),
awful.button({ }, 3, function()
awful.menu.client_list({ theme = { width = 250 } })
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
end),

View File

@ -541,6 +541,28 @@ function menu.clients(args, item_args, filter)
return m
end
local clients_menu = nil
--- Use menu.clients to build and open the client menu if it isn't already open.
-- Close the client menu if it is already open.
-- See `awful.menu.clients` for more information.
-- @tparam[opt] table args Menu table, see `new()` for more information.
-- @tparam[opt] table item_args Table that will be merged into each item, see
-- `new()` for more information.
-- @tparam[opt] func filter A function taking a client as an argument and
-- returning `true` or `false` to indicate whether the client should be
-- included in the menu.
-- @return The menu.
function menu.client_list(args, item_args, filter)
if clients_menu and clients_menu.wibox.visible then
clients_menu:hide()
clients_menu = nil
else
clients_menu = menu.clients(args, item_args, filter)
end
return clients_menu
end
--------------------------------------------------------------------------------
--- Default awful.menu.entry constructor