My intention was to create a simple popup, where I can decided to suspend/reboot/shutdown for awesome-wm. I was also motivated by iQuit3 to implement such a feature in my config. However, as I use awesome I followed a different approach and used the capabilities of awesome. The result is a menu generated by awful.menu
(docs of awful.menu), which is displayed centered on the focused screen. It can be controlled with your standard keybindings for awful menu (e.g. up,k and down, j to scroll Esc to cancel) or with the mouse.
Here is a screenshot of the menu taken from an install of the community edition of awesome:
You can add the follwing code to your rc.lua
, but it must be placed somewhere before you use it (e.g. in a keybinding)
Code to generate the menu
-- {{{ Helper function for quitmenu
myquitmenu = {
{ "log out", function() awesome.quit() end, menubar.utils.lookup_icon("system-log-out") },
{ "suspend", "systemctl suspend", menubar.utils.lookup_icon("system-suspend") },
{ "hibernate", "systemctl hibernate", menubar.utils.lookup_icon("system-suspend-hibernate") },
{ "reboot", "systemctl reboot", menubar.utils.lookup_icon("system-reboot") },
{ "shutdown", "poweroff", menubar.utils.lookup_icon("system-shutdown") }
}
m_theme={
border_width=4,
border_color="#16A085",
height=48,
width=200,
font="sans bold 16"
}
quitpopup = awful.menu({items=myquitmenu,theme=m_theme})
local function quitmenu()
s = awful.screen.focused()
m_coords = {
x = s.geometry.x + s.workarea.width/2-100,
y = s.geometry.y + s.workarea.height/2-120
}
quitpopup:show({coords=m_coords})
end
-- }}}
You can open the menu by calling quitmenu()
in rc.lua
Here is a example keybinding to Ctrl+Super+q:
awful.key({ modkey, "Control" }, "q", quitmenu,
{description = "open the quitmenu widget", group = "launcher"}),
You can add other entries to myquitmenu
if you like (e.g. a cancel button), the entries of this version are the ones of the exitmenu in the freedesktop menu of the community edition.
Example of appending a cancel entry to myquitmenu
{ "Cancel", function() quitpopup:hide() end, "/usr/share/icons/Papirus-Dark/48x48/emblems/emblem-error.svg"},
If the number of items in the menu changes you will have to change the y-shift (120
) in this line accordingly: y = s.geometry.y + s.workarea.height/2-120
to keep the menu centered. The height of an entry is 48, therefore, the shift is number_of_entries * 24
(e.g. 5 * 24 = 120
in the example)