Commit a0aef86a authored by Martin Flöser's avatar Martin Flöser
Browse files

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.
parent ca5747c0
......@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "shell_client.h"
#include "virtualdesktops.h"
#include "wayland_server.h"
#include "workspace.h"
#include <KWayland/Client/surface.h>
......@@ -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<Test::ShellSurfaceType>("type"); \
QTest::addColumn<int>("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> surface(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type);
QScopedPointer<QObject> 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<Surface> surface2(Test::createSurface());
QScopedPointer<QObject> 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"
......@@ -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);
}
......
......@@ -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<Rules*> m_rules;
QScopedPointer<KXMessages> m_temporaryRulesMessages;
KSharedConfig::Ptr m_config;
KWIN_SINGLETON(RuleBook)
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment