Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,012 changes: 971 additions & 41 deletions autotests/integration/xdgshellwindow_test.cpp

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions autotests/test_transientplacementwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ private Q_SLOTS:
void reservationRequiresExactPersistedFrame();
void memoryFrameIsTheProvidersWholePixelImage();
void deferredManualWinnerSurvivesCompletion();
void restoredFrameDoesNotReplaceASiblingsUpdate_data();
void restoredFrameDoesNotReplaceASiblingsUpdate();
void failedFlushIsNotRetriedByDestructor();
void failedReservationDoesNotHoldKey();
void duplicateGlobalKeyRefusesReservation();
Expand Down Expand Up @@ -292,6 +294,66 @@ void TransientPlacementWriterTest::deferredManualWinnerSurvivesCompletion()
QCOMPARE(writer.snapshot().entries.value(QStringLiteral("app")), later);
}

void TransientPlacementWriterTest::restoredFrameDoesNotReplaceASiblingsUpdate_data()
{
QTest::addColumn<int>("order");
QTest::addColumn<bool>("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;
Expand Down
16 changes: 16 additions & 0 deletions src/scripting/transienttilingapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,22 @@ void TransientTilingApi::restoreWindow(Window *window)
}
}

int TransientTilingApi::settleWindow(Window *window, const QString &providerToken)
{
if (!m_workspace || !window || window->isDeleted()) {
return -1;
}
return static_cast<int>(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;
Expand Down
25 changes: 25 additions & 0 deletions src/scripting/transienttilingapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ 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, 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 @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;

/**
* The transient leaf's absolute window geometry (the master's placed rectangle,
* including the tile padding and strut adjustments).
Expand Down
13 changes: 13 additions & 0 deletions src/tiles/transientplacementwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ 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.
// 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;
return Result::Deferred;
}
Expand Down
5 changes: 3 additions & 2 deletions src/tiles/transienttilecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down
126 changes: 122 additions & 4 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ 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. 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) {
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.
Expand Down Expand Up @@ -1078,6 +1090,7 @@ bool Window::startInteractiveMoveResize()
m_interactiveMoveResize.initialMaximizeMode = requestedMaximizeMode();
m_interactiveMoveResize.initialQuickTileMode = requestedQuickTileMode();
m_interactiveMoveResize.initialGeometryRestore = geometryRestore();
m_interactiveMoveResize.stepped = false;

updateElectricGeometryRestore();
performDelayedRaise();
Expand Down Expand Up @@ -1129,6 +1142,14 @@ void Window::finishInteractiveMoveResize(bool cancel)
workspace()->outline()->hide();

m_interactiveMoveResize.counter++;
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, 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;
Comment thread
archledger marked this conversation as resolved.
Resolved
}
Q_EMIT interactiveMoveResizeFinished();
}

Expand Down Expand Up @@ -1223,6 +1244,7 @@ void Window::updateInteractiveMoveResize(const QPointF &global, Qt::KeyboardModi
}
}

m_interactiveMoveResize.stepped = true;
doInteractiveResizeSync(nextMoveResizeGeom);
Q_EMIT interactiveMoveResizeStepped(nextMoveResizeGeom);
}
Expand Down Expand Up @@ -1254,6 +1276,7 @@ void Window::updateInteractiveMoveResize(const QPointF &global, Qt::KeyboardModi
}
}

m_interactiveMoveResize.stepped = true;
move(nextMoveResizeGeom.topLeft());
Q_EMIT interactiveMoveResizeStepped(nextMoveResizeGeom);
}
Expand Down Expand Up @@ -4959,7 +4982,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();
}
}

Expand Down Expand Up @@ -5247,6 +5271,78 @@ 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;
}
// 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.
// 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) || 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
&& !sameFrameGeometry(frame, ownership.target);
if (!onFloating && !placedByUser) {
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.
m_transientOwnership.reset();
Q_EMIT transientReleaseSettled(QRectF(frame));
return TransientSettleResult::Settled;
}

RectF Window::transientFloatingFrame() const
{
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
{
return floating;
}

Window::TransientRestoreClaim Window::claimTransientRestoreWithMaximizeNormalization(quint64 generation)
{
return {};
Expand Down Expand Up @@ -5722,11 +5818,26 @@ bool Window::canStartTransientRestoreRequest(const RectF &target) const
return false;
}

bool Window::isTransientGeometrySettled() const
{
return false;
}

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
Expand All @@ -5738,7 +5849,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);
}
Expand Down Expand Up @@ -6092,10 +6203,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);
}
}

Expand Down
Loading