Search code examples
awesome-wm

Menu key as a sticky modkey for Awesome WM


I am considering switching to Awesome WM (for several reasons, hackability being probably the most important - I am a heavy Emacs user;-)).

I used to use a tiling WM (StumpWM) for some time several years ago, and it had a nice feature of binding only one key as a "prefix". I set it up to be the (otherwise useless for me) "menu" key, so essentially all WM bindings were "press menu, release it, press something else".

From the docs/tutorials I can see that Awesome has a slightly different approach of binding its functions to "modkey+something".

Is it possible to use "menu" as a "sticky modkey" as I was used to? Or rather, how do I do that?


Solution

  • You could create a "normal" keybinding for the Menu key, start a keygrabber in there and use that to get the "something" that follows. It would mean that you have to reinvent some wheels yourself, because the code in AwesomeWM will not manage keybindings for you, but it should be workable.

    Quick example that does not do much to get you started:

    diff --git a/awesomerc.lua b/awesomerc.lua
    index 5d2bd2c10..7973b210a 100644
    --- a/awesomerc.lua
    +++ b/awesomerc.lua
    @@ -242,6 +243,12 @@ root.buttons(gears.table.join(
     -- {{{ Key bindings
     -- @DOC_GLOBAL_KEYBINDINGS@
     globalkeys = gears.table.join(
    +    awful.key({}, "Menu", nil, function()
    +        keygrabber.run(function(mods, key, action)
    +            print("You did:", gears.debug.dump_return(mods), key, action)
    +            keygrabber.stop()
    +        end)
    +    end),
         awful.key({ modkey,           }, "s",      hotkeys_popup.show_help,
                   {description="show help", group="awesome"}),
         awful.key({ modkey,           }, "Left",   awful.tag.viewprev,
    

    What this does is to print the first "keyboard event" after the Menu key was released. This could e.g. be "a key was released that was pressed before the Menu key was released", but you would likely only care about things like "'s' was pressed"...