Copying doesn't work under Phosh - wl_data_device::set_selection uses invalid serial 0
(Originally reported at https://gitlab.alpinelinux.org/alpine/aports/-/issues/14179 )
On postmarketOS Edge on a PinePhone device, in the Phosh/Phoc compositor, programs like gnome-contacts and secrets that use gtk 4.8.1 are unable to put text into the clipboard. With secrets this happens when tapping the buttons to copy username / password. With gnome-contacts this happens with copying the text of any text field.
Pasting was tested with firefox and with wl-paste
. Specifically with the latter, running WAYLAND_DEBUG=client wl-paste --watch cat
reported absolutely no events when copying text from secrets or gnome-contacts.
The programs are able to paste their own text into themselves; I assume gtk bypasses the wayland protocol when it pastes to itself. In any case, they are still unable to paste each other's copied text.
Here is the relevant part of WAYLAND_CLIENT=debug secrets
:
[2896947.954] wl_touch@9.down(3984, 134782748, wl_surface@27, 0, 397.33203125, 575.33203125)
[2896948.220] wl_touch@9.frame()
[2897082.214] wl_touch@9.up(3985, 134782788, 0)
[2897082.365] wl_touch@9.frame()
[2897090.371] -> wl_data_source@43.destroy()
[2897090.470] -> wl_data_device_manager@4.create_data_source(new id wl_data_source@51)
[2897090.504] -> wl_data_source@51.offer("text/plain;charset=utf-8")
[2897090.529] -> wl_data_source@51.offer("text/plain")
[2897090.567] -> wl_data_device@23.set_selection(wl_data_source@51, 0)
Notice the wl_data_device::set_selection requests uses serial 0. Serial 0 is invalid, and wlroots (used by phoc) does validate the serial, and drops the request if the validation fails.
The last time copying worked on that distro was when it used gtk 4.6.6. Given that, I noticed that there are two relevant commits between 4.6.6 and 4.8.1:
gdk/wayland: Use last press serial for clipboard/primary selections
gdk/wayland: Stop storing the last serial in GdkWaylandDisplay
I reverted these two commits in a local build of gtk 4.8.1, and now those two programs are able to copy text successfully. WAYLAND_CLIENT=debug
confirms that the set_selection requests now use a proper serial instead of 0.
In the downstream issue, one person reported they did not have any problems with secrets on their desktop, under the sway compositor. I also assume it works under GNOME since you folks presumably didn't break it. So at this point, the only repro I'm aware of is with Phosh/Phoc on a PinePhone.
That said, given the code is serial = _gdk_wayland_seat_get_implicit_grab_serial (seat, NULL);
, it seems to me that _gdk_wayland_seat_get_implicit_grab_serial
will only consider pointer events since the event
param is NULL
. So perhaps it will repro with any compositor as long as the user does not have a mouse, only a touch screen.