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

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2007 Rivo Laks <rivolaks@hot.ee>
0006     SPDX-FileCopyrightText: 2010 Jorge Mata <matamax123@gmail.com>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 #include "trackmouse_config.h"
0011 
0012 #include <config-kwin.h>
0013 
0014 // KConfigSkeleton
0015 #include "trackmouseconfig.h"
0016 
0017 #include <kwineffects_interface.h>
0018 
0019 #include <KActionCollection>
0020 #include <KGlobalAccel>
0021 #include <KLocalizedString>
0022 #include <KPluginFactory>
0023 
0024 #include <QAction>
0025 #include <QLabel>
0026 #include <QVBoxLayout>
0027 
0028 K_PLUGIN_CLASS(KWin::TrackMouseEffectConfig)
0029 
0030 namespace KWin
0031 {
0032 
0033 static const QString s_toggleTrackMouseActionName = QStringLiteral("TrackMouse");
0034 
0035 TrackMouseEffectConfig::TrackMouseEffectConfig(QObject *parent, const KPluginMetaData &data)
0036     : KCModule(parent, data)
0037 {
0038     TrackMouseConfig::instance(KWIN_CONFIG);
0039     m_ui.setupUi(widget());
0040 
0041     addConfig(TrackMouseConfig::self(), widget());
0042 
0043     m_actionCollection = new KActionCollection(this, QStringLiteral("kwin"));
0044     m_actionCollection->setComponentDisplayName(i18n("KWin"));
0045     m_actionCollection->setConfigGroup(QStringLiteral("TrackMouse"));
0046     m_actionCollection->setConfigGlobal(true);
0047 
0048     QAction *a = m_actionCollection->addAction(s_toggleTrackMouseActionName);
0049     a->setText(i18n("Track mouse"));
0050     a->setProperty("isConfigurationAction", true);
0051 
0052     KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>());
0053     KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>());
0054 
0055     connect(m_ui.shortcut, &KKeySequenceWidget::keySequenceChanged,
0056             this, &TrackMouseEffectConfig::shortcutChanged);
0057 }
0058 
0059 TrackMouseEffectConfig::~TrackMouseEffectConfig()
0060 {
0061 }
0062 
0063 void TrackMouseEffectConfig::load()
0064 {
0065     KCModule::load();
0066 
0067     if (QAction *a = m_actionCollection->action(s_toggleTrackMouseActionName)) {
0068         auto shortcuts = KGlobalAccel::self()->shortcut(a);
0069         if (!shortcuts.isEmpty()) {
0070             m_ui.shortcut->setKeySequence(shortcuts.first());
0071         }
0072     }
0073 }
0074 
0075 void TrackMouseEffectConfig::save()
0076 {
0077     KCModule::save();
0078     m_actionCollection->writeSettings();
0079     OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"),
0080                                          QStringLiteral("/Effects"),
0081                                          QDBusConnection::sessionBus());
0082     interface.reconfigureEffect(QStringLiteral("trackmouse"));
0083 }
0084 
0085 void TrackMouseEffectConfig::defaults()
0086 {
0087     KCModule::defaults();
0088     m_ui.shortcut->clearKeySequence();
0089 }
0090 
0091 void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq)
0092 {
0093     if (QAction *a = m_actionCollection->action(QStringLiteral("TrackMouse"))) {
0094         KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << seq, KGlobalAccel::NoAutoloading);
0095     }
0096     setNeedsSave(true);
0097 }
0098 
0099 } // namespace
0100 
0101 #include "trackmouse_config.moc"
0102 
0103 #include "moc_trackmouse_config.cpp"