Closed Bug 2075886 Opened 1 month ago Closed 12 days ago

[Wayland] Tab drag opens a new window with multiple seats

Categories

(Core :: Widget: Gtk, defect)

Firefox 156
defect

Tracking

()

RESOLVED FIXED
162 Branch
Tracking Status
firefox162 --- fixed

People

(Reporter: gabriel, Assigned: sinker)

References

(Blocks 2 open bugs)

Details

(Keywords: helpwanted)

Attachments

(2 files, 1 external file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0

Steps to reproduce

  1. Start a Hyprland 0.56.2 session with the Cua Hyprland plugin loaded (https://github.com/trycua/cua, libs/cua-driver/hyprland-plugin). The plugin adds two wl_seat globals, "Cua-Agent" and "Cua-Agent-2", after Hyprland's own seat, so wayland-info lists three wl_seat globals. The physical mouse and keyboard stay on Hyprland's seat, which is advertised first
  2. Start Firefox with a fresh profile: firefox --new-instance --profile "$(mktemp -d)"
  3. Open at least two tabs
  4. Press the mouse button on a tab and drag it a short distance sideways along the tab strip

Also reproduces in Troubleshoot Mode (--safe-mode) with a fresh profile.

Actual results

As soon as the pointer moves, the tab is detached into a new browser window, as if it had been dragged outside the tab strip. The tab can never be reordered within the strip.

The drag log (MOZ_LOG=WidgetDrag:5,WidgetDragService:5, attached) shows the session failing immediately, before gtk_drag_begin is reached:

  nsDragSessionSource::InvokeDragSession
  InvokeDragSession | rv: NS_ERROR_FAILURE | Ending drag session due to internal error

WAYLAND_DEBUG=1 shows no wl_data_device.start_drag. Same session: GTK4 (Nautilus) and Chromium drag tabs and files fine. Tab drag works when only one wl_seat is visible to the browser.

Expected results

The tab is reordered within the tab strip, as it is when the compositor advertises only one wl_seat.

The "InvokeDragSessionImpl() originGdkWindow" log line never appears, so the early return on a missing origin GdkWindow is the likely failure point:

  1. GdkGetPointer() (widget/gtk/WidgetUtilsGtk.cpp) calls the deprecated gdk_device_manager_get_client_pointer().
  2. GTK3's Wayland backend returns the master pointer of the first entry in its device list, but prepends each seat's devices as they are added. With several seats this is the pointer of the LAST advertised seat, not the one the user is using.
  3. nsDragSessionSource::InvokeDragSessionImpl() calls gdk_device_get_window_at_position() on that pointer, gets NULL, and returns NS_ERROR_FAILURE. No wl_data_device.start_drag is sent (confirmed with WAYLAND_DEBUG=1), and the tabbrowser falls back to detaching the tab.

Checks:

  • Reproduced with stock Firefox 156.0 (fresh profile, also in Troubleshoot Mode) and with Zen (Gecko-based).
  • Same session: GTK4 (Nautilus) and Chromium drag tabs and files fine.
  • Zen nested in a single-seat compositor (cage): tab drag works.
  • Zen with an LD_PRELOAD shim that hides every wl_seat after the first from all wl_registry listeners (GTK's and Gecko's): tab drag works.

Suggested fix: take the pointer from GTK's default seat, which is the first seat added, e.g. gdk_seat_get_pointer(gdk_display_get_default_seat(display)).

Better still, use the device that delivered the triggering button press.

Separately, nsWaylandDisplay::SetSeat() overwrites mSeat for every wl_seat announced, so Gecko's own Wayland code also ends up on the last seat.

Possibly related: bug 1719036 (multiseat paste uses the wrong seat), bug 1978847 (same tab drag symptom on a multi-seat sway setup, closed by
the reporter with a different explanation).

The Bugbug bot thinks this bug should belong to the 'Core::Widget: Gtk' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Widget: Gtk
Product: Firefox → Core
Severity: -- → S3

It's a bit corner case so patches welcome - I may not work on that.

Keywords: helpwanted

On Wayland, nsDragSessionSource::InvokeDragSessionImpl() finds the origin
window with gdk_device_get_window_at_position() on GdkGetPointer(). That
returns the window the device's seat last entered. GdkGetPointer() returns
gdk_device_manager_get_client_pointer(), which GTK picks from the seat that
added a device most recently (gdk_wayland_device_manager_get_client_pointer()).
When the compositor announces more than one wl_seat, that is usually not the
seat the user is dragging with. If that seat's pointer is not over a Firefox
window, the lookup returns NULL and the drag is aborted.

Take the device from the saved button press (GetLastPointerDownEvent()) when
there is one. That is the device gtk_drag_begin_with_coordinates() drags with,
since it gets the device from the same event, and its pointer is over the
window that was pressed.

Callers with no press to go by have the same wrong-seat problem, so
GdkGetPointer() now returns the pointer of gdk_display_get_default_seat(),
which on Wayland is the first seat announced. On X11, GTK's default seat is
the seat of the X client pointer, so nothing changes there. The seat API is
GTK 3.20, so it is looked up with dlsym() and the old call stays as the
fallback.

Assignee: nobody → thinker.li
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Pushed by stransky@redhat.com: https://github.com/mozilla-firefox/firefox/commit/4b059d6b1cd1 https://hg.mozilla.org/integration/autoland/rev/7ee4a1b33192 Use the right seat's pointer for drags with several Wayland seats. r=stransky,gtk-reviewers
Status: ASSIGNED → RESOLVED
Closed: 12 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: