From 23862e512d1f208dfaff498110db69e1886d41d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 29 Apr 2015 12:02:54 +0200 Subject: [PATCH] Move implementation of ::palette to AbstractClient Includes moving of the colorscheme and DecorationPalette related functionality. --- abstract_client.cpp | 64 +++++++++++++++++++++++++++++++++ abstract_client.h | 19 +++++++++- client.cpp | 53 ++------------------------- client.h | 22 ------------ decorations/decoratedclient.cpp | 1 + 5 files changed, 85 insertions(+), 74 deletions(-) diff --git a/abstract_client.cpp b/abstract_client.cpp index d00bf21426..20dd3aea69 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "abstract_client.h" +#include "decorations/decorationpalette.h" #include "focuschain.h" #ifdef KWIN_BUILD_TABBOX #include "tabbox.h" @@ -27,11 +28,15 @@ along with this program. If not, see . namespace KWin { +QHash> AbstractClient::s_palettes; +std::shared_ptr AbstractClient::s_defaultPalette; + AbstractClient::AbstractClient() : Toplevel() #ifdef KWIN_BUILD_TABBOX , m_tabBoxClient(QSharedPointer(new TabBox::TabBoxClientImpl(this))) #endif + , m_colorScheme(QStringLiteral("kdeglobals")) { } @@ -355,4 +360,63 @@ void AbstractClient::doMinimize() { } +QPalette AbstractClient::palette() const +{ + if (!m_palette) { + return QPalette(); + } + return m_palette->palette(); +} + +const Decoration::DecorationPalette *AbstractClient::decorationPalette() const +{ + return m_palette.get(); +} + +void AbstractClient::updateColorScheme(QString path) +{ + if (path.isEmpty()) { + path = QStringLiteral("kdeglobals"); + } + + if (!m_palette || m_colorScheme != path) { + m_colorScheme = path; + + if (m_palette) { + disconnect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &AbstractClient::handlePaletteChange); + } + + auto it = s_palettes.find(m_colorScheme); + + if (it == s_palettes.end() || it->expired()) { + m_palette = std::make_shared(m_colorScheme); + if (m_palette->isValid()) { + s_palettes[m_colorScheme] = m_palette; + } else { + if (!s_defaultPalette) { + s_defaultPalette = std::make_shared(QStringLiteral("kdeglobals")); + s_palettes[QStringLiteral("kdeglobals")] = s_defaultPalette; + } + + m_palette = s_defaultPalette; + } + + if (m_colorScheme == QStringLiteral("kdeglobals")) { + s_defaultPalette = m_palette; + } + } else { + m_palette = it->lock(); + } + + connect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &AbstractClient::handlePaletteChange); + + emit paletteChanged(palette()); + } +} + +void AbstractClient::handlePaletteChange() +{ + emit paletteChanged(palette()); +} + } diff --git a/abstract_client.h b/abstract_client.h index 6411e7e978..02170a113a 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -24,6 +24,8 @@ along with this program. If not, see . #include "options.h" #include "rules.h" +#include + namespace KWin { @@ -34,6 +36,11 @@ namespace TabBox class TabBoxClientImpl; } +namespace Decoration +{ +class DecorationPalette; +} + class AbstractClient : public Toplevel { Q_OBJECT @@ -202,7 +209,8 @@ public: virtual bool noBorder() const = 0; virtual void setNoBorder(bool set) = 0; virtual void blockActivityUpdates(bool b = true) = 0; - virtual QPalette palette() const = 0; + QPalette palette() const; + const Decoration::DecorationPalette *decorationPalette() const; virtual bool isResizable() const = 0; virtual bool isMovable() const = 0; virtual bool isMovableAcrossScreens() const = 0; @@ -302,6 +310,7 @@ Q_SIGNALS: void minimizedChanged(); void clientMinimized(KWin::AbstractClient* client, bool animate); void clientUnminimized(KWin::AbstractClient* client, bool animate); + void paletteChanged(const QPalette &p); protected: AbstractClient(); @@ -351,7 +360,10 @@ protected: // TODO: remove boolean trap virtual bool belongsToSameApplication(const AbstractClient *other, bool active_hack) const = 0; + void updateColorScheme(QString path); + private: + void handlePaletteChange(); QSharedPointer m_tabBoxClient; bool m_firstInTabBox = false; bool m_skipSwitcher = false; @@ -363,6 +375,11 @@ private: bool m_minimized = false; QTimer *m_autoRaiseTimer = nullptr; int m_desktop = 0; // 0 means not on any desktop yet + + QString m_colorScheme; + std::shared_ptr m_palette; + static QHash> s_palettes; + static std::shared_ptr s_defaultPalette; }; } diff --git a/client.cpp b/client.cpp index 5b789cb227..a15506cd01 100644 --- a/client.cpp +++ b/client.cpp @@ -76,9 +76,6 @@ const long ClientWinMask = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; -QHash> Client::s_palettes; -std::shared_ptr Client::s_defaultPalette; - // Creating a client: // - only by calling Workspace::createClient() // - it creates a new client and calls manage() for it @@ -135,7 +132,6 @@ Client::Client() , needsXWindowMove(false) , m_decoInputExtent() , m_focusOutTimer(nullptr) - , m_colorScheme(QStringLiteral("kdeglobals")) , m_clientSideDecorated(false) { // TODO: Do all as initialization @@ -185,6 +181,7 @@ Client::Client() connect(this, &Client::clientFinishUserMovedResized, this, &Client::moveResizedChanged); connect(this, &Client::clientStartUserMovedResized, this, &Client::removeCheckScreenConnection); connect(this, &Client::clientFinishUserMovedResized, this, &Client::setupCheckScreenConnection); + connect(this, &Client::paletteChanged, this, &Client::triggerDecorationRepaint); connect(clientMachine(), &ClientMachine::localhostChanged, this, &Client::updateCaption); connect(options, &Options::condensedTitleChanged, this, &Client::updateCaption); @@ -2119,47 +2116,7 @@ Xcb::StringProperty Client::fetchColorScheme() const void Client::readColorScheme(Xcb::StringProperty &property) { - QString path = QString::fromUtf8(property); - path = rules()->checkDecoColor(path); - - if (path.isEmpty()) { - path = QStringLiteral("kdeglobals"); - } - - if (!m_palette || m_colorScheme != path) { - m_colorScheme = path; - - if (m_palette) { - disconnect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &Client::handlePaletteChange); - } - - auto it = s_palettes.find(m_colorScheme); - - if (it == s_palettes.end() || it->expired()) { - m_palette = std::make_shared(m_colorScheme); - if (m_palette->isValid()) { - s_palettes[m_colorScheme] = m_palette; - } else { - if (!s_defaultPalette) { - s_defaultPalette = std::make_shared(QStringLiteral("kdeglobals")); - s_palettes[QStringLiteral("kdeglobals")] = s_defaultPalette; - } - - m_palette = s_defaultPalette; - } - - if (m_colorScheme == QStringLiteral("kdeglobals")) { - s_defaultPalette = m_palette; - } - } else { - m_palette = it->lock(); - } - - connect(m_palette.get(), &Decoration::DecorationPalette::changed, this, &Client::handlePaletteChange); - - emit paletteChanged(palette()); - triggerDecorationRepaint(); - } + AbstractClient::updateColorScheme(rules()->checkDecoColor(QString::fromUtf8(property))); } void Client::updateColorScheme() @@ -2168,12 +2125,6 @@ void Client::updateColorScheme() readColorScheme(property); } -void Client::handlePaletteChange() -{ - emit paletteChanged(palette()); - triggerDecorationRepaint(); -} - bool Client::isClient() const { return true; diff --git a/client.h b/client.h index 4e4443ef4f..df39da56de 100644 --- a/client.h +++ b/client.h @@ -28,7 +28,6 @@ along with this program. If not, see . #include "tabgroup.h" #include "abstract_client.h" #include "xcbutils.h" -#include "decorations/decorationpalette.h" // Qt #include #include @@ -524,9 +523,6 @@ public: void cancelFocusOutTimer(); - QPalette palette() const override; - const Decoration::DecorationPalette *decorationPalette() const; - /** * Restores the Client after it had been hidden due to show on screen edge functionality. * In addition the property gets deleted so that the Client knows that it is visible again. @@ -605,7 +601,6 @@ Q_SIGNALS: void moveResizedChanged(); void skipTaskbarChanged(); void skipPagerChanged(); - void paletteChanged(const QPalette &p); /** * Emitted whenever the Client's TabGroup changed. That is whenever the Client is moved to @@ -726,8 +721,6 @@ private: **/ void updateShowOnScreenEdge(); - void handlePaletteChange(); - Xcb::Window m_client; Xcb::Window m_wrapper; Xcb::Window m_frame; @@ -861,11 +854,6 @@ private: QTimer *m_focusOutTimer; - QString m_colorScheme; - std::shared_ptr m_palette; - static QHash> s_palettes; - static std::shared_ptr s_defaultPalette; - QList m_connections; bool m_clientSideDecorated; }; @@ -1081,16 +1069,6 @@ inline bool Client::hiddenPreview() const return mapping_state == Kept; } -inline QPalette Client::palette() const -{ - return m_palette->palette(); -} - -inline const Decoration::DecorationPalette *Client::decorationPalette() const -{ - return m_palette.get(); -} - template inline void Client::print(T &stream) const { diff --git a/decorations/decoratedclient.cpp b/decorations/decoratedclient.cpp index 83b7ea175d..9ebd24168c 100644 --- a/decorations/decoratedclient.cpp +++ b/decorations/decoratedclient.cpp @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "decoratedclient.h" +#include "decorationpalette.h" #include "decorationrenderer.h" #include "client.h" #include "composite.h"