Skip to content

Add xdg-toplevel-drag-v1 so a client can drag a window along with its data - #249

Open
sachahjkl wants to merge 2 commits into
bea4dev:mainfrom
sachahjkl:feat/xdg-toplevel-drag
Open

sachahjkl wants to merge 2 commits into
bea4dev:mainfrom
sachahjkl:feat/xdg-toplevel-drag

Conversation

@sachahjkl

@sachahjkl sachahjkl commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Adds the staging protocol xdg-toplevel-drag-v1 (xdg_toplevel_drag_manager_v1). A client attaches a toplevel to the wl_data_source of a drag, and the compositor moves that window with the pointer until the drag ends. Browsers and toolkits use it to tear a tab off into a new window and to dock it back: Chromium and Qt use it, and KWin implements it.

The window moves through the same code as an interactive move. The first commit splits that code out of MoveSurfaceGrab into a WindowMove that does not depend on a pointer grab. A config therefore gets onWindowMove events with the new source "toplevel-drag", and its snapping, tiling and workspace rules apply as for a title bar drag. Without a move handler, the window is placed in the space directly, as before.

  • The window keeps the client's offset under the pointer (relative to its window geometry), from start_drag or from attach, whichever comes last.
  • The attached window is left out of hit testing during the drag, so it is never its own drop target. The drop lands on the window under it, and the normal DnD rules apply.
  • A window attached before its first buffer (a torn-off tab) is placed at the pointer directly, so its first frame shows there. Its move, and the config's events, start on the commit that maps it.
  • When the drag is dropped or cancelled, the window stays where the move left it (the move's end event).
  • An attached window that unmaps or is destroyed is detached, as the protocol says.
  • Errors: invalid_source for a second drag object on one source, toplevel_attached for an attach over a live attached toplevel, ongoing_drag for a destroy during the drag.

smithay's DnDGrab is wrapped in a small ToplevelDragGrab that moves the window on each motion before the DnD grab sees it, so the smithay fork does not change. The bindings come from the wayland-protocols version already in Cargo.lock (feature staging).

Tested with unit tests for the state of a drag object (attach before and during the drag, drop, detach on unmap, the error cases) and tests/toplevel_drag.rs in shojiwm_rs, which runs a backendless compositor with a real Wayland client:

  • An existing window attached with an offset jumps to keep that offset under the pointer, follows the pointer over a second window, the second window gets the enter and the drop although the dragged window covers the pointer, and the window stays where it was dropped. Destroying the drag object after the drop raises no error.
  • A new toplevel attached during the drag before its first buffer is placed at the pointer, keeps its place when its buffer arrives, and follows the pointer after that.

cargo test --workspace --all-targets passes except virtual_keyboard_binds::input_method_keyboard_grab_gets_the_keymap_of_the_keys_it_is_sent, which fails the same way on main on this machine. npm run typecheck passes. Not tried with a browser yet.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant