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
This commit is contained in:
Martin Flöser 2018-03-11 17:13:32 +01:00
parent f1f97bb395
commit d61eaa2d66
11 changed files with 126 additions and 11 deletions

View file

@ -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();
}

View file

@ -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);

View file

@ -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()

View file

@ -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)},

View file

@ -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

View file

@ -101,6 +101,7 @@ private Q_SLOTS:
void updateEnableshortcut();
void updateEnabledisableglobalshortcuts();
void updateEnableblockcompositing();
void updateEnabledesktopfile();
// internal
void detected(bool);
private:

View file

@ -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>

View file

@ -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);

View file

@ -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)

View file

@ -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*);
};

View file

@ -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()