cyber-sushi / makima

Linux daemon to remap and create macros for keyboards, mice and controllers
GNU General Public License v3.0
145 stars 1 forks source link

How to correctly bind alt+tab #12

Closed dannyglover closed 5 months ago

dannyglover commented 5 months ago

Me again :)

So I have one last binding I'm trying to get working, Alt+Tab. I'm trying to get it so that one modifier combo keeps the tab switcher open, whilst an additional modifier acts the same as holding the Alt key on the keyboard down, and pressing tab once at a time to change the active selection.

Failed attempts:

# doesn't show the tab switcher
BTN_SELECT-BTN_TL2 = ["KEY_LEFTALT"]
BTN_SELECT-BTN_TL2-BTN_TR2 = ["KEY_TAB"]
# shows the switcher, but cycles through the windows too fast to be usable
# hold down alt+tab on your keyboard and you'll see what I mean.
BTN_SELECT-BTN_TL2 = ["KEY_LEFTALT", "KEY_TAB"]

Any ideas how to get this working as intended? Thanks again and thanks for your continued patience :)

cyber-sushi commented 5 months ago

I don't have an environment that supports Alt-Tab but I think I get what you mean

I'll probably do some tests on a live USB with Gnome or KDE and see if I can come up with something

dannyglover commented 5 months ago

I don't have an environment that supports Alt-Tab but I think I get what you mean

I'll probably do some tests on a live USB with Gnome or KDE and see if I can come up with something

No rush :)

I guess this functionality goes against the grain of your current implementation... As getting this to work will require a modifier to hold a key down (alt) and another to press a key once per press (tab) to get the functionality working correctly.

Naturally, the press part of that problem is already taken care of. It's just the holding part that needs solving.

cyber-sushi commented 5 months ago

Yes that's part of the issue, I'd like to solve it without breaking a bunch of other use cases, but it may be doable

dannyglover commented 5 months ago

Yes that's part of the issue, I'd like to solve it without breaking a bunch of other use cases, but it may be doable

I don't know if you'll like these ideas, but I have some suggestions that would extend the existing config system, without requiring new stuff.

option 1

BTN_SELECT-BTN_TL2 = ["KEY_LEFTALT-HOLD", "KEY_TAB"] This one could be parsed simply with some good ole' string substring stuff. Don't detect a hypen? Default "press" behavior. Kind of goes along with your BTN_X-BTN-Y system.

option 2

BTN_SELECT-BTN_TL2 = ["KEY_LEFTALT-HOLD", "KEY_TAB", "HOLD", "PRESS"] OR BTN_SELECT-BTN_TL2 = ["KEY_LEFTALT-HOLD", "KEY_TAB", ["HOLD", "PRESS"]] This is more complicated syntax for the user, but an option.

Adding either of the options could allow for some powerful keybinds. In the case of either option, I'd suggest making the "hold" key release after the user releases either the first key (select in this case), or all the keys in the modifier. My interpretation of modifiers is that the first key/button in the sequence is the "activator" key/button.

cyber-sushi commented 5 months ago

The way it works is that when you press modifiers in any order, they're stored in a vector, then when you press a key that's not tagged as a modifier, it checks if the currently pressed modifiers match any of the mappings, if they do, then it fires the associated sequence, otherwise it fires the default event

Currently, if any of the modifiers in use is lifted while you're pressing a mapped combination, the associated sequence is automatically lifted as well, which is how combinations usually work in an OS

The key sequence on the right, however, is directly parsed as a Vector of evdev::Key events, which means that by adding the "HOLD" part, it would have to be parsed as a Vector of Strings and change some other stuff so it's not exactly drop-in

I might do it if it's necessary, but I'll consider the options and see which one is the most clean

Thanks for the suggestions

cyber-sushi commented 5 months ago

Hello! I've released v0.8.2 which includes support for this feature

The syntax for your case would be:

BTN_SELECT-BTN_TL2 = ["KEY_LEFTALT"]

-BTN_TR2 = ["KEY_TAB"]

The dash in front of the keybinding means that it can be chained with other combinations, so you can press Select and TL2 to act as Alt, and then tap TR2 as if you were tapping Tab

Currently, using it alone will still emit the Tab event, but I can change that (or I can add a setting to change the behavior), what do you think?

I've tried keeping the syntax as simple as possible

Edit: i've released v0.8.3 and v0.8.4 with a new setting (CHAIN_ONLY) to control whether the chained binding should emit its event or not when pressed alone

dannyglover commented 5 months ago

Hello! I've released v0.8.2 which includes support for this feature

The syntax for your case would be:

BTN_SELECT-BTN_TL2 = ["KEY_LEFTALT"]

-BTN_TR2 = ["KEY_TAB"]

The dash in front of the keybinding means that it can be chained with other combinations, so you can press Select and TL2 to act as Alt, and then tap TR2 as if you were tapping Tab

Currently, using it alone will still emit the Tab event, but I can change that (or I can add a setting to change the behavior), what do you think?

I've tried keeping the syntax as simple as possible

Edit: i've released v0.8.3 and v0.8.4 with a new setting (CHAIN_ONLY) to control whether the chained binding should emit its event or not when pressed alone

Absolutely fantastic work! I love the edition of CHAIN_ONLY. I pulled the latest changes and tested, and it works perfectly. Great job!