From d61eaa2d66b0749d6b03bfd1d6c6a93751187a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Sun, 11 Mar 2018 17:13:32 +0100 Subject: [PATCH] Add a new desktopfile name rule Summary: This allows to override the desktop file name. CCBUG: 351055 Test Plan: Created a window rule for telegram-desktop to fix the icon Reviewers: #kwin, #plasma Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D11266 --- abstract_client.cpp | 4 +- abstract_client.h | 2 +- .../integration/shell_client_rules_test.cpp | 29 ++++++++ dbusinterface.cpp | 1 + kcmkwin/kwinrules/ruleswidget.cpp | 6 ++ kcmkwin/kwinrules/ruleswidget.h | 1 + kcmkwin/kwinrules/ruleswidgetbase.ui | 70 +++++++++++++++++-- manage.cpp | 2 +- rules.cpp | 14 +++- rules.h | 6 +- shell_client.cpp | 2 +- 11 files changed, 126 insertions(+), 11 deletions(-) diff --git a/abstract_client.cpp b/abstract_client.cpp index 10bd76b664..393e17bcc0 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -1664,12 +1664,14 @@ bool AbstractClient::dockWantsInput() const return false; } -void AbstractClient::setDesktopFileName(const QByteArray &name) +void AbstractClient::setDesktopFileName(QByteArray name) { + name = rules()->checkDesktopFile(name).toUtf8(); if (name == m_desktopFileName) { return; } m_desktopFileName = name; + updateWindowRules(Rules::DesktopFile); emit desktopFileNameChanged(); } diff --git a/abstract_client.h b/abstract_client.h index b964293543..237f3b1c49 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -1008,7 +1008,7 @@ protected: void startDecorationDoubleClickTimer(); void invalidateDecorationDoubleClickTimer(); - void setDesktopFileName(const QByteArray &name); + void setDesktopFileName(QByteArray name); QString iconFromDesktopFile() const; void updateApplicationMenuServiceName(const QString &serviceName); diff --git a/autotests/integration/shell_client_rules_test.cpp b/autotests/integration/shell_client_rules_test.cpp index 73d23a485a..ed75bd4f33 100644 --- a/autotests/integration/shell_client_rules_test.cpp +++ b/autotests/integration/shell_client_rules_test.cpp @@ -58,6 +58,8 @@ private Q_SLOTS: void testApplyInitialKeepBelow(); void testApplyInitialShortcut_data(); void testApplyInitialShortcut(); + void testApplyInitialDesktopfile_data(); + void testApplyInitialDesktopfile(); void testOpacityActive_data(); void testOpacityActive(); }; @@ -342,6 +344,33 @@ void TestShellClientRules::testApplyInitialShortcut() QCOMPARE(c->shortcut(), sequence); } +TEST_DATA(testApplyInitialDesktopfile) + +void TestShellClientRules::testApplyInitialDesktopfile() +{ + // install the temporary rule + QFETCH(int, ruleNumber); + QString rule = QStringLiteral("desktopfile=org.kde.kwin\ndesktopfilerule=%1").arg(ruleNumber); + QMetaObject::invokeMethod(RuleBook::self(), "temporaryRulesMessage", Q_ARG(QString, rule)); + + 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); + QCOMPARE(c->desktop(), 1); + QCOMPARE(c->isMinimized(), false); + QCOMPARE(c->isActive(), true); + QCOMPARE(c->skipTaskbar(), false); + QCOMPARE(c->skipPager(), false); + QCOMPARE(c->skipSwitcher(), false); + QCOMPARE(c->keepAbove(), false); + QCOMPARE(c->keepBelow(), false); + QCOMPARE(c->shortcut(), QKeySequence()); + QCOMPARE(c->desktopFileName(), QByteArrayLiteral("org.kde.kwin")); +} + TEST_FORCE_DATA(testOpacityActive) void TestShellClientRules::testOpacityActive() diff --git a/dbusinterface.cpp b/dbusinterface.cpp index ea5f5955da..9bfd9950a8 100644 --- a/dbusinterface.cpp +++ b/dbusinterface.cpp @@ -198,6 +198,7 @@ QVariantMap DBusInterface::queryWindowInfo() const QVariantMap ret{ {QStringLiteral("resourceClass"), c->resourceClass()}, {QStringLiteral("resourceName"), c->resourceName()}, + {QStringLiteral("desktopFile"), c->desktopFileName()}, {QStringLiteral("role"), c->windowRole()}, {QStringLiteral("caption"), c->captionNormal()}, {QStringLiteral("clientMachine"), c->wmClientMachine(true)}, diff --git a/kcmkwin/kwinrules/ruleswidget.cpp b/kcmkwin/kwinrules/ruleswidget.cpp index 240027f24d..ddd1deba40 100644 --- a/kcmkwin/kwinrules/ruleswidget.cpp +++ b/kcmkwin/kwinrules/ruleswidget.cpp @@ -125,6 +125,7 @@ RulesWidget::RulesWidget(QWidget* parent) SETUP(fsplevel, force); SETUP(fpplevel, force); SETUP(type, force); + SETUP(desktopfile, set); SETUP(ignoregeometry, set); SETUP(minsize, force); SETUP(maxsize, force); @@ -230,6 +231,7 @@ UPDATE_ENABLE_SLOT(maxsize) UPDATE_ENABLE_SLOT(strictgeometry) UPDATE_ENABLE_SLOT(disableglobalshortcuts) UPDATE_ENABLE_SLOT(blockcompositing) +UPDATE_ENABLE_SLOT(desktopfile) #undef UPDATE_ENABLE_SLOT @@ -546,6 +548,7 @@ void RulesWidget::setRules(Rules* rules) CHECKBOX_FORCE_RULE(strictgeometry,); CHECKBOX_FORCE_RULE(disableglobalshortcuts,); CHECKBOX_FORCE_RULE(blockcompositing,); + LINEEDIT_SET_RULE(desktopfile,) } #undef GENERIC_RULE @@ -650,6 +653,7 @@ Rules* RulesWidget::rules() const CHECKBOX_FORCE_RULE(strictgeometry,); CHECKBOX_FORCE_RULE(disableglobalshortcuts,); CHECKBOX_FORCE_RULE(blockcompositing,); + LINEEDIT_SET_RULE(desktopfile,); return rules; } @@ -770,6 +774,7 @@ void RulesWidget::prefillUnusedValues(const KWindowInfo& info) //CHECKBOX_PREFILL( strictgeometry, ); //CHECKBOX_PREFILL( disableglobalshortcuts, ); //CHECKBOX_PREFILL( blockcompositing, ); + LINEEDIT_PREFILL(desktopfile, , info.desktopFileName()); } void RulesWidget::prefillUnusedValues(const QVariantMap& info) @@ -808,6 +813,7 @@ void RulesWidget::prefillUnusedValues(const QVariantMap& info) //CHECKBOX_PREFILL( strictgeometry, ); //CHECKBOX_PREFILL( disableglobalshortcuts, ); //CHECKBOX_PREFILL( blockcompositing, ); + LINEEDIT_PREFILL(desktopfile, , info.value("desktopFile").toString()); } #undef GENERIC_PREFILL diff --git a/kcmkwin/kwinrules/ruleswidget.h b/kcmkwin/kwinrules/ruleswidget.h index 714ed885c9..3f48c643a7 100644 --- a/kcmkwin/kwinrules/ruleswidget.h +++ b/kcmkwin/kwinrules/ruleswidget.h @@ -101,6 +101,7 @@ private Q_SLOTS: void updateEnableshortcut(); void updateEnabledisableglobalshortcuts(); void updateEnableblockcompositing(); + void updateEnabledesktopfile(); // internal void detected(bool); private: diff --git a/kcmkwin/kwinrules/ruleswidgetbase.ui b/kcmkwin/kwinrules/ruleswidgetbase.ui index b24124a8cf..6ca054f22d 100644 --- a/kcmkwin/kwinrules/ruleswidgetbase.ui +++ b/kcmkwin/kwinrules/ruleswidgetbase.ui @@ -2501,21 +2501,78 @@ while it's active! - + + + + Desktop file name + + + + + + + + + + false + + + + Do Not Affect + + + + + Apply Initially + + + + + Remember + + + + + Force + + + + + Apply Now + + + + + Force Temporarily + + + + + + + + false + + + org.kde.kwin + + + + Qt::Horizontal - + Block compositing - + false @@ -2537,14 +2594,14 @@ while it's active! - + false - + Qt::Vertical @@ -2684,6 +2741,9 @@ while it's active! enable_type rule_type type + enable_desktopfile + rule_desktopfile + desktopfile enable_blockcompositing rule_blockcompositing tabs diff --git a/manage.cpp b/manage.cpp index 8daebebe72..efa607e45d 100644 --- a/manage.cpp +++ b/manage.cpp @@ -146,7 +146,7 @@ bool Client::manage(xcb_window_t w, bool isMapped) setModal((info->state() & NET::Modal) != 0); // Needs to be valid before handling groups readTransientProperty(transientCookie); - setDesktopFileName(QByteArray(info->desktopFileName())); + setDesktopFileName(rules()->checkDesktopFile(QByteArray(info->desktopFileName()), true).toUtf8()); getIcons(); connect(this, &Client::desktopFileNameChanged, this, &Client::getIcons); diff --git a/rules.cpp b/rules.cpp index 8804dc57c3..6bb91bf3c3 100644 --- a/rules.cpp +++ b/rules.cpp @@ -82,6 +82,7 @@ Rules::Rules() , strictgeometryrule(UnusedForceRule) , shortcutrule(UnusedSetRule) , disableglobalshortcutsrule(UnusedForceRule) + , desktopfilerule(UnusedSetRule) { } @@ -192,6 +193,7 @@ void Rules::readFromCfg(const KConfigGroup& cfg) READ_FORCE_RULE(strictgeometry, , false); READ_SET_RULE(shortcut, , QString()); READ_FORCE_RULE(disableglobalshortcuts, , false); + READ_SET_RULE(desktopfile, , QString()); } #undef READ_MATCH_STRING @@ -290,6 +292,7 @@ void Rules::write(KConfigGroup& cfg) const WRITE_FORCE_RULE(strictgeometry,); WRITE_SET_RULE(shortcut,); WRITE_FORCE_RULE(disableglobalshortcuts,); + WRITE_SET_RULE(desktopfile,); } #undef WRITE_MATCH_STRING @@ -333,7 +336,8 @@ bool Rules::isEmpty() const && autogroupidrule == UnusedForceRule && strictgeometryrule == UnusedForceRule && shortcutrule == UnusedSetRule - && disableglobalshortcutsrule == UnusedForceRule); + && disableglobalshortcutsrule == UnusedForceRule + && desktopfilerule == UnusedSetRule); } Rules::SetRule Rules::readSetRule(const KConfigGroup& cfg, const QString& key) @@ -553,6 +557,10 @@ bool Rules::update(AbstractClient* c, int selection) updated = updated || noborder != c->noBorder(); noborder = c->noBorder(); } + if NOW_REMEMBER(DesktopFile, desktopfile) { + updated = updated || desktopfile != c->desktopFileName(); + desktopfile = c->desktopFileName(); + } return updated; } @@ -663,6 +671,7 @@ APPLY_FORCE_RULE(autogroupid, AutogroupById, QString) APPLY_FORCE_RULE(strictgeometry, StrictGeometry, bool) APPLY_RULE(shortcut, Shortcut, QString) APPLY_FORCE_RULE(disableglobalshortcuts, DisableGlobalShortcuts, bool) +APPLY_RULE(desktopfile, DesktopFile, QString) #undef APPLY_RULE @@ -732,6 +741,7 @@ void Rules::discardUsed(bool withdrawn) DISCARD_USED_FORCE_RULE(strictgeometry); DISCARD_USED_SET_RULE(shortcut); DISCARD_USED_FORCE_RULE(disableglobalshortcuts); + DISCARD_USED_SET_RULE(desktopfile); } #undef DISCARD_USED_SET_RULE #undef DISCARD_USED_FORCE_RULE @@ -866,6 +876,7 @@ CHECK_FORCE_RULE(AutogroupById, QString) CHECK_FORCE_RULE(StrictGeometry, bool) CHECK_RULE(Shortcut, QString) CHECK_FORCE_RULE(DisableGlobalShortcuts, bool) +CHECK_RULE(DesktopFile, QString) #undef CHECK_RULE #undef CHECK_FORCE_RULE @@ -932,6 +943,7 @@ void AbstractClient::applyWindowRules() workspace()->disableGlobalShortcutsForClient(rules()->checkDisableGlobalShortcuts(false)); } else setOpacity(rules()->checkOpacityInactive(qRound(opacity() * 100.0)) / 100.0); + setDesktopFileName(rules()->checkDesktopFile(desktopFileName()).toUtf8()); } void Client::updateWindowRules(Rules::Types selection) diff --git a/rules.h b/rules.h index f5367bf394..8ee403f17a 100644 --- a/rules.h +++ b/rules.h @@ -89,6 +89,7 @@ public: bool checkStrictGeometry(bool strict) const; QString checkShortcut(QString s, bool init = false) const; bool checkDisableGlobalShortcuts(bool disable) const; + QString checkDesktopFile(QString desktopFile, bool init = false) const; private: MaximizeMode checkMaximizeVert(MaximizeMode mode, bool init) const; MaximizeMode checkMaximizeHoriz(MaximizeMode mode, bool init) const; @@ -109,7 +110,7 @@ public: Shade = 1<<6, SkipTaskbar = 1<<7, SkipPager = 1<<8, SkipSwitcher = 1<<9, Above = 1<<10, Below = 1<<11, Fullscreen = 1<<12, NoBorder = 1<<13, OpacityActive = 1<<14, OpacityInactive = 1<<15, - Activity = 1<<16, Screen = 1<<17, All = 0xffffffff + Activity = 1<<16, Screen = 1<<17, DesktopFile = 1 << 18, All = 0xffffffff }; Q_DECLARE_FLAGS(Types, Type) void write(KConfigGroup&) const; @@ -157,6 +158,7 @@ public: bool applyStrictGeometry(bool& strict) const; bool applyShortcut(QString& shortcut, bool init) const; bool applyDisableGlobalShortcuts(bool& disable) const; + bool applyDesktopFile(QString &desktopFile, bool init) const; private: #endif bool matchType(NET::WindowType match_type) const; @@ -283,6 +285,8 @@ private: SetRule shortcutrule; bool disableglobalshortcuts; ForceRule disableglobalshortcutsrule; + QString desktopfile; + SetRule desktopfilerule; friend QDebug& operator<<(QDebug& stream, const Rules*); }; diff --git a/shell_client.cpp b/shell_client.cpp index 59f5a32930..65ab9e27b5 100644 --- a/shell_client.cpp +++ b/shell_client.cpp @@ -135,7 +135,6 @@ void ShellClient::initSurface(T *shellSurface) resourceName = info.fileName().toUtf8(); } setResourceClass(resourceName, shellSurface->windowClass()); - setDesktopFileName(shellSurface->windowClass()); connect(shellSurface, &T::windowClassChanged, this, [this, resourceName] (const QByteArray &windowClass) { setResourceClass(resourceName, windowClass); @@ -197,6 +196,7 @@ void ShellClient::initSurface(T *shellSurface) if (!m_internal) { setupWindowRules(false); } + setDesktopFileName(rules()->checkDesktopFile(shellSurface->windowClass(), true).toUtf8()); } void ShellClient::init()