From faab23e9147ff0701e83b8eb39d5ca1680b07d08 Mon Sep 17 00:00:00 2001 From: Yifan Zhu Date: Thu, 11 Jan 2024 15:31:04 -0800 Subject: [PATCH] kcms/options: port to KCModule methods Remove code that duplicates functionality of KCModule. Previously the various config items were not fully ported to using KCModule methods, and kept custom versions of isSaveNeeded and isDefault. When called from KWinOptions::updateUnmanagedState, these methods incorrectly reports that there are still changes to be saved. This patch set ports all configs in window behavior to methods provided by KCModule, solving the problem. BUG: 477940 --- src/kcms/options/main.cpp | 24 ++++++++++++------------ src/kcms/options/mouse.cpp | 20 -------------------- src/kcms/options/mouse.h | 3 --- src/kcms/options/windows.cpp | 36 ++---------------------------------- src/kcms/options/windows.h | 11 ----------- 5 files changed, 14 insertions(+), 80 deletions(-) diff --git a/src/kcms/options/main.cpp b/src/kcms/options/main.cpp index 9d865768be..1fdcf7bbde 100644 --- a/src/kcms/options/main.cpp +++ b/src/kcms/options/main.cpp @@ -144,21 +144,21 @@ void KWinOptions::defaults() void KWinOptions::updateUnmanagedState() { - bool isNeedSave = false; - isNeedSave |= mFocus->isSaveNeeded(); - isNeedSave |= mTitleBarActions->isSaveNeeded(); - isNeedSave |= mWindowActions->isSaveNeeded(); - isNeedSave |= mMoving->isSaveNeeded(); - isNeedSave |= mAdvanced->isSaveNeeded(); + bool changed = false; + changed |= mFocus->needsSave(); + changed |= mTitleBarActions->needsSave(); + changed |= mWindowActions->needsSave(); + changed |= mMoving->needsSave(); + changed |= mAdvanced->needsSave(); - unmanagedWidgetChangeState(isNeedSave); + unmanagedWidgetChangeState(changed); bool isDefault = true; - isDefault &= mFocus->isDefaults(); - isDefault &= mTitleBarActions->isDefaults(); - isDefault &= mWindowActions->isDefaults(); - isDefault &= mMoving->isDefaults(); - isDefault &= mAdvanced->isDefaults(); + isDefault &= mFocus->representsDefaults(); + isDefault &= mTitleBarActions->representsDefaults(); + isDefault &= mWindowActions->representsDefaults(); + isDefault &= mMoving->representsDefaults(); + isDefault &= mAdvanced->representsDefaults(); unmanagedWidgetDefaultState(isDefault); } diff --git a/src/kcms/options/mouse.cpp b/src/kcms/options/mouse.cpp index b4e55a6cb0..3059681eaa 100644 --- a/src/kcms/options/mouse.cpp +++ b/src/kcms/options/mouse.cpp @@ -50,16 +50,6 @@ void KTitleBarActionsConfig::save() } } -bool KTitleBarActionsConfig::isDefaults() const -{ - return managedWidgetDefaultState(); -} - -bool KTitleBarActionsConfig::isSaveNeeded() const -{ - return managedWidgetChangeState(); -} - KWindowActionsConfig::KWindowActionsConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent) : KCModule(parent, KPluginMetaData()) , standAlone(_standAlone) @@ -88,14 +78,4 @@ void KWindowActionsConfig::save() } } -bool KWindowActionsConfig::isDefaults() const -{ - return managedWidgetDefaultState(); -} - -bool KWindowActionsConfig::isSaveNeeded() const -{ - return managedWidgetChangeState(); -} - #include "moc_mouse.cpp" diff --git a/src/kcms/options/mouse.h b/src/kcms/options/mouse.h index b54a670962..9bc89cc2ed 100644 --- a/src/kcms/options/mouse.h +++ b/src/kcms/options/mouse.h @@ -44,9 +44,6 @@ public: void save() override; - bool isDefaults() const; - bool isSaveNeeded() const; - protected: void initialize(KWinOptionsSettings *settings); diff --git a/src/kcms/options/windows.cpp b/src/kcms/options/windows.cpp index 7f91f3c428..59408ce833 100644 --- a/src/kcms/options/windows.cpp +++ b/src/kcms/options/windows.cpp @@ -142,11 +142,9 @@ void KFocusConfig::focusPolicyChanged() break; } - m_unmanagedChangeState = m_settings->focusPolicy() != selectedFocusPolicy || loadedNextFocusPrefersMouseItem != selectedNextFocusPrefersMouseItem; - unmanagedWidgetChangeState(m_unmanagedChangeState); + unmanagedWidgetChangeState(m_settings->focusPolicy() != selectedFocusPolicy || loadedNextFocusPrefersMouseItem != selectedNextFocusPrefersMouseItem); - m_unmanagedDefaultState = focusPolicy == defaultFocusPolicyIndex; - unmanagedWidgetDefaultState(m_unmanagedDefaultState); + unmanagedWidgetDefaultState(focusPolicy == defaultFocusPolicyIndex); // the auto raise related widgets are: autoRaise m_ui->kcfg_AutoRaise->setEnabled(focusPolicy != CLICK_TO_FOCUS && focusPolicy != CLICK_TO_FOCUS_MOUSE_PRECEDENT); @@ -224,16 +222,6 @@ void KFocusConfig::defaults() m_ui->windowFocusPolicy->setCurrentIndex(defaultFocusPolicyIndex); } -bool KFocusConfig::isDefaults() const -{ - return managedWidgetDefaultState() && m_unmanagedDefaultState; -} - -bool KFocusConfig::isSaveNeeded() const -{ - return managedWidgetChangeState() || m_unmanagedChangeState; -} - KWinAdvancedConfigForm::KWinAdvancedConfigForm(QWidget *parent) : QWidget(parent) { @@ -286,16 +274,6 @@ void KAdvancedConfig::save(void) } } -bool KAdvancedConfig::isDefaults() const -{ - return managedWidgetDefaultState(); -} - -bool KAdvancedConfig::isSaveNeeded() const -{ - return managedWidgetChangeState(); -} - KWinMovingConfigForm::KWinMovingConfigForm(QWidget *parent) : QWidget(parent) { @@ -330,14 +308,4 @@ void KMovingConfig::save(void) } } -bool KMovingConfig::isDefaults() const -{ - return managedWidgetDefaultState(); -} - -bool KMovingConfig::isSaveNeeded() const -{ - return managedWidgetChangeState(); -} - #include "moc_windows.cpp" diff --git a/src/kcms/options/windows.h b/src/kcms/options/windows.h index 55ba293030..e74f1a4de4 100644 --- a/src/kcms/options/windows.h +++ b/src/kcms/options/windows.h @@ -64,9 +64,6 @@ public: void save() override; void defaults() override; - bool isDefaults() const; - bool isSaveNeeded() const; - protected: void initialize(KWinOptionsSettings *settings); @@ -77,8 +74,6 @@ private Q_SLOTS: private: bool standAlone; - bool m_unmanagedChangeState = false; - bool m_unmanagedDefaultState = true; KWinFocusConfigForm *m_ui; KWinOptionsSettings *m_settings; @@ -94,9 +89,6 @@ public: void save() override; - bool isDefaults() const; - bool isSaveNeeded() const; - protected: void initialize(KWinOptionsSettings *settings); @@ -114,9 +106,6 @@ public: void save() override; - bool isDefaults() const; - bool isSaveNeeded() const; - protected: void initialize(KWinOptionsSettings *settings, KWinOptionsKDEGlobalsSettings *globalSettings);