[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] /: Add a new desktopfile name rule
From:       Martin_Flöser <null () kde ! org>
Date:       2018-03-18 8:16:20
Message-ID: E1exTUK-0002Qp-9x () code ! kde ! org
[Download RAW message or body]

Git commit d61eaa2d66b0749d6b03bfd1d6c6a93751187a84 by Martin Flöser.
Committed on 18/03/2018 at 08:15.
Pushed by graesslin into branch 'master'.

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

M  +3    -1    abstract_client.cpp
M  +1    -1    abstract_client.h
M  +29   -0    autotests/integration/shell_client_rules_test.cpp
M  +1    -0    dbusinterface.cpp
M  +6    -0    kcmkwin/kwinrules/ruleswidget.cpp
M  +1    -0    kcmkwin/kwinrules/ruleswidget.h
M  +65   -5    kcmkwin/kwinrules/ruleswidgetbase.ui
M  +1    -1    manage.cpp
M  +13   -1    rules.cpp
M  +5    -1    rules.h
M  +1    -1    shell_client.cpp

https://commits.kde.org/kwin/d61eaa2d66b0749d6b03bfd1d6c6a93751187a84

diff --git a/abstract_client.cpp b/abstract_client.cpp
index 10bd76b66..393e17bcc 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 b96429354..237f3b1c4 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 73d23a485..ed75bd4f3 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> 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);
+    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 ea5f5955d..9bfd9950a 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 240027f24..ddd1deba4 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 714ed885c..3f48c643a 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 b24124a8c..6ca054f22 100644
--- a/kcmkwin/kwinrules/ruleswidgetbase.ui
+++ b/kcmkwin/kwinrules/ruleswidgetbase.ui
@@ -2501,21 +2501,78 @@ while it's active!</string>
          </item>
         </widget>
        </item>
-       <item row="15" column="1" colspan="5">
+       <item row="15" column="1">
+        <widget class="QCheckBox" name="enable_desktopfile">
+         <property name="text">
+          <string>Desktop file name</string>
+         </property>
+         <property name="shortcut">
+          <string/>
+         </property>
+        </widget>
+       </item>
+       <item row="15" column="2" colspan="3">
+        <widget class="QComboBox" name="rule_desktopfile">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <item>
+          <property name="text">
+           <string>Do Not Affect</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Apply Initially</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Remember</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Force</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Apply Now</string>
+          </property>
+         </item>
+         <item>
+          <property name="text">
+           <string>Force Temporarily</string>
+          </property>
+         </item>
+        </widget>
+       </item>
+       <item row="15" column="5">
+        <widget class="QLineEdit" name="desktopfile">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <property name="placeholderText">
+          <string>org.kde.kwin</string>
+         </property>
+        </widget>
+       </item>
+       <item row="16" column="1" colspan="5">
         <widget class="Line" name="line_7">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
         </widget>
        </item>
-       <item row="16" column="1">
+       <item row="17" column="1">
         <widget class="QCheckBox" name="enable_blockcompositing">
          <property name="text">
           <string>Block compositing</string>
          </property>
         </widget>
        </item>
-       <item row="16" column="2" colspan="3">
+       <item row="17" column="2" colspan="3">
         <widget class="QComboBox" name="rule_blockcompositing">
          <property name="enabled">
           <bool>false</bool>
@@ -2537,14 +2594,14 @@ while it's active!</string>
          </item>
         </widget>
        </item>
-       <item row="16" column="5">
+       <item row="17" column="5">
         <widget class="YesNoBox" name="blockcompositing" native="true">
          <property name="enabled">
           <bool>false</bool>
          </property>
         </widget>
        </item>
-       <item row="17" column="2">
+       <item row="18" column="2">
         <spacer name="verticalSpacer_5">
          <property name="orientation">
           <enum>Qt::Vertical</enum>
@@ -2684,6 +2741,9 @@ while it's active!</string>
   <tabstop>enable_type</tabstop>
   <tabstop>rule_type</tabstop>
   <tabstop>type</tabstop>
+  <tabstop>enable_desktopfile</tabstop>
+  <tabstop>rule_desktopfile</tabstop>
+  <tabstop>desktopfile</tabstop>
   <tabstop>enable_blockcompositing</tabstop>
   <tabstop>rule_blockcompositing</tabstop>
   <tabstop>tabs</tabstop>
diff --git a/manage.cpp b/manage.cpp
index 8daebebe7..efa607e45 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 8804dc57c..6bb91bf3c 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 f5367bf39..8ee403f17 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 59f5a3293..65ab9e27b 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()


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic