From 550bc71188dab41846ff7b108fce0612ecaac0cd Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 11:29:54 -0500 Subject: [PATCH 01/10] Keep a sibling's update when the owner re-records its restored frame While a key's owner restores, the writer holds one deferred update for the key and the latest sequence takes it, whoever sent it. The provider records the owner's restored frame when it lands, so that record replaced a sibling's manual update made during the restore, and the completion then persisted the owner's frame over the user's newer placement. The contract has the sibling's update win: the restored owner's own frame must not overwrite it. The owner's record of the reservation's own frame no longer takes the slot from another window's update; it is suppressed. A frame the released owner was moved to by hand differs from the reservation's and is a manual update like any other, so the latest still wins there, and a sibling's update after the owner's still replaces it. restoredFrameDoesNotReplaceASiblingsUpdate covers the three orders, at the completion and at the owner's destruction. Signed-off-by: Wisbendji Fimerlus --- autotests/test_transientplacementwriter.cpp | 62 +++++++++++++++++++++ src/tiles/transientplacementwriter.cpp | 9 +++ 2 files changed, 71 insertions(+) diff --git a/autotests/test_transientplacementwriter.cpp b/autotests/test_transientplacementwriter.cpp index 818a2ce1c5..792d80fd37 100644 --- a/autotests/test_transientplacementwriter.cpp +++ b/autotests/test_transientplacementwriter.cpp @@ -40,6 +40,8 @@ private Q_SLOTS: void reservationRequiresExactPersistedFrame(); void memoryFrameIsTheProvidersWholePixelImage(); void deferredManualWinnerSurvivesCompletion(); + void restoredFrameDoesNotReplaceASiblingsUpdate_data(); + void restoredFrameDoesNotReplaceASiblingsUpdate(); void failedFlushIsNotRetriedByDestructor(); void failedReservationDoesNotHoldKey(); void duplicateGlobalKeyRefusesReservation(); @@ -292,6 +294,66 @@ void TransientPlacementWriterTest::deferredManualWinnerSurvivesCompletion() QCOMPARE(writer.snapshot().entries.value(QStringLiteral("app")), later); } +void TransientPlacementWriterTest::restoredFrameDoesNotReplaceASiblingsUpdate_data() +{ + QTest::addColumn("order"); + QTest::addColumn("destroyed"); + QTest::newRow("restored-frame-after-the-sibling") << 0 << false; + QTest::newRow("restored-frame-after-the-sibling, owner destroyed") << 0 << true; + QTest::newRow("sibling-after-the-restored-frame") << 1 << false; + QTest::newRow("owner-moved-by-hand-after-the-sibling") << 2 << false; +} + +void TransientPlacementWriterTest::restoredFrameDoesNotReplaceASiblingsUpdate() +{ + // While the owner restores, the key has one deferred slot. A sibling's manual update in it + // is the user's newer placement; the owner's own record of the frame it is restored to (the + // reservation's frame, which the provider re-records when it lands) is not, and must not + // take the slot from it whatever its sequence. A frame the released owner was moved to by + // hand is a manual update like any other: the latest wins. + QFETCH(int, order); + QFETCH(bool, destroyed); + using Result = TransientPlacementWriter::Result; + QTemporaryDir directory; + QVERIFY(directory.isValid()); + TransientPlacementWriter writer(directory.filePath(QStringLiteral("placementrc"))); + QObject provider; + const auto token = writer.registerProvider(&provider); + const auto owner = QUuid::createUuid(); + const auto sibling = QUuid::createUuid(); + const QRectF original(73, 91, 430, 310); + const QRectF manual(200, 100, 600, 400); + const QRectF moved(260, 140, 500, 380); + QVERIFY(writer.trackWindow(owner, QStringLiteral("app"))); + QCOMPARE(writer.record(token, 1, {owner, original, 1, TransientPlacementWriter::Origin::Manual}), Result::Accepted); + QCOMPARE(writer.reserve(token, reservation(writer, owner, original)), Result::Accepted); + QCOMPARE(writer.activateReservation(token, owner, QStringLiteral("generation-1")), Result::Accepted); + QCOMPARE(writer.beginRestore(owner, QStringLiteral("generation-1")), Result::Accepted); + QVERIFY(writer.trackWindow(sibling, QStringLiteral("app"))); + QRectF expected; + if (order == 0) { + QCOMPARE(writer.record(token, 2, {sibling, manual, 20, TransientPlacementWriter::Origin::Manual}), Result::Deferred); + QCOMPARE(writer.record(token, 3, {owner, original, 30, TransientPlacementWriter::Origin::Manual}), Result::Suppressed); + expected = manual; + } else if (order == 1) { + QCOMPARE(writer.record(token, 2, {owner, original, 20, TransientPlacementWriter::Origin::Manual}), Result::Deferred); + QCOMPARE(writer.record(token, 3, {sibling, manual, 30, TransientPlacementWriter::Origin::Manual}), Result::Deferred); + expected = manual; + } else { + QCOMPARE(writer.record(token, 2, {sibling, manual, 20, TransientPlacementWriter::Origin::Manual}), Result::Deferred); + QCOMPARE(writer.record(token, 3, {owner, moved, 30, TransientPlacementWriter::Origin::Manual}), Result::Deferred); + expected = moved; + } + QCOMPARE(writer.snapshot().entries.value(QStringLiteral("app")), original); + if (destroyed) { + QVERIFY(writer.forgetWindow(owner)); + } else { + QCOMPARE(writer.completeRestore(owner, QStringLiteral("generation-1")), Result::Accepted); + } + QVERIFY(!writer.isReserved(owner)); + QCOMPARE(writer.snapshot().entries.value(QStringLiteral("app")), expected); +} + void TransientPlacementWriterTest::failedFlushIsNotRetriedByDestructor() { QTemporaryDir directory; diff --git a/src/tiles/transientplacementwriter.cpp b/src/tiles/transientplacementwriter.cpp index 33576b5c46..c29e7d8dd3 100644 --- a/src/tiles/transientplacementwriter.cpp +++ b/src/tiles/transientplacementwriter.cpp @@ -254,6 +254,15 @@ TransientPlacementWriter::Result TransientPlacementWriter::record(const QUuid &p if (reservation->deferred && update.eventSequence <= reservation->deferred->eventSequence) { return Result::OutdatedEvent; } + if (reservation->phase == Phase::Restoring && reservation->owner == update.window + && reservation->deferred && reservation->deferred->window != update.window + && sameFrame(update.frame, reservation->original)) { + // The owner's record of the frame it is restored to (the reservation's own frame, + // re-recorded when it lands) is not a newer placement: a sibling's manual update + // keeps the one deferred slot whatever the sequences say. A frame the released + // owner was moved to by hand differs from it and takes the slot as the latest. + return Result::Suppressed; + } reservation->deferred = update; return Result::Deferred; } From 5a448dfa8e7bce2e66d1b7628a53d7cecad5cc1c Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 11:35:51 -0500 Subject: [PATCH 02/10] Synchronize a configure-less request across an output boundary A request that needs no configure publishes its image on the output's pixels and takes the requested geometry with it. Where the image's center fell on another output than the request's, that synchronization was skipped so that no output changed under the request, and the window stayed unsettled until its next commit: with two outputs, a window centered within a fraction of a pixel of their boundary could not be admitted to a transient tile. The request now goes through synchronizeConfigureGeometry, the synchronization a configure's commit uses. It writes the requested geometry and, when the center has moved to another output, takes that output and its scale, transform and color with it under the same fences, as it does for a committed frame. A newer request made by one of its callbacks ends this one. testConfigurelessRequestSynchronizesRequestedGeometry: the boundary row now ends with the request on its image and on the image's output; a row with a second output of another scale follows the configure that scale change brings. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 52 ++++++++++++------- src/xdgshellwindow.cpp | 23 +++++--- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 10b7d6c5a6..9a3ef203cd 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -10588,18 +10588,20 @@ QByteArray frameText(const QRectF &frame) void TestXdgShellWindow::testConfigurelessRequestSynchronizesRequestedGeometry_data() { QTest::addColumn("outputs"); + QTest::addColumn("secondScale"); QTest::addColumn("request"); QTest::addColumn("anchored"); - QTest::addColumn("synchronized"); + QTest::addColumn("crosses"); // A 361-wide client on a 4/3 output is 481 device pixels, a 360.75-wide frame: a request // for 361 asks the client for the size it has. - QTest::newRow("in-place") << 1 << QRectF(102, 102, 361, 240) << false << true; - QTest::newRow("moved") << 1 << QRectF(132, 123, 361, 240) << false << true; + QTest::newRow("in-place") << 1 << 4.0 / 3.0 << QRectF(102, 102, 361, 240) << false << false; + QTest::newRow("moved") << 1 << 4.0 / 3.0 << QRectF(132, 123, 361, 240) << false << false; // As during a resize from the top-left corner: the bottom-right corner stays, so the // published frame's top-left is not the request's. - QTest::newRow("bottom-right-kept") << 1 << QRectF(132, 123, 361, 240) << true << true; + QTest::newRow("bottom-right-kept") << 1 << 4.0 / 3.0 << QRectF(132, 123, 361, 240) << true << false; // The request's center belongs to the second output, its image's to the first. - QTest::newRow("center-on-an-output-boundary") << 2 << QRectF(1019.0625, 123, 361, 240) << false << false; + QTest::newRow("center-on-an-output-boundary") << 2 << 4.0 / 3.0 << QRectF(1019.0625, 123, 361, 240) << false << true; + QTest::newRow("center-on-a-boundary-to-another-scale") << 2 << 1.25 << QRectF(1019.0625, 123, 361, 240) << false << true; } void TestXdgShellWindow::testConfigurelessRequestSynchronizesRequestedGeometry() @@ -10607,15 +10609,16 @@ void TestXdgShellWindow::testConfigurelessRequestSynchronizesRequestedGeometry() // An ordinary request for the client size the window already has is resolved without a // configure: its image on the output's pixels is published at once, and from then on that // image is the requested geometry, as after a configure's commit. Where the image's center - // would be on another output than the request's, the requested geometry stays as it was - // asked and no output changes under the request. + // is on another output than the request's, the request follows its image there, the + // output's properties with it, as a commit's synchronization would take it. QFETCH(int, outputs); + QFETCH(qreal, secondScale); QFETCH(QRectF, request); QFETCH(bool, anchored); - QFETCH(bool, synchronized); + QFETCH(bool, crosses); QList config{Test::OutputInfo{.geometry = Rect(0, 0, 1200, 900), .scale = 4.0 / 3.0}}; if (outputs == 2) { - config.append(Test::OutputInfo{.geometry = Rect(1200, 0, 1200, 900), .scale = 4.0 / 3.0}); + config.append(Test::OutputInfo{.geometry = Rect(1200, 0, 1200, 900), .scale = secondScale}); } Test::setOutputConfig(config); workspace()->setActiveOutput(QPoint(100, 100)); @@ -10626,6 +10629,7 @@ void TestXdgShellWindow::testConfigurelessRequestSynchronizesRequestedGeometry() QVERIFY(window); QVERIFY(!configure.isEmpty() || configure.wait()); shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); Test::render(surface.get(), QSize(361, 240), Qt::blue); QVERIFY(Test::waylandSync()); auto toplevel = static_cast(window); @@ -10638,27 +10642,35 @@ void TestXdgShellWindow::testConfigurelessRequestSynchronizesRequestedGeometry() if (anchored) { toplevel->m_configureGravity = Gravity::TopLeft; } - const QRectF image(request.topLeft(), before.size()); - QCOMPARE(workspace()->outputAt(image.center()) == workspace()->outputAt(request.center()), synchronized); + const auto first = workspace()->outputAt(before.center()); + QCOMPARE(workspace()->outputAt(request.center()) != first, crosses); window->moveResize(request); + // An output of another scale asks the client again; the client answers at the size it has. + for (int i = 0; i < 3 && toplevel->hasPendingNativeGeometry(); ++i) { + QVERIFY(!configure.isEmpty() || configure.wait()); + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + Test::render(surface.get(), QSize(361, 240), Qt::blue); + QVERIFY(Test::waylandSync()); + } QVERIFY(!toplevel->hasPendingNativeGeometry()); const QRectF frame = window->frameGeometry(); - QCOMPARE(frame.size(), before.size()); if (anchored) { + QCOMPARE(frame.size(), before.size()); QCOMPARE(frame.x() + frame.width(), request.x() + request.width()); QCOMPARE(frame.y() + frame.height(), request.y() + request.height()); QVERIFY(frame.x() != request.x()); } else { - QVERIFY2(exactFrame(frame, image), frameText(frame).constData()); + QCOMPARE(frame.topLeft(), request.topLeft()); + QVERIFY(frame != request); } - if (synchronized) { - QVERIFY2(exactFrame(window->moveResizeGeometry(), frame), frameText(window->moveResizeGeometry()).constData()); - QCOMPARE(window->moveResizeOutput(), workspace()->outputAt(frame.center())); - } else { - QVERIFY2(exactFrame(window->moveResizeGeometry(), request), frameText(window->moveResizeGeometry()).constData()); - QCOMPARE(window->moveResizeOutput(), workspace()->outputAt(request.center())); - QVERIFY(window->moveResizeOutput() != workspace()->outputAt(frame.center())); + // Settled: what is published is what is requested, on the output the frame is on. + QVERIFY2(exactFrame(window->moveResizeGeometry(), frame), frameText(window->moveResizeGeometry()).constData()); + QCOMPARE(window->moveResizeOutput(), workspace()->outputAt(frame.center())); + QCOMPARE(window->nextTargetScale(), window->moveResizeOutput()->scale()); + if (crosses) { + QCOMPARE(window->moveResizeOutput(), first); } } diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index 9395bd267e..d857084859 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -299,15 +299,24 @@ void XdgSurfaceWindow::dispatchMoveResize(const RectF &rect, MoveResizeMode mode } else { // The request is resolved here, with no configure and nothing for the client to // commit: what is published is the request's image on the output's pixels, and - // the requested geometry follows it, as it does when a configure's commit lands - // (synchronizeCommittedGeometry). Left at the rectangle that was asked for, it - // would differ from the frame until the client's next commit, and the window - // would read as unsettled for that long. Half a pixel must not carry the - // center to another output: there the request stays as it was asked. A guarded + // the requested geometry follows it through the synchronization a configure's + // commit uses (synchronizeCommittedGeometry). Left at the rectangle that was + // asked for, it would differ from the frame until the client's next commit, and + // the window would read as unsettled for that long. Where half a pixel carries + // the image's center to another output, the synchronization takes the output + // and its properties with it, as it does for a committed frame. A guarded // request keeps its rectangle on purpose: its caller compares the requested // geometry with the rectangle it asked for (a tile's, a restoration's). - if (target != rect && workspace()->outputAt(target.center()) == moveResizeOutput()) { - setMoveResizeGeometry(target); + if (target != rect) { + const auto requestIsCurrent = [this, generation]() { + return geometryRequestIsCurrent(generation) && transientGeometryRequestIsCurrent(generation); + }; + // A refused synchronization leaves the request as it was asked; a newer + // request from one of its callbacks ends this one. + if (synchronizeConfigureGeometry(target, m_geometryRequestOrigin, requestIsCurrent).outcome != AssignmentStepOutcome::AppliedCurrent + && !current()) { + return; + } } updateGeometry(target); } From 0efa9be495a346dae14680646c44328fe3260f85 Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 11:50:53 -0500 Subject: [PATCH 03/10] Let the policy settle a released window's record A release that is not the explicit restore is detach-only: the window stays where it stands and its record (Restoring) keeps the automatic rectangle out of the placement memory. Nothing ever ended that record. The explicit restore claims an owned record only, so after a removed desktop or output, a second window of the app or a move of the master, the window kept the tile's size and could not be admitted again until it closed. On the ThinkPad the desktop-removal scenario of the re-entry tests left the master at 4,38 714x858 and every later toggle on it was Busy. Generic revocation stays detach-only and the native layer still never requests the floating frame for a released record. What is new is the record's end: Window::settleReleasedTransientOwnership, the facade's settleWindow(window, token). The policy that admitted the window gives it its floating frame back with an ordinary request, or leaves it where the user put it, and asks for the record to be settled. The native layer does it only for the provider that admitted the window, with no live restoration, in an ordinary mode outside every tile, with nothing of the native geometry in flight and the frame the requested geometry, and with the window off the automatic rectangle. Every other answer changes nothing, so the rectangle still cannot reach the memory, and a policy that never asks leaves the record until the window closes, as before. The writer finalizes as for a completed restoration: a deferred update for the key is applied, else the entry stays. testTransientTilingFacadeReleasedMaster releases the master by a desktop removal, a key conflict and a move by hand. It pins the refusals (another provider, an unanswered configure, the automatic rectangle), the settlement, the memory's entry and a second session on the same window. testTransientTilingFacadeKeyConflict still pins that the release alone restores nothing. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 185 ++++++++++++++++++ src/scripting/transienttilingapi.cpp | 8 + src/scripting/transienttilingapi.h | 13 ++ src/window.cpp | 47 +++++ src/window.h | 24 +++ src/xdgshellwindow.cpp | 7 + src/xdgshellwindow.h | 1 + 7 files changed, 285 insertions(+) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 9a3ef203cd..592f81017e 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -403,6 +403,8 @@ private Q_SLOTS: void testTransientTilingFacadeClosedSibling(); void testTransientTilingFacadeMasterClosed(); void testTransientTilingFacadeKeyConflict(); + void testTransientTilingFacadeReleasedMaster_data(); + void testTransientTilingFacadeReleasedMaster(); void testTransientTilingFacadeProviderKeepsRecording_data(); void testTransientTilingFacadeProviderKeepsRecording(); void testControllerProviderRecordDuringApplication(); @@ -10527,6 +10529,13 @@ struct TilingFacade return QMetaObject::invokeMethod(api, "restoreWindow", Q_ARG(Window *, window)); } + int settleWindow(Window *window, const QString &token) const + { + int result = notCallable; + QMetaObject::invokeMethod(api, "settleWindow", Q_RETURN_ARG(int, result), Q_ARG(Window *, window), Q_ARG(QString, token)); + return result; + } + QRectF masterWindowRect() const { QRectF rect; @@ -11001,6 +11010,182 @@ void TestXdgShellWindow::testTransientTilingFacadeKeyConflict() QCOMPARE(facade.releaseTile(again.value(QStringLiteral("generation")).toInt()), int(TransientTileController::Result::Accepted)); } +void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() +{ + QTest::addColumn("release"); + QTest::newRow("desktop-removed") << 0; + QTest::newRow("key-conflict") << 1; + QTest::newRow("moved-by-hand") << 2; +} + +void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() +{ + // A release that is not the explicit restore is detach-only: the master stays where it + // stands and its record is held, which keeps the automatic rectangle out of the memory. + // Nothing native ever ended that record, so the window kept the tile's size and could not + // be admitted again until it closed (the ThinkPad after a desktop removal, a second window + // of the app, a move of the master). The policy ends it: it gives the window its floating + // frame back with an ordinary request, or leaves it where the user put it, and asks the + // facade to settle the record. The native layer does that only when the window's geometry + // is settled and the window no longer stands on the automatic rectangle. + QFETCH(int, release); + using Settle = Window::TransientSettleResult; + const TilingFacade facade; + QVERIFY(facade.api); + QVERIFY(!facade.hasTree()); + const auto releaseTree = qScopeGuard([&]() { + if (facade.hasTree()) { + facade.releaseTile(facade.generation()); + } + }); + auto desktops = VirtualDesktopManager::self(); + const auto restoreDesktops = qScopeGuard([desktops]() { + desktops->setCount(1); + }); + const QString key = QStringLiteral("org.example.facade.released.") + QString::fromLatin1(QTest::currentDataTag()); + std::unique_ptr surface(Test::createSurface()); + std::unique_ptr shell(Test::createXdgToplevelSurface(surface.get())); + shell->set_app_id(key); + QSignalSpy configure(shell->xdgSurface(), &Test::XdgSurface::configureRequested); + QSignalSpy toplevelConfigure(shell.get(), &Test::XdgToplevel::configureRequested); + Window *master = Test::renderAndWaitForShown(surface.get(), QSize(200, 100), Qt::red); + QVERIFY(master); + QVERIFY(!configure.isEmpty() || configure.wait()); + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + Test::render(surface.get(), QSize(200, 100), Qt::red); + QVERIFY(Test::waylandSync()); + // The client's side of a configure: acknowledge the newest one and commit its size (the + // size it has where the configure leaves the choice to it). + QSize committed(200, 100); + const auto follow = [&]() { + if (configure.isEmpty() && !configure.wait()) { + return false; + } + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + const QSize asked = toplevelConfigure.last().at(0).value(); + if (!asked.isEmpty()) { + committed = asked; + } + Test::render(surface.get(), committed, Qt::blue); + return Test::waylandSync(); + }; + auto toplevel = static_cast(master); + // Until nothing of the native geometry is in flight: a release, an activation or a + // deactivation each bring a configure of their own. + const auto answerAll = [&]() { + for (int i = 0; i < 6 && toplevel->hasPendingNativeGeometry(); ++i) { + if (!follow()) { + return false; + } + } + return !toplevel->hasPendingNativeGeometry(); + }; + const QRectF floating = master->frameGeometry(); + QObject provider; + const QString token = facade.registerProvider(&provider); + QVERIFY(!token.isEmpty()); + QVERIFY(facade.trackWindow(master)); + QCOMPARE(facade.record(token, 1, master, scriptRecord(floating), 1), int(TransientPlacementWriter::Result::Accepted)); + // Nothing to settle: no record, then an owned one. + QCOMPARE(facade.settleWindow(master, token), int(Settle::NotReleased)); + auto output = master->moveResizeOutput(); + desktops->setCount(2); + const auto first = desktops->currentDesktop(output); + const auto second = desktops->desktops().constLast(); + QVERIFY(first != second); + const QVariantMap tree = facade.createTile(output, first, QRectF(0, 0, 0.5, 1)); + QCOMPARE(tree.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); + QCOMPARE(facade.admitTile(tree.value(QStringLiteral("generation")).toInt(), master, token), int(TransientTileController::Result::Accepted)); + const QRectF managed = facade.masterWindowRect(); + QVERIFY(follow()); + QVERIFY(master->tile()); + QVERIFY2(exactFrame(master->frameGeometry(), managed), frameText(master->frameGeometry()).constData()); + QCOMPARE(facade.settleWindow(master, token), int(Settle::NotReleased)); + QVERIFY(master->m_transientOwnership); + + std::unique_ptr siblingSurface; + std::unique_ptr siblingShell; + QRectF expected = floating; + int revision = 1; + if (release == 0) { + desktops->setCurrent(second); + desktops->removeVirtualDesktop(first); + } else if (release == 1) { + siblingSurface = Test::createSurface(); + siblingShell = Test::createXdgToplevelSurface(siblingSurface.get()); + siblingShell->set_app_id(key); + Window *sibling = Test::renderAndWaitForShown(siblingSurface.get(), QSize(220, 120), Qt::green); + QVERIFY(sibling); + QVERIFY(facade.trackWindow(sibling)); + } else { + // The user's own move: the request itself releases the master, and its place wins. + expected = QRectF(300, 200, 260, 180); + master->moveResize(expected); + } + QTRY_VERIFY(!facade.hasTree()); + QVERIFY(master->m_transientOwnership); + QCOMPARE(master->m_transientOwnership->phase, Window::TransientOwnershipPhase::Restoring); + QVERIFY(!master->tile()); + + // Only the provider that admitted the window settles its record. + QCOMPARE(facade.settleWindow(master, QUuid::createUuid().toString()), int(Settle::StaleProvider)); + if (release != 2) { + // The release changed the window's states; until the client has answered that + // configure the geometry is not settled. + if (toplevel->hasPendingNativeGeometry()) { + QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); + QVERIFY(answerAll()); + } + // Settled, but still on the automatic rectangle: the record stays, the memory's + // barrier with it. + QVERIFY2(exactFrame(master->frameGeometry(), managed), frameText(master->frameGeometry()).constData()); + QCOMPARE(facade.settleWindow(master, token), int(Settle::AtManagedRectangle)); + QVERIFY(master->m_transientOwnership); + // The policy gives the window its floating frame back: an ordinary request. + master->moveResize(floating); + } + // The client has not answered the request yet. + QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); + QVERIFY(master->m_transientOwnership); + QVERIFY(answerAll()); + QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); + if (release == 2) { + // The provider records the place the user chose; the key is still reserved. + QCOMPARE(facade.record(token, ++revision, master, scriptRecord(expected), revision), int(TransientPlacementWriter::Result::Deferred)); + } + QSignalSpy settled(master, &Window::transientReleaseSettled); + QCOMPARE(facade.settleWindow(master, token), int(Settle::Settled)); + QCOMPARE(settled.count(), 1); + QVERIFY(!master->m_transientOwnership); + QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); + QVERIFY(exactFrame(facade.entry(key), scriptRecord(expected))); + QCOMPARE(facade.settleWindow(master, token), int(Settle::NotReleased)); + + // The window is free again: a new session admits it and the explicit restore returns it. + if (siblingSurface) { + siblingShell.reset(); + siblingSurface.reset(); + QVERIFY(Test::waylandSync()); + QTRY_COMPARE(workspace()->windows().count(), 1); + // The master is the active window again; the client answers that configure. + QTRY_COMPARE(workspace()->activeWindow(), master); + QVERIFY(answerAll()); + } + const auto desktop = desktops->currentDesktop(output); + const QVariantMap again = facade.createTile(output, desktop, QRectF(0, 0, 0.5, 1)); + QCOMPARE(again.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); + QCOMPARE(facade.admitTile(again.value(QStringLiteral("generation")).toInt(), master, token), int(TransientTileController::Result::Accepted)); + QVERIFY(follow()); + QVERIFY(master->tile()); + QVERIFY(facade.restoreWindow(master)); + QVERIFY(follow()); + QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); + QVERIFY(!master->m_transientOwnership); + QTRY_VERIFY(!facade.hasTree()); +} + void TestXdgShellWindow::testTransientTilingFacadeProviderKeepsRecording_data() { QTest::addColumn("moment"); diff --git a/src/scripting/transienttilingapi.cpp b/src/scripting/transienttilingapi.cpp index 68a3ebe815..44fba7f73c 100644 --- a/src/scripting/transienttilingapi.cpp +++ b/src/scripting/transienttilingapi.cpp @@ -228,6 +228,14 @@ void TransientTilingApi::restoreWindow(Window *window) } } +int TransientTilingApi::settleWindow(Window *window, const QString &providerToken) +{ + if (!m_workspace || !window || window->isDeleted()) { + return -1; + } + return static_cast(window->settleReleasedTransientOwnership(QUuid(providerToken))); +} + QRectF TransientTilingApi::masterWindowRect() const { auto controller = m_workspace ? m_workspace->transientTileController() : nullptr; diff --git a/src/scripting/transienttilingapi.h b/src/scripting/transienttilingapi.h index 53297d86c7..d27336c091 100644 --- a/src/scripting/transienttilingapi.h +++ b/src/scripting/transienttilingapi.h @@ -111,6 +111,19 @@ class TransientTilingApi : public QObject */ Q_INVOKABLE void restoreWindow(Window *window); + /** + * End the record of a window the native layer released without restoring it (a removed + * desktop or output, a second window of its app, a move of the window): the master the + * tiler has since given its floating frame back with an ordinary request, or one the user + * moved. The native layer settles it only for the provider that admitted the window, once + * the window's geometry is settled and it no longer stands on the automatic rectangle, so + * that rectangle never reaches the memory. Returns Window::TransientSettleResult: 0 + * settled (the window can be admitted again), 1 nothing to settle, 2 another provider's, + * 3 not settled yet (ask again after the client's next commit), 4 still on the automatic + * rectangle, 5 refused by the writer; -1 without a window. + */ + Q_INVOKABLE int settleWindow(Window *window, const QString &providerToken); + /** * The transient leaf's absolute window geometry (the master's placed rectangle, * including the tile padding and strut adjustments). diff --git a/src/window.cpp b/src/window.cpp index 55090e7622..c2b965d2fa 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -5247,6 +5247,48 @@ Window::TransientRestoreConsumption Window::consumeExplicitUntileOrRestore() return TransientRestoreConsumption::RestoreStopped; } +Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUuid &provider) +{ + if (isDeleted() || !m_transientOwnership) { + return TransientSettleResult::NotReleased; + } + const auto &ownership = *m_transientOwnership; + const auto generation = ownership.generation; + // A released record whose tile request was made; a live restoration completes at its own + // boundary (completeTransientRestoration), a superseded or cancelled one never does. + if (ownership.phase != TransientOwnershipPhase::Restoring || ownership.releasing || ownership.executing + || ownership.request || m_activeTransientRequest || m_requestedTransientTileGeneration + || ownership.progress != TransientRequestProgress::Requested + || (ownership.restoreAttempt && transientRestoreAttemptIsCurrent(generation, ownership.restoreAttempt->sequence))) { + return TransientSettleResult::NotReleased; + } + if (provider.isNull() || provider != ownership.provider || !ownership.writer || !ownership.writer->isProviderRegistered(provider) + || !ownership.writer->ownsRestoringReservation(internalId(), QString::number(generation))) { + return TransientSettleResult::StaleProvider; + } + // A maximized, full-screen or tiled window returns to the frame it had before, which for a + // released window is the automatic rectangle: its record waits for the ordinary state. + if (m_requestedTile || m_tile || !isTransientGeometrySettled()) { + return TransientSettleResult::Unsettled; + } + if (exactFrameGeometry(frameGeometry(), ownership.target) && !exactFrameGeometry(ownership.target, ownership.floating)) { + return TransientSettleResult::AtManagedRectangle; + } + if (ownership.writer->completeRestore(internalId(), QString::number(generation)) != TransientPlacementWriter::Result::Accepted) { + return TransientSettleResult::Refused; + } + ref(); + const auto lifetime = qScopeGuard([this]() { + unref(); + }); + // As after a completed restoration, the close cleanup stays connected: the writer forgets + // the tracked window at its destruction. + const RectF frame = frameGeometry(); + m_transientOwnership.reset(); + Q_EMIT transientReleaseSettled(QRectF(frame)); + return TransientSettleResult::Settled; +} + Window::TransientRestoreClaim Window::claimTransientRestoreWithMaximizeNormalization(quint64 generation) { return {}; @@ -5722,6 +5764,11 @@ bool Window::canStartTransientRestoreRequest(const RectF &target) const return false; } +bool Window::isTransientGeometrySettled() const +{ + return false; +} + bool Window::isTransientTileTargetFeasible(const RectF &target) const { return false; diff --git a/src/window.h b/src/window.h index caae1e39e3..440c03319c 100644 --- a/src/window.h +++ b/src/window.h @@ -1414,6 +1414,27 @@ class KWIN_EXPORT Window : public QObject NoStart, }; TransientRestoreConsumption consumeExplicitUntileOrRestore(); + /** + * The end of a released record that no explicit restoration will complete. A release that + * is not the explicit restore is detach-only: the window stays where it stands and its + * record (Restoring) keeps the automatic rectangle out of the placement memory. The policy + * that admitted the window ends that record once the window is somewhere else: back on its + * floating frame by the policy's own ordinary request, or where the user put it. Settled + * only for the provider that admitted the window, with no live restoration, in an ordinary + * mode outside every tile, with the native geometry settled (nothing scheduled, sent or + * acknowledged, the frame the requested geometry) and off the automatic rectangle; every + * other answer changes nothing. The writer finalizes as it does for a completed + * restoration: a deferred update for the key is applied, else the entry stays. + */ + enum class TransientSettleResult { + Settled, + NotReleased, + StaleProvider, + Unsettled, + AtManagedRectangle, + Refused, + }; + TransientSettleResult settleReleasedTransientOwnership(const QUuid &provider); /** * NT04's read-only state/completion contract. The state query reflects the native record * only - no protocol logging and no timeout participates - for the placement policy that @@ -1807,6 +1828,7 @@ protected Q_SLOTS: void readyForPaintingChanged(); void maximizeGeometryRestoreChanged(); void transientRestorationCompleted(const QRectF &restoredFrame); + void transientReleaseSettled(const QRectF &frame); void fullscreenGeometryRestoreChanged(); void offscreenRenderingChanged(); void targetScaleChanged(); @@ -2405,6 +2427,8 @@ protected Q_SLOTS: quint64 requestedTransientTileGeneration() const; void commitTileFromConfigure(Tile *tile, quint64 transientGeneration); virtual bool canStartTransientTileRequest(const RectF &target) const; + // Nothing of the native geometry is in flight and the frame is the requested geometry. + virtual bool isTransientGeometrySettled() const; virtual bool canStartTransientRestoreRequest(const RectF &target) const; virtual bool isTransientTileTargetFeasible(const RectF &target) const; // Backend hooks of requestMoveResizeForAssignment(). Support is consulted before any mutation; diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index d857084859..a0868eb1f5 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -945,6 +945,13 @@ bool XdgToplevelWindow::canStartTransientTileRequest(const RectF &target) const return !hasPendingNativeGeometry() && !requestedTile() && !tile() && isTransientTileTargetFeasible(target); } +bool XdgToplevelWindow::isTransientGeometrySettled() const +{ + return m_isInitialized && readyForPainting() && !isInteractiveMoveResize() && !hasPendingNativeGeometry() + && !isFullScreen() && !isRequestedFullScreen() && maximizeMode() == MaximizeRestore && requestedMaximizeMode() == MaximizeRestore + && frameGeometry() == moveResizeGeometry(); // RectF: an exact comparison +} + bool XdgToplevelWindow::canStartTransientRestoreRequest(const RectF &target) const { // Pending admission geometry is allowed. Do not clear a pending configure gravity (one an diff --git a/src/xdgshellwindow.h b/src/xdgshellwindow.h index 4e07002fe0..33e613e047 100644 --- a/src/xdgshellwindow.h +++ b/src/xdgshellwindow.h @@ -239,6 +239,7 @@ class XdgToplevelWindow final : public XdgSurfaceWindow void doSetPreferredBufferTransform() override; void doSetPreferredColorDescription() override; bool canStartTransientTileRequest(const RectF &target) const override; + bool isTransientGeometrySettled() const override; bool canStartTransientRestoreRequest(const RectF &target) const override; bool isTransientTileTargetFeasible(const RectF &target) const override; bool supportsAssignmentGeometryRequest() const override; From 2068a3574e57c57af017ffbfbd30b4eb28237046 Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 12:26:55 -0500 Subject: [PATCH 04/10] Fit a window to a tile that is off its pixel grid A transient tile's rectangle is whole logical pixels. A frame is on the output's device pixels over a client size on the client's own grid, and at a fractional scale most whole rectangles are neither: at 133% only every third pixel is. Such a tile was refused (Ineligible), so tiling worked on the ThinkPad only because its master column, 714x858, happens to be on the grid; another master fraction or panel size would not be. The window now takes the tile's top-left corner and the largest size it reaches inside the tile (Window::transientTileFrame): the tile's rectangle where that is reachable, else the image of a size asked one device pixel smaller for as long as the image is larger than the tile. That frame is the request's target, the admission's and the rectangle an owned maximize or full screen returns to. A rectangle with nothing reachable inside it (the client's size limits) is still refused. The facade's masterWindowRect stays the tile's rectangle, the layout's boundary. A decoration that changes its borders when its window is tiled changes, in the middle of the admission, which sizes the client reaches. The request's frame stays current while it is at the tile's corner, inside the tile, short of it by no more than a fit is, and still reachable (isTransientTileFrame). The feasibility check compared sizes number by number. A size read back from a rectangle is the difference of two corners, and a frame's is a client size plus borders; where the output's pixel is not a binary fraction (0.8 at 125%, two thirds at 150%) either differs in its last bits from the number the grid gives. At 110%, 125%, 150% and 175% a window with a fractional frame was admitted to a tile and then refused its restoration, as its own floating frame read as unreachable; 133% and 200% are binary fractions and never showed it. Sizes are now compared as counts of the output's pixels. The settle operation's test for the automatic rectangle allows for the same last bits. testTransientRequestFractional pins the fit, its refusal below the client's minimum and the currency rule. A row of testTransientTilingFacadeFractionalScale tiles into a column that is off the grid. testTransientTilingFacadeScales runs two whole sessions at 100% to 200%, plain and decorated, on and off the grid. testTransientTilingFacadeReleasedMaster gains rows at 125%. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 285 ++++++++++++++++-- src/tiles/transienttilecontroller.cpp | 5 +- src/window.cpp | 28 +- src/window.h | 18 ++ src/xdgshellwindow.cpp | 107 ++++++- src/xdgshellwindow.h | 2 + 6 files changed, 403 insertions(+), 42 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 592f81017e..5dafd0e8c9 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -402,6 +402,8 @@ private Q_SLOTS: void testTransientTilingFacadeFractionalScale(); void testTransientTilingFacadeClosedSibling(); void testTransientTilingFacadeMasterClosed(); + void testTransientTilingFacadeScales_data(); + void testTransientTilingFacadeScales(); void testTransientTilingFacadeKeyConflict(); void testTransientTilingFacadeReleasedMaster_data(); void testTransientTilingFacadeReleasedMaster(); @@ -10395,14 +10397,33 @@ void TestXdgShellWindow::testTransientRequestConstraints() void TestXdgShellWindow::testTransientRequestFractional_data() { - QTest::addColumn("fits"); - QTest::newRow("snapped") << true; - QTest::newRow("nonrepresentable") << false; + QTest::addColumn("tileSize"); + QTest::addColumn("minimum"); + QTest::addColumn("frameSize"); + // The output's pixel is 0.8 logical pixels: a 200x100 tile is on it. + QTest::newRow("snapped") << QSizeF(200, 100) << QSize() << QSizeF(200, 100); + // 201x101 is not (251.25 x 126.25 device pixels). A client asked for 201x101 is 251x126 + // device pixels, a 200.8 x 100.8 frame: the largest the window reaches inside the tile. + QTest::newRow("off-the-pixel-grid") << QSizeF(201, 101) << QSize() << QSizeF(200.8, 100.8); + // One axis on the grid, the other not. + QTest::newRow("height-off-the-pixel-grid") << QSizeF(200, 101) << QSize() << QSizeF(200, 100.8); + // The client's own grid is a whole logical pixel. A 202-wide client is 252.5 device pixels, + // which is 253: a 202.4 frame, wider than the tile. The one that fits is 201 wide. + QTest::newRow("client-size-over-the-tile") << QSizeF(202, 100) << QSize() << QSizeF(200.8, 100); + // Nothing inside the tile is a size the client accepts: refused, as before. + QTest::newRow("below-the-minimum") << QSizeF(201, 101) << QSize(201, 101) << QSizeF(); } void TestXdgShellWindow::testTransientRequestFractional() { - QFETCH(bool, fits); + // A tile's rectangle is whole logical pixels, and on a fractional-scale output most of + // them are off the pixels a frame can have. The window is not refused for that: it takes + // the tile's corner and the largest size it can reach inside the tile, and that frame is + // the request's target. A rectangle with no reachable size inside it is still refused. + QFETCH(QSizeF, tileSize); + QFETCH(QSize, minimum); + QFETCH(QSizeF, frameSize); + const bool reachable = frameSize.isValid(); Test::OutputInfo output; output.geometry = Rect(0, 0, 1280, 1024); output.scale = 1.25; @@ -10410,22 +10431,53 @@ void TestXdgShellWindow::testTransientRequestFractional() workspace()->setActiveOutput(QPoint(100, 100)); std::unique_ptr surface(Test::createSurface()); std::unique_ptr shell(Test::createXdgToplevelSurface(surface.get())); + if (minimum.isValid()) { + shell->set_min_size(minimum.width(), minimum.height()); + } QSignalSpy configure(shell->xdgSurface(), &Test::XdgSurface::configureRequested); - Window *window = Test::renderAndWaitForShown(surface.get(), QSize(200, 100), Qt::red); + QSignalSpy toplevelConfigure(shell.get(), &Test::XdgToplevel::configureRequested); + Window *window = Test::renderAndWaitForShown(surface.get(), QSize(220, 120), Qt::red); QVERIFY(window); QVERIFY(!configure.isEmpty() || configure.wait()); shell->xdgSurface()->ack_configure(configure.last().at(0).value()); - Test::render(surface.get(), QSize(200, 100), Qt::red); + configure.clear(); + Test::render(surface.get(), QSize(220, 120), Qt::red); QVERIFY(Test::waylandSync()); QCOMPARE(window->nextTargetScale(), 1.25); RequestTestTile tile(window); - tile.setTargetForTest(RectF(100, 100, fits ? 200 : 201, fits ? 100 : 101)); - QCOMPARE(window->isTransientTileTargetFeasible(tile.windowGeometry()), fits); + const RectF rectangle(QPointF(100, 100), tileSize); + tile.setTargetForTest(rectangle); + const RectF frame = window->transientTileFrame(tile.windowGeometry()); + const bool onGrid = frameSize == tileSize; + QCOMPARE(window->isTransientTileTargetFeasible(tile.windowGeometry()), onGrid); + QCOMPARE(window->isTransientTileTargetFeasible(frame), reachable); + // RectF compares exactly. Without a fit it is the rectangle itself, which is refused. + QCOMPARE(frame, reachable ? RectF(QPointF(100, 100), frameSize) : rectangle); + // The fit is the tile's frame. So is a fit under other borders, a size of the client or + // two below it (a 200x100 client is 250x125 device pixels, inside every tile here and + // within a step of the client's grid and two device pixels of it); nothing at another + // corner, larger than the tile or further inside. + QVERIFY(window->isTransientTileFrame(frame, rectangle)); + QVERIFY(window->isTransientTileFrame(RectF(100, 100, 200, 100), rectangle)); + QVERIFY(!window->isTransientTileFrame(RectF(100.8, 100, 200, 100), rectangle)); + QVERIFY(!window->isTransientTileFrame(RectF(100, 100, 203.2, 100), rectangle)); + QVERIFY(!window->isTransientTileFrame(RectF(100, 100, 196.8, 100), rectangle)); + QVERIFY(!window->isTransientTileFrame(RectF(100, 100, 200, 96.8), rectangle)); QObject owner; auto authority = std::make_shared(); authority->owner = &owner; const auto receipt = window->requestTransientTile(std::make_unique(window, &tile, authority)); - QCOMPARE(receipt.outcome, fits ? Window::TransientRequestOutcome::Applied : Window::TransientRequestOutcome::Rejected); + QCOMPARE(receipt.outcome, reachable ? Window::TransientRequestOutcome::Applied : Window::TransientRequestOutcome::Rejected); + if (!reachable) { + return; + } + // The request is for the fitted frame, and the client's commit lands on it exactly. + QCOMPARE(window->moveResizeGeometry(), frame); + QVERIFY(!configure.isEmpty() || configure.wait()); + shell->xdgSurface()->ack_configure(configure.last().at(0).value()); + Test::render(surface.get(), toplevelConfigure.last().at(0).value(), Qt::blue); + QVERIFY(Test::waylandSync()); + QCOMPARE(window->frameGeometry(), frame); } void TestXdgShellWindow::testTransientRequestDecorated() @@ -10689,17 +10741,30 @@ void TestXdgShellWindow::testTransientTilingFacadeFractionalScale_data() QTest::addColumn("client"); QTest::addColumn("floating"); QTest::addColumn("request"); + QTest::addColumn("relative"); + QTest::addColumn("tile"); + QTest::addColumn("managed"); + // A quarter of the output: 600x450 less the tile padding, both on the output's pixel grid. + const QRectF quarter(0, 0, 0.5, 0.5); + const QRectF onGrid(4, 4, 594, 444); // The output's pixel is 0.75 logical pixels. A title bar a decoration snapped to it (50.25, // 67 device pixels) over a 241-high client is a whole 291-high frame over a fractional client // (240.75); a 361-wide client is 481 device pixels, a 360.75-wide frame. - QTest::newRow("title-bar") << true << QSize(360, 241) << QRectF(102, 102, 360, 291) << QRectF(); - QTest::newRow("fractional-frame") << false << QSize(361, 240) << QRectF(102, 102, 360.75, 240) << QRectF(); - QTest::newRow("title-bar-fractional-frame") << true << QSize(361, 240) << QRectF(102, 102, 360.75, 290.25) << QRectF(); + QTest::newRow("title-bar") << true << QSize(360, 241) << QRectF(102, 102, 360, 291) << QRectF() << quarter << onGrid << onGrid; + QTest::newRow("fractional-frame") << false << QSize(361, 240) << QRectF(102, 102, 360.75, 240) << QRectF() << quarter << onGrid << onGrid; + QTest::newRow("title-bar-fractional-frame") << true << QSize(361, 240) << QRectF(102, 102, 360.75, 290.25) << QRectF() << quarter << onGrid << onGrid; // A script places the window first, in whole pixels: the image of the frame it has, where // it is or elsewhere. The client's size is already that one, so no configure follows. - QTest::newRow("whole-pixel-request") << true << QSize(361, 240) << QRectF(102, 102, 360.75, 290.25) << QRectF(102, 102, 361, 290); - QTest::newRow("whole-pixel-move") << true << QSize(361, 240) << QRectF(102, 102, 360.75, 290.25) << QRectF(132, 123, 361, 290); - QTest::newRow("whole-pixel-move-without-a-title-bar") << false << QSize(361, 240) << QRectF(102, 102, 360.75, 240) << QRectF(132, 123, 361, 240); + QTest::newRow("whole-pixel-request") << true << QSize(361, 240) << QRectF(102, 102, 360.75, 290.25) << QRectF(102, 102, 361, 290) << quarter << onGrid << onGrid; + QTest::newRow("whole-pixel-move") << true << QSize(361, 240) << QRectF(102, 102, 360.75, 290.25) << QRectF(132, 123, 361, 290) << quarter << onGrid << onGrid; + QTest::newRow("whole-pixel-move-without-a-title-bar") << false << QSize(361, 240) << QRectF(102, 102, 360.75, 240) << QRectF(132, 123, 361, 240) << quarter << onGrid << onGrid; + // A master column of 55% over the whole height: 654 wide is on the output's pixels (872), + // 892 high is not (1189.33). An 892-high client is 1189 device pixels, an 891.75-high + // frame: the window's in that tile. (Decorated windows in such a tile, at this and the + // other scales: testTransientTilingFacadeScales.) + const QRectF column(0, 0, 0.55, 1); + const QRectF offGrid(4, 4, 654, 892); + QTest::newRow("tile-off-the-pixel-grid") << false << QSize(361, 240) << QRectF(102, 102, 360.75, 240) << QRectF() << column << offGrid << QRectF(4, 4, 654, 891.75); } void TestXdgShellWindow::testTransientTilingFacadeFractionalScale() @@ -10711,6 +10776,9 @@ void TestXdgShellWindow::testTransientTilingFacadeFractionalScale() QFETCH(QSize, client); QFETCH(QRectF, floating); QFETCH(QRectF, request); + QFETCH(QRectF, relative); + QFETCH(QRectF, tile); + QFETCH(QRectF, managed); Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1200, 900), .scale = 4.0 / 3.0}}); workspace()->setActiveOutput(QPoint(100, 100)); const TilingFacade facade; @@ -10788,19 +10856,19 @@ void TestXdgShellWindow::testTransientTilingFacadeFractionalScale() auto output = window->moveResizeOutput(); auto desktop = VirtualDesktopManager::self()->currentDesktop(output); - // A quarter of the output: 600x450 less the tile padding, both on the output's pixel grid. - const QRectF quarter(0, 0, 0.5, 0.5); - const QRectF managed(4, 4, 594, 444); - const QVariantMap tree = facade.createTile(output, desktop, quarter); + // The tile's rectangle is the layout's, in whole pixels; the window's frame in it is the + // largest it reaches there: the rectangle itself where that is on the window's pixel grid. + const QVariantMap tree = facade.createTile(output, desktop, relative); QCOMPARE(tree.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); QVERIFY(tree.value(QStringLiteral("generation")).toInt() > 0); - QVERIFY2(exactFrame(facade.masterWindowRect(), managed), frameText(facade.masterWindowRect()).constData()); + QVERIFY2(exactFrame(facade.masterWindowRect(), tile), frameText(facade.masterWindowRect()).constData()); QCOMPARE(facade.admitTile(tree.value(QStringLiteral("generation")).toInt(), window, token), int(TransientTileController::Result::Accepted)); QVERIFY(window->m_transientOwnership); QVERIFY(follow()); QVERIFY2(exactFrame(window->frameGeometry(), managed), frameText(window->frameGeometry()).constData()); QVERIFY(window->tile()); QVERIFY(window->m_transientOwnership); + QVERIFY2(exactFrame(facade.masterWindowRect(), tile), frameText(facade.masterWindowRect()).constData()); // The explicit restore for this window: the Window Restore action, addressed to the window. QSignalSpy treeChanged(facade.api, SIGNAL(treeChanged())); @@ -10815,7 +10883,7 @@ void TestXdgShellWindow::testTransientTilingFacadeFractionalScale() QVERIFY(exactFrame(facade.entry(key), scriptRecord(floating))); // Nothing of the first session is left on the window: it is admitted and restored again. - const QVariantMap again = facade.createTile(output, desktop, quarter); + const QVariantMap again = facade.createTile(output, desktop, relative); QCOMPARE(again.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); QCOMPARE(facade.admitTile(again.value(QStringLiteral("generation")).toInt(), window, token), int(TransientTileController::Result::Accepted)); QVERIFY(follow()); @@ -10827,6 +10895,151 @@ void TestXdgShellWindow::testTransientTilingFacadeFractionalScale() QTRY_VERIFY(!facade.hasTree()); } +void TestXdgShellWindow::testTransientTilingFacadeScales_data() +{ + QTest::addColumn("scale"); + QTest::addColumn("decorated"); + QTest::addColumn("client"); + QTest::addColumn("relative"); + // A master column of 55% over the whole height, 654x892 less nothing: off the pixels of + // every fractional scale here on at least one axis. + const QRectF column(0, 0, 0.55, 1); + // 600x400: on the pixels of 125%, 150% and 175%, so only the floating frame is fractional. + const QRectF onGrid(0, 0, 0.505, 406.0 / 900); + // The client sizes are the ones whose frame, stored as a rectangle's corners at 102,102, + // reads back a last bit away from the size on the pixel grid (a 101-high client at 125% + // is 126 device pixels, 100.8; 102 + 100.8 - 102 is not 100.8). + QTest::newRow("100%") << 1.0 << false << QSize(201, 101) << column; + QTest::newRow("110%") << 1.1 << false << QSize(201, 101) << column; + QTest::newRow("125%") << 1.25 << false << QSize(201, 101) << column; + QTest::newRow("125%-tile-on-the-pixel-grid") << 1.25 << false << QSize(201, 101) << onGrid; + QTest::newRow("125%-title-bar") << 1.25 << true << QSize(361, 241) << column; + QTest::newRow("133%") << 4.0 / 3.0 << false << QSize(201, 101) << column; + QTest::newRow("150%") << 1.5 << false << QSize(201, 101) << column; + QTest::newRow("150%-tile-on-the-pixel-grid") << 1.5 << false << QSize(201, 101) << onGrid; + QTest::newRow("150%-title-bar") << 1.5 << true << QSize(361, 241) << column; + QTest::newRow("150%-title-bar-tile-on-the-pixel-grid") << 1.5 << true << QSize(361, 241) << onGrid; + QTest::newRow("175%") << 1.75 << false << QSize(201, 101) << column; + QTest::newRow("175%-title-bar") << 1.75 << true << QSize(361, 241) << column; + QTest::newRow("200%") << 2.0 << false << QSize(201, 101) << column; +} + +void TestXdgShellWindow::testTransientTilingFacadeScales() +{ + // A whole session at each scale: admitted to the tile, restored to the exact floating + // frame, admitted again. At 133% and 200% the output's pixel is a binary fraction and + // every size on its grid is an exact number; at 110%, 125%, 150% and 175% it is not, and a + // size read back from a rectangle or put together from a client size and borders differs + // from the grid's in its last bit. Nothing may be refused or left unfinished for that. + QFETCH(qreal, scale); + QFETCH(bool, decorated); + QFETCH(QSize, client); + QFETCH(QRectF, relative); + Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1200, 900), .scale = scale}}); + workspace()->setActiveOutput(QPoint(100, 100)); + const TilingFacade facade; + QVERIFY(facade.api); + QVERIFY(!facade.hasTree()); + const auto releaseTree = qScopeGuard([&]() { + if (facade.hasTree()) { + facade.releaseTile(facade.generation()); + } + }); + const QString key = QStringLiteral("org.example.facade.scale.") + QString::fromLatin1(QTest::currentDataTag()).remove(QLatin1Char('%')); + std::unique_ptr surface(Test::createSurface()); + std::unique_ptr shell(Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly)); + shell->set_app_id(key); + std::unique_ptr decoration; + if (decorated) { + decoration = Test::createXdgToplevelDecorationV1(shell.get()); + decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side); + } + QSignalSpy configure(shell->xdgSurface(), &Test::XdgSurface::configureRequested); + QSignalSpy toplevelConfigure(shell.get(), &Test::XdgToplevel::configureRequested); + QSize committed = client; + // The client's side of a configure: acknowledge the newest one and commit its size (the + // size it has where the configure leaves the choice to it). + const auto follow = [&]() { + if (configure.isEmpty() && !configure.wait()) { + return false; + } + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + const QSize asked = toplevelConfigure.last().at(0).value(); + if (!asked.isEmpty()) { + committed = asked; + } + Test::render(surface.get(), committed, Qt::blue); + return Test::waylandSync(); + }; + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(configure.wait()); + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + Window *window = Test::renderAndWaitForShown(surface.get(), client, Qt::blue); + QVERIFY(window); + QCOMPARE(window->isDecorated(), decorated); + QVERIFY(follow()); + // The decoration's own borders, which it keeps when its window is tiled. + const QMarginsF borders = decorated ? window->nextDecoration()->nextState()->borders() : QMarginsF(); + QCOMPARE(borders.top() > 0, decorated); + auto toplevel = static_cast(window); + const auto answerAll = [&]() { + for (int i = 0; i < 6 && toplevel->hasPendingNativeGeometry(); ++i) { + if (!follow()) { + return false; + } + } + return !toplevel->hasPendingNativeGeometry(); + }; + window->move(QPointF(102, 102)); + QVERIFY(answerAll()); + QCOMPARE(window->nextTargetScale(), scale); + const QRectF floating = window->frameGeometry(); + QCOMPARE(floating.topLeft(), QPointF(102, 102)); + QVERIFY2(exactFrame(window->moveResizeGeometry(), floating), frameText(window->moveResizeGeometry()).constData()); + + QObject provider; + const QString token = facade.registerProvider(&provider); + QVERIFY(!token.isEmpty()); + QVERIFY(facade.trackWindow(window)); + QCOMPARE(facade.record(token, 1, window, scriptRecord(floating), 1), int(TransientPlacementWriter::Result::Accepted)); + + auto output = window->moveResizeOutput(); + auto desktop = VirtualDesktopManager::self()->currentDesktop(output); + for (int session = 0; session < 2; ++session) { + const QVariantMap tree = facade.createTile(output, desktop, relative); + QCOMPARE(tree.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); + const QRectF tile = facade.masterWindowRect(); + QCOMPARE(facade.admitTile(tree.value(QStringLiteral("generation")).toInt(), window, token), int(TransientTileController::Result::Accepted)); + QVERIFY(window->m_transientOwnership); + QVERIFY(follow()); + QVERIFY(answerAll()); + // In the tile: its corner, and the largest size the client reaches inside it. One more + // step of the client's grid (a whole logical pixel here) would be over the tile. + const QRectF frame = window->frameGeometry(); + QVERIFY(window->tile()); + QVERIFY(window->m_transientOwnership); + QCOMPARE(frame.topLeft(), tile.topLeft()); + QVERIFY2(frame.width() <= tile.width() && frame.height() <= tile.height(), frameText(frame).constData()); + QCOMPARE(decorated ? window->nextDecoration()->nextState()->borders() : QMarginsF(), borders); + QVERIFY2(borders.left() + borders.right() + std::round((committed.width() + 1) * scale) / scale > tile.width(), frameText(frame).constData()); + QVERIFY2(borders.top() + borders.bottom() + std::round((committed.height() + 1) * scale) / scale > tile.height(), frameText(frame).constData()); + QVERIFY2(exactFrame(frame, QRectF(window->transientTileFrame(RectF(tile)))), frameText(frame).constData()); + QVERIFY2(exactFrame(window->moveResizeGeometry(), frame), frameText(window->moveResizeGeometry()).constData()); + + // The explicit restore: the exact floating frame, the record's end and the tree's. + QVERIFY(facade.restoreWindow(window)); + QVERIFY(follow()); + QVERIFY(answerAll()); + QVERIFY2(exactFrame(window->frameGeometry(), floating), frameText(window->frameGeometry()).constData()); + QVERIFY(!window->tile()); + QVERIFY(!window->m_transientOwnership); + QTRY_VERIFY(!facade.hasTree()); + QVERIFY(exactFrame(facade.entry(key), scriptRecord(floating))); + } +} + void TestXdgShellWindow::testTransientTilingFacadeClosedSibling() { // The provider tracks every window it watches, and a key has one window at a reservation. @@ -11013,9 +11226,16 @@ void TestXdgShellWindow::testTransientTilingFacadeKeyConflict() void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() { QTest::addColumn("release"); - QTest::newRow("desktop-removed") << 0; - QTest::newRow("key-conflict") << 1; - QTest::newRow("moved-by-hand") << 2; + QTest::addColumn("scale"); + QTest::addColumn("client"); + QTest::newRow("desktop-removed") << 0 << 1.0 << QSize(200, 100); + QTest::newRow("key-conflict") << 1 << 1.0 << QSize(200, 100); + QTest::newRow("moved-by-hand") << 2 << 1.0 << QSize(200, 100); + // The output's pixel is 0.8: the floating frame is 200.8x100.8 and the tile's rectangle + // (634 wide, 792.5 device pixels) is off the grid, so the automatic rectangle is the + // window's fit in it and none of the frames is a binary fraction. + QTest::newRow("desktop-removed-at-125%") << 0 << 1.25 << QSize(201, 101); + QTest::newRow("moved-by-hand-at-125%") << 2 << 1.25 << QSize(201, 101); } void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() @@ -11029,7 +11249,13 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() // facade to settle the record. The native layer does that only when the window's geometry // is settled and the window no longer stands on the automatic rectangle. QFETCH(int, release); + QFETCH(qreal, scale); + QFETCH(QSize, client); using Settle = Window::TransientSettleResult; + if (scale != 1.0) { + Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1280, 1024), .scale = scale}}); + workspace()->setActiveOutput(QPoint(100, 100)); + } const TilingFacade facade; QVERIFY(facade.api); QVERIFY(!facade.hasTree()); @@ -11048,16 +11274,17 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() shell->set_app_id(key); QSignalSpy configure(shell->xdgSurface(), &Test::XdgSurface::configureRequested); QSignalSpy toplevelConfigure(shell.get(), &Test::XdgToplevel::configureRequested); - Window *master = Test::renderAndWaitForShown(surface.get(), QSize(200, 100), Qt::red); + Window *master = Test::renderAndWaitForShown(surface.get(), client, Qt::red); QVERIFY(master); QVERIFY(!configure.isEmpty() || configure.wait()); shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); configure.clear(); - Test::render(surface.get(), QSize(200, 100), Qt::red); + Test::render(surface.get(), client, Qt::red); QVERIFY(Test::waylandSync()); + QCOMPARE(master->nextTargetScale(), scale); // The client's side of a configure: acknowledge the newest one and commit its size (the // size it has where the configure leaves the choice to it). - QSize committed(200, 100); + QSize committed = client; const auto follow = [&]() { if (configure.isEmpty() && !configure.wait()) { return false; @@ -11098,7 +11325,9 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() const QVariantMap tree = facade.createTile(output, first, QRectF(0, 0, 0.5, 1)); QCOMPARE(tree.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); QCOMPARE(facade.admitTile(tree.value(QStringLiteral("generation")).toInt(), master, token), int(TransientTileController::Result::Accepted)); - const QRectF managed = facade.masterWindowRect(); + // The automatic rectangle: the window's frame in the tile. + const QRectF managed(master->transientTileFrame(RectF(facade.masterWindowRect()))); + QCOMPARE(exactFrame(managed, facade.masterWindowRect()), scale == 1.0); QVERIFY(follow()); QVERIFY(master->tile()); QVERIFY2(exactFrame(master->frameGeometry(), managed), frameText(master->frameGeometry()).constData()); diff --git a/src/tiles/transienttilecontroller.cpp b/src/tiles/transienttilecontroller.cpp index 482abcde41..545c75e5fe 100644 --- a/src/tiles/transienttilecontroller.cpp +++ b/src/tiles/transienttilecontroller.cpp @@ -582,7 +582,8 @@ bool TransientTileController::admissionCurrent(Window *window, quint64 generatio if (m_ownershipGeneration) { const auto &ownership = *window->m_transientOwnership; if (!window->transientProviderIsCurrent(ownership) - || !sameFrame(ownership.target, m_tile->windowGeometry()) || !window->isTransientTileTargetFeasible(ownership.target)) { + || !window->isTransientTileFrame(ownership.target, m_tile->windowGeometry()) + || !window->isTransientTileTargetFeasible(ownership.target)) { return false; } if (ownership.progress == Window::TransientRequestProgress::NoRequest @@ -616,7 +617,7 @@ TransientTileController::Result TransientTileController::admit(quint64 generatio // then the headroom for the whole synchronous path and its failure cleanup, a known shortage // refused rather than superseded after a write. if (!window || !writer || !activity || key.isEmpty() || placementKey(window) != key || !freeOfNativeMembership(window) - || !window->transientAdmissionEligible(m_tile->windowGeometry())) { + || !window->transientAdmissionEligible(window->transientTileFrame(m_tile->windowGeometry()))) { return Result::Ineligible; } if (!window->transientAdmissionHeadroom()) { diff --git a/src/window.cpp b/src/window.cpp index c2b965d2fa..58c19ad91e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -68,6 +68,17 @@ bool exactFrameGeometry(const RectF &left, const RectF &right) return left.x() == right.x() && left.y() == right.y() && left.width() == right.width() && left.height() == right.height(); } +// The same frame up to the arithmetic's last bits. Where an output's pixel is not a binary +// fraction (125%, 150%), the frame a commit publishes and the rectangle that was asked for can +// differ there; frames that are different on any output differ by far more. +bool sameFrameGeometry(const RectF &left, const RectF &right) +{ + const auto same = [](qreal a, qreal b) { + return std::abs(a - b) < 1.0 / 1024; + }; + return same(left.x(), right.x()) && same(left.y(), right.y()) && same(left.width(), right.width()) && same(left.height(), right.height()); +} + quint64 nextAssociationChange(quint64 current) { // Saturate rather than allowing an old pending notification to match a wrapped identity. @@ -4959,7 +4970,8 @@ Window::TransientTileRequest::TransientTileRequest(Window *window, Tile *tile, q , m_initialGeometryGeneration(window ? window->geometryRequestGeneration() : 0) { if (m_tile && m_manager && m_output && m_desktop) { - m_target = m_tile->windowGeometry(); + // The window's frame in the tile: the tile's rectangle where the window reaches it. + m_target = window ? window->transientTileFrame(m_tile->windowGeometry()) : m_tile->windowGeometry(); } } @@ -5271,7 +5283,7 @@ Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUu if (m_requestedTile || m_tile || !isTransientGeometrySettled()) { return TransientSettleResult::Unsettled; } - if (exactFrameGeometry(frameGeometry(), ownership.target) && !exactFrameGeometry(ownership.target, ownership.floating)) { + if (sameFrameGeometry(frameGeometry(), ownership.target) && !sameFrameGeometry(ownership.target, ownership.floating)) { return TransientSettleResult::AtManagedRectangle; } if (ownership.writer->completeRestore(internalId(), QString::number(generation)) != TransientPlacementWriter::Result::Accepted) { @@ -5774,6 +5786,16 @@ bool Window::isTransientTileTargetFeasible(const RectF &target) const return false; } +RectF Window::transientTileFrame(const RectF &tile) const +{ + return tile; +} + +bool Window::isTransientTileFrame(const RectF &frame, const RectF &tile) const +{ + return exactFrameGeometry(frame, transientTileFrame(tile)); +} + bool Window::transientRequestTargetIsCurrent(const TransientTileRequest &request) const { if (request.m_window != this || !request.m_tile || !request.m_manager || !request.m_output || !request.m_desktop @@ -5785,7 +5807,7 @@ bool Window::transientRequestTargetIsCurrent(const TransientTileRequest &request || moveResizeOutput() != request.m_output || !request.m_tile->isActive() || !isOnDesktop(request.m_desktop)) { return false; } - return exactFrameGeometry(request.m_target, request.m_tile->windowGeometry()) + return isTransientTileFrame(request.m_target, request.m_tile->windowGeometry()) && request.m_output->geometryF().contains(request.m_target) && isTransientTileTargetFeasible(request.m_target); } diff --git a/src/window.h b/src/window.h index 440c03319c..cfbc91da75 100644 --- a/src/window.h +++ b/src/window.h @@ -2431,6 +2431,24 @@ protected Q_SLOTS: virtual bool isTransientGeometrySettled() const; virtual bool canStartTransientRestoreRequest(const RectF &target) const; virtual bool isTransientTileTargetFeasible(const RectF &target) const; + /** + * The frame this window takes in a transient tile. A tile's rectangle is whole logical + * pixels; a frame is on the output's device pixels over a client size on the client's own + * grid, and at a fractional scale most whole rectangles are neither. The window takes the + * tile's top-left corner and the largest size it reaches inside the tile, which is the + * rectangle itself where that is reachable. A rectangle nothing inside which is reachable + * is returned as it is, and refused where its feasibility is checked. + */ + virtual RectF transientTileFrame(const RectF &tile) const; + /** + * Whether @p frame is a frame this window takes in a tile of rectangle @p tile: the one + * transientTileFrame() gives now, or one it gave under other borders. A decoration that + * changes its borders when its window is tiled changes, in the middle of the admission, + * which sizes the client reaches; the request's frame is then still at the tile's corner + * and inside the tile, short of it by no more than a fit ever is. Reachability is the + * caller's separate check (isTransientTileTargetFeasible). + */ + virtual bool isTransientTileFrame(const RectF &frame, const RectF &tile) const; // Backend hooks of requestMoveResizeForAssignment(). Support is consulted before any mutation; // a dispatcher reports what it staged or published through the stack-bound request. virtual bool supportsAssignmentGeometryRequest() const; diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index a0868eb1f5..91805308cd 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -53,6 +53,23 @@ namespace KWin static bool changeMaximizeRecursion = false; static bool isFiniteExtent(const RectF &rect); +// Whether two logical lengths are the same number of an output's pixels. A size read back from +// a rectangle is the difference of two corners, and a frame's size is a client size plus its +// borders: wherever the output's pixel is not a binary fraction (0.8 at 125%, two thirds at +// 150%) either differs in its last bits from the number the pixel grid itself gives, and an +// exact comparison of the two refuses a frame the window has had all along. Sizes that are +// different on the grid differ by a whole pixel; the tolerance is far below that and far above +// the arithmetic's noise. +static bool samePixels(qreal left, qreal right, qreal scale) +{ + return std::abs(left - right) * scale < 1.0 / 1024; +} + +static bool samePixels(const QSizeF &left, const QSizeF &right, qreal scale) +{ + return samePixels(left.width(), right.width(), scale) && samePixels(left.height(), right.height(), scale); +} + XdgSurfaceWindow::XdgSurfaceWindow(XdgSurfaceInterface *shellSurface) : WaylandWindow(shellSurface->surface()) , m_shellSurface(shellSurface) @@ -980,6 +997,76 @@ bool XdgToplevelWindow::isTransientTileTargetFeasible(const RectF &target) const return isTransientRestoreFrameFeasible(target); } +RectF XdgToplevelWindow::transientTileFrame(const RectF &tile) const +{ + if (isDeleted() || !surface() || isTransientRestoreFrameFeasible(tile)) { + return tile; + } + const qreal scale = nextTargetScale(); + const qreal clientScale = surface()->serverScale() * surface()->compositorToClientScale(); + for (qreal value : {tile.x(), tile.y(), tile.width(), tile.height(), scale, clientScale}) { + if (!std::isfinite(value)) { + return tile; + } + } + if (tile.width() <= 0 || tile.height() <= 0 || scale <= 0 || clientScale <= 0) { + return tile; + } + // The size a request for the tile would publish is the tile's size taken to the output's + // pixels, to the client's grid and back (dispatchMoveResize, then the commit), and each of + // those roundings can go up: a 892-high tile at 133% under a 50.25 title bar asks the + // client for 842, which commits a 892.5-high frame. So the size is asked one device pixel + // smaller on an axis for as long as its image is larger than the tile there. An image is + // at most half a step of the client's grid and one device pixel over what was asked, which + // bounds the steps and keeps the fit within a step of that grid and two device pixels of + // the tile. + // Counted in whole device pixels, so that every step is one of the grid's own numbers. + const int steps = int(std::ceil(scale / clientScale)) + 2; + qreal width = std::round(tile.width() * scale); + qreal height = std::round(tile.height() * scale); + for (int step = 0; step <= steps && width > 0 && height > 0; ++step) { + const QSizeF client = surface()->snappedSize(nextFrameSizeToClientSize(QSizeF(width / scale, height / scale))); + const QSizeF image = nextClientSizeToFrameSize(snapToPixels(client, scale)); + const bool wide = image.width() > tile.width() && !samePixels(image.width(), tile.width(), scale); + const bool tall = image.height() > tile.height() && !samePixels(image.height(), tile.height(), scale); + if (!wide && !tall) { + // Inside the tile; reachable unless the client's limits or a grid coarser than + // the client's (a scale below one) say otherwise, and then nothing smaller is. + const RectF frame(tile.topLeft(), image); + return isTransientRestoreFrameFeasible(frame) ? frame : tile; + } + if (wide) { + --width; + } + if (tall) { + --height; + } + } + return tile; +} + +bool XdgToplevelWindow::isTransientTileFrame(const RectF &frame, const RectF &tile) const +{ + if (Window::isTransientTileFrame(frame, tile)) { + return true; + } + if (isDeleted() || !surface() || frame.x() != tile.x() || frame.y() != tile.y()) { + return false; + } + const qreal scale = nextTargetScale(); + const qreal clientScale = surface()->serverScale() * surface()->compositorToClientScale(); + if (!std::isfinite(scale) || !std::isfinite(clientScale) || scale <= 0 || clientScale <= 0) { + return false; + } + // A fit is short of its tile by less than a step of the client's grid and two device + // pixels on an axis (transientTileFrame). + const qreal slack = 1 / clientScale + 2 / scale; + const auto fits = [scale, slack](qreal size, qreal extent) { + return (size <= extent || samePixels(size, extent, scale)) && extent - size < slack; + }; + return fits(frame.width(), tile.width()) && fits(frame.height(), tile.height()); +} + bool XdgToplevelWindow::isTransientRestoreFrameFeasible(const RectF &target) const { for (qreal value : {target.x(), target.y(), target.width(), target.height()}) { @@ -990,12 +1077,14 @@ bool XdgToplevelWindow::isTransientRestoreFrameFeasible(const RectF &target) con if (target.width() <= 0 || target.height() <= 0) { return false; } - const auto constrained = constrainFrameSize(target.size()); - if (constrained.width() != target.width() || constrained.height() != target.height()) { + // Every comparison here is of sizes on the output's pixels (samePixels): the target's is + // read back from a rectangle, the others are computed on the grid. + const qreal scale = nextTargetScale(); + if (!samePixels(constrainFrameSize(target.size()), target.size(), scale)) { return false; } - const auto snappedFrame = snapToPixels(target.size(), nextTargetScale()); - if (snappedFrame.width() != target.width() || snappedFrame.height() != target.height()) { + const auto snappedFrame = snapToPixels(target.size(), scale); + if (!samePixels(snappedFrame, target.size(), scale)) { return false; } // The size a configure can carry is on the client's own grid (whole logical pixels without @@ -1005,8 +1094,8 @@ bool XdgToplevelWindow::isTransientRestoreFrameFeasible(const RectF &target) con // snapped back to the output's pixels and decorated again - which is the path a geometry // request takes (moveResizeInternal, then the commit's clientGeometry). const auto client = surface()->snappedSize(nextFrameSizeToClientSize(snappedFrame)); - const auto roundTrip = nextClientSizeToFrameSize(snapToPixels(client, nextTargetScale())); - return roundTrip.width() == target.width() && roundTrip.height() == target.height(); + const auto roundTrip = nextClientSizeToFrameSize(snapToPixels(client, scale)); + return samePixels(roundTrip, target.size(), scale); } std::function XdgToplevelWindow::transientRestoreStateConstraint(const RectF &target, bool normalizeMaximize, bool geometryReady) const @@ -1116,7 +1205,7 @@ Window::TransientRestoreClaim XdgToplevelWindow::claimTransientRestoreWithMaximi return {}; } } else if (!isFiniteExtent(target) || target.width() < minSize().width() || target.height() < minSize().height() - || snapToPixels(target.size(), nextTargetScale()) != target.size()) { + || !samePixels(snapToPixels(target.size(), nextTargetScale()), target.size(), nextTargetScale())) { // Maximized or fullscreen borders are not the borders that A will use. These are only necessary // checks; exact frame/client feasibility follows the same-decoration response. return {}; @@ -2390,7 +2479,7 @@ std::optional XdgToplevelWindow::ownedFullSc if (!transientOwnershipIsCurrent(generation)) { return std::nullopt; } - const RectF managed = m_transientOwnership->tile->windowGeometry(); + const RectF managed = transientTileFrame(m_transientOwnership->tile->windowGeometry()); if (!isFiniteExtent(managed)) { return std::nullopt; } @@ -2722,7 +2811,7 @@ std::optional XdgToplevelWindow::ownedMaximize if (!transientOwnershipIsCurrent(generation)) { return std::nullopt; } - const RectF managed = m_transientOwnership->tile->windowGeometry(); + const RectF managed = transientTileFrame(m_transientOwnership->tile->windowGeometry()); if (!ownedMaximizeFeasible(managed, mode, oldMode)) { return std::nullopt; } diff --git a/src/xdgshellwindow.h b/src/xdgshellwindow.h index 33e613e047..94bca37f80 100644 --- a/src/xdgshellwindow.h +++ b/src/xdgshellwindow.h @@ -242,6 +242,8 @@ class XdgToplevelWindow final : public XdgSurfaceWindow bool isTransientGeometrySettled() const override; bool canStartTransientRestoreRequest(const RectF &target) const override; bool isTransientTileTargetFeasible(const RectF &target) const override; + RectF transientTileFrame(const RectF &tile) const override; + bool isTransientTileFrame(const RectF &frame, const RectF &tile) const override; bool supportsAssignmentGeometryRequest() const override; private: From 66bac50d0676f6c1e1baa579f9182a75dd0eff22 Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 13:13:47 -0500 Subject: [PATCH 05/10] Settle a released record on evidence, land a request on its rectangle The settle operation refused only the rectangle recorded at the admission. A released window can stand on another automatic one. The workspace's re-check of a window's position (a panel, a strut, an output's size) asks a tiled window for its tile's rectangle with a public request, which releases the master and then puts it on the tile's rectangle as it is then; where the tile is off the pixel grid that is not the fit the window was admitted to. A transfer to another output carries the tile's size along. In each case the record would have been settled with the window on an automatic rectangle, and the next admission's reservation asks the provider to record that frame. The record now ends on positive evidence only: the window is on its floating frame, or the user's own interactive move or resize left it where it stands (a mark the record gets when such an operation ends without being cancelled). Any other frame answers AtManagedRectangle. The facade's floatingFrame(window) gives the record's floating frame, which follows the window to another output: where the policy returns a released master. A frame that answers a configure is put together where the window stands and then moved to the configure's place. On an output whose pixel is not a binary fraction its corners can be a last bit away from the rectangle the configure was sent for: a restoration from a tile at 542,362 came back 200.79999999999995 wide for a floating frame of 200.8 at 125%. The configure's own rectangle is published where the frame is that rectangle on the output's pixels. ownedMaximizeFeasible and the minimum check of the restore from a maximized or full-screen state compared sizes number by number, as the feasibility check did: an owned unmaximize could fall to the legacy path and release the window on such an output. Both compare pixels now. The fit's step count is bounded whatever the scales are. testTransientTilingFacadeReleasedMaster: the user's move is a real interactive one (unsettled while it lasts), and new rows release the master by a script's request, the workspace's re-check (also at 125%, where it lands off the fit), a transfer to another output and a maximize after the release; none settles before the window is back on its floating frame. With the previous check three of them settle. A live restoration answers NotReleased. testTransientTilingFacadeScales: rows at 75% and with the tile away from the output's origin (six fail without the landing change), and a maximize round trip in the tile. testTransientTilingFacadeBordersChangeWhenTiled: a decoration that puts its own title bar back as the window is tiled, with a tile off the grid; the admission keeps the frame it was made for. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 326 ++++++++++++++++-- src/scripting/transienttilingapi.cpp | 8 + src/scripting/transienttilingapi.h | 26 +- src/tiles/transientplacementwriter.cpp | 4 + src/window.cpp | 24 +- src/window.h | 30 +- src/xdgshellwindow.cpp | 41 ++- 7 files changed, 397 insertions(+), 62 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 5dafd0e8c9..abc2bb56d5 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -404,6 +404,7 @@ private Q_SLOTS: void testTransientTilingFacadeMasterClosed(); void testTransientTilingFacadeScales_data(); void testTransientTilingFacadeScales(); + void testTransientTilingFacadeBordersChangeWhenTiled(); void testTransientTilingFacadeKeyConflict(); void testTransientTilingFacadeReleasedMaster_data(); void testTransientTilingFacadeReleasedMaster(); @@ -10588,6 +10589,13 @@ struct TilingFacade return result; } + QRectF floatingFrame(Window *window) const + { + QRectF frame; + QMetaObject::invokeMethod(api, "floatingFrame", Q_RETURN_ARG(QRectF, frame), Q_ARG(Window *, window)); + return frame; + } + QRectF masterWindowRect() const { QRectF rect; @@ -10906,10 +10914,24 @@ void TestXdgShellWindow::testTransientTilingFacadeScales_data() const QRectF column(0, 0, 0.55, 1); // 600x400: on the pixels of 125%, 150% and 175%, so only the floating frame is fractional. const QRectF onGrid(0, 0, 0.505, 406.0 / 900); + // The bottom-right 55% by 60%: 654x534 at 542,362. A frame that lands there is put + // together at the place the window came from and then moved, so its corners are other + // numbers than a frame's at the output's origin. + const QRectF corner(0.45, 0.4, 0.55, 0.6); // The client sizes are the ones whose frame, stored as a rectangle's corners at 102,102, // reads back a last bit away from the size on the pixel grid (a 101-high client at 125% // is 126 device pixels, 100.8; 102 + 100.8 - 102 is not 100.8). + QTest::newRow("75%") << 0.75 << false << QSize(201, 101) << column; + QTest::newRow("75%-tile-off-the-origin") << 0.75 << false << QSize(201, 101) << corner; QTest::newRow("100%") << 1.0 << false << QSize(201, 101) << column; + QTest::newRow("110%-tile-off-the-origin") << 1.1 << false << QSize(201, 101) << corner; + QTest::newRow("125%-tile-off-the-origin") << 1.25 << false << QSize(201, 101) << corner; + QTest::newRow("125%-title-bar-tile-off-the-origin") << 1.25 << true << QSize(361, 241) << corner; + QTest::newRow("133%-tile-off-the-origin") << 4.0 / 3.0 << false << QSize(201, 101) << corner; + QTest::newRow("150%-tile-off-the-origin") << 1.5 << false << QSize(201, 101) << corner; + QTest::newRow("150%-title-bar-tile-off-the-origin") << 1.5 << true << QSize(361, 241) << corner; + QTest::newRow("175%-tile-off-the-origin") << 1.75 << false << QSize(201, 101) << corner; + QTest::newRow("175%-title-bar-tile-off-the-origin") << 1.75 << true << QSize(361, 241) << corner; QTest::newRow("110%") << 1.1 << false << QSize(201, 101) << column; QTest::newRow("125%") << 1.25 << false << QSize(201, 101) << column; QTest::newRow("125%-tile-on-the-pixel-grid") << 1.25 << false << QSize(201, 101) << onGrid; @@ -10926,11 +10948,12 @@ void TestXdgShellWindow::testTransientTilingFacadeScales_data() void TestXdgShellWindow::testTransientTilingFacadeScales() { - // A whole session at each scale: admitted to the tile, restored to the exact floating - // frame, admitted again. At 133% and 200% the output's pixel is a binary fraction and - // every size on its grid is an exact number; at 110%, 125%, 150% and 175% it is not, and a - // size read back from a rectangle or put together from a client size and borders differs - // from the grid's in its last bit. Nothing may be refused or left unfinished for that. + // A whole session at each scale: admitted to the tile, maximized and back, restored to + // the exact floating frame, admitted again. At 75%, 133% and 200% the output's pixel is a + // binary fraction and every size on its grid is an exact number; at 110%, 125%, 150% and + // 175% it is not, and a size read back from a rectangle or put together from a client + // size and borders differs from the grid's in its last bit. Nothing may be refused or + // left unfinished for that. QFETCH(qreal, scale); QFETCH(bool, decorated); QFETCH(QSize, client); @@ -11028,6 +11051,21 @@ void TestXdgShellWindow::testTransientTilingFacadeScales() QVERIFY2(exactFrame(frame, QRectF(window->transientTileFrame(RectF(tile)))), frameText(frame).constData()); QVERIFY2(exactFrame(window->moveResizeGeometry(), frame), frameText(window->moveResizeGeometry()).constData()); + if (session == 0) { + // An ordinary maximize keeps the ownership, and its end returns the window to + // its frame in the tile, not to the tile's rectangle. + window->maximize(MaximizeFull); + QVERIFY(answerAll()); + QCOMPARE(window->maximizeMode(), MaximizeFull); + QVERIFY(window->m_transientOwnership); + window->maximize(MaximizeRestore); + QVERIFY(answerAll()); + QCOMPARE(window->maximizeMode(), MaximizeRestore); + QVERIFY(window->m_transientOwnership); + QVERIFY(window->tile()); + QVERIFY2(exactFrame(window->frameGeometry(), frame), frameText(window->frameGeometry()).constData()); + } + // The explicit restore: the exact floating frame, the record's end and the tree's. QVERIFY(facade.restoreWindow(window)); QVERIFY(follow()); @@ -11040,6 +11078,118 @@ void TestXdgShellWindow::testTransientTilingFacadeScales() } } +void TestXdgShellWindow::testTransientTilingFacadeBordersChangeWhenTiled() +{ + // A decoration can change its borders when its window is tiled, in the middle of the + // admission: the sizes the client reaches change with them, and with them the largest one + // inside a tile that is off the pixel grid. The request's frame was that fit when the + // request was made; it stays the request's while it is at the tile's corner, inside the + // tile by no more than a fit is, and still reachable. Here the title bar is set by hand + // before the admission and the decoration puts its own back as the window is tiled. + const qreal scale = 4.0 / 3.0; + Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1200, 900), .scale = scale}}); + workspace()->setActiveOutput(QPoint(100, 100)); + const TilingFacade facade; + QVERIFY(facade.api); + QVERIFY(!facade.hasTree()); + const auto releaseTree = qScopeGuard([&]() { + if (facade.hasTree()) { + facade.releaseTile(facade.generation()); + } + }); + const QString key = QStringLiteral("org.example.facade.borders"); + std::unique_ptr surface(Test::createSurface()); + std::unique_ptr shell(Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly)); + shell->set_app_id(key); + std::unique_ptr decoration(Test::createXdgToplevelDecorationV1(shell.get())); + decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side); + QSignalSpy configure(shell->xdgSurface(), &Test::XdgSurface::configureRequested); + QSignalSpy toplevelConfigure(shell.get(), &Test::XdgToplevel::configureRequested); + QSize committed(360, 241); + const auto follow = [&]() { + if (configure.isEmpty() && !configure.wait()) { + return false; + } + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + const QSize asked = toplevelConfigure.last().at(0).value(); + if (!asked.isEmpty()) { + committed = asked; + } + Test::render(surface.get(), committed, Qt::blue); + return Test::waylandSync(); + }; + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(configure.wait()); + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + Window *window = Test::renderAndWaitForShown(surface.get(), committed, Qt::blue); + QVERIFY(window); + QVERIFY(window->isDecorated()); + QVERIFY(follow()); + auto toplevel = static_cast(window); + const auto answerAll = [&]() { + for (int i = 0; i < 6 && toplevel->hasPendingNativeGeometry(); ++i) { + if (!follow()) { + return false; + } + } + return !toplevel->hasPendingNativeGeometry(); + }; + window->move(QPointF(102, 102)); + QVERIFY(answerAll()); + + // The decoration's own borders, and the window's fit under them in a tile whose height + // (892, 1189.33 device pixels) is off the grid. + const QMarginsF own = window->nextDecoration()->nextState()->borders(); + const RectF tile(4, 4, 654, 892); + const RectF ownFit = window->transientTileFrame(tile); + const int ownPixels = qRound((own.top() + own.bottom()) * scale); + // A title bar a few device pixels taller, under which the fit is another one that the + // client still reaches under the decoration's own borders: a height whose client part is + // the image of a whole client size. + RectF fit; + for (int taller = 1; taller <= 12 && fit.isNull(); ++taller) { + auto state = window->nextDecoration()->nextState(); + state->setBorders(QMarginsF(own.left(), own.top() + taller / scale, own.right(), own.bottom())); + Q_EMIT window->nextDecoration()->nextStateChanged(state); + QVERIFY(follow()); + QVERIFY(answerAll()); + const RectF candidate = window->transientTileFrame(tile); + const int clientPixels = qRound(candidate.height() * scale) - ownPixels; + const bool reachable = qRound(qRound(clientPixels / scale) * scale) == clientPixels; + if (qRound(candidate.height() * scale) != qRound(ownFit.height() * scale) && reachable) { + fit = candidate; + } + } + QVERIFY2(!fit.isNull(), "no title bar within a dozen device pixels gives another fit"); + const QRectF floating = window->frameGeometry(); + QVERIFY2(exactFrame(window->moveResizeGeometry(), floating), frameText(window->moveResizeGeometry()).constData()); + + QObject provider; + const QString token = facade.registerProvider(&provider); + QVERIFY(!token.isEmpty()); + QVERIFY(facade.trackWindow(window)); + QCOMPARE(facade.record(token, 1, window, scriptRecord(floating), 1), int(TransientPlacementWriter::Result::Accepted)); + auto output = window->moveResizeOutput(); + auto desktop = VirtualDesktopManager::self()->currentDesktop(output); + const QVariantMap tree = facade.createTile(output, desktop, QRectF(0, 0, 0.55, 1)); + QCOMPARE(tree.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); + QVERIFY2(exactFrame(facade.masterWindowRect(), QRectF(tile)), frameText(facade.masterWindowRect()).constData()); + QCOMPARE(facade.admitTile(tree.value(QStringLiteral("generation")).toInt(), window, token), int(TransientTileController::Result::Accepted)); + QVERIFY(follow()); + QVERIFY(answerAll()); + // The decoration has its own borders again, and under them the fit is another frame. + QCOMPARE(window->nextDecoration()->nextState()->borders(), own); + QVERIFY(window->transientTileFrame(tile) != fit); + // The window is in the tile on the frame the request was made for. + QVERIFY(window->tile()); + QVERIFY(window->m_transientOwnership); + QVERIFY2(exactFrame(window->frameGeometry(), QRectF(fit)), frameText(window->frameGeometry()).constData()); + QVERIFY(window->isTransientTileFrame(fit, tile)); + QVERIFY(window->isTransientTileTargetFeasible(fit)); +} + void TestXdgShellWindow::testTransientTilingFacadeClosedSibling() { // The provider tracks every window it watches, and a key has one window at a reservation. @@ -11223,19 +11373,46 @@ void TestXdgShellWindow::testTransientTilingFacadeKeyConflict() QCOMPARE(facade.releaseTile(again.value(QStringLiteral("generation")).toInt()), int(TransientTileController::Result::Accepted)); } +namespace +{ + +// How the native layer comes to release the master without restoring it. +enum ReleasedBy { + DesktopRemoved, + KeyConflict, + MovedByHand, + MovedByARequest, + RecheckedByTheWorkspace, + SentToAnotherOutput, + MaximizedAfterwards, +}; + +} + void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() { QTest::addColumn("release"); QTest::addColumn("scale"); QTest::addColumn("client"); - QTest::newRow("desktop-removed") << 0 << 1.0 << QSize(200, 100); - QTest::newRow("key-conflict") << 1 << 1.0 << QSize(200, 100); - QTest::newRow("moved-by-hand") << 2 << 1.0 << QSize(200, 100); + QTest::newRow("desktop-removed") << int(DesktopRemoved) << 1.0 << QSize(200, 100); + QTest::newRow("key-conflict") << int(KeyConflict) << 1.0 << QSize(200, 100); + QTest::newRow("moved-by-hand") << int(MovedByHand) << 1.0 << QSize(200, 100); + // A script's request, or the compositor's own: not the user's hand. + QTest::newRow("moved-by-a-request") << int(MovedByARequest) << 1.0 << QSize(200, 100); + // The workspace re-checks every window's position when the work area changes (a panel, a + // strut, an output's size), and asks a tiled one for its tile's rectangle. + QTest::newRow("re-checked-by-the-workspace") << int(RecheckedByTheWorkspace) << 1.0 << QSize(200, 100); + QTest::newRow("sent-to-another-output") << int(SentToAnotherOutput) << 1.0 << QSize(200, 100); + QTest::newRow("maximized-afterwards") << int(MaximizedAfterwards) << 1.0 << QSize(200, 100); // The output's pixel is 0.8: the floating frame is 200.8x100.8 and the tile's rectangle // (634 wide, 792.5 device pixels) is off the grid, so the automatic rectangle is the // window's fit in it and none of the frames is a binary fraction. - QTest::newRow("desktop-removed-at-125%") << 0 << 1.25 << QSize(201, 101); - QTest::newRow("moved-by-hand-at-125%") << 2 << 1.25 << QSize(201, 101); + QTest::newRow("desktop-removed-at-125%") << int(DesktopRemoved) << 1.25 << QSize(201, 101); + QTest::newRow("moved-by-hand-at-125%") << int(MovedByHand) << 1.25 << QSize(201, 101); + // There the rectangle the re-check asks for is the tile's own, off the pixel grid: the + // window lands on its image, which is neither the fit it was admitted to nor inside the + // tile. + QTest::newRow("re-checked-by-the-workspace-at-125%") << int(RecheckedByTheWorkspace) << 1.25 << QSize(201, 101); } void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() @@ -11247,7 +11424,9 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() // of the app, a move of the master). The policy ends it: it gives the window its floating // frame back with an ordinary request, or leaves it where the user put it, and asks the // facade to settle the record. The native layer does that only when the window's geometry - // is settled and the window no longer stands on the automatic rectangle. + // is settled and the window stands on its floating frame or where the user's own move + // left it: every other frame can be an automatic rectangle, and not only the one the + // window was admitted to. QFETCH(int, release); QFETCH(qreal, scale); QFETCH(QSize, client); @@ -11336,22 +11515,55 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() std::unique_ptr siblingSurface; std::unique_ptr siblingShell; - QRectF expected = floating; int revision = 1; - if (release == 0) { + switch (release) { + case DesktopRemoved: + case MaximizedAfterwards: desktops->setCurrent(second); desktops->removeVirtualDesktop(first); - } else if (release == 1) { + break; + case KeyConflict: { siblingSurface = Test::createSurface(); siblingShell = Test::createXdgToplevelSurface(siblingSurface.get()); siblingShell->set_app_id(key); Window *sibling = Test::renderAndWaitForShown(siblingSurface.get(), QSize(220, 120), Qt::green); QVERIFY(sibling); QVERIFY(facade.trackWindow(sibling)); - } else { - // The user's own move: the request itself releases the master, and its place wins. - expected = QRectF(300, 200, 260, 180); - master->moveResize(expected); + break; + } + case MovedByHand: { + // The user's own move: its first step releases the master. While it lasts the + // geometry is not settled; where it ends is the user's placement. + QSignalSpy finished(master, &Window::interactiveMoveResizeFinished); + workspace()->slotWindowMove(); + QCOMPARE(workspace()->moveResizeWindow(), master); + for (const auto key : {Qt::Key_Right, Qt::Key_Right, Qt::Key_Down}) { + master->keyPressEvent(key); + master->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos(), Qt::KeyboardModifiers()); + } + QTRY_VERIFY(!facade.hasTree()); + QVERIFY(master->isInteractiveMove()); + QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); + master->keyPressEvent(Qt::Key_Enter); + QCOMPARE(finished.count(), 1); + QVERIFY(!master->isInteractiveMove()); + break; + } + case MovedByARequest: + master->moveResize(QRectF(300, 200, 260, 180)); + break; + case RecheckedByTheWorkspace: + // What Workspace::rearrange() calls for every window: a tiled one is asked for its + // tile's rectangle with a public request, which releases the master. + master->checkWorkspacePosition(); + break; + case SentToAnotherOutput: { + const auto outputs = workspace()->outputs(); + QCOMPARE(outputs.count(), 2); + master->sendToOutput(outputs.at(0) == output ? outputs.at(1) : outputs.at(0)); + QVERIFY(master->moveResizeOutput() != output); + break; + } } QTRY_VERIFY(!facade.hasTree()); QVERIFY(master->m_transientOwnership); @@ -11360,37 +11572,70 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() // Only the provider that admitted the window settles its record. QCOMPARE(facade.settleWindow(master, QUuid::createUuid().toString()), int(Settle::StaleProvider)); - if (release != 2) { - // The release changed the window's states; until the client has answered that - // configure the geometry is not settled. - if (toplevel->hasPendingNativeGeometry()) { - QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); - QVERIFY(answerAll()); - } - // Settled, but still on the automatic rectangle: the record stays, the memory's - // barrier with it. + // The release changed the window's states, and some releases its geometry; until the + // client has answered those configures the geometry is not settled. + if (toplevel->hasPendingNativeGeometry()) { + QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); + QVERIFY(answerAll()); + } + QVERIFY(!toplevel->hasPendingNativeGeometry()); + if (release == MaximizedAfterwards) { + // A mode owns the frame and gives it back to the rectangle the window had before: + // the record waits for the ordinary state. + master->maximize(MaximizeFull); + QVERIFY(answerAll()); + QCOMPARE(master->maximizeMode(), MaximizeFull); + QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); + master->maximize(MaximizeRestore); + QVERIFY(answerAll()); + QCOMPARE(master->maximizeMode(), MaximizeRestore); QVERIFY2(exactFrame(master->frameGeometry(), managed), frameText(master->frameGeometry()).constData()); - QCOMPARE(facade.settleWindow(master, token), int(Settle::AtManagedRectangle)); - QVERIFY(master->m_transientOwnership); - // The policy gives the window its floating frame back: an ordinary request. - master->moveResize(floating); } - // The client has not answered the request yet. - QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); - QVERIFY(master->m_transientOwnership); - QVERIFY(answerAll()); - QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); - if (release == 2) { + QRectF expected = master->frameGeometry(); + if (release == MovedByHand) { + QVERIFY2(!exactFrame(expected, managed) && !exactFrame(expected, floating), frameText(expected).constData()); // The provider records the place the user chose; the key is still reserved. QCOMPARE(facade.record(token, ++revision, master, scriptRecord(expected), revision), int(TransientPlacementWriter::Result::Deferred)); + } else { + // Settled, and on a rectangle nothing says the user chose: the tile's frame the + // window was admitted to, or another one (the tile's new rectangle, the tile's size + // on another output, a script's request). The record stays, the memory's barrier + // with it. + const bool admittedFrame = release == DesktopRemoved || release == KeyConflict || release == MaximizedAfterwards + || (release == RecheckedByTheWorkspace && scale == 1.0); + QCOMPARE(exactFrame(expected, managed), admittedFrame); + QVERIFY2(!exactFrame(expected, floating), frameText(expected).constData()); + QCOMPARE(facade.settleWindow(master, token), int(Settle::AtManagedRectangle)); + QVERIFY(master->m_transientOwnership); + // The policy gives the window its floating frame back: an ordinary request for the + // frame the record holds, which followed the window to another output. + expected = facade.floatingFrame(master); + QVERIFY(expected.isValid()); + QCOMPARE(exactFrame(expected, floating), release != SentToAnotherOutput); + QCOMPARE(workspace()->outputAt(expected.center()), master->moveResizeOutput()); + master->moveResize(expected); + // The client has not answered the request yet. + QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); + QVERIFY(master->m_transientOwnership); + QVERIFY(answerAll()); } + QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); QSignalSpy settled(master, &Window::transientReleaseSettled); QCOMPARE(facade.settleWindow(master, token), int(Settle::Settled)); QCOMPARE(settled.count(), 1); QVERIFY(!master->m_transientOwnership); + QVERIFY(!facade.floatingFrame(master).isValid()); QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); - QVERIFY(exactFrame(facade.entry(key), scriptRecord(expected))); + // The memory: the user's place, recorded while the key was reserved, or the entry as it + // was (the tiler returns the window without recording anything). + QVERIFY(exactFrame(facade.entry(key), scriptRecord(release == MovedByHand ? expected : floating))); QCOMPARE(facade.settleWindow(master, token), int(Settle::NotReleased)); + if (release != MovedByHand) { + // The policy records the frame the window settled at. It is the entry already, except + // on another output, where the next admission's reservation needs it. + QCOMPARE(facade.record(token, ++revision, master, scriptRecord(expected), revision), int(TransientPlacementWriter::Result::Accepted)); + QVERIFY(exactFrame(facade.entry(key), scriptRecord(expected))); + } // The window is free again: a new session admits it and the explicit restore returns it. if (siblingSurface) { @@ -11402,13 +11647,18 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() QTRY_COMPARE(workspace()->activeWindow(), master); QVERIFY(answerAll()); } + output = master->moveResizeOutput(); const auto desktop = desktops->currentDesktop(output); const QVariantMap again = facade.createTile(output, desktop, QRectF(0, 0, 0.5, 1)); QCOMPARE(again.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); QCOMPARE(facade.admitTile(again.value(QStringLiteral("generation")).toInt(), master, token), int(TransientTileController::Result::Accepted)); QVERIFY(follow()); QVERIFY(master->tile()); + QVERIFY(exactFrame(facade.floatingFrame(master), expected)); QVERIFY(facade.restoreWindow(master)); + // A live restoration completes at its own boundary; there is nothing to settle. + QCOMPARE(facade.settleWindow(master, token), int(Settle::NotReleased)); + QVERIFY(master->m_transientOwnership); QVERIFY(follow()); QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); QVERIFY(!master->m_transientOwnership); diff --git a/src/scripting/transienttilingapi.cpp b/src/scripting/transienttilingapi.cpp index 44fba7f73c..052f8c1a1f 100644 --- a/src/scripting/transienttilingapi.cpp +++ b/src/scripting/transienttilingapi.cpp @@ -236,6 +236,14 @@ int TransientTilingApi::settleWindow(Window *window, const QString &providerToke return static_cast(window->settleReleasedTransientOwnership(QUuid(providerToken))); } +QRectF TransientTilingApi::floatingFrame(Window *window) const +{ + if (!m_workspace || !window || window->isDeleted()) { + return {}; + } + return QRectF(window->transientFloatingFrame()); +} + QRectF TransientTilingApi::masterWindowRect() const { auto controller = m_workspace ? m_workspace->transientTileController() : nullptr; diff --git a/src/scripting/transienttilingapi.h b/src/scripting/transienttilingapi.h index d27336c091..916f6064d5 100644 --- a/src/scripting/transienttilingapi.h +++ b/src/scripting/transienttilingapi.h @@ -113,17 +113,27 @@ class TransientTilingApi : public QObject /** * End the record of a window the native layer released without restoring it (a removed - * desktop or output, a second window of its app, a move of the window): the master the - * tiler has since given its floating frame back with an ordinary request, or one the user - * moved. The native layer settles it only for the provider that admitted the window, once - * the window's geometry is settled and it no longer stands on the automatic rectangle, so - * that rectangle never reaches the memory. Returns Window::TransientSettleResult: 0 - * settled (the window can be admitted again), 1 nothing to settle, 2 another provider's, - * 3 not settled yet (ask again after the client's next commit), 4 still on the automatic - * rectangle, 5 refused by the writer; -1 without a window. + * desktop or output, a second window of its app, a move of the window, a change of the + * work area): the master the tiler has since given its floating frame back with an + * ordinary request for floatingFrame(), or one the user moved or resized. The native + * layer settles it only for the provider that admitted the window, once the window's + * geometry is settled and the window stands on its floating frame or where the user's + * own interactive move or resize left it; any other frame may be an automatic rectangle + * and never reaches the memory. Returns Window::TransientSettleResult: 0 settled (the + * window can be admitted again), 1 nothing to settle, 2 another provider's, 3 not settled + * yet (a configure the client has not answered, or the window is maximized, full screen + * or tiled: ask again), 4 neither on its floating frame nor placed by the user, 5 refused + * by the writer; -1 without a window. */ Q_INVOKABLE int settleWindow(Window *window, const QString &providerToken); + /** + * The floating frame of a window's record, owned or released: where the explicit restore + * returns it, and where a tiler returns a master the native layer released without + * restoring it. It follows the window to another output. Null without a record. + */ + Q_INVOKABLE QRectF floatingFrame(Window *window) const; + /** * The transient leaf's absolute window geometry (the master's placed rectangle, * including the tile padding and strut adjustments). diff --git a/src/tiles/transientplacementwriter.cpp b/src/tiles/transientplacementwriter.cpp index c29e7d8dd3..4e01dd015b 100644 --- a/src/tiles/transientplacementwriter.cpp +++ b/src/tiles/transientplacementwriter.cpp @@ -261,6 +261,10 @@ TransientPlacementWriter::Result TransientPlacementWriter::record(const QUuid &p // re-recorded when it lands) is not a newer placement: a sibling's manual update // keeps the one deferred slot whatever the sequences say. A frame the released // owner was moved to by hand differs from it and takes the slot as the latest. + // An owner moved by hand back onto exactly that frame is not told apart from the + // landing and is suppressed too: the sibling's update is the newer placement + // either way. After a transfer to another output the frame the owner is restored + // to is no longer the reservation's, and the latest record wins as before. return Result::Suppressed; } reservation->deferred = update; diff --git a/src/window.cpp b/src/window.cpp index 58c19ad91e..e3095ff35b 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -70,7 +70,8 @@ bool exactFrameGeometry(const RectF &left, const RectF &right) // The same frame up to the arithmetic's last bits. Where an output's pixel is not a binary // fraction (125%, 150%), the frame a commit publishes and the rectangle that was asked for can -// differ there; frames that are different on any output differ by far more. +// differ there; frames that are different on any output differ by far more. The tolerance is +// in logical pixels (the comparison knows no output), below a thousandth of one. bool sameFrameGeometry(const RectF &left, const RectF &right) { const auto same = [](qreal a, qreal b) { @@ -1140,6 +1141,11 @@ void Window::finishInteractiveMoveResize(bool cancel) workspace()->outline()->hide(); m_interactiveMoveResize.counter++; + if (!cancel && m_transientOwnership && m_transientOwnership->phase == TransientOwnershipPhase::Restoring) { + // The operation's own first request released the record; where it ended is the place + // the user chose. A cancelled one put the window back. + m_transientOwnership->placedByUser = true; + } Q_EMIT interactiveMoveResizeFinished(); } @@ -5283,7 +5289,15 @@ Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUu if (m_requestedTile || m_tile || !isTransientGeometrySettled()) { return TransientSettleResult::Unsettled; } - if (sameFrameGeometry(frameGeometry(), ownership.target) && !sameFrameGeometry(ownership.target, ownership.floating)) { + // Positive evidence only. The rectangle recorded at the admission is not the only + // automatic one a released window can stand on: a work-area re-check releases the window + // with a public request for the tile's rectangle as it is then, and a transfer to another + // output carries the tile's size along. The record ends on the floating frame, or where + // the user's own move or resize left the window. + const RectF frame = frameGeometry(); + const bool onFloating = sameFrameGeometry(frame, ownership.floating); + const bool placedByUser = ownership.placedByUser && !sameFrameGeometry(frame, ownership.target); + if (!onFloating && !placedByUser) { return TransientSettleResult::AtManagedRectangle; } if (ownership.writer->completeRestore(internalId(), QString::number(generation)) != TransientPlacementWriter::Result::Accepted) { @@ -5295,12 +5309,16 @@ Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUu }); // As after a completed restoration, the close cleanup stays connected: the writer forgets // the tracked window at its destruction. - const RectF frame = frameGeometry(); m_transientOwnership.reset(); Q_EMIT transientReleaseSettled(QRectF(frame)); return TransientSettleResult::Settled; } +RectF Window::transientFloatingFrame() const +{ + return m_transientOwnership ? m_transientOwnership->floating : RectF(); +} + Window::TransientRestoreClaim Window::claimTransientRestoreWithMaximizeNormalization(quint64 generation) { return {}; diff --git a/src/window.h b/src/window.h index cfbc91da75..5d0f64f7f9 100644 --- a/src/window.h +++ b/src/window.h @@ -1418,13 +1418,19 @@ class KWIN_EXPORT Window : public QObject * The end of a released record that no explicit restoration will complete. A release that * is not the explicit restore is detach-only: the window stays where it stands and its * record (Restoring) keeps the automatic rectangle out of the placement memory. The policy - * that admitted the window ends that record once the window is somewhere else: back on its - * floating frame by the policy's own ordinary request, or where the user put it. Settled - * only for the provider that admitted the window, with no live restoration, in an ordinary - * mode outside every tile, with the native geometry settled (nothing scheduled, sent or - * acknowledged, the frame the requested geometry) and off the automatic rectangle; every - * other answer changes nothing. The writer finalizes as it does for a completed - * restoration: a deferred update for the key is applied, else the entry stays. + * that admitted the window ends that record once the window stands on a frame that is + * known not to be automatic: its floating frame (the policy's own ordinary request for + * transientFloatingFrame(), or the compositor's replay of it), or where the user's own + * interactive move or resize left it. Any other frame can be an automatic rectangle (the + * tile's frame the window was admitted to, the tile's rectangle a work-area re-check asks + * for as it releases the window, either of them carried to another output) and is + * answered AtManagedRectangle. Settled only for the provider that admitted the window + * (StaleProvider otherwise, also when the writer no longer holds the record's + * reservation), with no live restoration (NotReleased), in an ordinary mode outside + * every tile and with the native geometry settled: nothing scheduled, sent or + * acknowledged, the frame the requested geometry (Unsettled otherwise). Every answer but + * Settled changes nothing. The writer finalizes as it does for a completed restoration: + * a deferred update for the key is applied, else the entry stays. */ enum class TransientSettleResult { Settled, @@ -1435,6 +1441,12 @@ class KWIN_EXPORT Window : public QObject Refused, }; TransientSettleResult settleReleasedTransientOwnership(const QUuid &provider); + /** + * The floating frame of this window's transient record, owned or released: where an + * explicit restoration returns it, carried along when the window is sent to another + * output. Null without a record. + */ + RectF transientFloatingFrame() const; /** * NT04's read-only state/completion contract. The state query reflects the native record * only - no protocol logging and no timeout participates - for the placement policy that @@ -2204,6 +2216,10 @@ protected Q_SLOTS: bool releasing = false; bool releaseWriterReady = false; bool committed = false; + // A released record's window was moved or resized by the user's own interactive + // operation, which ended without being cancelled: where it stands is the user's + // placement, not an automatic rectangle (settleReleasedTransientOwnership). + bool placedByUser = false; QMetaObject::Connection closeCleanup; std::shared_ptr noRequestProof; std::unique_ptr request; diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index 91805308cd..999bc591de 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -70,6 +70,18 @@ static bool samePixels(const QSizeF &left, const QSizeF &right, qreal scale) return samePixels(left.width(), right.width(), scale) && samePixels(left.height(), right.height(), scale); } +// Smaller by a pixel's worth, not by the last bits of a read-back size. +static bool belowPixels(qreal length, qreal limit, qreal scale) +{ + return length < limit && !samePixels(length, limit, scale); +} + +// The same rectangle on an output's pixels. +static bool samePixels(const RectF &left, const RectF &right, qreal scale) +{ + return samePixels(left.x(), right.x(), scale) && samePixels(left.y(), right.y(), scale) && samePixels(left.size(), right.size(), scale); +} + XdgSurfaceWindow::XdgSurfaceWindow(XdgSurfaceInterface *shellSurface) : WaylandWindow(shellSurface->surface()) , m_shellSurface(shellSurface) @@ -913,6 +925,18 @@ void XdgToplevelWindow::handleRoleCommit() } } + // A frame that answers a request is that request. It is put together where the window + // stands and then moved to the configure's place, so where the output's pixel is not a + // binary fraction its corners can be a last bit away from the rectangle the configure was + // sent for, though it is that rectangle on the output's pixels: a restoration from a tile + // at 542,362 came back 200.79999999999995 wide for a floating frame of 200.8 at 125%. The + // configure's own rectangle is published then, so a restoration returns the floating + // frame it saved bit for bit, and a tiled window stands on the frame it was admitted to. + if (placement && !fullscreen && !isInteractiveMove() && frameGeometry != placement->bounds + && samePixels(frameGeometry, placement->bounds, targetScale())) { + frameGeometry = placement->bounds; + } + const bool synchronized = synchronizeCommittedGeometry(frameGeometry, origin, generation); if (!configureCommitIsCurrent(generation)) { return; @@ -1021,7 +1045,8 @@ RectF XdgToplevelWindow::transientTileFrame(const RectF &tile) const // bounds the steps and keeps the fit within a step of that grid and two device pixels of // the tile. // Counted in whole device pixels, so that every step is one of the grid's own numbers. - const int steps = int(std::ceil(scale / clientScale)) + 2; + // Bounded whatever the two scales are. + const int steps = int(std::min(std::ceil(scale / clientScale), 64.0)) + 2; qreal width = std::round(tile.width() * scale); qreal height = std::round(tile.height() * scale); for (int step = 0; step <= steps && width > 0 && height > 0; ++step) { @@ -1030,8 +1055,8 @@ RectF XdgToplevelWindow::transientTileFrame(const RectF &tile) const const bool wide = image.width() > tile.width() && !samePixels(image.width(), tile.width(), scale); const bool tall = image.height() > tile.height() && !samePixels(image.height(), tile.height(), scale); if (!wide && !tall) { - // Inside the tile; reachable unless the client's limits or a grid coarser than - // the client's (a scale below one) say otherwise, and then nothing smaller is. + // Inside the tile. Not reachable only where the client's size limits say so, and + // then no other size inside the tile is offered: the tile is refused. const RectF frame(tile.topLeft(), image); return isTransientRestoreFrameFeasible(frame) ? frame : tile; } @@ -1204,7 +1229,8 @@ Window::TransientRestoreClaim XdgToplevelWindow::claimTransientRestoreWithMaximi if (!isTransientRestoreFrameFeasible(target)) { return {}; } - } else if (!isFiniteExtent(target) || target.width() < minSize().width() || target.height() < minSize().height() + } else if (!isFiniteExtent(target) || belowPixels(target.width(), minSize().width(), nextTargetScale()) + || belowPixels(target.height(), minSize().height(), nextTargetScale()) || !samePixels(snapToPixels(target.size(), nextTargetScale()), target.size(), nextTargetScale())) { // Maximized or fullscreen borders are not the borders that A will use. These are only necessary // checks; exact frame/client feasibility follows the same-decoration response. @@ -2791,9 +2817,12 @@ bool XdgToplevelWindow::ownedMaximizeFeasible(const RectF &managed, MaximizeMode if (released == MaximizeRestore) { return true; } + // Compared on the output's pixels: the constrained size is put together from a client size + // and its borders, the managed one is read back from a rectangle (samePixels). const QSizeF constrained = constrainFrameSize(managed.size()); - return (!(released & MaximizeHorizontal) || constrained.width() == managed.width()) - && (!(released & MaximizeVertical) || constrained.height() == managed.height()); + const qreal scale = nextTargetScale(); + return (!(released & MaximizeHorizontal) || samePixels(constrained.width(), managed.width(), scale)) + && (!(released & MaximizeVertical) || samePixels(constrained.height(), managed.height(), scale)); } std::optional XdgToplevelWindow::ownedMaximizePlan(MaximizeMode mode, MaximizeMode oldMode, const RectF &restore) const From a848a151711b7aabd9db5aaf486498e1acb06ed8 Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 13:28:25 -0500 Subject: [PATCH 06/10] Carry a released record's floating frame to its window's screen When the output a tiled window is on is removed, the window is released and the workspace's re-check of its position puts it on another output. The record's floating frame stayed on the removed output's coordinates. The record now ends only with the window on that frame (or where the user's own move left it), so the policy had nowhere to return such a window and its record lasted until it closed. checkWorkspacePosition moves the floating frame with the window's screen area, as it moves the maximize and full-screen restore fields and as sendToOutput does on a transfer. Nothing changes while the screen area is the same. testTransientTilingFacadeReleasedMaster, row output-removed: the window's output is unplugged; the record's floating frame is on the remaining output, the window is returned to it and the record is settled. Without the change the floating frame is unchanged, on coordinates that are gone. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 17 ++++++++++++++++- src/window.cpp | 11 +++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index abc2bb56d5..5beb5ae50f 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -11384,6 +11384,7 @@ enum ReleasedBy { MovedByARequest, RecheckedByTheWorkspace, SentToAnotherOutput, + OutputRemoved, MaximizedAfterwards, }; @@ -11403,6 +11404,9 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() // strut, an output's size), and asks a tiled one for its tile's rectangle. QTest::newRow("re-checked-by-the-workspace") << int(RecheckedByTheWorkspace) << 1.0 << QSize(200, 100); QTest::newRow("sent-to-another-output") << int(SentToAnotherOutput) << 1.0 << QSize(200, 100); + // The session's output is unplugged: the window is put on the other one, and its + // floating frame was on coordinates that are gone. + QTest::newRow("output-removed") << int(OutputRemoved) << 1.0 << QSize(200, 100); QTest::newRow("maximized-afterwards") << int(MaximizedAfterwards) << 1.0 << QSize(200, 100); // The output's pixel is 0.8: the floating frame is 200.8x100.8 and the tile's rectangle // (634 wide, 792.5 device pixels) is off the grid, so the automatic rectangle is the @@ -11435,6 +11439,10 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1280, 1024), .scale = scale}}); workspace()->setActiveOutput(QPoint(100, 100)); } + if (release == OutputRemoved) { + // The window opens on the second output, the one that goes. + workspace()->setActiveOutput(QPoint(1280 + 640, 512)); + } const TilingFacade facade; QVERIFY(facade.api); QVERIFY(!facade.hasTree()); @@ -11564,6 +11572,13 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() QVERIFY(master->moveResizeOutput() != output); break; } + case OutputRemoved: { + QCOMPARE(output->geometry(), Rect(1280, 0, 1280, 1024)); + Test::setOutputConfig({Rect(0, 0, 1280, 1024)}); + QCOMPARE(workspace()->outputs().count(), 1); + QCOMPARE(master->moveResizeOutput(), workspace()->outputs().constFirst()); + break; + } } QTRY_VERIFY(!facade.hasTree()); QVERIFY(master->m_transientOwnership); @@ -11611,7 +11626,7 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() // frame the record holds, which followed the window to another output. expected = facade.floatingFrame(master); QVERIFY(expected.isValid()); - QCOMPARE(exactFrame(expected, floating), release != SentToAnotherOutput); + QCOMPARE(exactFrame(expected, floating), release != SentToAnotherOutput && release != OutputRemoved); QCOMPARE(workspace()->outputAt(expected.center()), master->moveResizeOutput()); master->moveResize(expected); // The client has not answered the request yet. diff --git a/src/window.cpp b/src/window.cpp index e3095ff35b..c25d404e65 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -6179,10 +6179,17 @@ void Window::checkWorkspacePosition(RectF oldGeometry, LogicalOutput *oldOutput) moveResize(ensureSpecialStateGeometry(decision.geometry)); setFullscreenGeometryRestore(moveToArea(m_fullscreenGeometryRestore, decision.oldScreenArea, decision.screenArea)); setGeometryRestore(moveToArea(m_maximizeGeometryRestore, decision.oldScreenArea, decision.screenArea)); - return; + break; case WorkspacePositionDecision::Kind::Geometry: moveResize(decision.geometry); - return; + break; + } + // A released record's floating frame follows the window's screen as the restore fields + // above do, and as it does on a transfer (sendToOutput): an output that was removed or + // resized takes its coordinates with it, and a floating frame left on them is one the + // policy could never return the window to. Untouched while the screen is the same. + if (!isDeleted() && decision.oldScreenArea != decision.screenArea && decision.oldScreenArea.isValid() && decision.screenArea.isValid()) { + rebaseTransientFloatingOnOutputTransfer(decision.oldScreenArea, decision.screenArea); } } From 8e8f02792a542a252a154b1577c34e362250d8bb Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 13:50:19 -0500 Subject: [PATCH 07/10] Let a later request make the user's placement stale The record of a released window is marked when the user's own interactive move or resize of it ends, and the settle operation takes that as evidence that the frame the window stands on is the user's choice. The mark lasted for the record's lifetime: a request after the user's hand had let go (the workspace's re-check of the window's position, a script's) moved the window somewhere nobody chose, and the record was still settled there. The mark is now the window's geometry request generation at the end of the user's operation, and it counts only while that is still the window's last request. testTransientTilingFacadeReleasedMaster, row moved-by-hand-then-by-a-request: after the user's move and a public request the settle answers AtManagedRectangle until the window is back on its floating frame. A window whose maximum size is below the tile is refused, as it was before the fit: the fit is the tile's size on the window's pixels, not a smaller window in a corner of the tile, and a request's frame is checked against its tile by that nearness. testTransientRequestFractional pins it (row above-the-maximum). Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 34 ++++++++++++++----- src/window.cpp | 10 ++++-- src/window.h | 12 ++++--- src/xdgshellwindow.cpp | 7 ++-- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 5beb5ae50f..c759a2f643 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -10400,19 +10400,23 @@ void TestXdgShellWindow::testTransientRequestFractional_data() { QTest::addColumn("tileSize"); QTest::addColumn("minimum"); + QTest::addColumn("maximum"); QTest::addColumn("frameSize"); // The output's pixel is 0.8 logical pixels: a 200x100 tile is on it. - QTest::newRow("snapped") << QSizeF(200, 100) << QSize() << QSizeF(200, 100); + QTest::newRow("snapped") << QSizeF(200, 100) << QSize() << QSize() << QSizeF(200, 100); // 201x101 is not (251.25 x 126.25 device pixels). A client asked for 201x101 is 251x126 // device pixels, a 200.8 x 100.8 frame: the largest the window reaches inside the tile. - QTest::newRow("off-the-pixel-grid") << QSizeF(201, 101) << QSize() << QSizeF(200.8, 100.8); + QTest::newRow("off-the-pixel-grid") << QSizeF(201, 101) << QSize() << QSize() << QSizeF(200.8, 100.8); // One axis on the grid, the other not. - QTest::newRow("height-off-the-pixel-grid") << QSizeF(200, 101) << QSize() << QSizeF(200, 100.8); + QTest::newRow("height-off-the-pixel-grid") << QSizeF(200, 101) << QSize() << QSize() << QSizeF(200, 100.8); // The client's own grid is a whole logical pixel. A 202-wide client is 252.5 device pixels, // which is 253: a 202.4 frame, wider than the tile. The one that fits is 201 wide. - QTest::newRow("client-size-over-the-tile") << QSizeF(202, 100) << QSize() << QSizeF(200.8, 100); + QTest::newRow("client-size-over-the-tile") << QSizeF(202, 100) << QSize() << QSize() << QSizeF(200.8, 100); // Nothing inside the tile is a size the client accepts: refused, as before. - QTest::newRow("below-the-minimum") << QSizeF(201, 101) << QSize(201, 101) << QSizeF(); + QTest::newRow("below-the-minimum") << QSizeF(201, 101) << QSize(201, 101) << QSize() << QSizeF(); + // A maximum below the tile: the window could stand in a corner of it, but a fit is the + // tile's size on the window's pixels. Refused, as before. + QTest::newRow("above-the-maximum") << QSizeF(201, 101) << QSize() << QSize(190, 90) << QSizeF(); } void TestXdgShellWindow::testTransientRequestFractional() @@ -10423,6 +10427,7 @@ void TestXdgShellWindow::testTransientRequestFractional() // the request's target. A rectangle with no reachable size inside it is still refused. QFETCH(QSizeF, tileSize); QFETCH(QSize, minimum); + QFETCH(QSize, maximum); QFETCH(QSizeF, frameSize); const bool reachable = frameSize.isValid(); Test::OutputInfo output; @@ -10435,14 +10440,19 @@ void TestXdgShellWindow::testTransientRequestFractional() if (minimum.isValid()) { shell->set_min_size(minimum.width(), minimum.height()); } + if (maximum.isValid()) { + shell->set_max_size(maximum.width(), maximum.height()); + } + // A window larger than the tile, or at its maximum where it has one. + const QSize initial = maximum.isValid() ? maximum : QSize(220, 120); QSignalSpy configure(shell->xdgSurface(), &Test::XdgSurface::configureRequested); QSignalSpy toplevelConfigure(shell.get(), &Test::XdgToplevel::configureRequested); - Window *window = Test::renderAndWaitForShown(surface.get(), QSize(220, 120), Qt::red); + Window *window = Test::renderAndWaitForShown(surface.get(), initial, Qt::red); QVERIFY(window); QVERIFY(!configure.isEmpty() || configure.wait()); shell->xdgSurface()->ack_configure(configure.last().at(0).value()); configure.clear(); - Test::render(surface.get(), QSize(220, 120), Qt::red); + Test::render(surface.get(), initial, Qt::red); QVERIFY(Test::waylandSync()); QCOMPARE(window->nextTargetScale(), 1.25); RequestTestTile tile(window); @@ -11381,6 +11391,7 @@ enum ReleasedBy { DesktopRemoved, KeyConflict, MovedByHand, + MovedByHandThenByARequest, MovedByARequest, RecheckedByTheWorkspace, SentToAnotherOutput, @@ -11398,6 +11409,8 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() QTest::newRow("desktop-removed") << int(DesktopRemoved) << 1.0 << QSize(200, 100); QTest::newRow("key-conflict") << int(KeyConflict) << 1.0 << QSize(200, 100); QTest::newRow("moved-by-hand") << int(MovedByHand) << 1.0 << QSize(200, 100); + // The user's move, then a request that is not the user's: the evidence is stale. + QTest::newRow("moved-by-hand-then-by-a-request") << int(MovedByHandThenByARequest) << 1.0 << QSize(200, 100); // A script's request, or the compositor's own: not the user's hand. QTest::newRow("moved-by-a-request") << int(MovedByARequest) << 1.0 << QSize(200, 100); // The workspace re-checks every window's position when the work area changes (a panel, a @@ -11539,7 +11552,8 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() QVERIFY(facade.trackWindow(sibling)); break; } - case MovedByHand: { + case MovedByHand: + case MovedByHandThenByARequest: { // The user's own move: its first step releases the master. While it lasts the // geometry is not settled; where it ends is the user's placement. QSignalSpy finished(master, &Window::interactiveMoveResizeFinished); @@ -11555,6 +11569,10 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() master->keyPressEvent(Qt::Key_Enter); QCOMPARE(finished.count(), 1); QVERIFY(!master->isInteractiveMove()); + if (release == MovedByHandThenByARequest) { + // The workspace's re-check, a script: a request after the user's hand let go. + master->moveResize(QRectF(300, 200, 260, 180)); + } break; } case MovedByARequest: diff --git a/src/window.cpp b/src/window.cpp index c25d404e65..351e3a500e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1143,8 +1143,9 @@ void Window::finishInteractiveMoveResize(bool cancel) m_interactiveMoveResize.counter++; if (!cancel && m_transientOwnership && m_transientOwnership->phase == TransientOwnershipPhase::Restoring) { // The operation's own first request released the record; where it ended is the place - // the user chose. A cancelled one put the window back. - m_transientOwnership->placedByUser = true; + // the user chose, for as long as no later request moves the window. A cancelled one + // put the window back. + m_transientOwnership->placedByUser = m_geometryRequestGeneration; } Q_EMIT interactiveMoveResizeFinished(); } @@ -5296,7 +5297,10 @@ Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUu // the user's own move or resize left the window. const RectF frame = frameGeometry(); const bool onFloating = sameFrameGeometry(frame, ownership.floating); - const bool placedByUser = ownership.placedByUser && !sameFrameGeometry(frame, ownership.target); + // The user's placement is evidence only while it is the window's last request: a later + // one (the workspace's re-check, a script's) has put the window somewhere nobody chose. + const bool placedByUser = ownership.placedByUser && *ownership.placedByUser == m_geometryRequestGeneration + && !sameFrameGeometry(frame, ownership.target); if (!onFloating && !placedByUser) { return TransientSettleResult::AtManagedRectangle; } diff --git a/src/window.h b/src/window.h index 5d0f64f7f9..1d6f89e47c 100644 --- a/src/window.h +++ b/src/window.h @@ -1421,7 +1421,8 @@ class KWIN_EXPORT Window : public QObject * that admitted the window ends that record once the window stands on a frame that is * known not to be automatic: its floating frame (the policy's own ordinary request for * transientFloatingFrame(), or the compositor's replay of it), or where the user's own - * interactive move or resize left it. Any other frame can be an automatic rectangle (the + * interactive move or resize left it and no later request has moved it. Any other frame + * can be an automatic rectangle (the * tile's frame the window was admitted to, the tile's rectangle a work-area re-check asks * for as it releases the window, either of them carried to another output) and is * answered AtManagedRectangle. Settled only for the provider that admitted the window @@ -2217,9 +2218,12 @@ protected Q_SLOTS: bool releaseWriterReady = false; bool committed = false; // A released record's window was moved or resized by the user's own interactive - // operation, which ended without being cancelled: where it stands is the user's - // placement, not an automatic rectangle (settleReleasedTransientOwnership). - bool placedByUser = false; + // operation, which ended without being cancelled: the window's geometry request + // generation at that end. While it is still the window's, where the window stands is + // the user's placement, not an automatic rectangle; any later request (the + // workspace's re-check, a script's) makes the evidence stale + // (settleReleasedTransientOwnership). + std::optional placedByUser; QMetaObject::Connection closeCleanup; std::shared_ptr noRequestProof; std::unique_ptr request; diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index 999bc591de..6ebea9f264 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -1055,8 +1055,11 @@ RectF XdgToplevelWindow::transientTileFrame(const RectF &tile) const const bool wide = image.width() > tile.width() && !samePixels(image.width(), tile.width(), scale); const bool tall = image.height() > tile.height() && !samePixels(image.height(), tile.height(), scale); if (!wide && !tall) { - // Inside the tile. Not reachable only where the client's size limits say so, and - // then no other size inside the tile is offered: the tile is refused. + // Inside the tile. Not reachable only where the client's size limits say so: a + // minimum above the tile, or a maximum below it. The fit is the tile's size on + // the window's pixels, never a smaller window in a corner of the tile (the + // request's frame is checked against the tile by that nearness, + // isTransientTileFrame), so such a tile is refused, as it was. const RectF frame(tile.topLeft(), image); return isTransientRestoreFrameFeasible(frame) ? frame : tile; } From bdb46ac5e1961ec6859bbe621e3b025a98c9cdba Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 16:25:20 -0500 Subject: [PATCH 08/10] Settle a released window on an output of another scale A transient record's floating frame goes along when its window is sent to another output, or when its output is removed: the corner is moved to the new area, the size stays. The size was on the pixels of the output the frame was taken on. On an output of another scale it is not: 200.8x100.8 from an output whose pixel is 0.8 is no size a window has on whole pixels. The policy returns a released window to floatingFrame(). The request then lands on 201x101, the frame is never the request, the window's geometry never settles, and settleWindow answers Unsettled for as long as the window lives. Seen with a 133% output and a 100% one: the master sent across with Window to Next Screen arrived at its floating size, its record was held, and it could not be admitted again until it was moved by hand. Brought back, the record's frame had drifted by the two translations. Window::transientFloatingImage() is the frame a request for the floating frame gives the window on the output it is on: the frame itself where the window reaches it, otherwise its corner with the size taken to the output's pixels and the client's grid and back, as dispatchMoveResize and the commit take it. floatingFrame() answers with it, and the settle operation takes a window that stands on it as standing on its floating frame. Nothing changes on the output the frame was taken on, or on any output whose pixels it is on. testTransientTilingFacadeReleasedMaster gains the row sent-to-an-output-of-another-scale (125% to 100%). Without the change floatingFrame() answers 200.8x100.8 there. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 24 ++++++++++++++++--- src/window.cpp | 11 +++++++-- src/window.h | 13 +++++++++- src/xdgshellwindow.cpp | 24 +++++++++++++++++++ src/xdgshellwindow.h | 1 + 5 files changed, 67 insertions(+), 6 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index c759a2f643..4446253696 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -11395,6 +11395,7 @@ enum ReleasedBy { MovedByARequest, RecheckedByTheWorkspace, SentToAnotherOutput, + SentToAnOutputOfAnotherScale, OutputRemoved, MaximizedAfterwards, }; @@ -11430,6 +11431,12 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() // window lands on its image, which is neither the fit it was admitted to nor inside the // tile. QTest::newRow("re-checked-by-the-workspace-at-125%") << int(RecheckedByTheWorkspace) << 1.25 << QSize(201, 101); + // From an output whose pixel is 0.8 to one whose pixel is 1: the floating frame is + // 200.8x100.8 and goes along as it is, but no window is 200.8 wide on whole pixels. A + // request for it lands on 201x101 and is never the frame, so the window's geometry never + // settled and its record stayed (a 133% laptop panel and a 100% second screen: the master + // sent across could not be tiled again until it was moved by hand). + QTest::newRow("sent-to-an-output-of-another-scale") << int(SentToAnOutputOfAnotherScale) << 1.25 << QSize(201, 101); } void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() @@ -11448,7 +11455,11 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() QFETCH(qreal, scale); QFETCH(QSize, client); using Settle = Window::TransientSettleResult; - if (scale != 1.0) { + if (release == SentToAnOutputOfAnotherScale) { + Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1280, 1024), .scale = scale}, + Test::OutputInfo{.geometry = Rect(1280, 0, 1280, 1024), .scale = 1.0}}); + workspace()->setActiveOutput(QPoint(100, 100)); + } else if (scale != 1.0) { Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1280, 1024), .scale = scale}}); workspace()->setActiveOutput(QPoint(100, 100)); } @@ -11583,11 +11594,13 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() // tile's rectangle with a public request, which releases the master. master->checkWorkspacePosition(); break; - case SentToAnotherOutput: { + case SentToAnotherOutput: + case SentToAnOutputOfAnotherScale: { const auto outputs = workspace()->outputs(); QCOMPARE(outputs.count(), 2); master->sendToOutput(outputs.at(0) == output ? outputs.at(1) : outputs.at(0)); QVERIFY(master->moveResizeOutput() != output); + QCOMPARE(master->moveResizeOutput()->scale() != scale, release == SentToAnOutputOfAnotherScale); break; } case OutputRemoved: { @@ -11644,8 +11657,13 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() // frame the record holds, which followed the window to another output. expected = facade.floatingFrame(master); QVERIFY(expected.isValid()); - QCOMPARE(exactFrame(expected, floating), release != SentToAnotherOutput && release != OutputRemoved); + QCOMPARE(exactFrame(expected, floating), + release != SentToAnotherOutput && release != SentToAnOutputOfAnotherScale && release != OutputRemoved); QCOMPARE(workspace()->outputAt(expected.center()), master->moveResizeOutput()); + if (release == SentToAnOutputOfAnotherScale) { + // The frame the window takes there: the floating size on that output's pixels. + QVERIFY2(exactFrame(QRectF(expected.topLeft(), QSizeF(201, 101)), expected), frameText(expected).constData()); + } master->moveResize(expected); // The client has not answered the request yet. QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); diff --git a/src/window.cpp b/src/window.cpp index 351e3a500e..48779fb4e8 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -5295,8 +5295,10 @@ Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUu // with a public request for the tile's rectangle as it is then, and a transfer to another // output carries the tile's size along. The record ends on the floating frame, or where // the user's own move or resize left the window. + // On an output of another scale than the one the floating frame was taken on, the + // window stands on that frame where it stands on its image there. const RectF frame = frameGeometry(); - const bool onFloating = sameFrameGeometry(frame, ownership.floating); + const bool onFloating = sameFrameGeometry(frame, ownership.floating) || sameFrameGeometry(frame, transientFloatingImage(ownership.floating)); // The user's placement is evidence only while it is the window's last request: a later // one (the workspace's re-check, a script's) has put the window somewhere nobody chose. const bool placedByUser = ownership.placedByUser && *ownership.placedByUser == m_geometryRequestGeneration @@ -5320,7 +5322,12 @@ Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUu RectF Window::transientFloatingFrame() const { - return m_transientOwnership ? m_transientOwnership->floating : RectF(); + return m_transientOwnership ? transientFloatingImage(m_transientOwnership->floating) : RectF(); +} + +RectF Window::transientFloatingImage(const RectF &floating) const +{ + return floating; } Window::TransientRestoreClaim Window::claimTransientRestoreWithMaximizeNormalization(quint64 generation) diff --git a/src/window.h b/src/window.h index 1d6f89e47c..eb50829ff1 100644 --- a/src/window.h +++ b/src/window.h @@ -1445,7 +1445,8 @@ class KWIN_EXPORT Window : public QObject /** * The floating frame of this window's transient record, owned or released: where an * explicit restoration returns it, carried along when the window is sent to another - * output. Null without a record. + * output, as the window takes it on the output it is on (transientFloatingImage()). + * Null without a record. */ RectF transientFloatingFrame() const; /** @@ -2469,6 +2470,16 @@ protected Q_SLOTS: * caller's separate check (isTransientTileTargetFeasible). */ virtual bool isTransientTileFrame(const RectF &frame, const RectF &tile) const; + /** + * The frame a request for a transient record's floating frame gives this window on the + * output it is on now. The floating frame was a frame of the window where it was taken. + * Carried to an output of another scale (sendToOutput, a removed output) its size is not + * on the pixels there: the window cannot take it, a request for it is never the frame, + * and the geometry of a window asked for it never settles. This is @p floating where the + * window reaches it, and otherwise its corner with its size taken to this output's + * pixels and to the client's grid and back, as a request and its commit take it. + */ + virtual RectF transientFloatingImage(const RectF &floating) const; // Backend hooks of requestMoveResizeForAssignment(). Support is consulted before any mutation; // a dispatcher reports what it staged or published through the stack-bound request. virtual bool supportsAssignmentGeometryRequest() const; diff --git a/src/xdgshellwindow.cpp b/src/xdgshellwindow.cpp index 6ebea9f264..ba212ea345 100644 --- a/src/xdgshellwindow.cpp +++ b/src/xdgshellwindow.cpp @@ -1073,6 +1073,30 @@ RectF XdgToplevelWindow::transientTileFrame(const RectF &tile) const return tile; } +RectF XdgToplevelWindow::transientFloatingImage(const RectF &floating) const +{ + // The frame itself wherever the window reaches it: on the output it was taken on, and on + // any other whose pixels it is on. + if (isDeleted() || !surface() || isTransientRestoreFrameFeasible(floating)) { + return floating; + } + const qreal scale = nextTargetScale(); + for (qreal value : {floating.x(), floating.y(), floating.width(), floating.height(), scale}) { + if (!std::isfinite(value)) { + return floating; + } + } + if (floating.width() <= 0 || floating.height() <= 0 || scale <= 0) { + return floating; + } + // What a request for the frame publishes (dispatchMoveResize, then the commit): the size + // to the output's pixels, to the client's grid and back. The corner stays. Where even + // that is not reachable (the client's size limits) the frame is left as it is. + const QSizeF client = surface()->snappedSize(nextFrameSizeToClientSize(snapToPixels(floating.size(), scale))); + const RectF image(floating.topLeft(), nextClientSizeToFrameSize(snapToPixels(client, scale))); + return isTransientRestoreFrameFeasible(image) ? image : floating; +} + bool XdgToplevelWindow::isTransientTileFrame(const RectF &frame, const RectF &tile) const { if (Window::isTransientTileFrame(frame, tile)) { diff --git a/src/xdgshellwindow.h b/src/xdgshellwindow.h index 94bca37f80..8508f4ecaa 100644 --- a/src/xdgshellwindow.h +++ b/src/xdgshellwindow.h @@ -244,6 +244,7 @@ class XdgToplevelWindow final : public XdgSurfaceWindow bool isTransientTileTargetFeasible(const RectF &target) const override; RectF transientTileFrame(const RectF &tile) const override; bool isTransientTileFrame(const RectF &frame, const RectF &tile) const override; + RectF transientFloatingImage(const RectF &floating) const override; bool supportsAssignmentGeometryRequest() const override; private: From b961ff80c619ece6c66cdf2ce6ffe8ba9ce959c2 Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 17:20:29 -0500 Subject: [PATCH 09/10] Give the floating image to a released record only, and test it wider After bdb46ac5e1. floatingFrame() answered with the image for an owned record too. An owned record's frame is the explicit restoration's exact target; the image is for the policy's own request, which returns a released window. It is now given for a released record only, and the two doc comments say which is which. The comment and the commit message said the window's geometry never settled. It does: the request ends with the frame and the requested geometry both on the image, and the settle answered AtManagedRectangle, not Unsettled, however often the window was asked back. The comments say that now. testTransientFloatingFrameOnAnotherScale, eight rows: plain and server-decorated windows from 125% and 133% to 100%, to 150% from 100% and from 125%, from 150% to 175%, and the same scale on both outputs. Each checks that the record keeps the size it was taken with and the corner it was moved to, that the policy is given a frame the window takes (asked for again, it is itself), that the window then stands on it with its requested geometry, that the record settles, and that a new session restores to that frame. With the image left out of the settle operation the six rows that change scale answer AtManagedRectangle. The row in testTransientTilingFacadeReleasedMaster checks the corner against the record's and that the record keeps 200.8x100.8. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 191 +++++++++++++++++- src/scripting/transienttilingapi.h | 8 +- src/window.cpp | 10 +- src/window.h | 20 +- 4 files changed, 212 insertions(+), 17 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 4446253696..76ea70a773 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -408,6 +408,8 @@ private Q_SLOTS: void testTransientTilingFacadeKeyConflict(); void testTransientTilingFacadeReleasedMaster_data(); void testTransientTilingFacadeReleasedMaster(); + void testTransientFloatingFrameOnAnotherScale_data(); + void testTransientFloatingFrameOnAnotherScale(); void testTransientTilingFacadeProviderKeepsRecording_data(); void testTransientTilingFacadeProviderKeepsRecording(); void testControllerProviderRecordDuringApplication(); @@ -10656,6 +10658,13 @@ bool exactFrame(const QRectF &left, const QRectF &right) return left.x() == right.x() && left.y() == right.y() && left.width() == right.width() && left.height() == right.height(); } +// The same size up to the arithmetic's last bits: a rectangle stores its edges, and a size read +// back from one that was moved differs there from the size it was given. +bool sameSize(const QSizeF &left, const QSizeF &right) +{ + return std::abs(left.width() - right.width()) < 1.0 / 1024 && std::abs(left.height() - right.height()) < 1.0 / 1024; +} + QByteArray frameText(const QRectF &frame) { return QByteArray::number(frame.x(), 'g', 17) + ',' + QByteArray::number(frame.y(), 'g', 17) + ' ' @@ -11433,9 +11442,10 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() QTest::newRow("re-checked-by-the-workspace-at-125%") << int(RecheckedByTheWorkspace) << 1.25 << QSize(201, 101); // From an output whose pixel is 0.8 to one whose pixel is 1: the floating frame is // 200.8x100.8 and goes along as it is, but no window is 200.8 wide on whole pixels. A - // request for it lands on 201x101 and is never the frame, so the window's geometry never - // settled and its record stayed (a 133% laptop panel and a 100% second screen: the master - // sent across could not be tiled again until it was moved by hand). + // request for it lands on 201x101, frame and requested geometry both, which is not the + // floating frame: the record answered AtManagedRectangle however often the window was + // asked back (a 133% laptop panel and a 100% second screen: the master sent across could + // not be tiled again until it was moved by hand). QTest::newRow("sent-to-an-output-of-another-scale") << int(SentToAnOutputOfAnotherScale) << 1.25 << QSize(201, 101); } @@ -11661,8 +11671,13 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() release != SentToAnotherOutput && release != SentToAnOutputOfAnotherScale && release != OutputRemoved); QCOMPARE(workspace()->outputAt(expected.center()), master->moveResizeOutput()); if (release == SentToAnOutputOfAnotherScale) { - // The frame the window takes there: the floating size on that output's pixels. - QVERIFY2(exactFrame(QRectF(expected.topLeft(), QSizeF(201, 101)), expected), frameText(expected).constData()); + // The frame the window takes there: the record's corner, the floating size on + // that output's pixels. The record keeps the size it was taken with, so a + // transfer back gives the window its own frame again. + const QRectF carried(master->m_transientOwnership->floating); + QVERIFY2(exactFrame(QRectF(carried.topLeft(), QSizeF(201, 101)), expected), frameText(expected).constData()); + QVERIFY2(sameSize(carried.size(), floating.size()), frameText(carried).constData()); + QVERIFY(!exactFrame(carried, expected)); } master->moveResize(expected); // The client has not answered the request yet. @@ -11716,6 +11731,172 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() QTRY_VERIFY(!facade.hasTree()); } +void TestXdgShellWindow::testTransientFloatingFrameOnAnotherScale_data() +{ + QTest::addColumn("from"); + QTest::addColumn("to"); + QTest::addColumn("decorated"); + QTest::addColumn("client"); + // 200.8x100.8 at 125%: no size of a window on whole pixels. + QTest::newRow("125%-to-100%") << 1.25 << 1.0 << false << QSize(201, 101); + QTest::newRow("125%-to-100%-title-bar") << 1.25 << 1.0 << true << QSize(361, 241); + // The pair it was seen with: a 133% panel and a 100% second screen, a decorated window + // (560.25x521.25 under a 50.25 title bar there). + QTest::newRow("133%-to-100%-title-bar") << 4.0 / 3.0 << 1.0 << true << QSize(361, 241); + // To a fractional scale, and from one to another. + QTest::newRow("100%-to-150%") << 1.0 << 1.5 << false << QSize(201, 101); + QTest::newRow("125%-to-150%-title-bar") << 1.25 << 1.5 << true << QSize(361, 241); + QTest::newRow("150%-to-175%") << 1.5 << 1.75 << false << QSize(201, 101); + // The same scale on both outputs: the frame goes along as it is. + QTest::newRow("125%-to-125%") << 1.25 << 1.25 << false << QSize(201, 101); + QTest::newRow("125%-to-125%-title-bar") << 1.25 << 1.25 << true << QSize(361, 241); +} + +void TestXdgShellWindow::testTransientFloatingFrameOnAnotherScale() +{ + // A released record's floating frame goes to another output with the size it was taken + // with. Where that size is not on the other output's pixels the window cannot stand on + // it, and the policy's request for it used to end on a rectangle the record did not + // know: the settle answered AtManagedRectangle for as long as the window lived. The + // policy is given the frame as the window takes it there, the record settles on it, and + // the record itself keeps the size it had. + QFETCH(qreal, from); + QFETCH(qreal, to); + QFETCH(bool, decorated); + QFETCH(QSize, client); + using Settle = Window::TransientSettleResult; + Test::setOutputConfig({Test::OutputInfo{.geometry = Rect(0, 0, 1280, 1024), .scale = from}, + Test::OutputInfo{.geometry = Rect(1280, 0, 1280, 1024), .scale = to}}); + workspace()->setActiveOutput(QPoint(100, 100)); + const TilingFacade facade; + QVERIFY(facade.api); + QVERIFY(!facade.hasTree()); + const auto releaseTree = qScopeGuard([&]() { + if (facade.hasTree()) { + facade.releaseTile(facade.generation()); + } + }); + const QString key = QStringLiteral("org.example.facade.image.") + QString::fromLatin1(QTest::currentDataTag()).remove(QLatin1Char('%')); + std::unique_ptr surface(Test::createSurface()); + std::unique_ptr shell(Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly)); + shell->set_app_id(key); + std::unique_ptr decoration; + if (decorated) { + decoration = Test::createXdgToplevelDecorationV1(shell.get()); + decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side); + } + QSignalSpy configure(shell->xdgSurface(), &Test::XdgSurface::configureRequested); + QSignalSpy toplevelConfigure(shell.get(), &Test::XdgToplevel::configureRequested); + QSize committed = client; + // The client's side of a configure: acknowledge the newest one and commit its size (the + // size it has where the configure leaves the choice to it). + const auto follow = [&]() { + if (configure.isEmpty() && !configure.wait()) { + return false; + } + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + const QSize asked = toplevelConfigure.last().at(0).value(); + if (!asked.isEmpty()) { + committed = asked; + } + Test::render(surface.get(), committed, Qt::blue); + return Test::waylandSync(); + }; + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(configure.wait()); + shell->xdgSurface()->ack_configure(configure.last().at(0).toUInt()); + configure.clear(); + Window *master = Test::renderAndWaitForShown(surface.get(), client, Qt::blue); + QVERIFY(master); + QCOMPARE(master->isDecorated(), decorated); + QVERIFY(follow()); + QCOMPARE(master->nextTargetScale(), from); + auto toplevel = static_cast(master); + const auto answerAll = [&]() { + for (int i = 0; i < 6 && toplevel->hasPendingNativeGeometry(); ++i) { + if (!follow()) { + return false; + } + } + return !toplevel->hasPendingNativeGeometry(); + }; + QVERIFY(answerAll()); + const QRectF floating = master->frameGeometry(); + QObject provider; + const QString token = facade.registerProvider(&provider); + QVERIFY(!token.isEmpty()); + QVERIFY(facade.trackWindow(master)); + QCOMPARE(facade.record(token, 1, master, scriptRecord(floating), 1), int(TransientPlacementWriter::Result::Accepted)); + const auto first = master->moveResizeOutput(); + const QVariantMap tree = facade.createTile(first, VirtualDesktopManager::self()->currentDesktop(first), QRectF(0, 0, 0.5, 1)); + QCOMPARE(tree.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); + QCOMPARE(facade.admitTile(tree.value(QStringLiteral("generation")).toInt(), master, token), int(TransientTileController::Result::Accepted)); + QVERIFY(answerAll()); + QVERIFY(master->tile()); + // An owned record's frame is the restoration's target, exactly. + QVERIFY2(exactFrame(facade.floatingFrame(master), floating), frameText(facade.floatingFrame(master)).constData()); + + const auto outputs = workspace()->outputs(); + QCOMPARE(outputs.count(), 2); + master->sendToOutput(outputs.at(0) == first ? outputs.at(1) : outputs.at(0)); + QVERIFY(master->moveResizeOutput() != first); + QTRY_VERIFY(!facade.hasTree()); + QVERIFY(master->m_transientOwnership); + QCOMPARE(master->m_transientOwnership->phase, Window::TransientOwnershipPhase::Restoring); + QVERIFY(answerAll()); + QCOMPARE(master->nextTargetScale(), to); + // Where the transfer left the window is the tile's size, carried along. + QVERIFY2(!exactFrame(master->frameGeometry(), floating), frameText(master->frameGeometry()).constData()); + QCOMPARE(facade.settleWindow(master, token), int(Settle::AtManagedRectangle)); + + // The record: the corner moved to the other output, the size as it was taken. + const QRectF carried(master->m_transientOwnership->floating); + QCOMPARE(workspace()->outputAt(carried.center()), master->moveResizeOutput()); + QVERIFY2(sameSize(carried.size(), floating.size()), frameText(carried).constData()); + // What the policy is given: that frame where the window reaches it, otherwise the same + // corner with a size the window takes there. + const QRectF expected = facade.floatingFrame(master); + QVERIFY2(exactFrame(expected, QRectF(master->transientFloatingImage(RectF(carried)))), frameText(expected).constData()); + QCOMPARE(exactFrame(expected, carried), from == to); + QVERIFY2(expected.topLeft() == carried.topLeft(), frameText(expected).constData()); + // A frame the window takes: asked for again, it is itself. + QVERIFY2(exactFrame(QRectF(master->transientFloatingImage(RectF(expected))), expected), frameText(expected).constData()); + // Within a device pixel and a step of the client's grid of the size it was. + QVERIFY2(std::abs(expected.width() - carried.width()) < 1 + 1 / to && std::abs(expected.height() - carried.height()) < 1 + 1 / to, + frameText(expected).constData()); + + master->moveResize(expected); + if (toplevel->hasPendingNativeGeometry()) { + QCOMPARE(facade.settleWindow(master, token), int(Settle::Unsettled)); + QVERIFY(answerAll()); + } + // The window stands on what it was asked for: frame and requested geometry. + QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); + QVERIFY2(exactFrame(QRectF(master->moveResizeGeometry()), expected), frameText(QRectF(master->moveResizeGeometry())).constData()); + QSignalSpy settled(master, &Window::transientReleaseSettled); + QCOMPARE(facade.settleWindow(master, token), int(Settle::Settled)); + QCOMPARE(settled.count(), 1); + QVERIFY(!master->m_transientOwnership); + QVERIFY(!facade.floatingFrame(master).isValid()); + + // The window is free again: the policy records where it settled, a new session admits it + // there and the explicit restore returns it to that frame. + QCOMPARE(facade.record(token, 2, master, scriptRecord(expected), 2), int(TransientPlacementWriter::Result::Accepted)); + const auto second = master->moveResizeOutput(); + const QVariantMap again = facade.createTile(second, VirtualDesktopManager::self()->currentDesktop(second), QRectF(0, 0, 0.5, 1)); + QCOMPARE(again.value(QStringLiteral("result")).toInt(), int(TransientTileController::Result::Accepted)); + QCOMPARE(facade.admitTile(again.value(QStringLiteral("generation")).toInt(), master, token), int(TransientTileController::Result::Accepted)); + QVERIFY(answerAll()); + QVERIFY(master->tile()); + QVERIFY(exactFrame(facade.floatingFrame(master), expected)); + QVERIFY(facade.restoreWindow(master)); + QVERIFY(answerAll()); + QVERIFY2(exactFrame(master->frameGeometry(), expected), frameText(master->frameGeometry()).constData()); + QVERIFY(!master->m_transientOwnership); + QTRY_VERIFY(!facade.hasTree()); +} + void TestXdgShellWindow::testTransientTilingFacadeProviderKeepsRecording_data() { QTest::addColumn("moment"); diff --git a/src/scripting/transienttilingapi.h b/src/scripting/transienttilingapi.h index 916f6064d5..a3d082ea64 100644 --- a/src/scripting/transienttilingapi.h +++ b/src/scripting/transienttilingapi.h @@ -128,9 +128,11 @@ class TransientTilingApi : public QObject Q_INVOKABLE int settleWindow(Window *window, const QString &providerToken); /** - * The floating frame of a window's record, owned or released: where the explicit restore - * returns it, and where a tiler returns a master the native layer released without - * restoring it. It follows the window to another output. Null without a record. + * The floating frame of @p window's transient record: of an owned window the frame an + * explicit restoration returns it to; of a released one that frame as the window takes + * it on the output it is on now (it follows the window to another output, and on an + * output of another scale its size is on that output's pixels) - the rectangle to ask + * for before settleWindow(). Null when the window has no record. */ Q_INVOKABLE QRectF floatingFrame(Window *window) const; diff --git a/src/window.cpp b/src/window.cpp index 48779fb4e8..fd94ef5142 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -5322,7 +5322,15 @@ Window::TransientSettleResult Window::settleReleasedTransientOwnership(const QUu RectF Window::transientFloatingFrame() const { - return m_transientOwnership ? transientFloatingImage(m_transientOwnership->floating) : RectF(); + if (!m_transientOwnership) { + return RectF(); + } + // An owned record's frame is the restoration's exact target, and so is a live + // restoration's. Only a released record is returned by the policy's own request. + const auto &ownership = *m_transientOwnership; + const bool released = ownership.phase == TransientOwnershipPhase::Restoring + && !(ownership.restoreAttempt && transientRestoreAttemptIsCurrent(ownership.generation, ownership.restoreAttempt->sequence)); + return released ? transientFloatingImage(ownership.floating) : ownership.floating; } RectF Window::transientFloatingImage(const RectF &floating) const diff --git a/src/window.h b/src/window.h index eb50829ff1..fe14a0216c 100644 --- a/src/window.h +++ b/src/window.h @@ -1443,10 +1443,12 @@ class KWIN_EXPORT Window : public QObject }; TransientSettleResult settleReleasedTransientOwnership(const QUuid &provider); /** - * The floating frame of this window's transient record, owned or released: where an - * explicit restoration returns it, carried along when the window is sent to another - * output, as the window takes it on the output it is on (transientFloatingImage()). - * Null without a record. + * The floating frame of this window's transient record. Of an owned record: where an + * explicit restoration returns the window, exactly. Of a released one: that frame, + * carried along when the window was sent to another output or its output went, as the + * window takes it on the output it is on now (transientFloatingImage()) - the rectangle + * the policy asks for to return the window, and on which the record settles. Null + * without a record. */ RectF transientFloatingFrame() const; /** @@ -2474,10 +2476,12 @@ protected Q_SLOTS: * The frame a request for a transient record's floating frame gives this window on the * output it is on now. The floating frame was a frame of the window where it was taken. * Carried to an output of another scale (sendToOutput, a removed output) its size is not - * on the pixels there: the window cannot take it, a request for it is never the frame, - * and the geometry of a window asked for it never settles. This is @p floating where the - * window reaches it, and otherwise its corner with its size taken to this output's - * pixels and to the client's grid and back, as a request and its commit take it. + * on the pixels there and the window cannot take it: a request for it ends with the + * frame and the requested geometry on its image, which is not the floating frame, so a + * released window asked for it stands on a rectangle nothing vouches for, however often + * it is asked. This is @p floating where the window reaches it, and otherwise its corner + * with its size taken to this output's pixels and to the client's grid and back, as a + * request and its commit take it. */ virtual RectF transientFloatingImage(const RectF &floating) const; // Backend hooks of requestMoveResizeForAssignment(). Support is consulted before any mutation; From 30bf729e04627c4c697a6f92048fb4f48371174b Mon Sep 17 00:00:00 2001 From: Wisbendji Fimerlus Date: Fri, 13 Nov 2026 17:56:19 -0500 Subject: [PATCH 10/10] Take the user's placement only from an operation that moved the window A released record settles where the user's own interactive move or resize left the window. The mark was set when such an operation ended without being cancelled, whether or not it had moved anything. A press on the title bar that is held and released, or the keyboard move ended at once, starts and ends an interactive move without a step. On a window an earlier release had left on an automatic rectangle (a script's request, the workspace's re-check, the tile's size on another output) that marked the rectangle as the user's choice, and the settle operation completed the record there: the floating frame was lost and the policy recorded the rectangle. The mark is now set only when the operation has stepped: the window was moved or resized by it at least once. testTransientTilingFacadeReleasedMaster gains the row moved-by-a-request-then-held-still. Without the change the settle operation answers Settled there instead of AtManagedRectangle. Signed-off-by: Wisbendji Fimerlus --- autotests/integration/xdgshellwindow_test.cpp | 22 +++++++++++++++++++ src/window.cpp | 9 ++++++-- src/window.h | 6 ++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index 76ea70a773..5697bf0615 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -11402,6 +11402,7 @@ enum ReleasedBy { MovedByHand, MovedByHandThenByARequest, MovedByARequest, + MovedByARequestThenHeldStill, RecheckedByTheWorkspace, SentToAnotherOutput, SentToAnOutputOfAnotherScale, @@ -11423,6 +11424,10 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster_data() QTest::newRow("moved-by-hand-then-by-a-request") << int(MovedByHandThenByARequest) << 1.0 << QSize(200, 100); // A script's request, or the compositor's own: not the user's hand. QTest::newRow("moved-by-a-request") << int(MovedByARequest) << 1.0 << QSize(200, 100); + // The same, and then the user takes the window and lets it go where it is (a press on + // the title bar held and released, the keyboard move ended at once): an interactive + // operation that moved nothing chose no place. + QTest::newRow("moved-by-a-request-then-held-still") << int(MovedByARequestThenHeldStill) << 1.0 << QSize(200, 100); // The workspace re-checks every window's position when the work area changes (a panel, a // strut, an output's size), and asks a tiled one for its tile's rectangle. QTest::newRow("re-checked-by-the-workspace") << int(RecheckedByTheWorkspace) << 1.0 << QSize(200, 100); @@ -11599,6 +11604,23 @@ void TestXdgShellWindow::testTransientTilingFacadeReleasedMaster() case MovedByARequest: master->moveResize(QRectF(300, 200, 260, 180)); break; + case MovedByARequestThenHeldStill: { + master->moveResize(QRectF(300, 200, 260, 180)); + QTRY_VERIFY(!facade.hasTree()); + QVERIFY(answerAll()); + const RectF standing = master->frameGeometry(); + QSignalSpy stepped(master, &Window::interactiveMoveResizeStepped); + QSignalSpy finished(master, &Window::interactiveMoveResizeFinished); + workspace()->slotWindowMove(); + QCOMPARE(workspace()->moveResizeWindow(), master); + QVERIFY(master->isInteractiveMove()); + master->keyPressEvent(Qt::Key_Enter); + QCOMPARE(finished.count(), 1); + QCOMPARE(stepped.count(), 0); + QVERIFY(!master->isInteractiveMove()); + QCOMPARE(master->frameGeometry(), standing); + break; + } case RecheckedByTheWorkspace: // What Workspace::rearrange() calls for every window: a tiled one is asked for its // tile's rectangle with a public request, which releases the master. diff --git a/src/window.cpp b/src/window.cpp index fd94ef5142..a5ea542cce 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1090,6 +1090,7 @@ bool Window::startInteractiveMoveResize() m_interactiveMoveResize.initialMaximizeMode = requestedMaximizeMode(); m_interactiveMoveResize.initialQuickTileMode = requestedQuickTileMode(); m_interactiveMoveResize.initialGeometryRestore = geometryRestore(); + m_interactiveMoveResize.stepped = false; updateElectricGeometryRestore(); performDelayedRaise(); @@ -1141,10 +1142,12 @@ void Window::finishInteractiveMoveResize(bool cancel) workspace()->outline()->hide(); m_interactiveMoveResize.counter++; - if (!cancel && m_transientOwnership && m_transientOwnership->phase == TransientOwnershipPhase::Restoring) { + if (!cancel && m_interactiveMoveResize.stepped && m_transientOwnership + && m_transientOwnership->phase == TransientOwnershipPhase::Restoring) { // The operation's own first request released the record; where it ended is the place // the user chose, for as long as no later request moves the window. A cancelled one - // put the window back. + // put the window back, and one that moved nothing (a press held and released on a + // window an earlier release left on an automatic rectangle) chose no place. m_transientOwnership->placedByUser = m_geometryRequestGeneration; } Q_EMIT interactiveMoveResizeFinished(); @@ -1241,6 +1244,7 @@ void Window::updateInteractiveMoveResize(const QPointF &global, Qt::KeyboardModi } } + m_interactiveMoveResize.stepped = true; doInteractiveResizeSync(nextMoveResizeGeom); Q_EMIT interactiveMoveResizeStepped(nextMoveResizeGeom); } @@ -1272,6 +1276,7 @@ void Window::updateInteractiveMoveResize(const QPointF &global, Qt::KeyboardModi } } + m_interactiveMoveResize.stepped = true; move(nextMoveResizeGeom.topLeft()); Q_EMIT interactiveMoveResizeStepped(nextMoveResizeGeom); } diff --git a/src/window.h b/src/window.h index fe14a0216c..e0b8145b2c 100644 --- a/src/window.h +++ b/src/window.h @@ -2222,7 +2222,8 @@ protected Q_SLOTS: bool committed = false; // A released record's window was moved or resized by the user's own interactive // operation, which ended without being cancelled: the window's geometry request - // generation at that end. While it is still the window's, where the window stands is + // generation at that end. An operation that moved nothing leaves no mark. While the + // generation is still the window's, where the window stands is // the user's placement, not an automatic rectangle; any later request (the // workspace's re-check, a script's) makes the evidence stale // (settleReleasedTransientOwnership). @@ -2797,6 +2798,9 @@ protected Q_SLOTS: RectF initialScreenArea; QTimer *delayedTimer = nullptr; uint32_t counter = 0; + // Whether the operation has moved or resized the window: one that started and ended + // where the window stood (a press on the title bar held and released) chose no place. + bool stepped = false; MaximizeMode initialMaximizeMode; QuickTileMode initialQuickTileMode; } m_interactiveMoveResize;