Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of ALT key release #10

Open
arakis opened this issue Mar 18, 2024 · 1 comment
Open

Handling of ALT key release #10

arakis opened this issue Mar 18, 2024 · 1 comment

Comments

@arakis
Copy link

arakis commented Mar 18, 2024

Without having i3-focus-last installed (yes, not the ideal way for opening first issue, but most apps have this problem, which I will mention now), I want to ask about the ALT key release behavior.

Most implementations of similar software simply ignore the ALT key release for accepting the new MRU list. For example, https://github.com/altdesktop/i3ipc-python/blob/master/examples/i3-cycle-focus.py uses a delay as a workaround.

So, in my opinion, after an ALT+Tab is detected, the MRU should only be committed after the ALT key has been released. I found this to be a working solution for that (Key-up detection without interfering with other processes):

#!/usr/bin/env python3
import asyncio
from evdev import InputDevice, ecodes, list_devices

async def monitor_key_events():
    # Find the keyboard device
    devices = [InputDevice(path) for path in list_devices()]
    keyboard_device = None

    for device in devices:
        if "keyboard" in device.name.lower():
            keyboard_device = device
            break

    if not keyboard_device:
        print("Keyboard device not found")
        return

    print(f"Monitoring key events on {keyboard_device.name}")

    # Monitor key events
    async def read_events(device):
        while True:
            event = await device.async_read_one()
            yield event

    async for event in read_events(keyboard_device):
        if event.type == ecodes.EV_KEY:
            if event.code == ecodes.KEY_LEFTMETA:
                if event.value == 0:  # Key release
                    print("Left WIN key released!")

async def main():
    task = asyncio.create_task(monitor_key_events())
    await task

if __name__ == "__main__":
    asyncio.run(main())

With this approach, you can detect the ALT key being released, even when i3 is binding that key, and the key is not "grabbed" or the key event is not stolen.

I apologize for not writing a clear issue, but I only wanted to share some thoughts/issues that I came across during my research over the past few days.

By the way, the Rofi plugin idea could be exactly the right direction. Do you also display the workspace number and process names (+ window title) as in Rofi window mode?

@lbonn
Copy link
Owner

lbonn commented Mar 18, 2024

Thanks for the ideas!

For the first point, I only use the simple Alt-Tab functionality as toggle, not full cycle through history as usually rofi is a better fit for that. So I've never considered it so far. The tool also supports sway on wayland, so I think the keyboard monitoring approach would not quite work. Using a timeout could be a possible but I would prefer it to be a client flag instead of a global server behavior.

For now, the window format is fixed https://github.com/lbonn/i3-focus-last/blob/master/src/lib.rs#L142 but that can be extended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants