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
This commit is contained in:
Martin Flöser 2018-03-12 18:06:33 +01:00
parent d61eaa2d66
commit d3aa33b51b
2 changed files with 38 additions and 0 deletions

View file

@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "workspace.h" #include "workspace.h"
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
#include <KWayland/Client/xdgshell.h>
using namespace KWin; using namespace KWin;
using namespace KWayland::Client; using namespace KWayland::Client;
@ -62,6 +63,7 @@ private Q_SLOTS:
void testApplyInitialDesktopfile(); void testApplyInitialDesktopfile();
void testOpacityActive_data(); void testOpacityActive_data();
void testOpacityActive(); void testOpacityActive();
void testMatchAfterNameChange();
}; };
void TestShellClientRules::initTestCase() void TestShellClientRules::initTestCase()
@ -416,5 +418,37 @@ void TestShellClientRules::testOpacityActive()
QCOMPARE(c2->opacity(), 0.8); 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> surface(Test::createSurface());
QScopedPointer<XdgShellSurface> 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) WAYLANDTEST_MAIN(TestShellClientRules)
#include "shell_client_rules_test.moc" #include "shell_client_rules_test.moc"

View file

@ -138,6 +138,10 @@ void ShellClient::initSurface(T *shellSurface)
connect(shellSurface, &T::windowClassChanged, this, connect(shellSurface, &T::windowClassChanged, this,
[this, resourceName] (const QByteArray &windowClass) { [this, resourceName] (const QByteArray &windowClass) {
setResourceClass(resourceName, windowClass); setResourceClass(resourceName, windowClass);
if (!m_internal) {
setupWindowRules(true);
applyWindowRules();
}
setDesktopFileName(windowClass); setDesktopFileName(windowClass);
} }
); );