mooz / xkeysnail

Yet another keyboard remapping tool for X environment
890 stars 112 forks source link

xkeysnail ported to hy (or: hy-lang) - in an attempt to make it work with wayland - and success with wayland! #171

Open reuleaux opened 1 year ago

reuleaux commented 1 year ago

Hi, I have ported xkeysnail to hy (or hy-lang) - in an attempt to make it work with wayland. (As in I prefer coding in a Lisp language over Python these days.)

Please find my code at http://git.a-rx.info/krm/

This was mostly tedious/mechanical work of porting python to hy (I hope I did not make too many mistakes), and then some little experimentation / adjustments of mine: some debug messages, etc. - my main contribution being a function active in transform.hy (instead of the original _get_active_window_wmclass there), which takes a wm parameter: either 'x or 'sway.

The secret was to rely on swaymsg to get the active window, and then ask its app_id with jq:

SWAYSOCK=$(ls /run/user/1000/sway-ipc.* | head -n 1) swaymsg -t get_tree | jq -r ".. | select(.type?) | select(.focused) | .app_id"

And I did succeed: this works for me with X-Windows, as well as Sway, example usage

./keyremap.hy -x -devices /dev/input/event0 /dev/input/event2 -- config.py

or

./keyremap.hy -sway -q config.py
./keyremap.hy -x -q config.py

etc.

-x and -sway being shortcuts to set the 'wm parameter .

I.e. it still takes a Python config file (although I created mine from a hy file using hy2py, as in the haredo file config.py.do), but I assume the code can be easily adjusted to take an original hy config file: config.hy file as well.

My config file is a little odd maybe: scrolling on f1/f2 - but that's how I work - and of course more example config files can be added later (the original xkeysnail-emacs config file perhaps in hy[?])

Be sure to have hy, as well as hyrule installed:

pip3 install -U hy
pip3 install -U hyrule

I tried to give proper credit to xkeysnail, but I did't find a licencse with the original xkeysnail [?] - anyway, in as far as this is my code (these are my contributions): they shall be covered by a BSD-2 license.

I don't really plan to maintain this code: for one thing I am busy with other bits. And then: some parts of the original xkeysnail code I understand only so much.

But if someone finds this piece of code useful (and want's to take it over perhaps [?]), I shall be more than happy.

Loose ends for me currently: I would like to get this working with river as well:

./keyremap.hy -river -q config.py

but I don't know the river-equivalent of swaymsg to get the currently focussed window (I haven't found a rivermsg), but this may possible nevertheless in some other way perhaps [?]).

I have left a detailed (river-) issue some time ago: https://github.com/riverwm/river/issues/786 That was before (this) my success with krm/keyremap/xkeysnail. I.e. the problem boils down to finding the active window / and the application running therein for river (as above: for sway)

I may dig deeper myself. (But if someone has a answer for that, I would be curious to know).

Thanks, -A