From b6ab50e6b722fd1482615f2e78f0d87d91928584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Wed, 5 Feb 2020 11:46:29 +0100 Subject: [PATCH] kcms/kwinoptions : convert Moving part to KConfigXT Test Plan: Behavior unchanged Reviewers: ervin, #kwin, zzag Reviewed By: #kwin, zzag Subscribers: zzag, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D27164 --- kcmkwin/kwinoptions/CMakeLists.txt | 2 + kcmkwin/kwinoptions/kwinoptions_settings.kcfg | 36 +++++ .../kwinoptions/kwinoptions_settings.kcfgc | 6 + kcmkwin/kwinoptions/main.cpp | 6 +- kcmkwin/kwinoptions/moving.ui | 20 +-- kcmkwin/kwinoptions/windows.cpp | 131 +----------------- kcmkwin/kwinoptions/windows.h | 24 +--- 7 files changed, 67 insertions(+), 158 deletions(-) create mode 100644 kcmkwin/kwinoptions/kwinoptions_settings.kcfg create mode 100644 kcmkwin/kwinoptions/kwinoptions_settings.kcfgc diff --git a/kcmkwin/kwinoptions/CMakeLists.txt b/kcmkwin/kwinoptions/CMakeLists.txt index eb071daad2..a5f0ccf420 100644 --- a/kcmkwin/kwinoptions/CMakeLists.txt +++ b/kcmkwin/kwinoptions/CMakeLists.txt @@ -17,6 +17,8 @@ ki18n_wrap_ui(kcm_kwinoptions_PART_SRCS moving.ui ) +kconfig_add_kcfg_files(kcm_kwinoptions_PART_SRCS kwinoptions_settings.kcfgc GENERATE_MOC) + qt5_add_dbus_interface(kcm_kwinoptions_PART_SRCS ${KWin_SOURCE_DIR}/org.kde.kwin.Effects.xml kwin_effects_interface) add_library(kcm_kwinoptions MODULE ${kcm_kwinoptions_PART_SRCS}) target_link_libraries(kcm_kwinoptions Qt5::DBus KF5::Completion KF5::I18n KF5::ConfigWidgets KF5::Service KF5::WindowSystem) diff --git a/kcmkwin/kwinoptions/kwinoptions_settings.kcfg b/kcmkwin/kwinoptions/kwinoptions_settings.kcfg new file mode 100644 index 0000000000..c664ee5dfe --- /dev/null +++ b/kcmkwin/kwinoptions/kwinoptions_settings.kcfg @@ -0,0 +1,36 @@ + + + + + + + false + + + + 10 + 0 + 100 + + + + 10 + 0 + 100 + + + + 0 + 0 + 100 + + + + false + + + + diff --git a/kcmkwin/kwinoptions/kwinoptions_settings.kcfgc b/kcmkwin/kwinoptions/kwinoptions_settings.kcfgc new file mode 100644 index 0000000000..7135009fb2 --- /dev/null +++ b/kcmkwin/kwinoptions/kwinoptions_settings.kcfgc @@ -0,0 +1,6 @@ +File=kwinoptions_settings.kcfg +ClassName=KWinOptionsSettings +Mutators=true +DefaultValueGetters=true +ParentInConstructor=true +Singleton=true diff --git a/kcmkwin/kwinoptions/main.cpp b/kcmkwin/kwinoptions/main.cpp index 66c03124d5..198e088567 100644 --- a/kcmkwin/kwinoptions/main.cpp +++ b/kcmkwin/kwinoptions/main.cpp @@ -50,7 +50,7 @@ class KMovingConfigStandalone : public KMovingConfig Q_OBJECT public: KMovingConfigStandalone(QWidget* parent, const QVariantList &) - : KMovingConfig(true, new KConfig("kwinrc"), parent) + : KMovingConfig(true, parent) {} }; @@ -88,7 +88,7 @@ KWinOptions::KWinOptions(QWidget *parent, const QVariantList &) tab->addTab(mWindowActions, i18n("W&indow Actions")); connect(mWindowActions, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); - mMoving = new KMovingConfig(false, mConfig, this); + mMoving = new KMovingConfig(false, this); mMoving->setObjectName(QLatin1String("KWin Moving")); tab->addTab(mMoving, i18n("Mo&vement")); connect(mMoving, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); @@ -230,6 +230,8 @@ void KActionsOptions::defaults() { mTitleBarActions->defaults(); mWindowActions->defaults(); + + emit defaulted(true); } void KActionsOptions::moduleChanged(bool state) diff --git a/kcmkwin/kwinoptions/moving.ui b/kcmkwin/kwinoptions/moving.ui index 97f38a8bdb..69019b3379 100644 --- a/kcmkwin/kwinoptions/moving.ui +++ b/kcmkwin/kwinoptions/moving.ui @@ -20,12 +20,12 @@ Window &geometry: - geometryTipOn + kcfg_GeometryTip - + Enable this option if you want a window's geometry to be displayed while it is being moved or resized. The window position relative to the top-left corner of the screen is displayed together with its size. @@ -40,12 +40,12 @@ Screen &edge snap zone: - borderSnap + kcfg_BorderSnapZone - + Here you can set the snap zone for screen edges, i.e. the 'strength' of the magnetic field which will make windows snap to the border when moved near it. @@ -67,7 +67,7 @@ - + Here you can set the snap zone for windows, i.e. the 'strength' of the magnetic field which will make windows snap to each other when they are moved near another window. @@ -89,7 +89,7 @@ - + Here you can set the snap zone for the screen center, i.e. the 'strength' of the magnetic field which will make windows snap to the center of the screen when moved near it. @@ -108,7 +108,7 @@ - + Here you can set that windows will be only snapped if you try to overlap them, i.e. they will not be snapped if the windows comes only near another window or border. @@ -123,7 +123,7 @@ &Window snap zone: - windowSnap + kcfg_WindowSnapZone @@ -133,7 +133,7 @@ &Center snap zone: - centerSnap + kcfg_CenterSnapZone @@ -143,7 +143,7 @@ &Snap windows: - OverlapSnap + kcfg_SnapOnlyWhenOverlapping diff --git a/kcmkwin/kwinoptions/windows.cpp b/kcmkwin/kwinoptions/windows.cpp index aaa534bb10..2e5f5a041f 100644 --- a/kcmkwin/kwinoptions/windows.cpp +++ b/kcmkwin/kwinoptions/windows.cpp @@ -37,13 +37,13 @@ #include #include "windows.h" +#include "kwinoptions_settings.h" #include #include // kwin config keywords #define KWIN_FOCUS "FocusPolicy" #define KWIN_PLACEMENT "Placement" -#define KWIN_GEOMETRY "GeometryTip" #define KWIN_AUTORAISE_INTERVAL "AutoRaiseInterval" #define KWIN_AUTORAISE "AutoRaise" #define KWIN_DELAYFOCUS_INTERVAL "DelayFocusInterval" @@ -56,19 +56,6 @@ #define KWIN_SEPARATE_SCREEN_FOCUS "SeparateScreenFocus" #define KWIN_ACTIVE_MOUSE_SCREEN "ActiveMouseScreen" -//CT 15mar 98 - magics -#define KWM_BRDR_SNAP_ZONE "BorderSnapZone" -#define KWM_BRDR_SNAP_ZONE_DEFAULT 10 -#define KWM_WNDW_SNAP_ZONE "WindowSnapZone" -#define KWM_WNDW_SNAP_ZONE_DEFAULT 10 -#define KWM_CNTR_SNAP_ZONE "CenterSnapZone" -#define KWM_CNTR_SNAP_ZONE_DEFAULT 0 - -#define MAX_BRDR_SNAP 100 -#define MAX_WNDW_SNAP 100 -#define MAX_CNTR_SNAP 100 -#define MAX_EDGE_RES 1000 - #define CLICK_TO_FOCUS 0 #define FOCUS_FOLLOWS_MOUSE 2 #define FOCUS_UNDER_MOUSE 4 @@ -492,34 +479,16 @@ KWinMovingConfigForm::KWinMovingConfigForm(QWidget* parent) KMovingConfig::~KMovingConfig() { - if (standAlone) - delete config; } -KMovingConfig::KMovingConfig(bool _standAlone, KConfig *_config, QWidget *parent) - : KCModule(parent), config(_config), standAlone(_standAlone) +KMovingConfig::KMovingConfig(bool _standAlone, QWidget *parent) + : KCModule(parent), m_config(KWinOptionsSettings::self()), standAlone(_standAlone) , m_ui(new KWinMovingConfigForm(this)) { - // Any changes goes to slotChanged() - connect(m_ui->geometryTipOn, SIGNAL(clicked()), SLOT(changed())); - connect(m_ui->borderSnap, SIGNAL(valueChanged(int)), SLOT(changed())); - connect(m_ui->windowSnap, SIGNAL(valueChanged(int)), SLOT(changed())); - connect(m_ui->centerSnap, SIGNAL(valueChanged(int)), SLOT(changed())); - connect(m_ui->OverlapSnap, SIGNAL(clicked()), SLOT(changed())); - + addConfig(m_config, m_ui); load(); } -void KMovingConfig::setGeometryTip(bool showGeometryTip) -{ - m_ui->geometryTipOn->setChecked(showGeometryTip); -} - -bool KMovingConfig::getGeometryTip() -{ - return m_ui->geometryTipOn->isChecked(); -} - void KMovingConfig::showEvent(QShowEvent *ev) { if (!standAlone) { @@ -529,54 +498,11 @@ void KMovingConfig::showEvent(QShowEvent *ev) KCModule::showEvent(ev); } -void KMovingConfig::load(void) -{ - QString key; - - KConfigGroup cg(config, "Windows"); - - //KS 10Jan2003 - Geometry Tip during window move/resize - bool showGeomTip = cg.readEntry(KWIN_GEOMETRY, false); - setGeometryTip(showGeomTip); - - - int v; - - v = cg.readEntry(KWM_BRDR_SNAP_ZONE, KWM_BRDR_SNAP_ZONE_DEFAULT); - if (v > MAX_BRDR_SNAP) setBorderSnapZone(MAX_BRDR_SNAP); - else if (v < 0) setBorderSnapZone(0); - else setBorderSnapZone(v); - - v = cg.readEntry(KWM_WNDW_SNAP_ZONE, KWM_WNDW_SNAP_ZONE_DEFAULT); - if (v > MAX_WNDW_SNAP) setWindowSnapZone(MAX_WNDW_SNAP); - else if (v < 0) setWindowSnapZone(0); - else setWindowSnapZone(v); - - v = cg.readEntry(KWM_CNTR_SNAP_ZONE, KWM_CNTR_SNAP_ZONE_DEFAULT); - if (v > MAX_CNTR_SNAP) setCenterSnapZone(MAX_CNTR_SNAP); - else if (v < 0) setCenterSnapZone(0); - else setCenterSnapZone(v); - - m_ui->OverlapSnap->setChecked(cg.readEntry("SnapOnlyWhenOverlapping", false)); - emit KCModule::changed(false); -} - void KMovingConfig::save(void) { - KConfigGroup cg(config, "Windows"); - cg.writeEntry(KWIN_GEOMETRY, getGeometryTip()); - - - cg.writeEntry(KWM_BRDR_SNAP_ZONE, getBorderSnapZone()); - cg.writeEntry(KWM_WNDW_SNAP_ZONE, getWindowSnapZone()); - cg.writeEntry(KWM_CNTR_SNAP_ZONE, getCenterSnapZone()); - cg.writeEntry("SnapOnlyWhenOverlapping", m_ui->OverlapSnap->isChecked()); - - const bool geometryTip = getGeometryTip(); - KConfigGroup(config, "Plugins").writeEntry("windowgeometryEnabled", geometryTip); + m_config->save(); if (standAlone) { - config->sync(); // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); @@ -586,54 +512,9 @@ void KMovingConfig::save(void) OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Effects"), QDBusConnection::sessionBus()); - if (geometryTip) { + if (m_config->geometryTip()) { interface.loadEffect(KWin::BuiltInEffects::nameForEffect(KWin::BuiltInEffect::WindowGeometry)); } else { interface.unloadEffect(KWin::BuiltInEffects::nameForEffect(KWin::BuiltInEffect::WindowGeometry)); } - emit KCModule::changed(false); } - -void KMovingConfig::defaults() -{ - setGeometryTip(false); - - //copied from kcontrol/konq/kwindesktop, aleXXX - setWindowSnapZone(KWM_WNDW_SNAP_ZONE_DEFAULT); - setBorderSnapZone(KWM_BRDR_SNAP_ZONE_DEFAULT); - setCenterSnapZone(KWM_CNTR_SNAP_ZONE_DEFAULT); - m_ui->OverlapSnap->setChecked(false); - - emit KCModule::changed(true); -} - -int KMovingConfig::getBorderSnapZone() -{ - return m_ui->borderSnap->value(); -} - -void KMovingConfig::setBorderSnapZone(int pxls) -{ - m_ui->borderSnap->setValue(pxls); -} - -int KMovingConfig::getWindowSnapZone() -{ - return m_ui->windowSnap->value(); -} - -void KMovingConfig::setWindowSnapZone(int pxls) -{ - m_ui->windowSnap->setValue(pxls); -} - -int KMovingConfig::getCenterSnapZone() -{ - return m_ui->centerSnap->value(); -} - -void KMovingConfig::setCenterSnapZone(int pxls) -{ - m_ui->centerSnap->setValue(pxls); -} - diff --git a/kcmkwin/kwinoptions/windows.h b/kcmkwin/kwinoptions/windows.h index 5e917beb25..2c24151429 100644 --- a/kcmkwin/kwinoptions/windows.h +++ b/kcmkwin/kwinoptions/windows.h @@ -41,6 +41,7 @@ class QSpinBox; class KColorButton; +class KWinOptionsSettings; class KWinFocusConfigForm : public QWidget, public Ui::KWinFocusConfigForm { @@ -118,37 +119,18 @@ class KMovingConfig : public KCModule { Q_OBJECT public: - KMovingConfig(bool _standAlone, KConfig *config, QWidget *parent); + KMovingConfig(bool _standAlone, QWidget *parent); ~KMovingConfig() override; - void load() override; void save() override; - void defaults() override; protected: void showEvent(QShowEvent *ev) override; -private Q_SLOTS: - void changed() { - emit KCModule::changed(true); - } - private: - bool getGeometryTip(void); //KS - - void setGeometryTip(bool); //KS - - KConfig *config; + KWinOptionsSettings *m_config; bool standAlone; KWinMovingConfigForm *m_ui; - - int getBorderSnapZone(); - void setBorderSnapZone(int); - int getWindowSnapZone(); - void setWindowSnapZone(int); - int getCenterSnapZone(); - void setCenterSnapZone(int); - }; class KAdvancedConfig : public KCModule