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

Adding Wayland Support #108

Open
rbreaves opened this issue Oct 28, 2020 · 2 comments
Open

Adding Wayland Support #108

rbreaves opened this issue Oct 28, 2020 · 2 comments

Comments

@rbreaves
Copy link
Contributor

rbreaves commented Oct 28, 2020

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.

rbreaves@2a8dd0e

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 .

@rbreaves
Copy link
Contributor Author

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.

  1. 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.

  1. 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.

@joshgoebel
Copy link

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:

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

2 participants