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

Add the 'catchall' keyword that matches all keys #4930

Merged
merged 2 commits into from Mar 3, 2024

Conversation

Cu3PO42
Copy link
Contributor

@Cu3PO42 Cu3PO42 commented Mar 2, 2024

Description

This keyword can be used to define arbitrary keybinds. The only special behavior that it exhibits is that it matches every key, including modifier keys. Any flags still apply normally.

Motivation

I use submaps to create modal keymaps similar to those implemented by many Vim configs, e.g. LazyVim. Then I might hit <leader> l m to launch my system monitor. While in a submap I would like to ignore any keys that are not mapped and open a help window that reminds me of my forgotten binds. Adding a catch-all bind seemed to be the most straight-forward way to achieve that.

This or a similar feature is also requsted by #3638, #3405 and #1972.

Fixed Issues

This commit also fixes an issue that keys bound via the code:KEYCODE format were not unbound correctly. This problem stemmed from a duplication of the code that translates the key specification in a bind rule (i.e. its second argument) to keysym/keycode. Since I had to touch that code anyway and to avoid similar problems in the future, I extracted that code into a function.

Open questions

Syntax

The keyword could theoretically collide with a keysym. However, I believe it to be unlikely that a keysym with such a name will ever exist, so this is a limited risk. To be extra sure or future proof for new keywords, it is conceivable to instead use syntax such as special:catchall. The current code: syntax for binding by keycode would be precedent for that.

I am also not 100% sold on the formatting by hyprctl or more specifically the casing of the name. I tried to remain consistent with the existing fields, specifically non_consuming being snake_case in the JSON output and everything being lowercase in the other output.

Footgun

Using this keyword outside a submap will prevent essentially all keys from being forwarded to applications (unless defined as non-consuming). This might make it difficult to revert the setting. The setting could be made to only work in a submap to mitigate that.

Since switching to a TTY should still work, I don't view this as a huge problem. I would rather remain consistent with existing behavior and introduce fewer special cases.

Documentation

I have prepared an accompanying PR at hyprwm/hyprland-wiki#499.

This keyword can be used to define arbitrary keybinds. The only special
behavior that it exhibits is that it matches every key, including
modifier keys. Any flags still apply normally.

This commit also fixes an issue that keys bound via the code:KEYCODE
format were not unbound correctly.
@vaxerski
Copy link
Member

vaxerski commented Mar 2, 2024

the warning in the wiki is relatable - how about ignore catchall outside submaps?

@Cu3PO42
Copy link
Contributor Author

Cu3PO42 commented Mar 2, 2024

That's definitely an option. In fact, that is what I intended to propose under the 'Footgun' section above. Since it is known at parse-time whether the bind would be in a submap, maybe it could even be a validation error instead of just ignoring it?

Update: I went ahead and implemented that.

A catchall keybind outside a submap would prevent essentially all key
events from going through to applications and would be difficult to
remove again.
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.

idk looks alright

@vaxerski vaxerski merged commit 964f1a4 into hyprwm:main Mar 3, 2024
11 checks passed
@Cu3PO42
Copy link
Contributor Author

Cu3PO42 commented Mar 3, 2024

Thank you for reviewing and merging that so quickly!

@vaxerski
Copy link
Member

vaxerski commented Mar 3, 2024

⛰️ 🚗

lisuke pushed a commit to lisuke/Hyprland that referenced this pull request Apr 15, 2024
* Add the 'catchall' keyword that matches all keys

This keyword can be used to define arbitrary keybinds. The only special
behavior that it exhibits is that it matches every key, including
modifier keys. Any flags still apply normally.

This commit also fixes an issue that keys bound via the code:KEYCODE
format were not unbound correctly.

* Disallow catchall keybinds outside of submaps

A catchall keybind outside a submap would prevent essentially all key
events from going through to applications and would be difficult to
remove again.
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.

None yet

2 participants