diff --git a/awesomerc.lua b/awesomerc.lua index b4fca8ff..d3390c57 100644 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -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), diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index 9186c7b1..78d1e55b 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -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