waycrate / swhkd

Sxhkd clone for Wayland (works on TTY and X11 too)
https://git.sr.ht/~shinyzenith/swhkd
BSD 2-Clause "Simplified" License
706 stars 48 forks source link

Hyper key not working #103

Open xircon opened 2 years ago

xircon commented 2 years ago

Version Information: Linux xircon-legion 5.17.1-zen1-1-zen #1 ZEN SMP PREEMPT Mon, 28 Mar 2022 21:56:46 +0000 x86_64 GNU/Linux

swhkd 1.1.7

Describe the bug: Cannot set hyper as a modifier.

Expected behavior: Have redefined caps to be a hyper modifier, works in sxhkd.

Actual behavior: Causes swhkd to not load.

To Reproduce: add a shorcut e.g. hyper+d

Additional information: Anything else you'd like us to know ?

Shinyzenith commented 2 years ago

Hi, thank you for the verbose report. Would you mind expanding on what the hyper key is? I'm not particularly familiar with that.

xircon commented 2 years ago

It is an additional modifier, so I now have Super, Alt, Control and Hyper. You can use xmodmap to do this on x11, but on wayland I used this:

https://ibnishak.github.io/blog/post/caps-to-hyper/

So in sxhkd you can use:

hyper+d
    <your-command-here>

Press and hold caps lock - press d.

I can define hyper in my sway config and it works:

set $mod3 Mod3
#######################
# Hyper key bindings: #
#######################

    bindsym $mod3+b exec --no-startup-id killall -SIGUSR1 waybar
    bindsym $mod3+n exec swaync-client -t -sw
    bindsym $mod3+s exec ~/.local/bin/grimm
    bindsym $mod3+u exec ~/scripts/ups.sh 

All of which function as expected.

For a full history of additional modifiers, search for space-cadet keyboards on lisp machines (spot the emacs user :smile:).

:edit: To get caps lock, I use:

input type:keyboard {
                xkb_layout "gb"
            xkb_options shift:both_capslock # <<<<<<<<<<<<<<
            }

Press both shifts to toggle caps lock.

Shinyzenith commented 2 years ago

OK I will get someone to look into this. I currently can't work on it due to my deteriorating health.

xircon commented 2 years ago

No problems, I completely understand, I am an old crip, easier and quicker to list what isn't wrong with me :rofl:

simonwiles commented 2 years ago

I was experimenting with migrating from sxhkd, but this is a show-stopper for me. With my existing sxhkd config:

hyper + f
  jumpapp firefox

...

I get:

[2022-08-19T00:09:53Z ERROR swhkd] Config Error: Error parsing config file "/etc/swhkd/swhkdrc". Unknown symbol at line 1.

99% of what I use sxhkd for is mapping commands to hyper combinations, fwiw.

Shinyzenith commented 2 years ago

patches are always welcome

ajanon commented 2 years ago

What is the difference between

hyper + f
  jumpapp firefox

and

capslock + f
  jumpapp firefox

in your case? If I understand correctly, this is exactly what you want: map the caps lock physical key to a command (which is what it means for swhkd).

swhkd reads input at a lower level than X11 libraries, so your custom rebind (with xmodmap, setxbkmap or any other) should not impact it in any way. (please correct me if I am wrong @angelofallars @EdenQwQ @Shinyzenith)

I think you should even be able to keep your custom config in X or wayland and both swhkd binds and your custom mappings should work together.

simonwiles commented 2 years ago

@ajanon -- thank you for the suggestion. With just:

capslock + f
  jumpapp firefox

I just get:

[... ERROR swhkd] Config Error: Error parsing config file "/etc/swhkd/swhkdrc". Invalid modifier at line 1.

This is similar to sxhkd, which why capslock has to be mapped to the hyper modifier first.

xircon commented 2 years ago

Yup, caps lock is not a "modifier" I get exactly the same. You can however use the hyper modifier in sway, so that is the route I took.

Shinyzenith commented 2 years ago

swhkd reads input at a lower level than X11 libraries, so your custom rebind

@ajanon You are correct!

redxtech commented 1 year ago

does that mean that there's no way to get binds with the hyper mod key working in swhkd?

samsonnagamani commented 1 year ago

I found the code to do with the "hyper" mod key, while trying to make the "alt graph" key work. It may be considered a breaking change. I've managed to get it working with the "alt gr" key so I'm assuming it would work with the "hyper" key, however I don't have a keyboard with the "hyper" key.

Also by "hyper" key I'm assuming you mean the "right logo/windows" button found on larger keyboards.

There are 2 main steps to get the hyper key working.

  1. Add "Hyper" in the "Modifier" enum in config.rs
    pub enum Modifier {
    Super,
    Hyper,
    Alt,
    Control,
    Shift,
    Any,
    }
  2. Map "RIGHTMETA" key to the "Hyper" Modifer enum in the "modifiers_map" hashmap located in daemon.rs
    let modifiers_map: HashMap<Key, config::Modifier> = HashMap::from([
        (Key::KEY_LEFTMETA, config::Modifier::Super),
        (Key::KEY_RIGHTMETA, config::Modifier::Hyper),
        (Key::KEY_LEFTALT, config::Modifier::Alt),
        (Key::KEY_RIGHTALT, config::Modifier::Alt),
        (Key::KEY_LEFTCTRL, config::Modifier::Control),
        (Key::KEY_RIGHTCTRL, config::Modifier::Control),
        (Key::KEY_LEFTSHIFT, config::Modifier::Shift),
        (Key::KEY_RIGHTSHIFT, config::Modifier::Shift),
    ]);

Again, I can't test whether this will work since I don't have that key available on my keyboard

Shinyzenith commented 1 year ago

@samsonnagamani Thanks for the patch! If anyone can test it and get it working, I'd be more than happy to merge and support this usecase.