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

Selection ownership gets lost immediately on weston-xwayland setup #139

Open
tusharsnx opened this issue Sep 11, 2022 · 7 comments
Open

Comments

@tusharsnx
Copy link

tusharsnx commented Sep 11, 2022

When xclip is used with Wayland compositor Weston, xclip loses selection ownership immediately and returns without waiting for SelectionRequest. Weston usually takes ownership before any X client on the server, due to which when xclip creates a window on the server and sets selection ownership together (b/c window creation request remains buffered until XGetSelectionOwner() ), the xclip receives SelectionClear immediately after it.

Debug log:

$ xclip -i -debug -sel clip <<< "hello"
xclip: debug: Debugging enabled.
Connected to X server.
Using selection: XA_CLIPBOARD
Using target: UTF8_STRING.
Waiting for selection requests, Control-C to quit

xclip: debug: Received SelectionClear event
Lost selection ownership. (window id 0x200001 did a copy).
xclip: debug: checking for requestors whose window has closed
Exiting.

Note: window id 0x200001 belongs to xwayland.

I have also tested the behaviour against master.

other reference issues:
microsoft/terminal#11945

@tusharsnx tusharsnx changed the title Selection ownership get losts immediately on weston-xwayland setup Selection ownership gets lost immediately on weston-xwayland setup Sep 11, 2022
@quartzjer
Copy link
Collaborator

Have you found any workarounds? I'm not sure how xclip could address this issue.

@tusharsnx
Copy link
Author

tusharsnx commented Jan 1, 2025

@quartzjer I haven't found any workarounds. I'm sure you'll agree that this is not really xclip's fault here. I'm not sure why Xwayland clears the selection during init. I also don't know if this is a wsl specific issue or Weston in general.

I don't have a Linux setup, so could you check if this also happens in a non-WSL Wayland environment? To see the bug you need to make sure the xclip selection triggers xwayland init (i.e. xwayland must not be init'd until then).

@hackerb9
Copy link
Collaborator

hackerb9 commented Jan 3, 2025

I've got Debian GNU/Linux but am not familiar with Weston. I was able to run Weston from a virtual terminal, but trying xclip just gives me an error that it cannot open the DISPLAY. Is there some set up needed to get it to run Xwayland automatically?

With Gnome (using the Mutter compositor), Xwayland is launched correctly as needed and the selection is not cleared.

@tusharsnx
Copy link
Author

tusharsnx commented Jan 4, 2025

You need to enable xwayland using --xwayland when running weston, and make sure xorg is also installed as xwayland would need it to talk to x11 clients.

@quartzjer Looks like this is a weston issue and not WSL-specific, but WSL is certainly the edge case since xclip is often the only xclient installed on the system since there's no GUI.

Weston starts a proxy x-server which only listens for clients until one of the clients wants to talk to an xserver. At this point, Weston starts the actual x-server to serve the client. Once xserver has started two things happen: the client gets its request fulfilled (E.g. XSetSelectionOwner) and at the same time Weston is preparing the window manager (wm) for Xwayland. These happen at the same time, asynchronously, and lead to race. If XSetSelectionOwner happens first and then wm is ready, WM will clear the selection during the init.

@hackerb9
Copy link
Collaborator

hackerb9 commented Jan 7, 2025

The bug does not occur under Debian GNU/Linux (Sid) which currently has Weston 14.0.1 and Xwayland 24.1.4. I am running a custom development version of xclip, but it should not matter.

Update:

I should mention, Weston looks graphical to me, so perhaps wm is already running? I tried using

weston --B headless --xwayland 

and it still seemed to work fine.

@hackerb9
Copy link
Collaborator

hackerb9 commented Jan 8, 2025

@quartzjer Looks like this is a weston issue and not WSL-specific, but WSL is certainly the edge case since xclip is often the only xclient installed on the system since there's no GUI.

Does the same problem happen when you try xsel instead of xclip?

@tusharsnx
Copy link
Author

Does the same problem happen when you try xsel instead of xclip?

I can't repro it anymore on wsl. It seems wsl startup now eagerly starts xwayland (and xserver) which makes this issue virtually non-existent.

If you run grep on weston's log, it shows Xwayland server is already running:

$ grep -i xwayland /mnt/wslg/weston.log
[11:33:21.407] Command line: /usr/bin/weston --backend=rdp-backend.so --modules=wslgd-notify.so --xwayland --socket=wayland-0 --shell=rdprail-shell.so --log=/mnt/wslg/weston.log --logger-scopes=log,rdp-backend,rdprail-shell
[11:33:21.443] Loading module '/usr/lib/libweston-9/xwayland.so'
[11:33:21.445] Registered plugin API 'weston_xwayland_v1' of size 32
[11:33:21.445] Registered plugin API 'weston_xwayland_surface_v1' of size 48
[11:33:21.445] Not using abstract fd for Xwayland
[11:33:21.529] Spawned Xwayland server, pid 46

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

3 participants