Quitmenu for awesome-wm

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") }
  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
-- }}}

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)


Hy @firefightux. Super cool application already uses it to prevent my laptop to logout of awesome when I press modkeyhift+q by accident. Cool work. I think it would be even cooler if you would provide this menu as an importable package in order to keep the rc.lua cleaner and would upload it to Github. I tried it myself but have not got the lua skills to do it. Maybe I accept the challenge on the weekend :smile:

Overall thank you :slight_smile:

1 Like

Hey, thank you for your appreciation and welcome to the forum!

You're welcome.

When I published that menu I thought it not big enough to create a separate package. In addition, I think it benefits users to read the code and modify it if necessary (e.g. new entries, border color). For a separate module I have to look on how to add options to theme it. Either way it is necessary to adjust rc.lua to integrate the menu anyway.
However, I am think about creating a separate lua module for this menu. Then one could copy that file to ~/.config/awesome and use it or I create a PKGBUILD like the one for lain. We will see. At the moment I am occupied with other things.

Forum kindly sponsored by