hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
20.94k stars 879 forks source link

Feature request: Keychords #865

Closed Phundrak closed 1 year ago

Phundrak commented 1 year ago

What are keychords?

Keychords are keybindings that can be chained to one another. A famous example is Emacs’ keybind for opening a file C-x C-f (read it as Ctrl-x then Ctrl-f).

Why keychords?

While simple keybindings are easy to implement and fast to press, their number can become quickly limited on a keyboard, especially when trying to keep things organized. Accidentally hit alt when typing Super+q? Guess your computer will shut down instead of just going to sleep. While keychords require a bit more hand movements, the amount of assignable keybindings becomes virtually limitless while allowing the user to keep their keybindings organized.

Additional and implementation ideas

Keybindings could be organized in keymaps which could be accessed by other keybindings. I believe this is how i3 handles their own keychords.

Something I really enjoy from Emacs and StumpWM is their which-key-mode showing the current keymap’s keybinds, so we never forget them.

fufexan commented 1 year ago

Do you mean something like this?

umop3plsdn commented 1 year ago

submap is the feature you are looking for on the wiki

Phundrak commented 1 year ago

Submaps look like a different feature. From what I understand, once you enter a submap, you will not exit it if you press another key than Escape. This looks like an interactive keymap rather than a simple keymap. With keychords, there is no need to press escape, you simply press for instance Super+Space a b and you’re done, the keybind is executed and you’re back on the global keymap.

vaxerski commented 1 year ago

From what I understand, once you enter a submap, you will not exit it if you press another key than Escape. This looks like an interactive keymap rather than a simple keymap.

no, read the wiki

I mean read, not skim over. What fufexan linked should tell you everything about configuring this.

Phundrak commented 1 year ago

Is that a difference between the functions bind and binde? If so, I think there should be at least a paragraph about it, I find it very easy to miss.

vaxerski commented 1 year ago

what

Phundrak commented 1 year ago

Per the wiki and the link shared earlier:

if you press ALT + R, you can enter a “resize” mode, resize with arrow keys, and leave with escape

Correct me if I’m wrong, but if I type Alt+R, I can type Right/Left/Up/Down as many times as I wish, and I’ll stay in the submap, right? Is that due to the code using binde instead of bind? Or is that due to the bindings being in the submap itself?

As I understand the Wiki, the only way to exit the submap is to reset it with something like bind=,escape,submap,reset. The comment given on that line seems to indicate resetting the submap is the only way to exit it, which is not the behaviour of keychords.

fufexan commented 1 year ago

binde means "repeatable bind", as in repeating when held. It does not influence whether you're still in the submap or not.

You can exit out of a submap with any keybind, as long as you set it. You can, for example, set the same key chord twice, once for your desired action, and the second time for exiting the submap. They will be executed in the order they're set in the config file.

Phundrak commented 1 year ago

I believe this should be explicitly documented then, the only mention of binde I can find in the wiki is the example code, and it can people believing submaps must be explicitly left, especially because of this line:

IMPORTANT: do not forget a keybind to reset the keymap while inside it! (In this case, escape)

As I now understand it, this is only because all the other bindings in the example use binde, this should also be explained.

fufexan commented 1 year ago

binde is mentioned in https://wiki.hyprland.org/Configuring/Binds/#bind-flags, but yes the submap section can be improved.

fufexan commented 1 year ago

https://github.com/hyprwm/hyprland-wiki/commit/75ae8c5c9fe3041bb730c932033494c379c6b78e fixed here.

vaxerski commented 1 year ago

should we close this then? Behavior possible already.