diff --git a/abstract_client.cpp b/abstract_client.cpp index 6155e25fc8..e69a35bdb5 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -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()); diff --git a/abstract_client.h b/abstract_client.h index 0d065dddb2..c3b011da25 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -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. diff --git a/inputpanelv1client.h b/inputpanelv1client.h index 93b127d5a9..95e538421d 100644 --- a/inputpanelv1client.h +++ b/inputpanelv1client.h @@ -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; } diff --git a/internal_client.cpp b/internal_client.cpp index da9b301b29..91d3615389 100644 --- a/internal_client.cpp +++ b/internal_client.cpp @@ -384,11 +384,6 @@ void InternalClient::updateDecoration(bool check_workspace_pos, bool force) } } -void InternalClient::updateColorScheme() -{ - AbstractClient::updateColorScheme(QString()); -} - void InternalClient::showOnScreenEdge() { } diff --git a/internal_client.h b/internal_client.h index 083d591e5e..ae6dbd4155 100644 --- a/internal_client.h +++ b/internal_client.h @@ -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; diff --git a/x11client.cpp b/x11client.cpp index eb0a0ffaef..a492168292 100644 --- a/x11client.cpp +++ b/x11client.cpp @@ -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 diff --git a/x11client.h b/x11client.h index affe77de92..843341b581 100644 --- a/x11client.h +++ b/x11client.h @@ -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); diff --git a/xdgshellclient.cpp b/xdgshellclient.cpp index 7b27e08872..f07557ad43 100644 --- a/xdgshellclient.cpp +++ b/xdgshellclient.cpp @@ -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; diff --git a/xdgshellclient.h b/xdgshellclient.h index 6e5e2dcb3a..8892f230d9 100644 --- a/xdgshellclient.h +++ b/xdgshellclient.h @@ -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;