xkeysnail
xkeysnail copied to clipboard
Adding Wayland Support
Updated 10/28/20
I have updated the wayland branch on my fork and it is really still just a proof of concept, I know there are better and fuller ways to make it all pythonic and less likely to break, but this was just to see if it works and it does.
The things I don't like when it comes to implementing it better is that dbus calls from a xkeysnail service or process running under sudo is difficult to do without calling the specific dbus session for the user - so I am at a bit of a loss on how to write it dynamically. I would also prefer to listen and not poll for the changes however often.
I also had to increase the delay to 40 microseconds because 10 did not always solve the sync issues.
https://github.com/rbreaves/xkeysnail/commit/2a8dd0e54f53751b0daaf8370c4a9538942b48d2
Any help or suggestions from others would be appreciated. If someone just wants to write a more solid solution based on this work then go for it lol!
Update Workaround: Add a delay of 10 microseconds on output.py fixes my problem. Now I can work on the rest of it tomorrow. Not sure why wayland messes with the timing of things because even when I monitor it it is not immediately apparent at all.
def send_key_action(key, action):
update_modifier_key_pressed(key, action)
update_pressed_keys(key, action)
time.sleep(0.01)
_uinput.write(ecodes.EV_KEY, key, action)
send_sync()
So I was doing some preliminary work to get Wayland support added for Gnome3 specifically but I am running into an interesting problem that I hope the collaborators here can help me with. @Lenbok @mooz
I know of a way to get the wm class name from the active program in Gnome3 with Wayland and have figured that out since last January actually, so adding Wayland support has always been something I figured I could work on eventually, if no one else were to add it.
Here's the rub though, it appears like the evdev library in xkeysnail is not properly removing or releasing modifier keys under Wayland? It reports that it is when I print it, but that is not how it behaves under Wayland. If I run the exact same code under x11 (without the real xlib based function running) it releases the key as expected, so I know it isn't from me creating a fake "get_active_window_wm_class" function.
My plan is to replace or update the "get_active_window_wm_class" function with a GDBus call that grabs the wm class name of the active window, but until I figure out what is hanging me up I am stuck.
What I plan to convert into python using a GDBus interface/call of some kind. https://gist.github.com/rbreaves/257c3edfa301786e66e964d7ac036269
The output of where I am stuck.
WM_CLASS 'Sublime_text' | active keymaps = [Anonymous keymap, Anonymous keymap, Sublime Text]
modifier discard: Key.RIGHT_CTRL
discard: Key.RIGHT_CTRL
add: Key.HOME
discard: Key.HOME
modifier add: Key.RIGHT_CTRL
add: Key.RIGHT_CTRL
RC-LShift-LEFT => Shift-HOME
modifier discard: Key.LEFT_SHIFT
discard: Key.LEFT_SHIFT
modifier discard: Key.RIGHT_CTRL
discard: Key.RIGHT_CTRL
The test branch https://github.com/rbreaves/xkeysnail/tree/wayland
sudo pip3 install --upgrade .
I could be wrong, but I feel like it’s too expensive to be polling the Gnome Shell ALL the time. I want an alternative, a signal that can be registered & listened to.. that way we can wait on refreshing the Window title until we know a change as occurred.
- it takes too long imo to run the eval GJS script to pull the window title in the manner I do it in my test.
I’m not sure that it’d improve any using dbus libraries in python - if they could even run while running undo sudo.
- I’m wonder if a single Eval command could be run & setup a virtual Signal for when Windows change & if that’d stabilize things vs making constant GJS calls.
https://feaneron.com/2019/01/31/gnome-shell-and-mutter-better-faster-cleaner/
GJS calls may be OK as long as you only run them when actual Window focus changes occur & not on every key press. Even now I think an optimization could occur on the x11 side as well.
Even now I think an optimization could occur on the x11 side as well.
Yes, you can request that X inform you about window changes and then we could be notified of them rather than having to query on every keypress. I'm not 100% sure this works with all window managers though. I saw different ways of implementing this functionality, it would need testing. If possible it'd definitely be a nice improvement for the X11 support though.
The notes I have on this:
- https://github.com/python-xlib/python-xlib/blob/master/Xlib/display.py#L153
- https://stackoverflow.com/questions/23786289/how-to-correctly-detect-application-name-when-changing-focus-event-occurs-with