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

Integrate keychord patch to support multi-layered keybindings #33

Closed
Frewacom opened this issue Feb 22, 2023 · 7 comments
Closed

Integrate keychord patch to support multi-layered keybindings #33

Frewacom opened this issue Feb 22, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@Frewacom
Copy link
Member

Frewacom commented Feb 22, 2023

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

@Frewacom Frewacom added the enhancement New feature or request label Feb 22, 2023
@yveszoundi
Copy link

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

  • I added almost an exact replica of the keychord patch, while accounting for few minor differences in dwl-guile
  • I attempted to separate each "layer" via a space (hard-coded limit of layers to 5, just like in the keychord patch)
  • I registered 2 key codes for the left and right shift keys, so that they can be used in key sequences
  • I didn't leverage the set-tag-keys binding in defaults.scm because of its assumptions/conventions that conflict with my typical settings (example below)
    • C-t 1 for (dwl:view 1)
    • C-t <rshift> S-1 for (dwl:tag 1)

Issues that I couldn't solve

  • "Layers" involving the shift key don't appear to work (i.e C-t <rshift> S-1)
  • 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)

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
Copy link
Member Author

Frewacom commented Mar 23, 2023

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
Copy link
Member Author

Frewacom commented Mar 26, 2023

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
Copy link

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:

  • Less robust validation
  • Lost ability to use custom keycodes with the custom bracket syntax
  • Unwarranted changes in keycodes.h to simplify parsing without "-" tokens: mouse-middle -> mousemiddle

@yveszoundi
Copy link

It looks good to me @Frewacom, great work.

  • I tested successfully my configuration against your latest changes
    • I am able to use custom key codes for left-shift and right-shift and everything behaves as expected
    • The integration feels exactly like in regular dwl patched with keychord
  • I also tested more vim-like vs emacs-like settings without problems C-t x o vs. C-t C-x o

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
(setq inhibit-defaults? #t)

(dwl:set-tty-keys "C-M")

(set-layouts 'default "[M]" 'dwl:monocle
           'tile    "[]=" 'dwl:tile)

(set-keys "C-t <return>"       '(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 <tab>"          '(dwl:cycle-layout 1)
        "C-t <left>"         '(dwl:focus-monitor 'DIRECTION-LEFT)
        "C-t <right>"        '(dwl:focus-monitor 'DIRECTION-RIGHT)
        "C-t <up>"           '(dwl:focus-monitor 'DIRECTION-UP)
        "C-t <down>"         '(dwl:focus-monitor 'DIRECTION-DOWN)
        "C-t [50] S-<left>"  '(dwl:tag-monitor 'DIRECTION-LEFT)
        "C-t [50] S-<right>" '(dwl:tag-monitor 'DIRECTION-RIGHT)
        "C-t [50] S-<up>"    '(dwl:tag-monitor 'DIRECTION-UP)
        "C-t [50] S-<down>"  '(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-<space>" 'dwl:toggle-floating
        "C-t q"              'dwl:quit
        "C-t <escape>"       'dwl:quit
        "C-<mouse-left>"     'dwl:move
        "C-<mouse-middle>"   'dwl:toggle-floating
        "C-<mouse-right>"    '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
Copy link
Member Author

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
Copy link

yveszoundi commented Mar 27, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants