pynput icon indicating copy to clipboard operation
pynput copied to clipboard

Wayland backend

Open tbm opened this issue 3 years ago • 12 comments

@TMiguelT made a good summary in https://github.com/moses-palmer/pynput/issues/184#issuecomment-534546626 about what it would take to create a wayland backend.

Is anyone working on this?

tbm avatar Dec 17 '20 04:12 tbm

Yes, the uinput backend is implemented: https://github.com/moses-palmer/pynput/blob/master/CHANGES.rst#v170-2020-08-30---a-new-backend-and-many-new-features-and-bug-fixes.

I believe it should automatically activate when you're on Linux, aren't on X11 and possibly you will have to run the script with sudo. Otherwise, I think the backend is called uinput if you want to force it to enable.

multimeric avatar Dec 17 '20 04:12 multimeric

I know about uinput, but I was referring to your comments about becoming a Wayland client.

tbm avatar Dec 17 '20 05:12 tbm

Oh right, no. As I explain in the comment you linked to, that approach wouldn't consistently work. Rather we will have to wait for a virtual device proposal to get passed and implemented in Wayland. I'm not sure where any of that stuff is up to, however.

multimeric avatar Dec 17 '20 05:12 multimeric

Oh right, I thought there might have been progress (on the Wayland side) since your comment was from a year ago.

tbm avatar Dec 17 '20 05:12 tbm

Oh it seems there has been some progress. So on the Wayland protocol side there are a few proposals but neither have been accepted:

  • https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/11
  • https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/12

What's interesting, though, is that both of these protocols are apparently already implemented in sway and other wlroots-based compositors. I think this code snippet demonstrates a CLI for manipulating the pointer (like xdotool) for compositors that support the protocol: https://github.com/swaywm/wlroots/blob/master/examples/virtual-pointer.c. I suppose there is some argument against building on a protocol that isn't yet officially part of Wayland, but still it looks like the best option at the moment.

multimeric avatar Dec 17 '20 05:12 multimeric

That sounds interesting.

Unfortunately, I'm not advanced enough to contribute support. If you add this or mouse support for uinput (#332), I'd be happy to test though.

tbm avatar Dec 18 '20 06:12 tbm

The long term solution for Wayland support would be to implement these protocols, but I am reluctant to do that before they have been finalised and thoroughly documented.

moses-palmer avatar Dec 18 '20 14:12 moses-palmer

Agreed. But in theory if someone urgently wanted this feature now, I think they could implement C bindings for these unstable protocols, and you could get Python automating the mouse + keyboard on certain Wayland environments (not stock Gnome, though, which I assume is the most common DE on Linux atm).

multimeric avatar Dec 18 '20 15:12 multimeric

Hi there! Now that Ubuntu 21 is out, and using Wayland by default, the library seems to be bugging a bit :confused:

But it does work... sometimes?

TheLastGimbus avatar May 03 '21 19:05 TheLastGimbus

Yes, it still works with applications running under XWayland, but Wayland being default on Ubuntu makes an implementation for the protocols listed above even more urgent.

moses-palmer avatar May 04 '21 08:05 moses-palmer

A global keybinds portal exists now, as of xdg-desktop-portal 1.16.

As for emulating input, it'll either need root or an external library such as libei (which is currently being worked on to go through xdg-desktop-portal as well).

You could also possibly manage this via the RemoteDesktop portal.

orowith2os avatar Jan 08 '23 21:01 orowith2os

As for emulating input, it'll either need root or an external library such as libei (which is currently being worked on to go through xdg-desktop-portal as well).

Looks like libei 1.0 was released in June, with 1.1.0 already being out by now. Here is the release announcement: https://lists.freedesktop.org/archives/wayland-devel/2023-June/042731.html

7RST1 avatar Oct 10 '23 09:10 7RST1