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

0001 /*
0002     SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0003     SPDX-FileCopyrightText: 2022 ivan tkachenko <me@ratijas.tk>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 #include "windowvieweffectkcm.h"
0008 
0009 #include <config-kwin.h>
0010 
0011 #include "windowviewconfig.h"
0012 
0013 #include <kwineffects_interface.h>
0014 
0015 #include <KActionCollection>
0016 #include <KGlobalAccel>
0017 #include <KLocalizedString>
0018 #include <KPluginFactory>
0019 
0020 #include <QAction>
0021 
0022 K_PLUGIN_CLASS(KWin::WindowViewEffectConfig)
0023 
0024 namespace KWin
0025 {
0026 
0027 WindowViewEffectConfig::WindowViewEffectConfig(QObject *parent, const KPluginMetaData &data)
0028     : KCModule(parent, data)
0029 {
0030     ui.setupUi(widget());
0031     WindowViewConfig::instance(KWIN_CONFIG);
0032     addConfig(WindowViewConfig::self(), widget());
0033 
0034     auto actionCollection = new KActionCollection(widget(), QStringLiteral("kwin"));
0035 
0036     actionCollection->setComponentDisplayName(i18n("KWin"));
0037     actionCollection->setConfigGroup(QStringLiteral("windowview"));
0038     actionCollection->setConfigGlobal(true);
0039 
0040     const QKeySequence defaultToggleShortcut = Qt::CTRL | Qt::Key_F9;
0041     QAction *toggleAction = actionCollection->addAction(QStringLiteral("Expose"));
0042     toggleAction->setText(i18n("Toggle Present Windows (Current desktop)"));
0043     toggleAction->setProperty("isConfigurationAction", true);
0044     KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcut});
0045     KGlobalAccel::self()->setShortcut(toggleAction, {defaultToggleShortcut});
0046 
0047     const QKeySequence defaultToggleShortcutAll = Qt::CTRL | Qt::Key_F10;
0048     toggleAction = actionCollection->addAction(QStringLiteral("ExposeAll"));
0049     toggleAction->setText(i18n("Toggle Present Windows (All desktops)"));
0050     toggleAction->setProperty("isConfigurationAction", true);
0051     KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcutAll});
0052     KGlobalAccel::self()->setShortcut(toggleAction, {defaultToggleShortcutAll});
0053 
0054     const QKeySequence defaultToggleShortcutClass = Qt::CTRL | Qt::Key_F7;
0055     toggleAction = actionCollection->addAction(QStringLiteral("ExposeClass"));
0056     toggleAction->setText(i18n("Toggle Present Windows (Window class)"));
0057     toggleAction->setProperty("isConfigurationAction", true);
0058     KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcutClass});
0059     KGlobalAccel::self()->setShortcut(toggleAction, {defaultToggleShortcutClass});
0060 
0061     toggleAction = actionCollection->addAction(QStringLiteral("ExposeClassCurrentDesktop"));
0062     toggleAction->setText(i18n("Toggle Present Windows (Window class on current desktop)"));
0063     toggleAction->setProperty("isConfigurationAction", true);
0064     KGlobalAccel::self()->setDefaultShortcut(toggleAction, QList<QKeySequence>()); // no default shortcut
0065     KGlobalAccel::self()->setShortcut(toggleAction, QList<QKeySequence>());
0066 
0067     ui.shortcutsEditor->addCollection(actionCollection);
0068     connect(ui.shortcutsEditor, &KShortcutsEditor::keyChange, this, &KCModule::markAsChanged);
0069 }
0070 
0071 void WindowViewEffectConfig::save()
0072 {
0073     KCModule::save();
0074     ui.shortcutsEditor->save();
0075 
0076     OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
0077                                          QStringLiteral("/Effects"),
0078                                          QDBusConnection::sessionBus());
0079     interface.reconfigureEffect(QStringLiteral("windowview"));
0080 }
0081 
0082 void WindowViewEffectConfig::defaults()
0083 {
0084     ui.shortcutsEditor->allDefault();
0085     KCModule::defaults();
0086 }
0087 
0088 } // namespace KWin
0089 
0090 #include "windowvieweffectkcm.moc"
0091 
0092 #include "moc_windowvieweffectkcm.cpp"