Skip to content

wip: wayland: Add xdg-toplevel-drag support - #702

Merged
iamsergio merged 15 commits into
mainfrom
pr/xdg_toplevel_drag
Nov 16, 2026
Merged

iamsergio merged 15 commits into
mainfrom
pr/xdg_toplevel_drag

Conversation

@iamsergio

Copy link
Copy Markdown
Contributor

Test with:
./bin/qtwidgets_dockwidgets -platform wayland --wayland-toplevel-drag

Known bugs:

  • There's some offset, window doesn't snap to where mouse cursor is
  • When releasing mouse, outside of a drop-area, then next drag wont start (needs a second mouse click)

@iamsergio iamsergio linked an issue Apr 30, 2026 that may be closed by this pull request
@iamsergio
iamsergio force-pushed the pr/xdg_toplevel_drag branch from 25ed37d to 7cc7ae1 Compare May 1, 2026 13:28
@iamsergio
iamsergio marked this pull request as draft September 24, 2026 21:00
@septatrix

Copy link
Copy Markdown

Can you provide any updates/ETA on this? It would be great to have better wayland integration :)

@iamsergio

Copy link
Copy Markdown
Contributor Author

Can you provide any updates/ETA on this? It would be great to have better wayland integration :)

I'm on it now

Test with:
./bin/qtwidgets_dockwidgets -platform wayland --wayland-toplevel-drag

Change-Id: Ic5043a6c66b7a9aa629d89b4b9c824140a310a83
So tst_wayland can test Config::Flag_WaylandToplevelDrag. QtWaylandCompositor
doesn't implement it, and Qt's client silently falls back to a regular
drag when the compositor lacks it.

The attached toplevel follows the pointer during the drag and, like desktop
compositors do, isn't picked as the drag target.

--no-toplevel-drag disables it, to test the fallback.

Change-Id: I9f3d6a3bf77096a52de1ec249e15c54cbd1d7732
The dragging state was picked when creating the DragController. QtQuick's
Platform creates it, so the flag, which can only be set after that, had no
effect with QtQuick. Neither did it after changing the flags at runtime.

Also shares the QDrag code with pixmap drags, so toplevel drags get the
fix from PR #766 too: a drop accepted by another application left the
DragController stuck in its dragging state.

Change-Id: If84a74e324794f6b2887c2c4656560f6b182b53e
Each frontend now runs the tests in both drag modes. KDDW_TEST_DRAG_MODE=pixmap
or toplevel runs only one.

With xdg-toplevel-drag a tab becomes a floating window as soon as its drag
starts, so tests that release it outside KDDW expect it to stay floating, and
tst_dragDockWidgetOntoAnother drops onto where dock2 is after dock1 left.
tst_dragTabToEmptySpaceKeepsItDocked is now tst_dragTabToEmptySpace.

Change-Id: I8daa259a22b9f422b3ccf8e784c615445a6eeed5
Only tst_cancelledTabReorderDragResetsTabBar stays QtWidgets only, as QtQuick
can't reorder tabs by dragging them. tst_tabDroppedOntoForeignWindowResetsTabBar
drags the tab off instead there.

QtQuick's TitleBar and TabBar views aren't the items that are shown, so the
tests get positions from their QML items. DropAcceptingWindow is now a
QRasterWindow, as QtQuick doesn't create a QApplication.

Change-Id: I6e17600b748570a521f76f46d4e57d5f9ac193b2
…inter

One drags a tab out of a group on the right of the main window, the other a
floating window by KDDW's title bar. Both fail: the offset given to
xdg-toplevel-drag is the cursor position when the drag started, not where the
window was grabbed, so the window drifts by the drag distance, and can end up
not under the pointer at all.

Change-Id: I23435aad0d93f409d8aa1b87c2ce687672f090b6
It was QCursor::pos() when the drag started, after the pointer already moved
past the drag threshold, so dragged windows drifted by that much. And when a
tab was further right than the new window is wide, the window wasn't under the
pointer at all.

Now it's where the window was grabbed, kept within the new window like
StateDragging does. It's computed from the global press position, as
Draggable::mapToWindow() doesn't account for the margins QtQuick's floating
windows have.

Change-Id: I5f06d8da883fddbbf85d2f6a6287c6b5c182ab55
Without it Qt silently falls back to a regular drag, but the native title bar
isn't forced anymore, so floating windows can't be moved. Fails when run with
KDDW_TEST_COMPOSITOR_ARGS=--no-toplevel-drag.

Change-Id: I807c5085d986adb6ce840ea9a483e7e6eb895fc1
Without compositor support, Qt silently falls back to a regular drag, but the
native title bar wasn't forced anymore, so floating windows couldn't be moved.

Whether the compositor supports it comes from Qt's private Wayland client API.
Qt supports xdg-toplevel-drag since 6.8, so with older Qt, or without
Qt6WaylandClientPrivate, the code isn't built and the flag is always ignored.

tst_wayland_no_toplevel_drag runs tst_wayland with the flag against a
compositor without support.

Change-Id: I222cf410272bbad186fd6bd470a3ee9daa24146d
With xdg-toplevel-drag the new window isn't under the pointer: the offset's y
is relative to the main window, and only x is kept within the new window.

Change-Id: I5a1699b251f1b36309bb1857472a1825c5cf525e
It was where the main window was pressed, so a dock widget dragged out from
low in a tall window ended up above the pointer. Like StateDragging, it's now
where the title bar or tab bar was pressed, kept within the new window in both
directions. Dragging a floating window still keeps the pointer where it was
pressed.

Change-Id: Iec20183dbb1a270c62b5b24c969aa926c944f7f8
Supporting Flag_WaylandToplevelDrag links to QtWaylandClient, even for
applications which only run on X11. The option allows opting out.

Also checks that the private headers exist. Before Qt 6.10 the
Qt6::WaylandClientPrivate target exists even if they're packaged separately
and not installed.

Change-Id: Ie7ae499a6ac144df080c3ee95be5fed073a8fc20
…positor

Clients only destroy xdg_toplevel_drag_v1 on dnd_finished or cancelled, and
QtWaylandCompositor doesn't send dnd_finished after a successful drop, so the
toplevel stayed attached. The next drag would have moved it, unless it attached
another one.

Change-Id: Id51eca3eb8e128bb97eee7f2b18a69141c67b05c
tst_toplevelDragNeedsSupport looked at KDDW_TEST_COMPOSITOR_ARGS, which isn't
set when running 'kddw_test_compositor --no-toplevel-drag -- tst_wayland', so
it failed there. Now it checks the registry.

Change-Id: I3233f91ca02c47b242a88aa328793dfd6fe485a0
Like StateDragging::onEntry() does. Both pixmap and toplevel drags use the
draggable right away.

Change-Id: I540942fad172b0ffd9486640d47771027a59081b
@iamsergio
iamsergio force-pushed the pr/xdg_toplevel_drag branch from 7cc7ae1 to b9c095a Compare November 16, 2026 15:43
@iamsergio
iamsergio marked this pull request as ready for review November 16, 2026 15:43
@iamsergio
iamsergio merged commit 70c384e into main Nov 16, 2026
36 checks passed
@iamsergio
iamsergio deleted the pr/xdg_toplevel_drag branch November 16, 2026 16:08
@iamsergio

Copy link
Copy Markdown
Contributor Author

@septatrix give it a go ./bin/qtwidgets_dockwidgets -platform wayland --wayland-toplevel-drag

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.

feat: Add support for wayland xdg-toplevel-drag

3 participants