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

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

Open
reuleaux opened this issue Mar 7, 2023 · 0 comments

Comments

@reuleaux
Copy link

reuleaux commented Mar 7, 2023

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_wm_class 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

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

No branches or pull requests

1 participant