From 59f66233f2a1a88709ba353fa10aaa2de69ddd18 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 18 Oct 2018 18:19:44 +0300 Subject: [PATCH] track files for schemes changes --track changes for wm default scheme --track changes for colors in specific scheme --- app/abstractwindowinterface.cpp | 37 ++++++++++++++++++++++++++++----- app/abstractwindowinterface.h | 3 +++ app/schemecolors.cpp | 11 ++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/app/abstractwindowinterface.cpp b/app/abstractwindowinterface.cpp index 4f8f8b7c5..d43acd8f5 100644 --- a/app/abstractwindowinterface.cpp +++ b/app/abstractwindowinterface.cpp @@ -23,8 +23,10 @@ #include "waylandinterface.h" #include +#include #include +#include #include namespace Latte { @@ -32,15 +34,23 @@ namespace Latte { AbstractWindowInterface::AbstractWindowInterface(QObject *parent) : QObject(parent) { - QString defaultSchemePath = SchemeColors::possibleSchemeFile("kdeglobals"); - SchemeColors *dScheme = new SchemeColors(this, defaultSchemePath); - - m_schemes["kdeglobals"] = dScheme; - m_schemes[defaultSchemePath] = dScheme; + updateDefaultScheme(); connect(this, &AbstractWindowInterface::windowRemoved, this, [&](WindowId wid) { m_windowScheme.remove(wid); }); + + //! track for changing default scheme + QString kdeSettingsFile = QDir::homePath() + "/.config/kdeglobals"; + + KDirWatch::self()->addFile(kdeSettingsFile); + + QObject::connect(KDirWatch::self(), &KDirWatch::dirty, + this, &AbstractWindowInterface::updateDefaultScheme, + Qt::QueuedConnection); + QObject::connect(KDirWatch::self(), &KDirWatch::created, + this, &AbstractWindowInterface::updateDefaultScheme, + Qt::QueuedConnection); } AbstractWindowInterface::~AbstractWindowInterface() @@ -67,6 +77,23 @@ void AbstractWindowInterface::removeDock(WindowId wid) //! Scheme support for windows +void AbstractWindowInterface::updateDefaultScheme() +{ + QString defaultSchemePath = SchemeColors::possibleSchemeFile("kdeglobals"); + + SchemeColors *dScheme; + + if (!m_schemes.contains(defaultSchemePath)) { + dScheme = new SchemeColors(this, defaultSchemePath); + } else { + dScheme = m_schemes[defaultSchemePath]; + } + + if (!m_schemes.contains("kdeglobal") || m_schemes["kdeglobals"]->schemeFile() != defaultSchemePath) { + m_schemes["kdeglobals"] = dScheme; + } +} + SchemeColors *AbstractWindowInterface::schemeForWindow(WindowId wid) { if (!m_windowScheme.contains(wid)) { diff --git a/app/abstractwindowinterface.h b/app/abstractwindowinterface.h index 998c704c2..1dbea9629 100644 --- a/app/abstractwindowinterface.h +++ b/app/abstractwindowinterface.h @@ -101,6 +101,9 @@ protected: std::list m_docks; QPointer m_activities; +private slots: + void updateDefaultScheme(); + private: //! scheme file and its loaded colors QMap m_schemes; diff --git a/app/schemecolors.cpp b/app/schemecolors.cpp index ab4982de7..26be722ca 100644 --- a/app/schemecolors.cpp +++ b/app/schemecolors.cpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace Latte { @@ -37,6 +38,16 @@ SchemeColors::SchemeColors(QObject *parent, QString scheme) : if (QFileInfo(pSchemeFile).exists()) { m_schemeFile = pSchemeFile; m_schemeName = scheme; + + //! track scheme file for changes + KDirWatch::self()->addFile(m_schemeFile); + + QObject::connect(KDirWatch::self(), &KDirWatch::dirty, + this, &SchemeColors::updateScheme, + Qt::QueuedConnection); + QObject::connect(KDirWatch::self(), &KDirWatch::created, + this, &SchemeColors::updateScheme, + Qt::QueuedConnection); } updateScheme();