[kwin] Window specific rule for decoration color scheme
Adds a new force rule to specify the color scheme to use on the window decoration. The scheme is stored by the name of the .colors file name. So for Oxygen.colors the value is Oxygen. When loaded the scheme is located and the full path to the colors file is used. This is because the X property also uses the full path.
This commit is contained in:
parent
1c5e5c8480
commit
49cf996aa7
3 changed files with 39 additions and 6 deletions
|
@ -2453,16 +2453,16 @@ void Client::updateColorScheme()
|
|||
auto resetToDefault = [this]() {
|
||||
m_palette = QApplication::palette();
|
||||
};
|
||||
QString path;
|
||||
if (!prop.isNull() && prop->format == 8 && prop->value_len > 0) {
|
||||
QString path = QString::fromUtf8(static_cast<const char*>(xcb_get_property_value(prop.data())));
|
||||
path = QString::fromUtf8(static_cast<const char*>(xcb_get_property_value(prop.data())));
|
||||
}
|
||||
path = rules()->checkDecoColor(path);
|
||||
if (!path.isNull()) {
|
||||
m_palette = KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path));
|
||||
} else {
|
||||
resetToDefault();
|
||||
}
|
||||
} else {
|
||||
resetToDefault();
|
||||
}
|
||||
triggerDecorationRepaint();
|
||||
}
|
||||
|
||||
|
|
28
rules.cpp
28
rules.cpp
|
@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QRegExp>
|
||||
#include <QTemporaryFile>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <ktoolinvocation.h>
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -70,6 +71,7 @@ Rules::Rules()
|
|||
, belowrule(UnusedSetRule)
|
||||
, fullscreenrule(UnusedSetRule)
|
||||
, noborderrule(UnusedSetRule)
|
||||
, decocolorrule(UnusedForceRule)
|
||||
, blockcompositingrule(UnusedForceRule)
|
||||
, fsplevelrule(UnusedForceRule)
|
||||
, acceptfocusrule(UnusedForceRule)
|
||||
|
@ -177,6 +179,8 @@ void Rules::readFromCfg(const KConfigGroup& cfg)
|
|||
READ_SET_RULE(below, , false);
|
||||
READ_SET_RULE(fullscreen, , false);
|
||||
READ_SET_RULE(noborder, , false);
|
||||
decocolor = readDecoColor(cfg);
|
||||
decocolorrule = decocolor.isEmpty() ? UnusedForceRule : readForceRule(cfg, QStringLiteral("decocolorrule"));
|
||||
READ_FORCE_RULE(blockcompositing, , false);
|
||||
READ_FORCE_RULE(fsplevel, limit0to4, 0); // fsp is 0-4
|
||||
READ_FORCE_RULE(acceptfocus, , false);
|
||||
|
@ -266,6 +270,14 @@ void Rules::write(KConfigGroup& cfg) const
|
|||
WRITE_SET_RULE(below,);
|
||||
WRITE_SET_RULE(fullscreen,);
|
||||
WRITE_SET_RULE(noborder,);
|
||||
auto colorToString = [](const QString &value) {
|
||||
if (value.endsWith(QStringLiteral(".colors"))) {
|
||||
return QFileInfo(value).baseName();
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
WRITE_FORCE_RULE(decocolor, colorToString);
|
||||
WRITE_FORCE_RULE(blockcompositing,);
|
||||
WRITE_FORCE_RULE(fsplevel,);
|
||||
WRITE_FORCE_RULE(acceptfocus,);
|
||||
|
@ -308,6 +320,7 @@ bool Rules::isEmpty() const
|
|||
&& belowrule == UnusedSetRule
|
||||
&& fullscreenrule == UnusedSetRule
|
||||
&& noborderrule == UnusedSetRule
|
||||
&& decocolorrule == UnusedForceRule
|
||||
&& blockcompositingrule == UnusedForceRule
|
||||
&& fsplevelrule == UnusedForceRule
|
||||
&& acceptfocusrule == UnusedForceRule
|
||||
|
@ -344,6 +357,17 @@ NET::WindowType Rules::readType(const KConfigGroup& cfg, const QString& key)
|
|||
return NET::Unknown;
|
||||
}
|
||||
|
||||
QString Rules::readDecoColor(const KConfigGroup &cfg)
|
||||
{
|
||||
QString themeName = cfg.readEntry("decocolor", QString());
|
||||
if (themeName.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
// find the actual scheme file
|
||||
return QStandardPaths::locate(QStandardPaths::GenericDataLocation,
|
||||
QStringLiteral("color-schemes/") + themeName + QStringLiteral(".colors"));
|
||||
}
|
||||
|
||||
bool Rules::matchType(NET::WindowType match_type) const
|
||||
{
|
||||
if (types != NET::AllTypesMask) {
|
||||
|
@ -625,6 +649,7 @@ APPLY_RULE(above, KeepAbove, bool)
|
|||
APPLY_RULE(below, KeepBelow, bool)
|
||||
APPLY_RULE(fullscreen, FullScreen, bool)
|
||||
APPLY_RULE(noborder, NoBorder, bool)
|
||||
APPLY_FORCE_RULE(decocolor, DecoColor, QString)
|
||||
APPLY_FORCE_RULE(blockcompositing, BlockCompositing, bool)
|
||||
APPLY_FORCE_RULE(fsplevel, FSP, int)
|
||||
APPLY_FORCE_RULE(acceptfocus, AcceptFocus, bool)
|
||||
|
@ -692,6 +717,7 @@ void Rules::discardUsed(bool withdrawn)
|
|||
DISCARD_USED_SET_RULE(below);
|
||||
DISCARD_USED_SET_RULE(fullscreen);
|
||||
DISCARD_USED_SET_RULE(noborder);
|
||||
DISCARD_USED_FORCE_RULE(decocolor);
|
||||
DISCARD_USED_FORCE_RULE(blockcompositing);
|
||||
DISCARD_USED_FORCE_RULE(fsplevel);
|
||||
DISCARD_USED_FORCE_RULE(acceptfocus);
|
||||
|
@ -824,6 +850,7 @@ CHECK_RULE(KeepAbove, bool)
|
|||
CHECK_RULE(KeepBelow, bool)
|
||||
CHECK_RULE(FullScreen, bool)
|
||||
CHECK_RULE(NoBorder, bool)
|
||||
CHECK_FORCE_RULE(DecoColor, QString)
|
||||
CHECK_FORCE_RULE(BlockCompositing, bool)
|
||||
CHECK_FORCE_RULE(FSP, int)
|
||||
CHECK_FORCE_RULE(AcceptFocus, bool)
|
||||
|
@ -877,6 +904,7 @@ void Client::applyWindowRules()
|
|||
setKeepBelow(keepBelow());
|
||||
setFullScreen(isFullScreen(), true);
|
||||
setNoBorder(noBorder());
|
||||
updateColorScheme();
|
||||
// FSP
|
||||
// AcceptFocus :
|
||||
if (workspace()->mostRecentlyActivatedClient() == this
|
||||
|
|
5
rules.h
5
rules.h
|
@ -77,6 +77,7 @@ public:
|
|||
bool checkKeepBelow(bool below, bool init = false) const;
|
||||
bool checkFullScreen(bool fs, bool init = false) const;
|
||||
bool checkNoBorder(bool noborder, bool init = false) const;
|
||||
QString checkDecoColor(QString schemeFile) const;
|
||||
bool checkBlockCompositing(bool block) const;
|
||||
int checkFSP(int fsp) const;
|
||||
bool checkAcceptFocus(bool focus) const;
|
||||
|
@ -144,6 +145,7 @@ public:
|
|||
bool applyKeepBelow(bool& below, bool init) const;
|
||||
bool applyFullScreen(bool& fs, bool init) const;
|
||||
bool applyNoBorder(bool& noborder, bool init) const;
|
||||
bool applyDecoColor(QString &schemeFile) const;
|
||||
bool applyBlockCompositing(bool& block) const;
|
||||
bool applyFSP(int& fsp) const;
|
||||
bool applyAcceptFocus(bool& focus) const;
|
||||
|
@ -191,6 +193,7 @@ private:
|
|||
static SetRule readSetRule(const KConfigGroup&, const QString& key);
|
||||
static ForceRule readForceRule(const KConfigGroup&, const QString& key);
|
||||
static NET::WindowType readType(const KConfigGroup&, const QString& key);
|
||||
static QString readDecoColor(const KConfigGroup &cfg);
|
||||
#ifndef KCMRULES
|
||||
static bool checkSetRule(SetRule rule, bool init);
|
||||
static bool checkForceRule(ForceRule rule);
|
||||
|
@ -255,6 +258,8 @@ private:
|
|||
SetRule fullscreenrule;
|
||||
bool noborder;
|
||||
SetRule noborderrule;
|
||||
QString decocolor;
|
||||
ForceRule decocolorrule;
|
||||
bool blockcompositing;
|
||||
ForceRule blockcompositingrule;
|
||||
int fsplevel;
|
||||
|
|
Loading…
Reference in a new issue