Search code examples
awesome-wm

ALT + TAB behaviour implementation


I'm trying to implement ALT + TAB behaviour.
I want to know when a user is holding the ALT key.

Why does this release function not work?

awful.key(
{}, 
'Alt_L',
function()
   altHold = true
end,
function()
   altHold = false
end 
),

IMPRACTICAL SOLUTION:

awful.key(
{}, 
'Alt_L',
function()
   altHold = true
end 
),  
awful.key(
{'Mod1'},
'Alt_L',
nil,
function()
   altHold = false
end 
)

This works, but any other hotkeys with ALT no longer work.

OTHER SOLUTION:

    keygrabber.run(
        function (mod, key, event)
            -- Stop alt-tabbing when the alt-key is released
            if gears.table.hasitem(mod, "Mod1") then
                if (key == "Alt_L" or key == "Escape") and event == "release" then
                    -- Make it visible

                    if key == "Escape" then
                        -- Cancel client selection
                        end
                    else
                        -- Raise clients in order to restore history

                        -- raise chosen client on top of all

                        -- restore minimized clients
                        end
                    end

                    keygrabber.stop()
                
                -- Pressed tab
                elseif key == "Tab" and event == "press" then
                    if gears.table.hasitem(mod, "Shift") then
                        -- Move to previous client on Shift-Tab
                        cyclePreview(-1)
                    else
                        -- Move to next client on each Tab-press
                        cyclePreview( 1)
                    end
                end
            end
        end
    )

This is a slightly modified version from Troglobit:
https://github.com/troglobit/awesome-switcher/blob/master/init.lua#L470-L525\
This gets called when ALT + TAB is pressed.
While holding ALT, the next TAB press calls previewCycle() function.
If ALT is released it selects the chosen client.
ESCAPE cancels the selection.


Solution

  • Random guess: When the key is released, the "alt" modifier is active, so you need a keybinding with Mod1 as modifier (is Alt Mod1? I'm not entirely sure). But of course, that key binding would then not react to key presses, so you need two.