Break show desktop mode if a new window is added

BUG: 479424
This commit is contained in:
Vlad Zahorodnii 2024-01-15 11:52:04 +02:00
parent 359f36d6ab
commit af39179446
3 changed files with 66 additions and 4 deletions

View file

@ -30,6 +30,8 @@ private Q_SLOTS:
void testRestoreFocusWithDesktopWindow();
void testQuitAfterActivatingHiddenWindow();
void testDontQuitAfterActivatingDock();
void testQuitAfterAddingWindow();
void testDontQuitAfterAddingDock();
};
void ShowingDesktopTest::initTestCase()
@ -187,5 +189,51 @@ void ShowingDesktopTest::testDontQuitAfterActivatingDock()
QVERIFY(!workspace()->showingDesktop());
}
void ShowingDesktopTest::testQuitAfterAddingWindow()
{
// This test verifies that the show desktop mode is deactivated after mapping a new window.
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
workspace()->slotToggleShowDesktop();
QVERIFY(workspace()->showingDesktop());
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::blue);
QVERIFY(!workspace()->showingDesktop());
}
void ShowingDesktopTest::testDontQuitAfterAddingDock()
{
// This test verifies that the show desktop mode is not broken after adding a dock.
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
QVERIFY(window->isActive());
workspace()->slotToggleShowDesktop();
QVERIFY(workspace()->showingDesktop());
std::unique_ptr<KWayland::Client::Surface> dockSurface{Test::createSurface()};
std::unique_ptr<Test::LayerSurfaceV1> dockShellSurface{Test::createLayerSurfaceV1(dockSurface.get(), QStringLiteral("dock"))};
dockShellSurface->set_size(1280, 50);
dockShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom);
dockShellSurface->set_exclusive_zone(50);
dockShellSurface->set_keyboard_interactivity(1);
dockSurface->commit(KWayland::Client::Surface::CommitFlag::None);
QSignalSpy dockConfigureRequestedSpy(dockShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
QVERIFY(dockConfigureRequestedSpy.wait());
auto dock = Test::renderAndWaitForShown(dockSurface.get(), dockConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
QVERIFY(dock->isActive());
QVERIFY(workspace()->showingDesktop());
workspace()->slotToggleShowDesktop();
}
WAYLANDTEST_MAIN(ShowingDesktopTest)
#include "showing_desktop_test.moc"

View file

@ -687,6 +687,10 @@ X11Window *Workspace::createUnmanaged(xcb_window_t windowId)
void Workspace::addX11Window(X11Window *window)
{
if (showingDesktop() && breaksShowingDesktop(window)) {
setShowingDesktop(false);
}
Group *grp = findGroup(window->window());
if (grp != nullptr) {
grp->gotLeader(window);
@ -769,6 +773,10 @@ void Workspace::removeDeleted(Window *c)
void Workspace::addWaylandWindow(Window *window)
{
if (showingDesktop() && breaksShowingDesktop(window)) {
setShowingDesktop(false);
}
setupWindowConnections(window);
window->updateLayer();
@ -1548,6 +1556,11 @@ void Workspace::focusToNull()
}
}
bool Workspace::breaksShowingDesktop(Window *window) const
{
return !(window->isUnmanaged() || window->isDock() || window->isDesktop() || window->belongsToDesktop());
}
void Workspace::setShowingDesktop(bool showing, bool animated)
{
const bool changed = showing != showing_desktop;
@ -1558,13 +1571,12 @@ void Workspace::setShowingDesktop(bool showing, bool animated)
for (int i = stacking_order.count() - 1; i > -1; --i) {
auto window = stacking_order.at(i);
if (window->isDeleted() || window->isUnmanaged()) {
if (window->isDeleted()) {
continue;
}
if (window->isDock() || window->isDesktop() || window->belongsToDesktop()) {
continue;
if (breaksShowingDesktop(window)) {
window->setHiddenByShowDesktop(showing_desktop);
}
window->setHiddenByShowDesktop(showing_desktop);
}
if (showing_desktop) {

View file

@ -612,6 +612,8 @@ private:
void createDpmsFilter();
void maybeDestroyDpmsFilter();
bool breaksShowingDesktop(Window *window) const;
struct Constraint
{
Window *below;