From a0aef86a7493892a975352c0615a5269d641dfb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Sun, 11 Feb 2018 18:27:34 +0100 Subject: [PATCH] Add test case for force opacity rules on ShellClient This is the first test for force rules. As those cannot be set through the temporary rules message the rulesrc must be modified. To support this RuleBook gained a setConfig method. To my positive surprise the rules already work as intended. --- .../integration/shell_client_rules_test.cpp | 62 +++++++++++++++++++ rules.cpp | 8 ++- rules.h | 6 ++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/autotests/integration/shell_client_rules_test.cpp b/autotests/integration/shell_client_rules_test.cpp index 89659d611e..73d23a485a 100644 --- a/autotests/integration/shell_client_rules_test.cpp +++ b/autotests/integration/shell_client_rules_test.cpp @@ -24,6 +24,7 @@ along with this program. If not, see . #include "shell_client.h" #include "virtualdesktops.h" #include "wayland_server.h" +#include "workspace.h" #include @@ -57,6 +58,8 @@ private Q_SLOTS: void testApplyInitialKeepBelow(); void testApplyInitialShortcut_data(); void testApplyInitialShortcut(); + void testOpacityActive_data(); + void testOpacityActive(); }; void TestShellClientRules::initTestCase() @@ -110,6 +113,20 @@ void TestShellClientRules::name##_data() \ QTest::newRow("xdgShellV6|ForceTemporarily") << Test::ShellSurfaceType::XdgShellV6 << 6; \ } +#define TEST_FORCE_DATA( name ) \ +void TestShellClientRules::name##_data() \ +{ \ + QTest::addColumn("type"); \ + QTest::addColumn("ruleNumber"); \ + QTest::newRow("wlShell|Force") << Test::ShellSurfaceType::WlShell << 2; \ + QTest::newRow("xdgShellV5|Force") << Test::ShellSurfaceType::XdgShellV5 << 2; \ + QTest::newRow("xdgShellV6|Force") << Test::ShellSurfaceType::XdgShellV6 << 2; \ + QTest::newRow("wlShell|ForceTemporarily") << Test::ShellSurfaceType::WlShell << 6; \ + QTest::newRow("xdgShellV5|ForceTemporarily") << Test::ShellSurfaceType::XdgShellV5 << 6; \ + QTest::newRow("xdgShellV6|ForceTemporarily") << Test::ShellSurfaceType::XdgShellV6 << 6; \ +} + + TEST_DATA(testApplyInitialDesktop) void TestShellClientRules::testApplyInitialDesktop() @@ -325,5 +342,50 @@ void TestShellClientRules::testApplyInitialShortcut() QCOMPARE(c->shortcut(), sequence); } +TEST_FORCE_DATA(testOpacityActive) + +void TestShellClientRules::testOpacityActive() +{ + KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); + config->group("General").writeEntry("count", 1); + + auto group = config->group("1"); + group.writeEntry("opacityactive", 90); + group.writeEntry("opacityinactive", 80); + QFETCH(int, ruleNumber); + group.writeEntry("opacityactiverule", ruleNumber); + group.writeEntry("opacityinactiverule", ruleNumber); + group.sync(); + + RuleBook::self()->setConfig(config); + workspace()->slotReconfigure(); + + QScopedPointer surface(Test::createSurface()); + QFETCH(Test::ShellSurfaceType, type); + QScopedPointer shellSurface(Test::createShellSurface(type, surface.data())); + + auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue); + QVERIFY(c); + QVERIFY(c->isActive()); + QCOMPARE(c->opacity(), 0.9); + + // open a second window + QScopedPointer surface2(Test::createSurface()); + QScopedPointer shellSurface2(Test::createShellSurface(type, surface2.data())); + + auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::blue); + QVERIFY(c2); + QVERIFY(c2->isActive()); + QVERIFY(!c->isActive()); + QCOMPARE(c2->opacity(), 0.9); + QCOMPARE(c->opacity(), 0.8); + + workspace()->activateClient(c); + QVERIFY(!c2->isActive()); + QVERIFY(c->isActive()); + QCOMPARE(c->opacity(), 0.9); + QCOMPARE(c2->opacity(), 0.8); +} + WAYLANDTEST_MAIN(TestShellClientRules) #include "shell_client_rules_test.moc" diff --git a/rules.cpp b/rules.cpp index 031dde3543..8804dc57c3 100644 --- a/rules.cpp +++ b/rules.cpp @@ -1043,12 +1043,14 @@ void RuleBook::edit(AbstractClient* c, bool whole_app) void RuleBook::load() { deleteAll(); - KConfig cfg(QStringLiteral(KWIN_NAME "rulesrc"), KConfig::NoGlobals); - int count = cfg.group("General").readEntry("count", 0); + if (!m_config) { + m_config = KSharedConfig::openConfig(QStringLiteral(KWIN_NAME "rulesrc"), KConfig::NoGlobals); + } + int count = m_config->group("General").readEntry("count", 0); for (int i = 1; i <= count; ++i) { - KConfigGroup cg(&cfg, QString::number(i)); + KConfigGroup cg(m_config, QString::number(i)); Rules* rule = new Rules(cg); m_rules.append(rule); } diff --git a/rules.h b/rules.h index 007ce5b71b..f5367bf394 100644 --- a/rules.h +++ b/rules.h @@ -299,6 +299,11 @@ public: void load(); void edit(AbstractClient* c, bool whole_app); void requestDiskStorage(); + + void setConfig(const KSharedConfig::Ptr &config) { + m_config = config; + } + private Q_SLOTS: void temporaryRulesMessage(const QString&); void cleanupTemporaryRules(); @@ -311,6 +316,7 @@ private: bool m_updatesDisabled; QList m_rules; QScopedPointer m_temporaryRulesMessages; + KSharedConfig::Ptr m_config; KWIN_SINGLETON(RuleBook) };