File indexing completed on 2024-11-10 04:56:49

0001 /*
0002     SPDX-FileCopyrightText: 2001 Waldo Bastian <bastian@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "main.h"
0008 
0009 #include <QLayout>
0010 // Added by qt3to4:
0011 #include <QVBoxLayout>
0012 
0013 #include <QtDBus>
0014 
0015 #include <KLocalizedString>
0016 #include <KPluginFactory>
0017 #include <kconfig.h>
0018 
0019 #include "kwinoptions_kdeglobals_settings.h"
0020 #include "kwinoptions_settings.h"
0021 #include "kwinoptionsdata.h"
0022 #include "mouse.h"
0023 #include "windows.h"
0024 
0025 K_PLUGIN_CLASS_WITH_JSON(KWinOptions, "kcm_kwinoptions.json")
0026 
0027 class KFocusConfigStandalone : public KFocusConfig
0028 {
0029     Q_OBJECT
0030 public:
0031     KFocusConfigStandalone(QWidget *parent, const QVariantList &)
0032         : KFocusConfig(true, nullptr, parent)
0033     {
0034         initialize(new KWinOptionsSettings(this));
0035     }
0036 };
0037 
0038 class KMovingConfigStandalone : public KMovingConfig
0039 {
0040     Q_OBJECT
0041 public:
0042     KMovingConfigStandalone(QWidget *parent, const QVariantList &)
0043         : KMovingConfig(true, nullptr, parent)
0044     {
0045         initialize(new KWinOptionsSettings(this));
0046     }
0047 };
0048 
0049 class KAdvancedConfigStandalone : public KAdvancedConfig
0050 {
0051     Q_OBJECT
0052 public:
0053     KAdvancedConfigStandalone(QWidget *parent, const QVariantList &)
0054         : KAdvancedConfig(true, nullptr, nullptr, parent)
0055     {
0056         initialize(new KWinOptionsSettings(this), new KWinOptionsKDEGlobalsSettings(this));
0057     }
0058 };
0059 
0060 KWinOptions::KWinOptions(QObject *parent, const KPluginMetaData &data)
0061     : KCModule(parent, data)
0062 {
0063     mSettings = new KWinOptionsSettings(this);
0064 
0065     QVBoxLayout *layout = new QVBoxLayout(widget());
0066     layout->setContentsMargins(0, 0, 0, 0);
0067     tab = new QTabWidget(widget());
0068     layout->addWidget(tab);
0069 
0070     const auto connectKCM = [this](KCModule *mod) {
0071         connect(mod, &KCModule::needsSaveChanged, this, &KWinOptions::updateUnmanagedState);
0072         connect(this, &KCModule::defaultsIndicatorsVisibleChanged, mod, [mod, this]() {
0073             mod->setDefaultsIndicatorsVisible(defaultsIndicatorsVisible());
0074         });
0075     };
0076 
0077     mFocus = new KFocusConfig(false, mSettings, widget());
0078     mFocus->setObjectName(QLatin1String("KWin Focus Config"));
0079     tab->addTab(mFocus->widget(), i18n("&Focus"));
0080     connectKCM(mFocus);
0081 
0082     mTitleBarActions = new KTitleBarActionsConfig(false, mSettings, widget());
0083     mTitleBarActions->setObjectName(QLatin1String("KWin TitleBar Actions"));
0084     tab->addTab(mTitleBarActions->widget(), i18n("Titlebar A&ctions"));
0085     connectKCM(mTitleBarActions);
0086 
0087     mWindowActions = new KWindowActionsConfig(false, mSettings, widget());
0088     mWindowActions->setObjectName(QLatin1String("KWin Window Actions"));
0089     tab->addTab(mWindowActions->widget(), i18n("W&indow Actions"));
0090     connectKCM(mWindowActions);
0091 
0092     mMoving = new KMovingConfig(false, mSettings, widget());
0093     mMoving->setObjectName(QLatin1String("KWin Moving"));
0094     tab->addTab(mMoving->widget(), i18n("Mo&vement"));
0095     connectKCM(mMoving);
0096 
0097     mAdvanced = new KAdvancedConfig(false, mSettings, new KWinOptionsKDEGlobalsSettings(this), widget());
0098     mAdvanced->setObjectName(QLatin1String("KWin Advanced"));
0099     tab->addTab(mAdvanced->widget(), i18n("Adva&nced"));
0100     connectKCM(mAdvanced);
0101 }
0102 
0103 void KWinOptions::load()
0104 {
0105     KCModule::load();
0106 
0107     mTitleBarActions->load();
0108     mWindowActions->load();
0109     mMoving->load();
0110     mAdvanced->load();
0111     // mFocus is last because it may send unmanagedWidgetStateChanged
0112     // that need to have the final word
0113     mFocus->load();
0114 }
0115 
0116 void KWinOptions::save()
0117 {
0118     KCModule::save();
0119 
0120     mFocus->save();
0121     mTitleBarActions->save();
0122     mWindowActions->save();
0123     mMoving->save();
0124     mAdvanced->save();
0125 
0126     // Send signal to all kwin instances
0127     QDBusMessage message =
0128         QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
0129     QDBusConnection::sessionBus().send(message);
0130 }
0131 
0132 void KWinOptions::defaults()
0133 {
0134     KCModule::defaults();
0135 
0136     mTitleBarActions->defaults();
0137     mWindowActions->defaults();
0138     mMoving->defaults();
0139     mAdvanced->defaults();
0140     // mFocus is last because it may send unmanagedWidgetDefaulted
0141     // that need to have the final word
0142     mFocus->defaults();
0143 }
0144 
0145 void KWinOptions::updateUnmanagedState()
0146 {
0147     bool changed = false;
0148     changed |= mFocus->needsSave();
0149     changed |= mTitleBarActions->needsSave();
0150     changed |= mWindowActions->needsSave();
0151     changed |= mMoving->needsSave();
0152     changed |= mAdvanced->needsSave();
0153 
0154     unmanagedWidgetChangeState(changed);
0155 
0156     bool isDefault = true;
0157     isDefault &= mFocus->representsDefaults();
0158     isDefault &= mTitleBarActions->representsDefaults();
0159     isDefault &= mWindowActions->representsDefaults();
0160     isDefault &= mMoving->representsDefaults();
0161     isDefault &= mAdvanced->representsDefaults();
0162 
0163     unmanagedWidgetDefaultState(isDefault);
0164 }
0165 
0166 KActionsOptions::KActionsOptions(QObject *parent, const KPluginMetaData &data)
0167     : KCModule(parent, data)
0168 {
0169     mSettings = new KWinOptionsSettings(this);
0170 
0171     QVBoxLayout *layout = new QVBoxLayout(widget());
0172     layout->setContentsMargins(0, 0, 0, 0);
0173     tab = new QTabWidget(widget());
0174     layout->addWidget(tab);
0175 
0176     mTitleBarActions = new KTitleBarActionsConfig(false, mSettings, widget());
0177     mTitleBarActions->setObjectName(QLatin1String("KWin TitleBar Actions"));
0178     tab->addTab(mTitleBarActions->widget(), i18n("&Titlebar Actions"));
0179     connect(mTitleBarActions, &KCModule::needsSaveChanged, this, [this]() {
0180         setNeedsSave(mTitleBarActions->needsSave());
0181     });
0182     connect(mTitleBarActions, &KCModule::representsDefaultsChanged, this, [this]() {
0183         setRepresentsDefaults(mTitleBarActions->representsDefaults());
0184     });
0185 
0186     mWindowActions = new KWindowActionsConfig(false, mSettings, widget());
0187     mWindowActions->setObjectName(QLatin1String("KWin Window Actions"));
0188     tab->addTab(mWindowActions->widget(), i18n("Window Actio&ns"));
0189     connect(mWindowActions, &KCModule::needsSaveChanged, this, [this]() {
0190         setNeedsSave(mWindowActions->needsSave());
0191     });
0192     connect(mWindowActions, &KCModule::representsDefaultsChanged, this, [this]() {
0193         setRepresentsDefaults(mWindowActions->representsDefaults());
0194     });
0195 }
0196 
0197 void KActionsOptions::load()
0198 {
0199     mTitleBarActions->load();
0200     mWindowActions->load();
0201 }
0202 
0203 void KActionsOptions::save()
0204 {
0205     mTitleBarActions->save();
0206     mWindowActions->save();
0207 
0208     setNeedsSave(false);
0209     // Send signal to all kwin instances
0210     QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
0211     QDBusConnection::sessionBus().send(message);
0212 }
0213 
0214 void KActionsOptions::defaults()
0215 {
0216     mTitleBarActions->defaults();
0217     mWindowActions->defaults();
0218 }
0219 
0220 void KActionsOptions::moduleChanged(bool state)
0221 {
0222     setNeedsSave(state);
0223 }
0224 
0225 #include "main.moc"
0226 
0227 #include "moc_main.cpp"