diff --git a/kcmkwin/kwinoptions/focus.ui b/kcmkwin/kwinoptions/focus.ui index 735f81c057..d958008d4c 100644 --- a/kcmkwin/kwinoptions/focus.ui +++ b/kcmkwin/kwinoptions/focus.ui @@ -22,12 +22,12 @@ Window &activation policy: - windowFocusPolicyCombo + windowFocusPolicy - + With this option you can specify how and when windows will be focused. @@ -72,12 +72,12 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - delayFocus + kcfg_DelayFocusInterval - + This is the delay after which the window the mouse pointer is over will automatically receive focus. @@ -104,12 +104,12 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - focusStealing + kcfg_FocusStealingPreventionLevel - + <html><head/><body><p>This option specifies how much KWin will try to prevent unwanted focus stealing caused by unexpected activation of new windows. (Note: This feature does not work with the <span style=" font-style:italic;">Focus under mouse</span> or <span style=" font-style:italic;">Focus strictly under mouse</span> focus policies.) </p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">None:</span> Prevention is turned off and new windows always become activated.</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Low:</span> Prevention is enabled; when some window does not have support for the underlying mechanism and KWin cannot reliably decide whether to activate the window or not, it will be activated. This setting may have both worse and better results than the medium level, depending on the applications.</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Medium:</span> Prevention is enabled.</li><li style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">High:</span> New windows get activated only if no window is currently active or if they belong to the currently active application. This setting is probably not really usable when not using mouse focus policy.</li><li style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Extreme:</span> All windows must be explicitly activated by the user.</li></ul><p>Windows that are prevented from stealing focus are marked as demanding attention, which by default means their taskbar entry will be highlighted. This can be changed in the Notifications control module.</p></body></html> @@ -148,7 +148,7 @@ - + When this option is enabled, the active window will be brought to the front when you click somewhere into the window contents. To change it for inactive windows, you need to change the settings in the Actions tab. @@ -160,7 +160,7 @@ - + When this option is enabled, a window in the background will automatically come to the front when the mouse pointer has been over it for some time. @@ -170,7 +170,7 @@ - + This is the delay after which the window that the mouse pointer is over will automatically come to the front. @@ -198,7 +198,7 @@ - + When this option is enabled, the active Xinerama screen (where new windows appear, for example) is the screen containing the mouse pointer. When disabled, the active Xinerama screen is the screen containing the focused window. By default this option is disabled for Click to focus and enabled for other focus policies. @@ -208,7 +208,7 @@ - + When this option is enabled, focus operations are limited only to the active Xinerama screen @@ -261,5 +261,38 @@ - + + + kcfg_AutoRaise + toggled(bool) + kcfg_AutoRaiseInterval + setEnabled(bool) + + + 338 + 189 + + + 485 + 189 + + + + + kcfg_AutoRaise + toggled(bool) + kcfg_ClickRaise + setDisabled(bool) + + + 338 + 189 + + + 333 + 155 + + + + diff --git a/kcmkwin/kwinoptions/kwinoptions_settings.kcfg b/kcmkwin/kwinoptions/kwinoptions_settings.kcfg index 5ad052b043..959c0dd6d2 100644 --- a/kcmkwin/kwinoptions/kwinoptions_settings.kcfg +++ b/kcmkwin/kwinoptions/kwinoptions_settings.kcfg @@ -100,6 +100,52 @@ + + ClickToFocus + + + + + + + + + + false + + + + 750 + 0 + + + + 300 + 0 + + + + false + + + + true + + + + false + + + + true + + + + 1 + 0 + 4 + + diff --git a/kcmkwin/kwinoptions/kwinoptions_settings.kcfgc b/kcmkwin/kwinoptions/kwinoptions_settings.kcfgc index 7135009fb2..2deb143785 100644 --- a/kcmkwin/kwinoptions/kwinoptions_settings.kcfgc +++ b/kcmkwin/kwinoptions/kwinoptions_settings.kcfgc @@ -3,4 +3,3 @@ ClassName=KWinOptionsSettings Mutators=true DefaultValueGetters=true ParentInConstructor=true -Singleton=true diff --git a/kcmkwin/kwinoptions/main.cpp b/kcmkwin/kwinoptions/main.cpp index d056e5a627..05e0776a82 100644 --- a/kcmkwin/kwinoptions/main.cpp +++ b/kcmkwin/kwinoptions/main.cpp @@ -33,6 +33,7 @@ #include "mouse.h" #include "windows.h" +#include "kwinoptions_settings.h" K_PLUGIN_FACTORY_DECLARATION(KWinOptionsFactory) @@ -41,7 +42,7 @@ class KFocusConfigStandalone : public KFocusConfig Q_OBJECT public: KFocusConfigStandalone(QWidget* parent, const QVariantList &) - : KFocusConfig(true, new KConfig("kwinrc"), parent) + : KFocusConfig(true, new KWinOptionsSettings(this), parent) {} }; @@ -50,7 +51,7 @@ class KMovingConfigStandalone : public KMovingConfig Q_OBJECT public: KMovingConfigStandalone(QWidget* parent, const QVariantList &) - : KMovingConfig(true, parent) + : KMovingConfig(true, new KWinOptionsSettings(this), parent) {} }; @@ -59,44 +60,49 @@ class KAdvancedConfigStandalone : public KAdvancedConfig Q_OBJECT public: KAdvancedConfigStandalone(QWidget* parent, const QVariantList &) - : KAdvancedConfig(true, parent) + : KAdvancedConfig(true, new KWinOptionsSettings(this), parent) {} }; KWinOptions::KWinOptions(QWidget *parent, const QVariantList &) : KCModule(parent) { - mConfig = new KConfig("kwinrc"); + mSettings = new KWinOptionsSettings(this); QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); tab = new QTabWidget(this); layout->addWidget(tab); - mFocus = new KFocusConfig(false, mConfig, this); + mFocus = new KFocusConfig(false, mSettings, this); mFocus->setObjectName(QLatin1String("KWin Focus Config")); tab->addTab(mFocus, i18n("&Focus")); connect(mFocus, qOverload(&KCModule::changed), this, qOverload(&KCModule::changed)); + connect(mFocus, qOverload(&KCModule::defaulted), this, qOverload(&KCModule::defaulted)); - mTitleBarActions = new KTitleBarActionsConfig(false, this); + // Need to relay unmanagedWidgetDefaultState and unmanagedWidgetChangeState to wrapping KCModule + connect(mFocus, &KFocusConfig::unmanagedWidgetDefaulted, this, &KWinOptions::unmanagedWidgetDefaultState); + connect(mFocus, &KFocusConfig::unmanagedWidgetStateChanged, this, &KWinOptions::unmanagedWidgetChangeState); + + mTitleBarActions = new KTitleBarActionsConfig(false, mSettings, this); mTitleBarActions->setObjectName(QLatin1String("KWin TitleBar Actions")); tab->addTab(mTitleBarActions, i18n("Titlebar A&ctions")); connect(mTitleBarActions, qOverload(&KCModule::changed), this, qOverload(&KCModule::changed)); connect(mTitleBarActions, qOverload(&KCModule::defaulted), this, qOverload(&KCModule::defaulted)); - mWindowActions = new KWindowActionsConfig(false, this); + mWindowActions = new KWindowActionsConfig(false, mSettings, this); mWindowActions->setObjectName(QLatin1String("KWin Window Actions")); tab->addTab(mWindowActions, i18n("W&indow Actions")); connect(mWindowActions, qOverload(&KCModule::changed), this, qOverload(&KCModule::changed)); connect(mWindowActions, qOverload(&KCModule::defaulted), this, qOverload(&KCModule::defaulted)); - mMoving = new KMovingConfig(false, this); + mMoving = new KMovingConfig(false, mSettings, this); mMoving->setObjectName(QLatin1String("KWin Moving")); tab->addTab(mMoving, i18n("Mo&vement")); connect(mMoving, qOverload(&KCModule::changed), this, qOverload(&KCModule::changed)); connect(mMoving, qOverload(&KCModule::defaulted), this, qOverload(&KCModule::defaulted)); - mAdvanced = new KAdvancedConfig(false, this); + mAdvanced = new KAdvancedConfig(false, mSettings, this); mAdvanced->setObjectName(QLatin1String("KWin Advanced")); tab->addTab(mAdvanced, i18n("Adva&nced")); connect(mAdvanced, qOverload(&KCModule::changed), this, qOverload(&KCModule::changed)); @@ -119,23 +125,17 @@ KWinOptions::KWinOptions(QWidget *parent, const QVariantList &) setAboutData(about); } -KWinOptions::~KWinOptions() -{ - delete mConfig; -} - void KWinOptions::load() { - mConfig->reparseConfiguration(); - mFocus->load(); mTitleBarActions->load(); mWindowActions->load(); mMoving->load(); mAdvanced->load(); - emit KCModule::changed(false); + // mFocus is last because it may send unmanagedWidgetStateChanged + // that need to have the final word + mFocus->load(); } - void KWinOptions::save() { mFocus->save(); @@ -145,8 +145,7 @@ void KWinOptions::save() mAdvanced->save(); emit KCModule::changed(false); - // Send signal to kwin - mConfig->sync(); + // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); @@ -156,11 +155,13 @@ void KWinOptions::save() void KWinOptions::defaults() { - mFocus->defaults(); mTitleBarActions->defaults(); mWindowActions->defaults(); mMoving->defaults(); mAdvanced->defaults(); + // mFocus is last because it may send unmanagedWidgetDefaulted + // that need to have the final word + mFocus->defaults(); } QString KWinOptions::quickHelp() const @@ -176,31 +177,26 @@ QString KWinOptions::quickHelp() const KActionsOptions::KActionsOptions(QWidget *parent, const QVariantList &) : KCModule(parent) { - mConfig = new KConfig("kwinrc"); + mSettings = new KWinOptionsSettings(this); QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); tab = new QTabWidget(this); layout->addWidget(tab); - mTitleBarActions = new KTitleBarActionsConfig(false, this); + mTitleBarActions = new KTitleBarActionsConfig(false, mSettings, this); mTitleBarActions->setObjectName(QLatin1String("KWin TitleBar Actions")); tab->addTab(mTitleBarActions, i18n("&Titlebar Actions")); connect(mTitleBarActions, qOverload(&KCModule::changed), this, qOverload(&KCModule::changed)); connect(mTitleBarActions, qOverload(&KCModule::defaulted), this, qOverload(&KCModule::defaulted)); - mWindowActions = new KWindowActionsConfig(false, this); + mWindowActions = new KWindowActionsConfig(false, mSettings, this); mWindowActions->setObjectName(QLatin1String("KWin Window Actions")); tab->addTab(mWindowActions, i18n("Window Actio&ns")); connect(mWindowActions, qOverload(&KCModule::changed), this, qOverload(&KCModule::changed)); connect(mWindowActions, qOverload(&KCModule::defaulted), this, qOverload(&KCModule::defaulted)); } -KActionsOptions::~KActionsOptions() -{ - delete mConfig; -} - void KActionsOptions::load() { mTitleBarActions->load(); @@ -213,8 +209,6 @@ void KActionsOptions::save() mWindowActions->save(); emit KCModule::changed(false); - // Send signal to kwin - mConfig->sync(); // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); diff --git a/kcmkwin/kwinoptions/main.h b/kcmkwin/kwinoptions/main.h index 50a8bcd8af..f85d61d5a0 100644 --- a/kcmkwin/kwinoptions/main.h +++ b/kcmkwin/kwinoptions/main.h @@ -28,7 +28,7 @@ #include #include -class KConfig; +class KWinOptionsSettings; class KFocusConfig; class KTitleBarActionsConfig; class KWindowActionsConfig; @@ -42,7 +42,6 @@ class KWinOptions : public KCModule public: KWinOptions(QWidget *parent, const QVariantList &args); - ~KWinOptions() override; void load() override; void save() override; @@ -59,7 +58,7 @@ private: KMovingConfig *mMoving; KAdvancedConfig *mAdvanced; - KConfig *mConfig; + KWinOptionsSettings *mSettings; }; class KActionsOptions : public KCModule @@ -69,7 +68,6 @@ class KActionsOptions : public KCModule public: KActionsOptions(QWidget *parent, const QVariantList &args); - ~KActionsOptions() override; void load() override; void save() override; @@ -79,7 +77,6 @@ protected Q_SLOTS: void moduleChanged(bool state); - private: QTabWidget *tab; @@ -87,7 +84,7 @@ private: KTitleBarActionsConfig *mTitleBarActions; KWindowActionsConfig *mWindowActions; - KConfig *mConfig; + KWinOptionsSettings *mSettings; }; #endif diff --git a/kcmkwin/kwinoptions/mouse.cpp b/kcmkwin/kwinoptions/mouse.cpp index 8be4dc6ffc..22c8a30318 100644 --- a/kcmkwin/kwinoptions/mouse.cpp +++ b/kcmkwin/kwinoptions/mouse.cpp @@ -136,11 +136,12 @@ void KTitleBarActionsConfig::paletteChanged() } -KTitleBarActionsConfig::KTitleBarActionsConfig(bool _standAlone, QWidget *parent) +KTitleBarActionsConfig::KTitleBarActionsConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent) : KCModule(parent), standAlone(_standAlone) , m_ui(new KWinMouseConfigForm(this)) + , m_settings(settings) { - addConfig(KWinOptionsSettings::self(), this); + addConfig(m_settings, this); // create the items for the maximize button actions createMaxButtonPixmaps(); @@ -193,11 +194,12 @@ void KTitleBarActionsConfig::save() } } -KWindowActionsConfig::KWindowActionsConfig(bool _standAlone, QWidget *parent) +KWindowActionsConfig::KWindowActionsConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent) : KCModule(parent), standAlone(_standAlone) , m_ui(new KWinActionsConfigForm(this)) + , m_settings(settings) { - addConfig(KWinOptionsSettings::self(), this); + addConfig(m_settings, this); load(); } diff --git a/kcmkwin/kwinoptions/mouse.h b/kcmkwin/kwinoptions/mouse.h index cbb5f43528..b6cf62a48d 100644 --- a/kcmkwin/kwinoptions/mouse.h +++ b/kcmkwin/kwinoptions/mouse.h @@ -31,6 +31,8 @@ class KConfig; #include "ui_actions.h" #include "ui_mouse.h" +class KWinOptionsSettings; + class KWinMouseConfigForm : public QWidget, public Ui::KWinMouseConfigForm { Q_OBJECT @@ -53,7 +55,7 @@ class KTitleBarActionsConfig : public KCModule public: - KTitleBarActionsConfig(bool _standAlone, QWidget *parent); + KTitleBarActionsConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent); void save() override; @@ -65,6 +67,7 @@ private: bool standAlone; KWinMouseConfigForm *m_ui; + KWinOptionsSettings *m_settings; void createMaximizeButtonTooltips(KComboBox* combo); @@ -79,7 +82,7 @@ class KWindowActionsConfig : public KCModule public: - KWindowActionsConfig(bool _standAlone, QWidget *parent); + KWindowActionsConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent); void save() override; @@ -90,6 +93,7 @@ private: bool standAlone; KWinActionsConfigForm *m_ui; + KWinOptionsSettings *m_settings; }; #endif diff --git a/kcmkwin/kwinoptions/windows.cpp b/kcmkwin/kwinoptions/windows.cpp index a05015031f..ecc81b6538 100644 --- a/kcmkwin/kwinoptions/windows.cpp +++ b/kcmkwin/kwinoptions/windows.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -41,28 +42,15 @@ #include #include -// kwin config keywords -#define KWIN_FOCUS "FocusPolicy" -#define KWIN_AUTORAISE_INTERVAL "AutoRaiseInterval" -#define KWIN_AUTORAISE "AutoRaise" -#define KWIN_DELAYFOCUS_INTERVAL "DelayFocusInterval" -#define KWIN_CLICKRAISE "ClickRaise" -#define KWIN_FOCUS_STEALING "FocusStealingPreventionLevel" -#define KWIN_INACTIVE_SKIP_TASKBAR "InactiveTabsSkipTaskbar" -#define KWIN_SEPARATE_SCREEN_FOCUS "SeparateScreenFocus" -#define KWIN_ACTIVE_MOUSE_SCREEN "ActiveMouseScreen" +#include "kwinoptions_settings.h" +#include -#define CLICK_TO_FOCUS 0 -#define FOCUS_FOLLOWS_MOUSE 2 -#define FOCUS_UNDER_MOUSE 4 -#define FOCUS_STRICTLY_UNDER_MOUSE 5 - - -KFocusConfig::~KFocusConfig() -{ - if (standAlone) - delete config; -} +#define CLICK_TO_FOCUS 0 +#define CLICK_TO_FOCUS_MOUSE_PRECEDENT 1 +#define FOCUS_FOLLOWS_MOUSE 2 +#define FOCUS_FOLLOWS_MOUSE_PRECEDENT 3 +#define FOCUS_UNDER_MOUSE 4 +#define FOCUS_STRICTLY_UNDER_MOUSE 5 KWinFocusConfigForm::KWinFocusConfigForm(QWidget* parent) : QWidget(parent) @@ -70,25 +58,17 @@ KWinFocusConfigForm::KWinFocusConfigForm(QWidget* parent) setupUi(parent); } -// removed the LCD display over the slider - this is not good GUI design :) RNolden 051701 -KFocusConfig::KFocusConfig(bool _standAlone, KConfig *_config, QWidget * parent) - : KCModule(parent), config(_config), standAlone(_standAlone) +KFocusConfig::KFocusConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget * parent) + : KCModule(parent), standAlone(_standAlone) , m_ui(new KWinFocusConfigForm(this)) + , m_settings(settings) { - connect(m_ui->focusStealing, SIGNAL(activated(int)), SLOT(changed())); - connect(m_ui->windowFocusPolicyCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed())); - connect(m_ui->windowFocusPolicyCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(focusPolicyChanged())); - connect(m_ui->windowFocusPolicyCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setDelayFocusEnabled())); - connect(m_ui->windowFocusPolicyCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateActiveMouseScreen())); - connect(m_ui->autoRaiseOn, SIGNAL(clicked()), SLOT(changed())); - connect(m_ui->autoRaiseOn, SIGNAL(toggled(bool)), SLOT(autoRaiseOnTog(bool))); - connect(m_ui->clickRaiseOn, SIGNAL(clicked()), SLOT(changed())); - connect(m_ui->autoRaise, SIGNAL(valueChanged(int)), SLOT(changed())); - connect(m_ui->delayFocus, SIGNAL(valueChanged(int)), SLOT(changed())); - connect(m_ui->separateScreenFocus, SIGNAL(clicked()), SLOT(changed())); - connect(m_ui->activeMouseScreen, SIGNAL(clicked()), SLOT(changed())); + addConfig(m_settings, this); - connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)), SLOT(updateMultiScreen())); + connect(m_ui->windowFocusPolicy, qOverload(&QComboBox::currentIndexChanged), this, &KFocusConfig::focusPolicyChanged); + + connect(qApp, &QGuiApplication::screenAdded, this, &KFocusConfig::updateMultiScreen); + connect(qApp, &QGuiApplication::screenRemoved, this, &KFocusConfig::updateMultiScreen); updateMultiScreen(); load(); @@ -97,135 +77,67 @@ KFocusConfig::KFocusConfig(bool _standAlone, KConfig *_config, QWidget * parent) void KFocusConfig::updateMultiScreen() { m_ui->multiscreenBehaviorLabel->setVisible(QApplication::screens().count() > 1); - m_ui->activeMouseScreen->setVisible(QApplication::screens().count() > 1); - m_ui->separateScreenFocus->setVisible(QApplication::screens().count() > 1); -} - - -int KFocusConfig::getFocus() -{ - int policy = m_ui->windowFocusPolicyCombo->currentIndex(); - if (policy == 1 || policy == 3) - --policy; // fix the NextFocusPrefersMouse condition - return policy; -} - -void KFocusConfig::setFocus(int foc) -{ - m_ui->windowFocusPolicyCombo->setCurrentIndex(foc); - - // this will disable/hide the auto raise delay widget if focus==click - focusPolicyChanged(); -} - -void KFocusConfig::setAutoRaiseInterval(int tb) -{ - m_ui->autoRaise->setValue(tb); -} - -void KFocusConfig::setDelayFocusInterval(int tb) -{ - m_ui->delayFocus->setValue(tb); -} - -int KFocusConfig::getAutoRaiseInterval() -{ - return m_ui->autoRaise->value(); -} - -int KFocusConfig::getDelayFocusInterval() -{ - return m_ui->delayFocus->value(); -} - -void KFocusConfig::setAutoRaise(bool on) -{ - m_ui->autoRaiseOn->setChecked(on); -} - -void KFocusConfig::setClickRaise(bool on) -{ - m_ui->clickRaiseOn->setChecked(on); + m_ui->kcfg_ActiveMouseScreen->setVisible(QApplication::screens().count() > 1); + m_ui->kcfg_SeparateScreenFocus->setVisible(QApplication::screens().count() > 1); } void KFocusConfig::focusPolicyChanged() { - switch (m_ui->windowFocusPolicyCombo->currentIndex()) { - case 0: + int selectedFocusPolicy = 0; + bool selectedNextFocusPrefersMouseItem = false; + const bool loadedNextFocusPrefersMouseItem = m_settings->nextFocusPrefersMouse(); + + int focusPolicy = m_ui->windowFocusPolicy->currentIndex(); + switch (focusPolicy) { + case CLICK_TO_FOCUS: m_ui->windowFocusPolicyDescriptionLabel->setText(i18n("Click to focus: A window becomes active when you click into it. This behavior is common on other operating systems and likely what you want.")); + selectedFocusPolicy = KWinOptionsSettings::EnumFocusPolicy::ClickToFocus; break; - case 1: + case CLICK_TO_FOCUS_MOUSE_PRECEDENT: m_ui->windowFocusPolicyDescriptionLabel->setText(i18n("Click to focus (mouse precedence): Mostly the same as Click to focus. If an active window has to be chosen by the system (eg. because the currently active one was closed) the window under the mouse is the preferred candidate. Unusual, but possible variant of Click to focus.")); + selectedFocusPolicy = KWinOptionsSettings::EnumFocusPolicy::ClickToFocus; + selectedNextFocusPrefersMouseItem = true; break; - case 2: + case FOCUS_FOLLOWS_MOUSE: m_ui->windowFocusPolicyDescriptionLabel->setText(i18n("Focus follows mouse: Moving the mouse onto a window will activate it. Eg. windows randomly appearing under the mouse will not gain the focus. Focus stealing prevention takes place as usual. Think as Click to focus just without having to actually click.")); + selectedFocusPolicy = KWinOptionsSettings::EnumFocusPolicy::FocusFollowsMouse; break; - case 3: + case FOCUS_FOLLOWS_MOUSE_PRECEDENT: m_ui->windowFocusPolicyDescriptionLabel->setText(i18n("This is mostly the same as Focus follows mouse. If an active window has to be chosen by the system (eg. because the currently active one was closed) the window under the mouse is the preferred candidate. Choose this, if you want a hover controlled focus.")); + selectedFocusPolicy = KWinOptionsSettings::EnumFocusPolicy::FocusFollowsMouse; + selectedNextFocusPrefersMouseItem = true; break; - case 4: + case FOCUS_UNDER_MOUSE: m_ui->windowFocusPolicyDescriptionLabel->setText(i18n("Focus under mouse: The focus always remains on the window under the mouse.
Warning: Focus stealing prevention and the tabbox ('Alt+Tab') contradict the activation policy and will not work. You very likely want to use Focus follows mouse (mouse precedence) instead!")); + selectedFocusPolicy = KWinOptionsSettings::EnumFocusPolicy::FocusUnderMouse; break; - case 5: + case FOCUS_STRICTLY_UNDER_MOUSE: m_ui->windowFocusPolicyDescriptionLabel->setText(i18n("Focus strictly under mouse: The focus is always on the window under the mouse (in doubt nowhere) very much like the focus behavior in an unmanaged legacy X11 environment.
Warning: Focus stealing prevention and the tabbox ('Alt+Tab') contradict the activation policy and will not work. You very likely want to use Focus follows mouse (mouse precedence) instead!")); + selectedFocusPolicy = KWinOptionsSettings::EnumFocusPolicy::FocusStrictlyUnderMouse; break; } - int policyIndex = getFocus(); + const bool changed = m_settings->focusPolicy() != selectedFocusPolicy || loadedNextFocusPrefersMouseItem != selectedNextFocusPrefersMouseItem; + unmanagedWidgetChangeState(changed); + emit unmanagedWidgetStateChanged(changed); + + const bool isDefault = focusPolicy == CLICK_TO_FOCUS; + unmanagedWidgetDefaultState(isDefault); + emit unmanagedWidgetDefaulted(isDefault); // the auto raise related widgets are: autoRaise - m_ui->autoRaiseOn->setEnabled(policyIndex != CLICK_TO_FOCUS); - autoRaiseOnTog(policyIndex != CLICK_TO_FOCUS && m_ui->autoRaiseOn->isChecked()); + m_ui->kcfg_AutoRaise->setEnabled(focusPolicy != CLICK_TO_FOCUS && focusPolicy != CLICK_TO_FOCUS_MOUSE_PRECEDENT); - m_ui->focusStealing->setDisabled(policyIndex == FOCUS_UNDER_MOUSE || policyIndex == FOCUS_STRICTLY_UNDER_MOUSE); - m_ui->focusStealingLabel->setEnabled(m_ui->focusStealing->isEnabled()); - - setDelayFocusEnabled(); - -} - -void KFocusConfig::setDelayFocusEnabled() -{ - int policyIndex = getFocus(); + m_ui->kcfg_FocusStealingPreventionLevel->setDisabled(focusPolicy == FOCUS_UNDER_MOUSE || focusPolicy == FOCUS_STRICTLY_UNDER_MOUSE); // the delayed focus related widgets are: delayFocus - m_ui->delayFocusOnLabel->setEnabled(policyIndex != CLICK_TO_FOCUS); - delayFocusOnTog(policyIndex != CLICK_TO_FOCUS); -} + m_ui->delayFocusOnLabel->setEnabled(focusPolicy != CLICK_TO_FOCUS); + m_ui->kcfg_DelayFocusInterval->setEnabled(focusPolicy != CLICK_TO_FOCUS); -void KFocusConfig::autoRaiseOnTog(bool a) -{ - m_ui->autoRaise->setEnabled(a); - m_ui->clickRaiseOn->setEnabled(!a); -} - -void KFocusConfig::delayFocusOnTog(bool a) -{ - m_ui->delayFocus->setEnabled(a); -} - -void KFocusConfig::setFocusStealing(int l) -{ - l = qMax(0, qMin(4, l)); - m_ui->focusStealing->setCurrentIndex(l); -} - -void KFocusConfig::setSeparateScreenFocus(bool s) -{ - m_ui->separateScreenFocus->setChecked(s); -} - -void KFocusConfig::setActiveMouseScreen(bool a) -{ - m_ui->activeMouseScreen->setChecked(a); -} - -void KFocusConfig::updateActiveMouseScreen() -{ // on by default for non click to focus policies - KConfigGroup cfg(config, "Windows"); - if (!cfg.hasKey(KWIN_ACTIVE_MOUSE_SCREEN)) - setActiveMouseScreen(getFocus() != 0); + if (m_settings->activeMouseScreen() == m_settings->defaultActiveMouseScreenValue()) { + m_ui->kcfg_ActiveMouseScreen->setChecked(focusPolicy != CLICK_TO_FOCUS && focusPolicy != CLICK_TO_FOCUS_MOUSE_PRECEDENT); + } } void KFocusConfig::showEvent(QShowEvent *ev) @@ -239,85 +151,56 @@ void KFocusConfig::showEvent(QShowEvent *ev) void KFocusConfig::load(void) { - QString key; + KCModule::load(); - KConfigGroup cg(config, "Windows"); + const bool loadedNextFocusPrefersMouseItem = m_settings->nextFocusPrefersMouse(); - const bool focusNextToMouse = cg.readEntry("NextFocusPrefersMouse", false); + int focusPolicy = m_settings->focusPolicy(); - key = cg.readEntry(KWIN_FOCUS); - if (key == "ClickToFocus") - setFocus(CLICK_TO_FOCUS + focusNextToMouse); - else if (key == "FocusFollowsMouse") - setFocus(FOCUS_FOLLOWS_MOUSE + focusNextToMouse); - else if (key == "FocusUnderMouse") - setFocus(FOCUS_UNDER_MOUSE); - else if (key == "FocusStrictlyUnderMouse") - setFocus(FOCUS_STRICTLY_UNDER_MOUSE); - - int k = cg.readEntry(KWIN_AUTORAISE_INTERVAL, 750); - setAutoRaiseInterval(k); - - k = cg.readEntry(KWIN_DELAYFOCUS_INTERVAL, 300); - setDelayFocusInterval(k); - - setAutoRaise(cg.readEntry(KWIN_AUTORAISE, false)); - setClickRaise(cg.readEntry(KWIN_CLICKRAISE, true)); - focusPolicyChanged(); // this will disable/hide the auto raise delay widget if focus==click - - setSeparateScreenFocus(cg.readEntry(KWIN_SEPARATE_SCREEN_FOCUS, false)); - // on by default for non click to focus policies - setActiveMouseScreen(cg.readEntry(KWIN_ACTIVE_MOUSE_SCREEN, getFocus() != 0)); - -// setFocusStealing( cg.readEntry(KWIN_FOCUS_STEALING, 2 )); - // TODO default to low for now - setFocusStealing(cg.readEntry(KWIN_FOCUS_STEALING, 1)); - - - emit KCModule::changed(false); + switch (focusPolicy) { + // the ClickToFocus and FocusFollowsMouse have special values when + // NextFocusPrefersMouse is true + case KWinOptionsSettings::EnumFocusPolicy::ClickToFocus: + m_ui->windowFocusPolicy->setCurrentIndex(CLICK_TO_FOCUS + loadedNextFocusPrefersMouseItem); + break; + case KWinOptionsSettings::EnumFocusPolicy::FocusFollowsMouse: + m_ui->windowFocusPolicy->setCurrentIndex(FOCUS_FOLLOWS_MOUSE + loadedNextFocusPrefersMouseItem); + break; + default: + // +2 to ignore the two special values + m_ui->windowFocusPolicy->setCurrentIndex(focusPolicy + 2); + break; + } } void KFocusConfig::save(void) { - int v; + KCModule::save(); - KConfigGroup cg(config, "Windows"); - - v = getFocus(); - if (v == CLICK_TO_FOCUS) - cg.writeEntry(KWIN_FOCUS, "ClickToFocus"); - else if (v == FOCUS_UNDER_MOUSE) - cg.writeEntry(KWIN_FOCUS, "FocusUnderMouse"); - else if (v == FOCUS_STRICTLY_UNDER_MOUSE) - cg.writeEntry(KWIN_FOCUS, "FocusStrictlyUnderMouse"); - else - cg.writeEntry(KWIN_FOCUS, "FocusFollowsMouse"); - - cg.writeEntry("NextFocusPrefersMouse", v != m_ui->windowFocusPolicyCombo->currentIndex()); - - v = getAutoRaiseInterval(); - if (v < 0) v = 0; - cg.writeEntry(KWIN_AUTORAISE_INTERVAL, v); - - v = getDelayFocusInterval(); - if (v < 0) v = 0; - cg.writeEntry(KWIN_DELAYFOCUS_INTERVAL, v); - - cg.writeEntry(KWIN_AUTORAISE, m_ui->autoRaiseOn->isChecked()); - - cg.writeEntry(KWIN_CLICKRAISE, m_ui->clickRaiseOn->isChecked()); - - cg.writeEntry(KWIN_SEPARATE_SCREEN_FOCUS, m_ui->separateScreenFocus->isChecked()); - cg.writeEntry(KWIN_ACTIVE_MOUSE_SCREEN, m_ui->activeMouseScreen->isChecked()); - - cg.writeEntry(KWIN_FOCUS_STEALING, m_ui->focusStealing->currentIndex()); - - cg.writeEntry(KWIN_SEPARATE_SCREEN_FOCUS, m_ui->separateScreenFocus->isChecked()); - cg.writeEntry(KWIN_ACTIVE_MOUSE_SCREEN, m_ui->activeMouseScreen->isChecked()); + int idxFocusPolicy = m_ui->windowFocusPolicy->currentIndex(); + switch (idxFocusPolicy) { + case CLICK_TO_FOCUS: + case CLICK_TO_FOCUS_MOUSE_PRECEDENT: + m_settings->setFocusPolicy(KWinOptionsSettings::EnumFocusPolicy::ClickToFocus); + break; + case FOCUS_FOLLOWS_MOUSE: + case FOCUS_FOLLOWS_MOUSE_PRECEDENT: + // the ClickToFocus and FocusFollowsMouse have special values when + // NextFocusPrefersMouse is true + m_settings->setFocusPolicy(KWinOptionsSettings::EnumFocusPolicy::FocusFollowsMouse); + break; + case FOCUS_UNDER_MOUSE: + m_settings->setFocusPolicy(KWinOptionsSettings::EnumFocusPolicy::FocusUnderMouse); + break; + case FOCUS_STRICTLY_UNDER_MOUSE: + m_settings->setFocusPolicy(KWinOptionsSettings::EnumFocusPolicy::FocusStrictlyUnderMouse); + break; + } + m_settings->setNextFocusPrefersMouse(idxFocusPolicy == CLICK_TO_FOCUS_MOUSE_PRECEDENT || idxFocusPolicy == FOCUS_FOLLOWS_MOUSE_PRECEDENT); + m_settings->save(); if (standAlone) { - config->sync(); // Send signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); @@ -328,21 +211,8 @@ void KFocusConfig::save(void) void KFocusConfig::defaults() { - setAutoRaiseInterval(0); - setDelayFocusInterval(0); - setFocus(CLICK_TO_FOCUS); - setAutoRaise(false); - setClickRaise(true); - setSeparateScreenFocus(false); - -// setFocusStealing(2); - // TODO default to low for now - setFocusStealing(1); - - // on by default for non click to focus policies - setActiveMouseScreen(getFocus() != 0); - setDelayFocusEnabled(); - emit KCModule::changed(true); + KCModule::defaults(); + m_ui->windowFocusPolicy->setCurrentIndex(CLICK_TO_FOCUS); } KWinAdvancedConfigForm::KWinAdvancedConfigForm(QWidget* parent) @@ -351,15 +221,12 @@ KWinAdvancedConfigForm::KWinAdvancedConfigForm(QWidget* parent) setupUi(parent); } -KAdvancedConfig::~KAdvancedConfig() -{ -} - -KAdvancedConfig::KAdvancedConfig(bool _standAlone, QWidget *parent) - : KCModule(parent), m_config(KWinOptionsSettings::self()), standAlone(_standAlone) +KAdvancedConfig::KAdvancedConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent) + : KCModule(parent), standAlone(_standAlone) , m_ui(new KWinAdvancedConfigForm(this)) + , m_settings(settings) { - addConfig(m_config, this); + addConfig(m_settings, this); m_ui->kcfg_Placement->setItemData(KWinOptionsSettings::PlacementChoices::Smart, "Smart"); m_ui->kcfg_Placement->setItemData(KWinOptionsSettings::PlacementChoices::Maximizing, "Maximizing"); @@ -399,12 +266,8 @@ KWinMovingConfigForm::KWinMovingConfigForm(QWidget* parent) setupUi(parent); } -KMovingConfig::~KMovingConfig() -{ -} - -KMovingConfig::KMovingConfig(bool _standAlone, QWidget *parent) - : KCModule(parent), m_config(KWinOptionsSettings::self()), standAlone(_standAlone) +KMovingConfig::KMovingConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent) + : KCModule(parent), m_config(settings), standAlone(_standAlone) , m_ui(new KWinMovingConfigForm(this)) { addConfig(m_config, this); @@ -422,7 +285,7 @@ void KMovingConfig::showEvent(QShowEvent *ev) void KMovingConfig::save(void) { - m_config->save(); + KCModule::save(); if (standAlone) { // Send signal to all kwin instances diff --git a/kcmkwin/kwinoptions/windows.h b/kcmkwin/kwinoptions/windows.h index 80f6ac3d6c..938411998d 100644 --- a/kcmkwin/kwinoptions/windows.h +++ b/kcmkwin/kwinoptions/windows.h @@ -71,56 +71,36 @@ class KFocusConfig : public KCModule { Q_OBJECT public: - KFocusConfig(bool _standAlone, KConfig *_config, QWidget *parent); - ~KFocusConfig() override; + KFocusConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent); void load() override; void save() override; void defaults() override; +Q_SIGNALS: + void unmanagedWidgetDefaulted(bool defaulted); + void unmanagedWidgetStateChanged(bool changed); + protected: void showEvent(QShowEvent *ev) override; private Q_SLOTS: - void setDelayFocusEnabled(); void focusPolicyChanged(); - void autoRaiseOnTog(bool);//CT 23Oct1998 - void delayFocusOnTog(bool); - void updateActiveMouseScreen(); void updateMultiScreen(); - void changed() { - emit KCModule::changed(true); - } - private: - int getFocus(void); - int getAutoRaiseInterval(void); - int getDelayFocusInterval(void); - - void setFocus(int); - void setAutoRaiseInterval(int); - void setAutoRaise(bool); - void setDelayFocusInterval(int); - void setClickRaise(bool); - void setSeparateScreenFocus(bool); - void setActiveMouseScreen(bool); - - void setFocusStealing(int); - - KConfig *config; bool standAlone; KWinFocusConfigForm *m_ui; + KWinOptionsSettings *m_settings; }; class KMovingConfig : public KCModule { Q_OBJECT public: - KMovingConfig(bool _standAlone, QWidget *parent); - ~KMovingConfig() override; + KMovingConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent); void save() override; @@ -137,8 +117,7 @@ class KAdvancedConfig : public KCModule { Q_OBJECT public: - KAdvancedConfig(bool _standAlone, QWidget *parent); - ~KAdvancedConfig() override; + KAdvancedConfig(bool _standAlone, KWinOptionsSettings *settings, QWidget *parent); void save() override; @@ -147,9 +126,9 @@ protected: private: - KWinOptionsSettings *m_config; bool standAlone; KWinAdvancedConfigForm *m_ui; + KWinOptionsSettings *m_settings; }; #endif // KKWMWINDOWS_H