engstrand-config / dwl-guile

Dynamic tiling Wayland compositor configurable in Guile Scheme, based on dwl and libguile - now with a REPL!
Other
97 stars 5 forks source link

Integrate keychord patch to support multi-layered keybindings #33

Closed Frewacom closed 1 year ago

Frewacom commented 1 year ago

Config syntax could look like:

(set-keys "M-x C-s-t" (lambda () ...))

where each "layer" is separated by a space, just like in Emacs.

Patch can be found here: https://github.com/djpohly/dwl/wiki/keychord

yveszoundi commented 1 year ago

I attempted to replicate what I implemented in dwl for dwl-guile, however I don't really know C programming.

My code changes are captured in a changes.diff file, because I already have an existing dwl fork (GitHub limitation).

My overall changes and notes

Issues that I couldn't solve

Thanks for this project. I tried Guix few days ago and your "home services" projects helped me understand quickly few concepts. I'm hoping switch to dwl-guile on Guix and this issue is the only blocker for me.

Frewacom commented 1 year ago

Hi, that's very nice to hear!

"Layers" involving the shift key don't appear to work (i.e C-t S-1)

I think this is because a key sequence can not only consist of a modifier without an actual key. An easy solution would be to just keep track of which "layer" we are currently parsing, and allow sequences without a key for layers > 0.

I didn't attempt to solve parsing issues for the validation of the "[" character (i.e. I typically have C-t [ and C-t ] for "change-masters" in dwm or dwl)

As you may have seen, I decided to use [ and ] for allowing users to use custom keycodes in their key sequences (e.g. C-[123]), which is why it can not be used in a key sequence directly. I guess we should change the delimiter for this to a key that is not used, or perhaps something like C-[[123]].

I'll have a look at adding these changes to the main branch, hopefully sometime this weekend. Thanks!

Frewacom commented 1 year ago

I have integrated the keychord patch into the main branch, so feel free to have a look and check if everything works as expected @yveszoundi. The issue with parsing [ has been fixed by simply checking if it is followed by another non-null character (and if it is, it will be parsed as a custom keycode instead).

~As for your issue with left and right shift, changing the keycode for <lshift> to 42 and <rshift> to 54 makes it work just fine for me (see https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h).~ Nevermind, it does not work.

yveszoundi commented 1 year ago

Thanks a lot, this is much appreciated. I'll start playing with it and I'll report back soon.

By the way, I did manage to do it myself, (the "quick and dirty way"), with some limitations:

yveszoundi commented 1 year ago

It looks good to me @Frewacom, great work.

I can now switch to dwl-guile on all my virtual machines, including those where I don't run Guix: I just apply the autostart patch to easily launch programs such as dtao-guile and wlr-randr from $XDG_DATA_HOME/dwl-guile/autostart.sh.

My dwl-guile configuration for reference ```scheme (setq inhibit-defaults? #t) (dwl:set-tty-keys "C-M") (set-layouts 'default "[M]" 'dwl:monocle 'tile "[]=" 'dwl:tile) (set-keys "C-t " '(dwl:spawn "bemenu-run" "-l" "10") "C-t c" '(dwl:spawn "foot") "C-t n" '(dwl:focus-stack 1) "C-t p" '(dwl:focus-stack -1) "C-t [" '(dwl:change-masters -1) "C-t ]" '(dwl:change-masters 1) "C-t [50] S-[" '(dwl:change-master-factor -0.05) "C-t [50] S-]" '(dwl:change-master-factor 0.05) "C-t " '(dwl:cycle-layout 1) "C-t " '(dwl:focus-monitor 'DIRECTION-LEFT) "C-t " '(dwl:focus-monitor 'DIRECTION-RIGHT) "C-t " '(dwl:focus-monitor 'DIRECTION-UP) "C-t " '(dwl:focus-monitor 'DIRECTION-DOWN) "C-t [50] S-" '(dwl:tag-monitor 'DIRECTION-LEFT) "C-t [50] S-" '(dwl:tag-monitor 'DIRECTION-RIGHT) "C-t [50] S-" '(dwl:tag-monitor 'DIRECTION-UP) "C-t [50] S-" '(dwl:tag-monitor 'DIRECTION-DOWN) "C-t k" 'dwl:kill-client "C-t `" 'dwl:zoom "C-t [62] S-e" 'dwl:toggle-fullscreen "C-t [62] S-" 'dwl:toggle-floating "C-t q" 'dwl:quit "C-t " 'dwl:quit "C-" 'dwl:move "C-" 'dwl:toggle-floating "C-" 'dwl:resize "C-t 1" '(dwl:view 1) "C-t 2" '(dwl:view 2) "C-t 3" '(dwl:view 3) "C-t 4" '(dwl:view 4) "C-t 5" '(dwl:view 5) "C-t 6" '(dwl:view 6) "C-t 7" '(dwl:view 7) "C-t 8" '(dwl:view 8) "C-t 9" '(dwl:view 9) "C-t [62] S-1" '(dwl:tag 1) "C-t [62] S-2" '(dwl:tag 2) "C-t [62] S-3" '(dwl:tag 3) "C-t [62] S-4" '(dwl:tag 4) "C-t [62] S-5" '(dwl:tag 5) "C-t [62] S-6" '(dwl:tag 6) "C-t [62] S-7" '(dwl:tag 7) "C-t [62] S-8" '(dwl:tag 8) "C-t [62] S-9" '(dwl:tag 9)) ```
Frewacom commented 1 year ago

Nice!

I am not entirely familiar with the autostart patch, but it is also possible to do something like this via Guile by adding a function to the startup hook (you can check the man page or dscm/init.scm on how to add it).

yveszoundi commented 1 year ago

Because the home-dwl-guile-service-type is very flexible, I previously wrapped my own build within a (package ...) block in the configuration (for guix).

I have now transitioned to a startup hook which is much better. Thanks!