File indexing completed on 2024-11-10 04:57:04

0001 /*
0002     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "overvieweffectkcm.h"
0007 
0008 #include <config-kwin.h>
0009 
0010 #include "overviewconfig.h"
0011 
0012 #include <kwineffects_interface.h>
0013 
0014 #include <KActionCollection>
0015 #include <KGlobalAccel>
0016 #include <KLocalizedString>
0017 #include <KPluginFactory>
0018 
0019 #include <QAction>
0020 
0021 K_PLUGIN_CLASS(KWin::OverviewEffectConfig)
0022 
0023 namespace KWin
0024 {
0025 
0026 OverviewEffectConfig::OverviewEffectConfig(QObject *parent, const KPluginMetaData &data)
0027     : KCModule(parent, data)
0028 {
0029     ui.setupUi(widget());
0030     OverviewConfig::instance(KWIN_CONFIG);
0031     addConfig(OverviewConfig::self(), widget());
0032 
0033     auto actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
0034 
0035     actionCollection->setComponentDisplayName(i18n("KWin"));
0036     actionCollection->setConfigGroup(QStringLiteral("Overview"));
0037     actionCollection->setConfigGlobal(true);
0038 
0039     QAction *cycleAction = actionCollection->addAction(QStringLiteral("Cycle Overview"));
0040     cycleAction->setText(i18nc("@action Overview and Grid View are the name of KWin effects", "Cycle through Overview and Grid View"));
0041     cycleAction->setProperty("isConfigurationAction", true);
0042     KGlobalAccel::self()->setDefaultShortcut(cycleAction, {});
0043     KGlobalAccel::self()->setShortcut(cycleAction, {});
0044 
0045     QAction *reverseCycleAction = actionCollection->addAction(QStringLiteral("Cycle Overview Opposite"));
0046     reverseCycleAction->setText(i18nc("@action Grid View and Overview are the name of KWin effects", "Cycle through Grid View and Overview"));
0047     reverseCycleAction->setProperty("isConfigurationAction", true);
0048     KGlobalAccel::self()->setDefaultShortcut(reverseCycleAction, {});
0049     KGlobalAccel::self()->setShortcut(reverseCycleAction, {});
0050 
0051     const QKeySequence defaultOverviewShortcut = Qt::META | Qt::Key_W;
0052     QAction *overviewAction = actionCollection->addAction(QStringLiteral("Overview"));
0053     overviewAction->setText(i18nc("@action Overview is the name of a KWin effect", "Toggle Overview"));
0054     overviewAction->setProperty("isConfigurationAction", true);
0055     KGlobalAccel::self()->setDefaultShortcut(overviewAction, {defaultOverviewShortcut});
0056     KGlobalAccel::self()->setShortcut(overviewAction, {defaultOverviewShortcut});
0057 
0058     const QKeySequence defaultGridShortcut = Qt::META | Qt::Key_G;
0059     QAction *gridAction = actionCollection->addAction(QStringLiteral("Grid View"));
0060     gridAction->setText(i18nc("@action Grid View is the name of a KWin effect", "Toggle Grid View"));
0061     gridAction->setProperty("isConfigurationAction", true);
0062     KGlobalAccel::self()->setDefaultShortcut(gridAction, {defaultGridShortcut});
0063     KGlobalAccel::self()->setShortcut(gridAction, {defaultGridShortcut});
0064 
0065     ui.shortcutsEditor->addCollection(actionCollection);
0066     connect(ui.shortcutsEditor, &KShortcutsEditor::keyChange, this, &KCModule::markAsChanged);
0067 }
0068 
0069 void OverviewEffectConfig::save()
0070 {
0071     KCModule::save();
0072     ui.shortcutsEditor->save();
0073 
0074     OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
0075                                          QStringLiteral("/Effects"),
0076                                          QDBusConnection::sessionBus());
0077     interface.reconfigureEffect(QStringLiteral("overview"));
0078 }
0079 
0080 void OverviewEffectConfig::defaults()
0081 {
0082     ui.shortcutsEditor->allDefault();
0083     KCModule::defaults();
0084 }
0085 
0086 } // namespace KWin
0087 
0088 #include "overvieweffectkcm.moc"
0089 
0090 #include "moc_overvieweffectkcm.cpp"