Commit 9e74199e authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Refactor color scheme related code

Currently, we have two functions that update the color scheme for a
client - updateColorScheme(QString) and updateColorScheme(). Even though
they both share the same name, they do different things. The first one
sets the specified color scheme, while the other determines the color
scheme preferred by the client and assigns it.

This change refactors the color scheme initialization code so we no
longer need those two methods. The setColorScheme() method sets the
specified color scheme, and the preferredColorScheme() method returns
the color scheme preferred by the client. Sub-classes of AbstractClient
can override the preferredColorScheme() method in order to add support
for platform-specific color scheme protocols.

The end result: color scheme related code is a bit more comprehensible.
parent eeeac049
......@@ -742,14 +742,25 @@ const Decoration::DecorationPalette *AbstractClient::decorationPalette() const
return m_palette.get();
}
void AbstractClient::updateColorScheme(QString path)
QString AbstractClient::preferredColorScheme() const
{
if (path.isEmpty()) {
path = QStringLiteral("kdeglobals");
return rules()->checkDecoColor(QString());
}
QString AbstractClient::colorScheme() const
{
return m_colorScheme;
}
void AbstractClient::setColorScheme(const QString &colorScheme)
{
QString requestedColorScheme = colorScheme;
if (requestedColorScheme.isEmpty()) {
requestedColorScheme = QStringLiteral("kdeglobals");
}
if (!m_palette || m_colorScheme != path) {
m_colorScheme = path;
if (!m_palette || m_colorScheme != requestedColorScheme) {
m_colorScheme = requestedColorScheme;
if (m_palette) {
disconnect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &AbstractClient::handlePaletteChange);
......@@ -784,6 +795,11 @@ void AbstractClient::updateColorScheme(QString path)
}
}
void AbstractClient::updateColorScheme()
{
setColorScheme(preferredColorScheme());
}
void AbstractClient::handlePaletteChange()
{
emit paletteChanged(palette());
......
......@@ -797,9 +797,10 @@ public:
QString applicationMenuObjectPath() const {
return m_applicationMenuObjectPath;
}
QString colorScheme() const {
return m_colorScheme;
}
virtual QString preferredColorScheme() const;
QString colorScheme() const;
void setColorScheme(const QString &colorScheme);
/**
* Request showing the application menu bar
......@@ -975,10 +976,7 @@ protected:
void setupWindowManagementInterface();
void destroyWindowManagementInterface();
void updateColorScheme(QString path);
virtual void updateColorScheme() = 0;
void updateColorScheme();
void setTransientFor(AbstractClient *transientFor);
/**
* Just removes the @p cl from the transients without any further checks.
......
......@@ -44,7 +44,6 @@ public:
bool supportsWindowRules() const override { return false; }
void closeWindow() override {}
bool takeFocus() override { return false; }
void updateColorScheme() override {}
bool wantsInput() const override { return false; }
bool isInputMethod() const override { return true; }
bool isInitialPositionSet() const override { return true; }
......
......@@ -384,11 +384,6 @@ void InternalClient::updateDecoration(bool check_workspace_pos, bool force)
}
}
void InternalClient::updateColorScheme()
{
AbstractClient::updateColorScheme(QString());
}
void InternalClient::showOnScreenEdge()
{
}
......
......@@ -65,7 +65,6 @@ public:
bool takeFocus() override;
void setNoBorder(bool set) override;
void updateDecoration(bool check_workspace_pos, bool force = false) override;
void updateColorScheme() override;
void showOnScreenEdge() override;
void destroyClient() override;
......
......@@ -370,7 +370,7 @@ bool X11Client::manage(xcb_window_t w, bool isMapped)
auto wmClientLeaderCookie = fetchWmClientLeader();
auto skipCloseAnimationCookie = fetchSkipCloseAnimation();
auto showOnScreenEdgeCookie = fetchShowOnScreenEdge();
auto colorSchemeCookie = fetchColorScheme();
auto colorSchemeCookie = fetchPreferredColorScheme();
auto firstInTabBoxCookie = fetchFirstInTabBox();
auto transientCookie = fetchTransient();
auto activitiesCookie = fetchActivities();
......@@ -603,7 +603,7 @@ bool X11Client::manage(xcb_window_t w, bool isMapped)
// Create client group if the window will have a decoration
bool dontKeepInArea = false;
readColorScheme(colorSchemeCookie);
setColorScheme(readPreferredColorScheme(colorSchemeCookie));
readApplicationMenuServiceName(applicationMenuServiceNameCookie);
readApplicationMenuObjectPath(applicationMenuObjectPathCookie);
......@@ -2552,20 +2552,20 @@ void X11Client::updateFirstInTabBox()
readFirstInTabBox(property);
}
Xcb::StringProperty X11Client::fetchColorScheme() const
Xcb::StringProperty X11Client::fetchPreferredColorScheme() const
{
return Xcb::StringProperty(m_client, atoms->kde_color_sheme);
}
void X11Client::readColorScheme(Xcb::StringProperty &property)
QString X11Client::readPreferredColorScheme(Xcb::StringProperty &property) const
{
AbstractClient::updateColorScheme(rules()->checkDecoColor(QString::fromUtf8(property)));
return rules()->checkDecoColor(QString::fromUtf8(property));
}
void X11Client::updateColorScheme()
QString X11Client::preferredColorScheme() const
{
Xcb::StringProperty property = fetchColorScheme();
readColorScheme(property);
Xcb::StringProperty property = fetchPreferredColorScheme();
return readPreferredColorScheme(property);
}
bool X11Client::isClient() const
......
......@@ -264,9 +264,9 @@ public:
Xcb::Property fetchFirstInTabBox() const;
void readFirstInTabBox(Xcb::Property &property);
void updateFirstInTabBox();
Xcb::StringProperty fetchColorScheme() const;
void readColorScheme(Xcb::StringProperty &property);
void updateColorScheme() override;
Xcb::StringProperty fetchPreferredColorScheme() const;
QString readPreferredColorScheme(Xcb::StringProperty &property) const;
QString preferredColorScheme() const override;
//sets whether the client should be faked as being on all activities (and be shown during session save)
void setSessionActivityOverride(bool needed);
......
......@@ -1326,13 +1326,12 @@ void XdgToplevelClient::updateFullScreenMode(bool set)
emit fullScreenChanged();
}
void XdgToplevelClient::updateColorScheme()
QString XdgToplevelClient::preferredColorScheme() const
{
if (m_paletteInterface) {
AbstractClient::updateColorScheme(rules()->checkDecoColor(m_paletteInterface->palette()));
} else {
AbstractClient::updateColorScheme(rules()->checkDecoColor(QString()));
return rules()->checkDecoColor(m_paletteInterface->palette());
}
return rules()->checkDecoColor(QString());
}
void XdgToplevelClient::installAppMenu(AppMenuInterface *appMenu)
......@@ -1390,16 +1389,11 @@ void XdgToplevelClient::installPalette(ServerSideDecorationPaletteInterface *pal
{
m_paletteInterface = palette;
auto updatePalette = [this](const QString &palette) {
AbstractClient::updateColorScheme(rules()->checkDecoColor(palette));
};
connect(m_paletteInterface, &ServerSideDecorationPaletteInterface::paletteChanged, this, [=](const QString &palette) {
updatePalette(palette);
});
connect(m_paletteInterface, &QObject::destroyed, this, [=]() {
updatePalette(QString());
});
updatePalette(palette->palette());
connect(m_paletteInterface, &ServerSideDecorationPaletteInterface::paletteChanged,
this, &XdgToplevelClient::updateColorScheme);
connect(m_paletteInterface, &QObject::destroyed,
this, &XdgToplevelClient::updateColorScheme);
updateColorScheme();
}
/**
......@@ -2018,11 +2012,6 @@ void XdgPopupClient::closeWindow()
{
}
void XdgPopupClient::updateColorScheme()
{
AbstractClient::updateColorScheme(QString());
}
bool XdgPopupClient::noBorder() const
{
return true;
......
......@@ -147,7 +147,7 @@ public:
bool noBorder() const override;
void setNoBorder(bool set) override;
void updateDecoration(bool check_workspace_pos, bool force = false) override;
void updateColorScheme() override;
QString preferredColorScheme() const override;
bool supportsWindowRules() const override;
bool takeFocus() override;
bool wantsInput() const override;
......@@ -246,7 +246,6 @@ public:
QRect transientPlacement(const QRect &bounds) const override;
bool isCloseable() const override;
void closeWindow() override;
void updateColorScheme() override;
bool noBorder() const override;
bool userCanSetNoBorder() const override;
void setNoBorder(bool set) override;
......
Markdown is supported
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