diff --git a/libkdecorations/kdecoration.cpp b/libkdecorations/kdecoration.cpp index 7c07798d04..b6aeb4ccfc 100644 --- a/libkdecorations/kdecoration.cpp +++ b/libkdecorations/kdecoration.cpp @@ -514,11 +514,19 @@ QString KDecorationDefines::tabDragMimeType() return QStringLiteral("text/ClientGroupItem"); } -KDecorationOptions::KDecorationOptions() - : d(new KDecorationOptionsPrivate) +KDecorationOptions::KDecorationOptions(QObject *parent) + : QObject(parent) + , d(new KDecorationOptionsPrivate(this)) { assert(KDecoration::options_ == NULL); KDecoration::options_ = this; + connect(this, &KDecorationOptions::activeFontChanged, this, &KDecorationOptions::fontsChanged); + connect(this, &KDecorationOptions::inactiveFontChanged, this, &KDecorationOptions::fontsChanged); + connect(this, &KDecorationOptions::smallActiveFontChanged, this, &KDecorationOptions::fontsChanged); + connect(this, &KDecorationOptions::smallInactiveFontChanged, this, &KDecorationOptions::fontsChanged); + connect(this, &KDecorationOptions::leftButtonsChanged, this, &KDecorationOptions::buttonsChanged); + connect(this, &KDecorationOptions::rightButtonsChanged, this, &KDecorationOptions::buttonsChanged); + connect(this, &KDecorationOptions::customButtonPositionsChanged, this, &KDecorationOptions::buttonsChanged); } KDecorationOptions::~KDecorationOptions() @@ -555,9 +563,9 @@ QPalette KDecorationOptions::palette(ColorType type, bool active) const return(*d->pal[idx]); } -unsigned long KDecorationOptions::updateSettings(KConfig* config) +void KDecorationOptions::updateSettings(KConfig* config) { - return d->updateSettings(config); + d->updateSettings(config); } bool KDecorationOptions::customButtonPositions() const diff --git a/libkdecorations/kdecoration.h b/libkdecorations/kdecoration.h index cae6a91b4b..5874f9131e 100644 --- a/libkdecorations/kdecoration.h +++ b/libkdecorations/kdecoration.h @@ -269,10 +269,11 @@ public: * It is accessible from the decorations either as KDecoration::options() * or KDecorationFactory::options(). */ -class KWIN_EXPORT KDecorationOptions : public KDecorationDefines +class KWIN_EXPORT KDecorationOptions : public QObject, public KDecorationDefines { + Q_OBJECT public: - KDecorationOptions(); + KDecorationOptions(QObject *parent = nullptr); virtual ~KDecorationOptions(); /** * Call to update settings when the config changes. Return value is @@ -378,9 +379,93 @@ public: */ WindowOperation operationMaxButtonClick(Qt::MouseButtons button) const; +Q_SIGNALS: /** - * @internal + * @brief Emitted when at least one of the color settings changed. + * + * @see color */ + void colorsChanged(); + /** + * @brief Emitted when the active font changed. + * + * @see font + */ + void activeFontChanged(); + /** + * @brief Emitted when the inactive font changed. + * + * @see font + */ + void inactiveFontChanged(); + /** + * @brief Emitted when the small active font changed + * + * @see font + */ + void smallActiveFontChanged(); + /** + * @brief Emitted when the small inactive font changed + * + * @see font + */ + void smallInactiveFontChanged(); + /** + * @brief Emitted if any of the fonts changed. + * + * @see activeFontChanged + * @see inactiveFontChanged + * @see smallInactiveFontChanged + * @see smallInactiveFontChanged + */ + void fontsChanged(); + /** + * @brief Emitted when the left title buttons changed. + * + * @see titleButtonsLeft + * @see defaultTitleButtonsLeft + */ + void leftButtonsChanged(); + /** + * @brief Emitted when the right title buttons changed. + * + * @see titleButtonsRight + * @see defaultTitleButtonsRight + */ + void rightButtonsChanged(); + /** + * @brief Emitted when the custom buttons position setting changed. + * + * @see customButtonPositions + */ + void customButtonPositionsChanged(); + /** + * @brief Emitted when one of the title buttons relevant settings changed. + * + * @see leftButtonsChanged + * @see rightButtonsChanged + * @see customButtonPositionsChanged + */ + void buttonsChanged(); + /** + * @brief Emitted when show tooltips setting changed. + * + * @see showTooltips + */ + void showTooltipsChanged(); + /** + * @brief Emitted when the border size setting changed. + * + * @see preferredBorderSize + */ + void borderSizeChanged(); + /** + * @brief This signal is emitted whenever the configuration changed. + * + * A decoration plugin should connect to this signal and evaluate whether + * some decoration specific settings need to be updated. + */ + void configChanged(); protected: /** @internal */ diff --git a/libkdecorations/kdecoration_p.cpp b/libkdecorations/kdecoration_p.cpp index 70085d9f0b..797b24a7be 100644 --- a/libkdecorations/kdecoration_p.cpp +++ b/libkdecorations/kdecoration_p.cpp @@ -31,8 +31,9 @@ DEALINGS IN THE SOFTWARE. #include #include -KDecorationOptionsPrivate::KDecorationOptionsPrivate() - : title_buttons_left(KDecorationOptions::defaultTitleButtonsLeft()) +KDecorationOptionsPrivate::KDecorationOptionsPrivate(KDecorationOptions *parent) + : q(parent) + , title_buttons_left(KDecorationOptions::defaultTitleButtonsLeft()) , title_buttons_right(KDecorationOptions::defaultTitleButtonsRight()) , custom_button_positions(false) , show_tooltips(true) @@ -57,9 +58,8 @@ KDecorationOptionsPrivate::~KDecorationOptionsPrivate() } } -unsigned long KDecorationOptionsPrivate::updateSettings(KConfig* config) +void KDecorationOptionsPrivate::updateSettings(KConfig* config) { - unsigned long changed = 0; KConfigGroup wmConfig(config, "WM"); // SettingColors @@ -126,11 +126,17 @@ unsigned long KDecorationOptionsPrivate::updateSettings(KConfig* config) colors[ColorFont+NUM_COLORS] = wmConfig.readEntry("inactiveForeground", colors[ColorFont+NUM_COLORS]); + bool colorsChanged = false; for (int i = 0; i < NUM_COLORS * 2; ++i) - if (old_colors[ i ] != colors[ i ]) - changed |= SettingColors; + if (old_colors[ i ] != colors[ i ]) { + colorsChanged = true; + break; + } + if (colorsChanged) { + emit q->colorsChanged(); + } // SettingFont QFont old_activeFont = activeFont; @@ -141,19 +147,25 @@ unsigned long KDecorationOptionsPrivate::updateSettings(KConfig* config) QFont activeFontGuess = QFontDatabase::systemFont(QFontDatabase::TitleFont); activeFont = wmConfig.readEntry("activeFont", activeFontGuess); + if (activeFont != old_activeFont) { + emit q->activeFontChanged(); + } inactiveFont = wmConfig.readEntry("inactiveFont", activeFont); + if (inactiveFont != old_inactiveFont) { + emit q->inactiveFontChanged(); + } activeFontSmall = activeFont; // TODO: Is it useful ? (Temporary hack) //activeFontSmall.setPointSize(activeFont.pointSize() - 2 > 0 ? activeFont.pointSize() - 2 : activeFont.pointSize()+1 ); activeFontSmall = wmConfig.readEntry("activeFontSmall", activeFontSmall); + if (activeFontSmall != old_activeFontSmall) { + emit q->smallActiveFontChanged(); + } inactiveFontSmall = wmConfig.readEntry("inactiveFontSmall", activeFontSmall); - - if (old_activeFont != activeFont - || old_inactiveFont != inactiveFont - || old_activeFontSmall != activeFontSmall - || old_inactiveFontSmall != inactiveFontSmall) - changed |= SettingFont; + if (inactiveFontSmall != old_inactiveFontSmall) { + emit q->smallInactiveFontChanged(); + } KConfigGroup styleConfig(config, "Style"); // SettingsButtons @@ -168,17 +180,22 @@ unsigned long KDecorationOptionsPrivate::updateSettings(KConfig* config) title_buttons_left = KDecorationOptions::defaultTitleButtonsLeft(); title_buttons_right = KDecorationOptions::defaultTitleButtonsRight(); } - if (old_custom_button_positions != custom_button_positions - || (custom_button_positions && - (old_title_buttons_left != title_buttons_left - || old_title_buttons_right != title_buttons_right))) - changed |= SettingButtons; + if (old_custom_button_positions != custom_button_positions) { + emit q->customButtonPositionsChanged(); + } + if (old_title_buttons_left != title_buttons_left) { + emit q->leftButtonsChanged(); + } + if (old_title_buttons_right != title_buttons_right) { + emit q->rightButtonsChanged(); + } // SettingTooltips bool old_show_tooltips = show_tooltips; show_tooltips = styleConfig.readEntry("ShowToolTips", true); - if (old_show_tooltips != show_tooltips) - changed |= SettingTooltips; + if (old_show_tooltips != show_tooltips) { + emit q->showTooltipsChanged(); + } // SettingBorder @@ -188,8 +205,9 @@ unsigned long KDecorationOptionsPrivate::updateSettings(KConfig* config) border_size = static_cast< BorderSize >(border_size_num); else border_size = BorderNormal; - if (old_border_size != border_size) - changed |= SettingBorder; + if (old_border_size != border_size) { + emit q->borderSizeChanged(); + } cached_border_size = BordersCount; // invalid // destroy cached values @@ -201,7 +219,7 @@ unsigned long KDecorationOptionsPrivate::updateSettings(KConfig* config) } } - return changed; + emit q->configChanged(); } KDecorationDefines::BorderSize KDecorationOptionsPrivate::findPreferredBorderSize(BorderSize size, diff --git a/libkdecorations/kdecoration_p.h b/libkdecorations/kdecoration_p.h index e1a38ed027..44124e3239 100644 --- a/libkdecorations/kdecoration_p.h +++ b/libkdecorations/kdecoration_p.h @@ -37,11 +37,12 @@ class KConfig; class KDecorationOptionsPrivate : public KDecorationDefines { public: - KDecorationOptionsPrivate(); + KDecorationOptionsPrivate(KDecorationOptions *parent); ~KDecorationOptionsPrivate(); - unsigned long updateSettings(KConfig*); // shared implementation + void updateSettings(KConfig*); // shared implementation BorderSize findPreferredBorderSize(BorderSize size, QList< BorderSize >) const; // shared implementation + KDecorationOptions *q; QColor colors[NUM_COLORS*2]; QPalette *pal[NUM_COLORS*2]; QFont activeFont, inactiveFont, activeFontSmall, inactiveFontSmall; diff --git a/options.cpp b/options.cpp index 517c3d45b9..f2eee2d857 100644 --- a/options.cpp +++ b/options.cpp @@ -107,7 +107,7 @@ int currentRefreshRate() } Options::Options(QObject *parent) - : QObject(parent) + : KDecorationOptions(parent) , m_settings(new Settings(KSharedConfig::openConfig())) , m_focusPolicy(ClickToFocus) , m_nextFocusPrefersMouse(false) diff --git a/options.h b/options.h index 6d5addbff9..8b3fde4fd2 100644 --- a/options.h +++ b/options.h @@ -23,7 +23,6 @@ along with this program. If not, see . #ifndef KWIN_OPTIONS_H #define KWIN_OPTIONS_H -#include #include #include "placement.h" @@ -47,7 +46,7 @@ enum HiddenPreviews { class Settings; -class Options : public QObject, public KDecorationOptions +class Options : public KDecorationOptions { Q_OBJECT Q_ENUMS(FocusPolicy)