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

Allow Multiple Simultaneous keys in a Keybind and add Left and Right mod distinction. #5966

Merged
merged 25 commits into from
May 16, 2024

Conversation

The-Briel-Deal
Copy link
Contributor

@The-Briel-Deal The-Briel-Deal commented May 9, 2024

Describe your PR, what does it fix/add?

I've seen many requests like:
#5517,
#1703,
https://www.reddit.com/r/hyprland/comments/12weag0/binding_capshjkl_to_arrow_keys_setting_all_window/,
https://www.reddit.com/r/hyprland/comments/12g1axe/unable_to_bind_keys_properly/,
https://www.reddit.com/r/hyprland/comments/17ybq1n/keybind_help/, and many more.

This has also been a highly desired feature myself, and I don't find the solution of submaps to be a particularly intuitive solution. In all of these threads and issues people are asking for the ability to arbitrarily bind multiple normal keys or specify the specific mod key they want to use (e.g. Control_L, Alt_L, Meta_R...). This change allows both of these things without breaking existing behaviors or adding large amounts of overhead to existing configs.

To use this use the sym flag "s", with this flag you must use the symbols shown in xev like "Control_L" for mods or "k" for the k key. You also must seperate mods and keys with "&" like this:

# You can use a single mod with multiple keys.
binds = Control_L, A&Z, exec, kitty
# You can also specify multiple specific mods.
binds = Control_L&Shift_L, K, exec, kitty
# You can also do both!
binds = Control_R&Super_R&Alt_L, J&K&L, exec, kitty

(Note that I had to use & as the separator because some keysyms have underscores like the mod keys above)

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

None of the above from my testing! Please do try it out and see if you can break it though.

Is it ready for merging, or does it need work?

It should be ready for merging!

@vaxerski
Copy link
Member

feel free to request my review when you feel this is ready

@The-Briel-Deal
Copy link
Contributor Author

feel free to request my review when you feel this is ready

Hey @vaxerski, I'm happy with where this is. I've gone through quite a few revisions of this and I'm happy with where this is at and can't find any edge cases. (There may be a weird flag combination since there are so many possible options with 9 flags)

Please take a look and let me know your thoughts. Here are two example keybinds below if you'de like to test. The keys are case insensitive and mods and keys are separated by &. I also updated the PR description with more info since you last saw.

binds = Control_R, a&z&s, exec, kitty
binds = Control_L&Control_R&Super_L, Y&u, exec, kitty

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this work with shadowing, though?

Multi-key binds to me make no sense - you can define submaps already and achieve the same thing.

e.g.:

bindr = SUPER, A, exec, kitty
binds = SUPER, R&A, exec, dolphin

user presses super, a, and r. Will shadowing work and block super+a from executing?

For mods, why not just store an internal modmask that distinguishes L/R mods?

src/managers/KeybindManager.cpp Outdated Show resolved Hide resolved
@The-Briel-Deal
Copy link
Contributor Author

The-Briel-Deal commented May 14, 2024

How will this work with shadowing, though?

Multi-key binds to me make no sense - you can define submaps already and achieve the same thing.

e.g.:

bindr = SUPER, A, exec, kitty
binds = SUPER, R&A, exec, dolphin

user presses super, a, and r. Will shadowing work and block super+a from executing?

For mods, why not just store an internal modmask that distinguishes L/R mods?

Good catch on shadowing, I'll look into this deeper this evening.

My primary justification for this feature is to have an un-opinionated option for users to bind anything they want. I don't really want to say "hey, these are the mods you are allowed to use". I really just want it to look at keysyms and treat them all the same no matter which you use, the only difference between mods and keys here is that if mods aren't an exact match then keypresses that are in the bind won't be be consumed (so if you have a Super_L, A&B bind and you press Super then A, then the key will be consumed, but A without the mod will not be consumed).

Let me give you a real world example I ran into. I personally never use my caps_lock, page_down, and page_up keys. So I wanted to be able to use these keys as mods for different hotkeys. But previously if your mod wasn't one of the 8 allowed mods, you just couldn't use it. I understand that a submap may work here, but they can get messy really quickly. And you can only use one layer, so caps_lock,e&r,exec,ranger was just not allowed.

So to sum it all up, I personally feel that we should leave these sort of options open to the user while staying out of the way for people who don't care about it.

@vaxerski
Copy link
Member

fair enough. As long as shadowing works, this looks ok to me

@The-Briel-Deal
Copy link
Contributor Author

fair enough. As long as shadowing works, this looks ok to me

It should be good now, shadowing is good and I resolved conflicts and merged in latest main. Wait to merge till tomorrow though, going to make a PR to the docs and run it as my main install for a bit and make sure there aren't any issues.

@The-Briel-Deal
Copy link
Contributor Author

Docs made hyprwm/hyprland-wiki#652! Everything should be good and tested!

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@vaxerski vaxerski merged commit d693c44 into hyprwm:main May 16, 2024
10 checks passed
@noahfraiture
Copy link

Hello, it seems that super_l is no different that super_l in configuration. I set mainMod to super_l but both super key do the same. I checked with wev and they are two distinct key

@The-Briel-Deal
Copy link
Contributor Author

Hello, it seems that super_l is no different that super_l in configuration. I set mainMod to super_l but both super key do the same. I checked with wev and they are two distinct key

Are you using the s flag? Can you show me the line in your config.

@noahfraiture
Copy link

The command is as simple as

$mainMod = SUPER_L # windows key

and then later things like this

bind = $mainMod, T, exec, kitty  # open terminal

But I saw that this wasn't merge in the 0.40.0 which is on pacman. Does it mean that I will have to simply replace all my bind by binds ?

@The-Briel-Deal
Copy link
Contributor Author

The-Briel-Deal commented May 28, 2024 via email

@graham33
Copy link

Thanks very much for this @The-Briel-Deal !

Does it mean that I will have to simply replace all my bind by binds ?

Yes, that worked for me. Just posting to make it super clear for others. For example I use:

$mainMod = Alt_R
binds = $mainMod, Q, exec, kitty
...

@The-Briel-Deal
Copy link
Contributor Author

Thanks very much for this @The-Briel-Deal !

Does it mean that I will have to simply replace all my bind by binds ?

Yes, that worked for me. Just posting to make it super clear for others. For example I use:

$mainMod = Alt_R
binds = $mainMod, Q, exec, kitty
...

Ty @graham33, I'm glad it wasn't just me that wanted this! I'm happy it works alright for you!

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

Successfully merging this pull request may close these issues.

4 participants