diff --git a/autotests/client/test_plasma_window_model.cpp b/autotests/client/test_plasma_window_model.cpp --- a/autotests/client/test_plasma_window_model.cpp +++ b/autotests/client/test_plasma_window_model.cpp @@ -571,6 +571,10 @@ QVERIFY(resizeRequestedSpy.isValid()); QSignalSpy virtualDesktopRequestedSpy(w, &PlasmaWindowInterface::virtualDesktopRequested); QVERIFY(virtualDesktopRequestedSpy.isValid()); + QSignalSpy keepAboveRequestedSpy(w, &PlasmaWindowInterface::keepAboveRequested); + QVERIFY(keepAboveRequestedSpy.isValid()); + QSignalSpy keepBelowRequestedSpy(w, &PlasmaWindowInterface::keepBelowRequested); + QVERIFY(keepBelowRequestedSpy.isValid()); QSignalSpy minimizedRequestedSpy(w, &PlasmaWindowInterface::minimizedRequested); QVERIFY(minimizedRequestedSpy.isValid()); QSignalSpy maximizeRequestedSpy(w, &PlasmaWindowInterface::maximizedRequested); @@ -582,13 +586,17 @@ model->requestActivate(-1); model->requestClose(-1); model->requestVirtualDesktop(-1, 1); + model->requestToggleKeepAbove(-1); + model->requestToggleKeepBelow(-1); model->requestToggleMinimized(-1); model->requestToggleMaximized(-1); model->requestActivate(1); model->requestClose(1); model->requestMove(1); model->requestResize(1); model->requestVirtualDesktop(1, 1); + model->requestToggleKeepAbove(1); + model->requestToggleKeepBelow(1); model->requestToggleMinimized(1); model->requestToggleMaximized(1); model->requestToggleShaded(1); @@ -661,6 +669,30 @@ QCOMPARE(minimizedRequestedSpy.count(), 0); QCOMPARE(maximizeRequestedSpy.count(), 0); QCOMPARE(shadeRequestedSpy.count(), 0); + // keep above + model->requestToggleKeepAbove(0); + QVERIFY(keepAboveRequestedSpy.wait()); + QCOMPARE(keepAboveRequestedSpy.count(), 1); + QCOMPARE(keepAboveRequestedSpy.first().first().toBool(), true); + QCOMPARE(activateRequestedSpy.count(), 1); + QCOMPARE(closeRequestedSpy.count(), 1); + QCOMPARE(moveRequestedSpy.count(), 1); + QCOMPARE(resizeRequestedSpy.count(), 1); + QCOMPARE(virtualDesktopRequestedSpy.count(), 1); + QCOMPARE(maximizeRequestedSpy.count(), 0); + QCOMPARE(shadeRequestedSpy.count(), 0); + // keep Below + model->requestToggleKeepBelow(0); + QVERIFY(keepBelowRequestedSpy.wait()); + QCOMPARE(keepBelowRequestedSpy.count(), 1); + QCOMPARE(keepBelowRequestedSpy.first().first().toBool(), true); + QCOMPARE(activateRequestedSpy.count(), 1); + QCOMPARE(closeRequestedSpy.count(), 1); + QCOMPARE(moveRequestedSpy.count(), 1); + QCOMPARE(resizeRequestedSpy.count(), 1); + QCOMPARE(virtualDesktopRequestedSpy.count(), 1); + QCOMPARE(maximizeRequestedSpy.count(), 0); + QCOMPARE(shadeRequestedSpy.count(), 0); // minimize model->requestToggleMinimized(0); QVERIFY(minimizedRequestedSpy.wait()); @@ -700,6 +732,20 @@ // the toggles can also support a different state QSignalSpy dataChangedSpy(model, &PlasmaWindowModel::dataChanged); QVERIFY(dataChangedSpy.isValid()); + // keepAbove + w->setKeepAbove(true); + QVERIFY(dataChangedSpy.wait()); + model->requestToggleKeepAbove(0); + QVERIFY(keepAboveRequestedSpy.wait()); + QCOMPARE(keepAboveRequestedSpy.count(), 2); + QCOMPARE(keepAboveRequestedSpy.last().first().toBool(), false); + // keepBelow + w->setKeepBelow(true); + QVERIFY(dataChangedSpy.wait()); + model->requestToggleKeepBelow(0); + QVERIFY(keepBelowRequestedSpy.wait()); + QCOMPARE(keepBelowRequestedSpy.count(), 2); + QCOMPARE(keepBelowRequestedSpy.last().first().toBool(), false); // minimize w->setMinimized(true); QVERIFY(dataChangedSpy.wait()); diff --git a/autotests/client/test_wayland_windowmanagement.cpp b/autotests/client/test_wayland_windowmanagement.cpp --- a/autotests/client/test_wayland_windowmanagement.cpp +++ b/autotests/client/test_wayland_windowmanagement.cpp @@ -61,6 +61,8 @@ void testRequests(); void testRequestsBoolean_data(); void testRequestsBoolean(); + void testKeepAbove(); + void testKeepBelow(); void testShowingDesktop(); void testRequestShowingDesktop_data(); void testRequestShowingDesktop(); @@ -475,6 +477,50 @@ QTEST(requestSpy.first().first().value(), "expectedValue"); } +void TestWindowManagement::testKeepAbove() +{ + using namespace KWayland::Server; + // this test verifies setting the showing desktop state + QVERIFY(!m_window->isKeepAbove()); + QSignalSpy keepAboveChangedSpy(m_window, &KWayland::Client::PlasmaWindow::keepAboveChanged); + QVERIFY(keepAboveChangedSpy.isValid()); + m_windowInterface->setKeepAbove(true); + QVERIFY(keepAboveChangedSpy.wait()); + QCOMPARE(keepAboveChangedSpy.count(), 1); + QVERIFY(m_window->isKeepAbove()); + // setting to same should not change + m_windowInterface->setKeepAbove(true); + QVERIFY(!keepAboveChangedSpy.wait(100)); + QCOMPARE(keepAboveChangedSpy.count(), 1); + // setting to other state should change + m_windowInterface->setKeepAbove(false); + QVERIFY(keepAboveChangedSpy.wait()); + QCOMPARE(keepAboveChangedSpy.count(), 2); + QVERIFY(!m_window->isKeepAbove()); +} + +void TestWindowManagement::testKeepBelow() +{ + using namespace KWayland::Server; + // this test verifies setting the showing desktop state + QVERIFY(!m_window->isKeepBelow()); + QSignalSpy keepBelowChangedSpy(m_window, &KWayland::Client::PlasmaWindow::keepBelowChanged); + QVERIFY(keepBelowChangedSpy.isValid()); + m_windowInterface->setKeepBelow(true); + QVERIFY(keepBelowChangedSpy.wait()); + QCOMPARE(keepBelowChangedSpy.count(), 1); + QVERIFY(m_window->isKeepBelow()); + // setting to same should not change + m_windowInterface->setKeepBelow(true); + QVERIFY(!keepBelowChangedSpy.wait(100)); + QCOMPARE(keepBelowChangedSpy.count(), 1); + // setting to other state should change + m_windowInterface->setKeepBelow(false); + QVERIFY(keepBelowChangedSpy.wait()); + QCOMPARE(keepBelowChangedSpy.count(), 2); + QVERIFY(!m_window->isKeepBelow()); +} + void TestWindowManagement::testParentWindow() { using namespace KWayland::Client; diff --git a/src/client/plasmawindowmanagement.h b/src/client/plasmawindowmanagement.h --- a/src/client/plasmawindowmanagement.h +++ b/src/client/plasmawindowmanagement.h @@ -403,6 +403,19 @@ * Requests to send the window to virtual @p desktop. **/ void requestVirtualDesktop(quint32 desktop); + + /** + * Requests the window at this model row index have its keep above state toggled. + * @since 5.35 + */ + void requestToggleKeepAbove(); + + /** + * Requests the window at this model row index have its keep below state toggled. + * @since 5.35 + */ + void requestToggleKeepBelow(); + /** * Requests the window at this model row index have its minimized state toggled. */ diff --git a/src/client/plasmawindowmanagement.cpp b/src/client/plasmawindowmanagement.cpp --- a/src/client/plasmawindowmanagement.cpp +++ b/src/client/plasmawindowmanagement.cpp @@ -882,6 +882,32 @@ org_kde_plasma_window_set_virtual_desktop(d->window, desktop); } +void PlasmaWindow::requestToggleKeepAbove() +{ + if (d->keepAbove) { + org_kde_plasma_window_set_state(d->window, + ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE, + 0); + } else { + org_kde_plasma_window_set_state(d->window, + ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE, + ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_ABOVE); + } +} + +void PlasmaWindow::requestToggleKeepBelow() +{ + if (d->keepBelow) { + org_kde_plasma_window_set_state(d->window, + ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW, + 0); + } else { + org_kde_plasma_window_set_state(d->window, + ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW, + ORG_KDE_PLASMA_WINDOW_MANAGEMENT_STATE_KEEP_BELOW); + } +} + void PlasmaWindow::requestToggleMinimized() { if (d->minimized) { diff --git a/src/client/plasmawindowmodel.h b/src/client/plasmawindowmodel.h --- a/src/client/plasmawindowmodel.h +++ b/src/client/plasmawindowmodel.h @@ -147,6 +147,18 @@ Q_INVOKABLE void requestVirtualDesktop(int row, quint32 desktop); /** + * Requests the window at this model row index have its keep above state toggled. + * @since 5.35 + */ + Q_INVOKABLE void requestToggleKeepAbove(int row); + + /** + * Requests the window at this model row index have its keep above state toggled. + * @since 5.35 + */ + Q_INVOKABLE void requestToggleKeepBelow(int row); + + /** * Requests the window at this model row index have its minimized state toggled. */ Q_INVOKABLE void requestToggleMinimized(int row); diff --git a/src/client/plasmawindowmodel.cpp b/src/client/plasmawindowmodel.cpp --- a/src/client/plasmawindowmodel.cpp +++ b/src/client/plasmawindowmodel.cpp @@ -315,6 +315,20 @@ } } +Q_INVOKABLE void PlasmaWindowModel::requestToggleKeepAbove(int row) +{ + if (row >= 0 && row < d->windows.count()) { + d->windows.at(row)->requestToggleKeepAbove(); + } +} + +Q_INVOKABLE void PlasmaWindowModel::requestToggleKeepBelow(int row) +{ + if (row >= 0 && row < d->windows.count()) { + d->windows.at(row)->requestToggleKeepBelow(); + } +} + Q_INVOKABLE void PlasmaWindowModel::requestToggleMinimized(int row) { if (row >= 0 && row < d->windows.count()) {