diff --git a/kcmkwin/kwintabbox/CMakeLists.txt b/kcmkwin/kwintabbox/CMakeLists.txt --- a/kcmkwin/kwintabbox/CMakeLists.txt +++ b/kcmkwin/kwintabbox/CMakeLists.txt @@ -10,6 +10,7 @@ layoutpreview.cpp main.cpp thumbnailitem.cpp + kwintabboxconfigform.cpp ) ki18n_wrap_ui(kcm_kwintabbox_PART_SRCS main.ui) diff --git a/kcmkwin/kwintabbox/kwintabboxconfigform.h b/kcmkwin/kwintabbox/kwintabboxconfigform.h new file mode 100644 --- /dev/null +++ b/kcmkwin/kwintabbox/kwintabboxconfigform.h @@ -0,0 +1,79 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2009 Martin Gräßlin +Copyright (C) 2020 Cyril Rossi + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ + +#ifndef __KWINTABBOXCONFIGFORM_H__ +#define __KWINTABBOXCONFIGFORM_H__ + +#include "tabboxconfig.h" + +#include "ui_main.h" + + +namespace KWin +{ + +class KWinTabBoxConfigForm : public QWidget, public Ui::KWinTabBoxConfigForm +{ + Q_OBJECT + +public: + enum EffectComboRole + { + LayoutPath = Qt::UserRole + 1, + AddonEffect, // i.e not builtin effects + }; + + explicit KWinTabBoxConfigForm(QWidget *parent); + + void setFilterScreen(TabBox::TabBoxConfig::ClientMultiScreenMode mode); + void setFilterDesktop(TabBox::TabBoxConfig::ClientDesktopMode mode); + void setFilterActivities(TabBox::TabBoxConfig::ClientActivitiesMode mode); + void setFilterMinimization(TabBox::TabBoxConfig::ClientMinimizedMode mode); + void setApplicationMode(TabBox::TabBoxConfig::ClientApplicationsMode mode); + void setShowDesktopMode(TabBox::TabBoxConfig::ShowDesktopMode mode); + void setSwitchingModeChanged(TabBox::TabBoxConfig::ClientSwitchingMode mode); + void setLayoutName(const QString &layoutName); + +signals: + void filterScreenChanged(int value); + void filterDesktopChanged(int value); + void filterActivitiesChanged(int value); + void filterMinimizationChanged(int value); + void applicationModeChanged(int value); + void showDesktopModeChanged(int value); + void switchingModeChanged(int value); + void layoutNameChanged(const QString &layoutName); + +private Q_SLOTS: + void tabBoxToggled(bool on); + void onFilterScreen(); + void onFilterDesktop(); + void onFilterActivites(); + void onFilterMinimization(); + void onApplicationMode(); + void onShowDesktopMode(); + void onSwitchingMode(); + void onEffectCombo(); +}; + +} // namespace + +#endif diff --git a/kcmkwin/kwintabbox/kwintabboxconfigform.cpp b/kcmkwin/kwintabbox/kwintabboxconfigform.cpp new file mode 100644 --- /dev/null +++ b/kcmkwin/kwintabbox/kwintabboxconfigform.cpp @@ -0,0 +1,185 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2009 Martin Gräßlin +Copyright (C) 2020 Cyril Rossi + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ + +#include "kwintabboxconfigform.h" + +namespace KWin +{ + +using namespace TabBox; + +KWinTabBoxConfigForm::KWinTabBoxConfigForm(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); + + effectConfigButton->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); + + if (QApplication::screens().count() < 2) { + filterScreens->hide(); + screenFilter->hide(); + } + + connect(kcfg_ShowTabBox, SIGNAL(clicked(bool)), SLOT(tabBoxToggled(bool))); + + connect(filterScreens, SIGNAL(clicked(bool)), SLOT(onFilterScreen())); + connect(currentScreen, SIGNAL(clicked(bool)), SLOT(onFilterScreen())); + connect(otherScreens, SIGNAL(clicked(bool)), SLOT(onFilterScreen())); + + connect(filterDesktops, SIGNAL(clicked(bool)), SLOT(onFilterDesktop())); + connect(currentDesktop, SIGNAL(clicked(bool)), SLOT(onFilterDesktop())); + connect(otherDesktops, SIGNAL(clicked(bool)), SLOT(onFilterDesktop())); + + connect(filterActivities, SIGNAL(clicked(bool)), SLOT(onFilterActivites())); + connect(currentActivity, SIGNAL(clicked(bool)), SLOT(onFilterActivites())); + connect(otherActivities, SIGNAL(clicked(bool)), SLOT(onFilterActivites())); + + connect(filterMinimization, SIGNAL(clicked(bool)), SLOT(onFilterMinimization())); + connect(visibleWindows, SIGNAL(clicked(bool)), SLOT(onFilterMinimization())); + connect(hiddenWindows, SIGNAL(clicked(bool)), SLOT(onFilterMinimization())); + + connect(oneAppWindow, SIGNAL(clicked(bool)), SLOT(onApplicationMode())); + connect(showDesktop, SIGNAL(clicked(bool)), SLOT(onShowDesktopMode())); + + connect(switchingModeCombo, SIGNAL(currentIndexChanged(int)), SLOT(onSwitchingMode())); + connect(effectCombo, SIGNAL(currentIndexChanged(int)), SLOT(onEffectCombo())); +} + +void KWinTabBoxConfigForm::setFilterScreen(TabBox::TabBoxConfig::ClientMultiScreenMode mode) +{ + filterScreens->setChecked(mode != TabBoxConfig::IgnoreMultiScreen); + currentScreen->setChecked(mode == TabBoxConfig::OnlyCurrentScreenClients); + otherScreens->setChecked(mode == TabBoxConfig::ExcludeCurrentScreenClients); +} + +void KWinTabBoxConfigForm::setFilterDesktop(TabBox::TabBoxConfig::ClientDesktopMode mode) +{ + filterDesktops->setChecked(mode != TabBoxConfig::AllDesktopsClients); + currentDesktop->setChecked(mode == TabBoxConfig::OnlyCurrentDesktopClients); + otherDesktops->setChecked(mode == TabBoxConfig::ExcludeCurrentDesktopClients); +} + +void KWinTabBoxConfigForm::setFilterActivities(TabBox::TabBoxConfig::ClientActivitiesMode mode) +{ + filterActivities->setChecked(mode != TabBoxConfig::AllActivitiesClients); + currentActivity->setChecked(mode == TabBoxConfig::OnlyCurrentActivityClients); + otherActivities->setChecked(mode == TabBoxConfig::ExcludeCurrentActivityClients); +} + +void KWinTabBoxConfigForm::setFilterMinimization(TabBox::TabBoxConfig::ClientMinimizedMode mode) +{ + filterMinimization->setChecked(mode != TabBoxConfig::IgnoreMinimizedStatus); + visibleWindows->setChecked(mode == TabBoxConfig::ExcludeMinimizedClients); + hiddenWindows->setChecked(mode == TabBoxConfig::OnlyMinimizedClients); +} + +void KWinTabBoxConfigForm::setApplicationMode(TabBox::TabBoxConfig::ClientApplicationsMode mode) +{ + oneAppWindow->setChecked(mode == TabBoxConfig::OneWindowPerApplication); +} + +void KWinTabBoxConfigForm::setShowDesktopMode(TabBox::TabBoxConfig::ShowDesktopMode mode) +{ + showDesktop->setChecked(mode == TabBoxConfig::ShowDesktopClient); +} + +void KWinTabBoxConfigForm::setSwitchingModeChanged(TabBox::TabBoxConfig::ClientSwitchingMode mode) +{ + switchingModeCombo->setCurrentIndex(mode); +} + +void KWinTabBoxConfigForm::setLayoutName(const QString &layoutName) +{ + effectCombo->setCurrentIndex(effectCombo->findData(layoutName)); +} + +void KWinTabBoxConfigForm::tabBoxToggled(bool on) +{ + // Highlight Windows options is availabled if no TabBox effect is selected + // or if Tabbox is not builtin effet. + on = !on || effectCombo->currentData(Qt::UserRole + 2).toBool(); + kcfg_HighlightWindows->setEnabled(on); +} + +void KWinTabBoxConfigForm::onFilterScreen() +{ + if (filterScreens->isChecked()) { + emit filterScreenChanged(currentScreen->isChecked() ? TabBoxConfig::OnlyCurrentScreenClients : TabBoxConfig::ExcludeCurrentScreenClients); + } else { + emit filterScreenChanged(TabBoxConfig::IgnoreMultiScreen); + } +} + +void KWinTabBoxConfigForm::onFilterDesktop() +{ + if (filterDesktops->isChecked()) { + emit filterDesktopChanged(currentDesktop->isChecked() ? TabBoxConfig::OnlyCurrentDesktopClients : TabBoxConfig::ExcludeCurrentDesktopClients); + } else { + emit filterDesktopChanged(TabBoxConfig::AllDesktopsClients); + } +} + +void KWinTabBoxConfigForm::onFilterActivites() +{ + if (filterActivities->isChecked()) { + emit filterActivitiesChanged(currentActivity->isChecked() ? TabBoxConfig::OnlyCurrentActivityClients : TabBoxConfig::ExcludeCurrentActivityClients); + } else { + emit filterActivitiesChanged(TabBoxConfig::AllActivitiesClients); + } +} + +void KWinTabBoxConfigForm::onFilterMinimization() +{ + if (filterMinimization->isChecked()) { + emit filterMinimizationChanged(visibleWindows->isChecked() ? TabBoxConfig::ExcludeMinimizedClients : TabBoxConfig::OnlyMinimizedClients); + } else { + emit filterMinimizationChanged(TabBoxConfig::IgnoreMinimizedStatus); + } +} + +void KWin::KWinTabBoxConfigForm::onApplicationMode() +{ + emit applicationModeChanged(oneAppWindow->isChecked() ? TabBoxConfig::OneWindowPerApplication : TabBoxConfig::AllWindowsAllApplications); +} + +void KWinTabBoxConfigForm::onShowDesktopMode() +{ + emit showDesktopModeChanged(showDesktop->isChecked() ? TabBoxConfig::ShowDesktopClient : TabBoxConfig::DoNotShowDesktopClient); +} + +void KWinTabBoxConfigForm::onSwitchingMode() +{ + emit switchingModeChanged(switchingModeCombo->currentIndex()); +} + +void KWinTabBoxConfigForm::onEffectCombo() +{ + const bool isAddonEffect = effectCombo->currentData(AddonEffect).toBool(); + effectConfigButton->setIcon(QIcon::fromTheme(isAddonEffect ? "view-preview" : "configure")); + if (!kcfg_ShowTabBox->isChecked()) { + return; + } + kcfg_HighlightWindows->setEnabled(isAddonEffect); + + emit layoutNameChanged(effectCombo->currentData().toString()); +} + +} // namespace diff --git a/kcmkwin/kwintabbox/main.h b/kcmkwin/kwintabbox/main.h --- a/kcmkwin/kwintabbox/main.h +++ b/kcmkwin/kwintabbox/main.h @@ -24,14 +24,14 @@ #include #include - -#include "ui_main.h" +#include "tabboxconfig.h" class KShortcutsEditor; class KActionCollection; namespace KWin { +class KWinTabBoxConfigForm; enum class BuiltInEffect; namespace TabBox { @@ -41,15 +41,6 @@ } - -class KWinTabBoxConfigForm : public QWidget, public Ui::KWinTabBoxConfigForm -{ - Q_OBJECT - -public: - explicit KWinTabBoxConfigForm(QWidget* parent); -}; - class KWinTabBoxConfig : public KCModule { Q_OBJECT @@ -64,33 +55,31 @@ void defaults() override; private Q_SLOTS: - void effectSelectionChanged(int index); + void updateUnmanagedState(); void configureEffectClicked(); - void tabBoxToggled(bool on); void shortcutChanged(const QKeySequence &seq); void slotGHNS(); + private: void updateUiFromConfig(KWinTabBoxConfigForm *ui, const TabBox::TabBoxSettings *config); - void updateConfigFromUi(const KWinTabBoxConfigForm *ui, TabBox::TabBoxSettings *config); void initLayoutLists(); + void createConnections(KWinTabBoxConfigForm *ui, TabBox::TabBoxSettings *config); private: - enum Mode { - CoverSwitch = 0, - FlipSwitch = 1, - Layout = 2 - }; - KWinTabBoxConfigForm* m_primaryTabBoxUi; - KWinTabBoxConfigForm* m_alternativeTabBoxUi; + KWinTabBoxConfigForm *m_primaryTabBoxUi; + KWinTabBoxConfigForm *m_alternativeTabBoxUi; KSharedConfigPtr m_config; - KActionCollection* m_actionCollection; - KShortcutsEditor* m_editor; + KActionCollection *m_actionCollection; + KShortcutsEditor *m_editor; TabBox::TabBoxSettings *m_tabBoxConfig; TabBox::TabBoxSettings *m_tabBoxAlternativeConfig; TabBox::SwitchEffectSettings *m_coverSwitchConfig; TabBox::SwitchEffectSettings *m_flipSwitchConfig; TabBox::PluginsSettings *m_pluginsConfig; + // Builtin effects' names + QString m_coverSwitch; + QString m_flipSwitch; }; } // namespace diff --git a/kcmkwin/kwintabbox/main.cpp b/kcmkwin/kwintabbox/main.cpp --- a/kcmkwin/kwintabbox/main.cpp +++ b/kcmkwin/kwintabbox/main.cpp @@ -49,6 +49,7 @@ #include // own +#include "kwintabboxconfigform.h" #include "layoutpreview.h" #include "kwintabboxsettings.h" #include "kwinswitcheffectsettings.h" @@ -61,11 +62,6 @@ using namespace TabBox; -KWinTabBoxConfigForm::KWinTabBoxConfigForm(QWidget* parent) - : QWidget(parent) -{ - setupUi(this); -} KWinTabBoxConfig::KWinTabBoxConfig(QWidget* parent, const QVariantList& args) : KCModule(parent, args) @@ -128,42 +124,13 @@ m_alternativeTabBoxUi->scCurrentReverse); #undef ADD_SHORTCUT - initLayoutLists(); - KWinTabBoxConfigForm *ui[2] = { m_primaryTabBoxUi, m_alternativeTabBoxUi }; - for (int i = 0; i < 2; ++i) { - ui[i]->effectConfigButton->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); - - connect(ui[i]->highlightWindowCheck, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->showTabBox, SIGNAL(clicked(bool)), SLOT(tabBoxToggled(bool))); - connect(ui[i]->effectCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed())); - connect(ui[i]->effectCombo, SIGNAL(currentIndexChanged(int)), SLOT(effectSelectionChanged(int))); - connect(ui[i]->effectConfigButton, SIGNAL(clicked(bool)), SLOT(configureEffectClicked())); - - connect(ui[i]->switchingModeCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed())); - connect(ui[i]->showDesktop, SIGNAL(clicked(bool)), SLOT(changed())); - - connect(ui[i]->filterDesktops, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->currentDesktop, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->otherDesktops, SIGNAL(clicked(bool)), SLOT(changed())); + addConfig(m_tabBoxConfig, m_primaryTabBoxUi); + addConfig(m_tabBoxAlternativeConfig, m_alternativeTabBoxUi); - connect(ui[i]->filterActivities, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->currentActivity, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->otherActivities, SIGNAL(clicked(bool)), SLOT(changed())); + createConnections(m_primaryTabBoxUi, m_tabBoxConfig); + createConnections(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); - connect(ui[i]->filterScreens, SIGNAL(clicked(bool)), SLOT(changed())); - if (QApplication::screens().count() < 2) { - ui[i]->filterScreens->hide(); - ui[i]->screenFilter->hide(); - } else { - connect(ui[i]->currentScreen, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->otherScreens, SIGNAL(clicked(bool)), SLOT(changed())); - } - - connect(ui[i]->oneAppWindow, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->filterMinimization, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->visibleWindows, SIGNAL(clicked(bool)), SLOT(changed())); - connect(ui[i]->hiddenWindows, SIGNAL(clicked(bool)), SLOT(changed())); - } + initLayoutLists(); // check focus policy - we don't offer configs for unreasonable focus policies KConfigGroup config(m_config, "Windows"); @@ -180,7 +147,6 @@ { } - static QList availableLnFPackages() { QList packages; @@ -213,8 +179,8 @@ void KWinTabBoxConfig::initLayoutLists() { // search the effect names - QString coverswitch = BuiltInEffects::effectData(BuiltInEffect::CoverSwitch).displayName; - QString flipswitch = BuiltInEffects::effectData(BuiltInEffect::FlipSwitch).displayName; + m_coverSwitch = BuiltInEffects::effectData(BuiltInEffect::CoverSwitch).name; + m_flipSwitch = BuiltInEffects::effectData(BuiltInEffect::FlipSwitch).name; QList offers = KPackage::PackageLoader::self()->listPackages("KWin/WindowSwitcher"); QStringList layoutNames, layoutPlugins, layoutPaths; @@ -254,20 +220,69 @@ int index = ui[i]->effectCombo->currentIndex(); QVariant data = ui[i]->effectCombo->itemData(index); ui[i]->effectCombo->clear(); - ui[i]->effectCombo->addItem(coverswitch); - ui[i]->effectCombo->addItem(flipswitch); + ui[i]->effectCombo->addItem(BuiltInEffects::effectData(BuiltInEffect::CoverSwitch).displayName, m_coverSwitch); + ui[i]->effectCombo->setItemData(ui[i]->effectCombo->count() - 1, false, KWinTabBoxConfigForm::AddonEffect); + ui[i]->effectCombo->addItem(BuiltInEffects::effectData(BuiltInEffect::FlipSwitch).displayName, m_flipSwitch); + ui[i]->effectCombo->setItemData(ui[i]->effectCombo->count() - 1, false, KWinTabBoxConfigForm::AddonEffect); for (int j = 0; j < layoutNames.count(); ++j) { ui[i]->effectCombo->addItem(layoutNames[j], layoutPlugins[j]); - ui[i]->effectCombo->setItemData(ui[i]->effectCombo->count() - 1, layoutPaths[j], Qt::UserRole+1); + ui[i]->effectCombo->setItemData(ui[i]->effectCombo->count() - 1, layoutPaths[j], KWinTabBoxConfigForm::LayoutPath); + ui[i]->effectCombo->setItemData(ui[i]->effectCombo->count() - 1, true, KWinTabBoxConfigForm::AddonEffect); } + ui[i]->effectCombo->model()->sort(0); + if (data.isValid()) { ui[i]->effectCombo->setCurrentIndex(ui[i]->effectCombo->findData(data)); } else if (index != -1) { ui[i]->effectCombo->setCurrentIndex(index); } } } +void KWinTabBoxConfig::createConnections(KWinTabBoxConfigForm *ui, TabBoxSettings *config) +{ + connect(ui->effectConfigButton, SIGNAL(clicked(bool)), SLOT(configureEffectClicked())); + + connect(ui, &KWinTabBoxConfigForm::filterScreenChanged, [this, config](int value) { + config->setMultiScreenMode(value); + updateUnmanagedState(); + }); + connect(ui, &KWinTabBoxConfigForm::filterDesktopChanged, [this, config](int value) { + config->setDesktopMode(value); + updateUnmanagedState(); + }); + connect(ui, &KWinTabBoxConfigForm::filterActivitiesChanged, [this, config](int value) { + config->setActivitiesMode(value); + updateUnmanagedState(); + }); + connect(ui, &KWinTabBoxConfigForm::filterMinimizationChanged, [this, config](int value) { + config->setMinimizedMode(value); + updateUnmanagedState(); + }); + connect(ui, &KWinTabBoxConfigForm::applicationModeChanged, [this, config](int value) { + config->setApplicationsMode(value); + updateUnmanagedState(); + }); + connect(ui, &KWinTabBoxConfigForm::showDesktopModeChanged, [this, config](int value) { + config->setShowDesktopMode(value); + updateUnmanagedState(); + }); + connect(ui, &KWinTabBoxConfigForm::switchingModeChanged, [this, config](int value) { + config->setSwitchingMode(value); + updateUnmanagedState(); + }); + connect(ui, &KWinTabBoxConfigForm::layoutNameChanged, [this, config](const QString &value) { + config->setLayoutName(value); + updateUnmanagedState(); + }); +} + +void KWinTabBoxConfig::updateUnmanagedState() +{ + unmanagedWidgetChangeState(m_tabBoxConfig->isSaveNeeded() || m_tabBoxAlternativeConfig->isSaveNeeded()); + unmanagedWidgetDefaultState(m_tabBoxConfig->isDefaults() && m_tabBoxAlternativeConfig->isDefaults()); +} + void KWinTabBoxConfig::load() { KCModule::load(); @@ -285,18 +300,18 @@ if (m_pluginsConfig->coverswitchEnabled()) { if (m_coverSwitchConfig->tabBox()) { - m_primaryTabBoxUi->effectCombo->setCurrentIndex(CoverSwitch); + m_primaryTabBoxUi->setLayoutName(m_coverSwitch); } if (m_coverSwitchConfig->tabBoxAlternative()) { - m_alternativeTabBoxUi->effectCombo->setCurrentIndex(CoverSwitch); + m_alternativeTabBoxUi->setLayoutName(m_coverSwitch); } } if (m_pluginsConfig->flipswitchEnabled()) { if (m_flipSwitchConfig->tabBox()) { - m_primaryTabBoxUi->effectCombo->setCurrentIndex(FlipSwitch); + m_primaryTabBoxUi->setLayoutName(m_flipSwitch); } if (m_flipSwitchConfig->tabBoxAlternative()) { - m_alternativeTabBoxUi->effectCombo->setCurrentIndex(FlipSwitch); + m_alternativeTabBoxUi->setLayoutName(m_flipSwitch); } } @@ -317,30 +332,23 @@ LOAD_SHORTCUT(scCurrentReverse); #undef LOAD_SHORTCUT } - emit changed(false); + + updateUnmanagedState(); } void KWinTabBoxConfig::save() { - KCModule::save(); - - // sync ui to config - updateConfigFromUi(m_primaryTabBoxUi, m_tabBoxConfig); - updateConfigFromUi(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); - m_tabBoxConfig->save(); - m_tabBoxAlternativeConfig->save(); - // effects - bool highlightWindows = m_primaryTabBoxUi->highlightWindowCheck->isChecked() || - m_alternativeTabBoxUi->highlightWindowCheck->isChecked(); - const bool coverSwitch = m_primaryTabBoxUi->showTabBox->isChecked() && - m_primaryTabBoxUi->effectCombo->currentIndex() == CoverSwitch; - const bool flipSwitch = m_primaryTabBoxUi->showTabBox->isChecked() && - m_primaryTabBoxUi->effectCombo->currentIndex() == FlipSwitch; - const bool coverSwitchAlternative = m_alternativeTabBoxUi->showTabBox->isChecked() && - m_alternativeTabBoxUi->effectCombo->currentIndex() == CoverSwitch; - const bool flipSwitchAlternative = m_alternativeTabBoxUi->showTabBox->isChecked() && - m_alternativeTabBoxUi->effectCombo->currentIndex() == FlipSwitch; + bool highlightWindows = m_primaryTabBoxUi->kcfg_HighlightWindows->isChecked() || + m_alternativeTabBoxUi->kcfg_HighlightWindows->isChecked(); + const bool coverSwitch = m_primaryTabBoxUi->kcfg_ShowTabBox->isChecked() && + m_primaryTabBoxUi->effectCombo->currentData() == m_coverSwitch; + const bool flipSwitch = m_primaryTabBoxUi->kcfg_ShowTabBox->isChecked() && + m_primaryTabBoxUi->effectCombo->currentData() == m_flipSwitch; + const bool coverSwitchAlternative = m_alternativeTabBoxUi->kcfg_ShowTabBox->isChecked() && + m_alternativeTabBoxUi->effectCombo->currentData() == m_coverSwitch; + const bool flipSwitchAlternative = m_alternativeTabBoxUi->kcfg_ShowTabBox->isChecked() && + m_alternativeTabBoxUi->effectCombo->currentData() == m_flipSwitch; // activate effects if not active if (coverSwitch || coverSwitchAlternative) { @@ -362,6 +370,9 @@ m_flipSwitchConfig->setTabBoxAlternative(flipSwitchAlternative); m_flipSwitchConfig->save(); + m_tabBoxConfig->save(); + m_tabBoxAlternativeConfig->save(); + // Reload KWin. QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); QDBusConnection::sessionBus().send(message); @@ -372,17 +383,14 @@ interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::CoverSwitch)); interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::FlipSwitch)); - emit changed(false); + KCModule::save(); } void KWinTabBoxConfig::defaults() { - KCModule::defaults(); - m_tabBoxConfig->setDefaults(); m_tabBoxAlternativeConfig->setDefaults(); - m_pluginsConfig->setDefaults(); m_coverSwitchConfig->setDefaults(); m_flipSwitchConfig->setDefaults(); @@ -404,116 +412,53 @@ RESET_SHORTCUT(m_alternativeTabBoxUi->scCurrent); RESET_SHORTCUT(m_alternativeTabBoxUi->scCurrentReverse); m_actionCollection->writeSettings(); - emit changed(true); -} -void KWinTabBoxConfig::updateUiFromConfig(KWinTabBoxConfigForm *ui, const KWin::TabBox::TabBoxSettings *config) -{ -#define CONFIGURE(SETTING, MODE, IS, VALUE) ui->SETTING->setChecked(config->MODE##Mode() IS TabBoxConfig::VALUE) - CONFIGURE(filterDesktops, desktop, !=, AllDesktopsClients); - CONFIGURE(currentDesktop, desktop, ==, OnlyCurrentDesktopClients); - CONFIGURE(otherDesktops, desktop, ==, ExcludeCurrentDesktopClients); - CONFIGURE(filterActivities, activities, !=, AllActivitiesClients); - CONFIGURE(currentActivity, activities, ==, OnlyCurrentActivityClients); - CONFIGURE(otherActivities, activities, ==, ExcludeCurrentActivityClients); - CONFIGURE(filterScreens, multiScreen, !=, IgnoreMultiScreen); - CONFIGURE(currentScreen, multiScreen, ==, OnlyCurrentScreenClients); - CONFIGURE(otherScreens, multiScreen, ==, ExcludeCurrentScreenClients); - CONFIGURE(oneAppWindow, applications, ==, OneWindowPerApplication); - CONFIGURE(filterMinimization, minimized, !=, IgnoreMinimizedStatus); - CONFIGURE(visibleWindows, minimized, ==, ExcludeMinimizedClients); - CONFIGURE(hiddenWindows, minimized, ==, OnlyMinimizedClients); - - ui->switchingModeCombo->setCurrentIndex(config->switchingMode()); - - // check boxes - ui->showTabBox->setChecked(config->showTabBox()); - ui->highlightWindowCheck->setChecked(config->highlightWindows()); - ui->effectCombo->setCurrentIndex(ui->effectCombo->findData(config->layoutName())); - CONFIGURE(showDesktop, showDesktop, ==, ShowDesktopClient); -#undef CONFIGURE + KCModule::defaults(); + updateUnmanagedState(); } -void KWinTabBoxConfig::updateConfigFromUi(const KWin::KWinTabBoxConfigForm *ui, TabBoxSettings *config) +void KWinTabBoxConfig::updateUiFromConfig(KWinTabBoxConfigForm *ui, const KWin::TabBox::TabBoxSettings *config) { - if (ui->filterDesktops->isChecked()) { - config->setDesktopMode(ui->currentDesktop->isChecked() ? TabBoxConfig::OnlyCurrentDesktopClients : TabBoxConfig::ExcludeCurrentDesktopClients); - } else { - config->setDesktopMode(TabBoxConfig::AllDesktopsClients); - } - if (ui->filterActivities->isChecked()) { - config->setActivitiesMode(ui->currentActivity->isChecked() ? TabBoxConfig::OnlyCurrentActivityClients : TabBoxConfig::ExcludeCurrentActivityClients); - } else { - config->setActivitiesMode(TabBoxConfig::AllActivitiesClients); - } - if (ui->filterScreens->isChecked()) { - config->setMultiScreenMode(ui->currentScreen->isChecked() ? TabBoxConfig::OnlyCurrentScreenClients : TabBoxConfig::ExcludeCurrentScreenClients); - } else { - config->setMultiScreenMode(TabBoxConfig::IgnoreMultiScreen); - } - config->setApplicationsMode(ui->oneAppWindow->isChecked() ? TabBoxConfig::OneWindowPerApplication : TabBoxConfig::AllWindowsAllApplications); - if (ui->filterMinimization->isChecked()) { - config->setMinimizedMode(ui->visibleWindows->isChecked() ? TabBoxConfig::ExcludeMinimizedClients : TabBoxConfig::OnlyMinimizedClients); - } else { - config->setMinimizedMode(TabBoxConfig::IgnoreMinimizedStatus); - } + ui->setFilterScreen(static_cast(config->multiScreenMode())); + ui->setFilterDesktop(static_cast(config->desktopMode())); + ui->setFilterActivities(static_cast(config->activitiesMode())); + ui->setFilterMinimization(static_cast(config->minimizedMode())); - config->setSwitchingMode(TabBoxConfig::ClientSwitchingMode(ui->switchingModeCombo->currentIndex())); + ui->setApplicationMode(static_cast(config->applicationsMode())); + ui->setShowDesktopMode(static_cast(config->showDesktopMode())); - config->setShowTabBox(ui->showTabBox->isChecked()); - config->setHighlightWindows(ui->highlightWindowCheck->isChecked()); - if (ui->effectCombo->currentIndex() >= Layout) { - config->setLayoutName(ui->effectCombo->itemData(ui->effectCombo->currentIndex()).toString()); - } - config->setShowDesktopMode(ui->showDesktop->isChecked() ? TabBoxConfig::ShowDesktopClient : TabBoxConfig::DoNotShowDesktopClient); -} - -#define CHECK_CURRENT_TABBOX_UI \ - Q_ASSERT(sender());\ - KWinTabBoxConfigForm *ui = nullptr;\ - QObject *dad = sender();\ - while (!ui && (dad = dad->parent()))\ - ui = qobject_cast(dad);\ - Q_ASSERT(ui); + ui->setSwitchingModeChanged(static_cast(config->switchingMode())); -void KWinTabBoxConfig::effectSelectionChanged(int index) -{ - CHECK_CURRENT_TABBOX_UI - ui->effectConfigButton->setIcon(QIcon::fromTheme(index < Layout ? "configure" : "view-preview")); - if (!ui->showTabBox->isChecked()) - return; - ui->highlightWindowCheck->setEnabled(index >= Layout); -} - -void KWinTabBoxConfig::tabBoxToggled(bool on) -{ - CHECK_CURRENT_TABBOX_UI - on = !on || ui->effectCombo->currentIndex() >= Layout; - ui->highlightWindowCheck->setEnabled(on); - emit changed(); + ui->setLayoutName(config->layoutName()); } void KWinTabBoxConfig::configureEffectClicked() { - CHECK_CURRENT_TABBOX_UI + Q_ASSERT(sender()); + KWinTabBoxConfigForm *ui = nullptr; + QObject *dad = sender(); + while (!ui && (dad = dad->parent())) { + ui = qobject_cast(dad); + } + Q_ASSERT(ui); + - const int effect = ui->effectCombo->currentIndex(); - if (effect >= Layout) { - // TODO: here we need to show the preview - new LayoutPreview(ui->effectCombo->itemData(effect, Qt::UserRole+1).toString(), this); + if (ui->effectCombo->currentData(KWinTabBoxConfigForm::AddonEffect).toBool()) { + // Show the preview for addon effect + new LayoutPreview(ui->effectCombo->currentData(KWinTabBoxConfigForm::LayoutPath).toString(), this); } else { + // For builtin effect, display a configuration dialog QPointer configDialog = new QDialog(this); configDialog->setLayout(new QVBoxLayout); configDialog->setWindowTitle(ui->effectCombo->currentText()); QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults, configDialog); connect(buttonBox, SIGNAL(accepted()), configDialog, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), configDialog, SLOT(reject())); - const QString name = BuiltInEffects::nameForEffect(effect == CoverSwitch ? BuiltInEffect::CoverSwitch : BuiltInEffect::FlipSwitch); - + const QString name = ui->effectCombo->currentData().toString(); KCModule *kcm = KPluginTrader::createInstanceFromQuery(QStringLiteral("kwin/effects/configs/"), QString(), QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(name), - configDialog); + configDialog); if (!kcm) { delete configDialog; return; @@ -540,10 +485,12 @@ void KWinTabBoxConfig::shortcutChanged(const QKeySequence &seq) { QString action; - if (sender()) + if (sender()) { action = sender()->property("shortcutAction").toString(); - if (action.isEmpty()) + } + if (action.isEmpty()) { return; + } QAction *a = m_actionCollection->action(action); KGlobalAccel::self()->setShortcut(a, QList() << seq, KGlobalAccel::NoAutoloading); m_actionCollection->writeSettings(); diff --git a/kcmkwin/kwintabbox/main.ui b/kcmkwin/kwintabbox/main.ui --- a/kcmkwin/kwintabbox/main.ui +++ b/kcmkwin/kwintabbox/main.ui @@ -534,7 +534,7 @@ - + @@ -544,7 +544,7 @@ - + The currently selected window will be highlighted by fading out all other windows. This option requires desktop effects to be active. @@ -593,8 +593,8 @@ - highlightWindowCheck - showTabBox + kcfg_HighlightWindows + kcfg_ShowTabBox effectCombo effectConfigButton switchingModeCombo @@ -680,7 +680,7 @@ - showTabBox + kcfg_ShowTabBox toggled(bool) widget_6 setEnabled(bool)