From d3aa33b51bd635008b519f565bdf0492e1531090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Mon, 12 Mar 2018 18:06:33 +0100 Subject: [PATCH] Reevaluate window rules when the (xdg) shell surface's appId changes Summary: Especially when a window is first mapped it might be that the appId is not yet set. So window rule matching doesn't happen. This change evaluates the window rules again after the appId changes, so rules for the appId match. Test Plan: added test case Reviewers: #kwin, #plasma Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D11268 --- .../integration/shell_client_rules_test.cpp | 34 +++++++++++++++++++ shell_client.cpp | 4 +++ 2 files changed, 38 insertions(+) diff --git a/autotests/integration/shell_client_rules_test.cpp b/autotests/integration/shell_client_rules_test.cpp index ed75bd4f33..250d97c4de 100644 --- a/autotests/integration/shell_client_rules_test.cpp +++ b/autotests/integration/shell_client_rules_test.cpp @@ -27,6 +27,7 @@ along with this program. If not, see . #include "workspace.h" #include +#include using namespace KWin; using namespace KWayland::Client; @@ -62,6 +63,7 @@ private Q_SLOTS: void testApplyInitialDesktopfile(); void testOpacityActive_data(); void testOpacityActive(); + void testMatchAfterNameChange(); }; void TestShellClientRules::initTestCase() @@ -416,5 +418,37 @@ void TestShellClientRules::testOpacityActive() QCOMPARE(c2->opacity(), 0.8); } +void TestShellClientRules::testMatchAfterNameChange() +{ + KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); + config->group("General").writeEntry("count", 1); + + auto group = config->group("1"); + group.writeEntry("above", true); + group.writeEntry("aboverule", 2); + group.writeEntry("wmclass", "org.kde.foo"); + group.writeEntry("wmclasscomplete", false); + group.writeEntry("wmclassmatch", 1); + group.sync(); + + RuleBook::self()->setConfig(config); + workspace()->slotReconfigure(); + + QScopedPointer surface(Test::createSurface()); + QScopedPointer shellSurface(Test::createXdgShellV6Surface(surface.data())); + + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); + QVERIFY(c); + QVERIFY(c->isActive()); + QCOMPARE(c->keepAbove(), false); + + QSignalSpy desktopFileNameSpy(c, &AbstractClient::desktopFileNameChanged); + QVERIFY(desktopFileNameSpy.isValid()); + + shellSurface->setAppId(QByteArrayLiteral("org.kde.foo")); + QVERIFY(desktopFileNameSpy.wait()); + QCOMPARE(c->keepAbove(), true); +} + WAYLANDTEST_MAIN(TestShellClientRules) #include "shell_client_rules_test.moc" diff --git a/shell_client.cpp b/shell_client.cpp index 65ab9e27b5..9b63f451c0 100644 --- a/shell_client.cpp +++ b/shell_client.cpp @@ -138,6 +138,10 @@ void ShellClient::initSurface(T *shellSurface) connect(shellSurface, &T::windowClassChanged, this, [this, resourceName] (const QByteArray &windowClass) { setResourceClass(resourceName, windowClass); + if (!m_internal) { + setupWindowRules(true); + applyWindowRules(); + } setDesktopFileName(windowClass); } );