From 80c8f93c8ea19e87178584e52193de00828a351c Mon Sep 17 00:00:00 2001 From: wheaney <42350981+wheaney@users.noreply.github.com> Date: Thu, 14 Aug 2025 22:16:32 -0700 Subject: [PATCH] Clean up how shortcuts are defined, add recenter shortcut --- kwin/src/breezydesktopeffect.cpp | 51 +++++++++++++++++-------- kwin/src/breezydesktopeffect.h | 6 ++- kwin/src/kcm/breezydesktopeffectkcm.cpp | 26 ++++++------- kwin/src/kcm/shortcuts.h | 25 ++++++++++++ 4 files changed, 78 insertions(+), 30 deletions(-) create mode 100644 kwin/src/kcm/shortcuts.h diff --git a/kwin/src/breezydesktopeffect.cpp b/kwin/src/breezydesktopeffect.cpp index ffcf90e..3ae15f9 100644 --- a/kwin/src/breezydesktopeffect.cpp +++ b/kwin/src/breezydesktopeffect.cpp @@ -1,3 +1,4 @@ +#include "kcm/shortcuts.h" #include "breezydesktopeffect.h" #include "breezydesktopconfig.h" #include "effect/effect.h" @@ -6,6 +7,7 @@ #include "core/rendertarget.h" #include "core/renderviewport.h" +#include #include #include #include @@ -69,21 +71,14 @@ BreezyDesktopEffect::BreezyDesktopEffect() m_shutdownTimer->setSingleShot(true); connect(m_shutdownTimer, &QTimer::timeout, this, &BreezyDesktopEffect::realDeactivate); - const QKeySequence defaultToggleShortcut = Qt::CTRL | Qt::META | Qt::Key_Backslash; - m_toggleAction = new QAction(this); - m_toggleAction->setObjectName(QStringLiteral("Breezy Desktop")); - m_toggleAction->setText(i18n("Toggle Breezy Desktop")); - KGlobalAccel::self()->setDefaultShortcut(m_toggleAction, {defaultToggleShortcut}); - KGlobalAccel::self()->setShortcut(m_toggleAction, {defaultToggleShortcut}); - m_toggleShortcut = KGlobalAccel::self()->shortcut(m_toggleAction); - connect(m_toggleAction, &QAction::triggered, this, &BreezyDesktopEffect::toggle); - - connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, [this](QAction *action, const QKeySequence &seq) { - if (action->objectName() == QStringLiteral("Breezy Desktop")) { - m_toggleShortcut.clear(); - m_toggleShortcut.append(seq); - } - }); + setupGlobalShortcut( + BreezyShortcuts::TOGGLE, + [this]() { this->toggle(); } + ); + setupGlobalShortcut( + BreezyShortcuts::RECENTER, + [this]() { this->recenter(); } + ); connect(effects, &EffectsHandler::cursorShapeChanged, this, &BreezyDesktopEffect::updateCursorImage); updateCursorImage(); @@ -123,6 +118,22 @@ BreezyDesktopEffect::BreezyDesktopEffect() m_cursorUpdateTimer->start(); } +void BreezyDesktopEffect::setupGlobalShortcut(const BreezyShortcuts::Shortcut &shortcut, std::function triggeredFunc) { + QAction *action = new QAction(this); + action->setObjectName(shortcut.actionName); + action->setText(shortcut.actionText); + KGlobalAccel::self()->setDefaultShortcut(action, {shortcut.shortcut}); + KGlobalAccel::self()->setShortcut(action, {shortcut.shortcut}); + QList shortcutKeys = KGlobalAccel::self()->shortcut(action); + connect(action, &QAction::triggered, this, triggeredFunc); + connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, [this, shortcut, &shortcutKeys](QAction *action, const QKeySequence &seq) { + if (action->objectName() == shortcut.actionName) { + shortcutKeys.clear(); + shortcutKeys.append(seq); + } + }); +} + void BreezyDesktopEffect::reconfigure(ReconfigureFlags) { BreezyDesktopConfig::self()->read(); @@ -194,6 +205,16 @@ void BreezyDesktopEffect::realDeactivate() setRunning(false); } +void BreezyDesktopEffect::recenter() +{ + qCCritical(KWIN_XR) << "\t\t\tBreezy - recenter"; + QFile controlFile(QStringLiteral("/dev/shm/xr_driver_control")); + if (controlFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + controlFile.write("recenter_screen=true\n"); + controlFile.close(); + } +} + bool BreezyDesktopEffect::isEnabled() const { return m_enabled; } diff --git a/kwin/src/breezydesktopeffect.h b/kwin/src/breezydesktopeffect.h index ffa222f..ef038ad 100644 --- a/kwin/src/breezydesktopeffect.h +++ b/kwin/src/breezydesktopeffect.h @@ -1,5 +1,6 @@ #pragma once +#include "kcm/shortcuts.h" #include #include @@ -63,6 +64,7 @@ namespace KWin void activate(); void deactivate(); void toggle(); + void recenter(); void updateImuRotation(); void updateCursorImage(); void updateCursorPos(); @@ -81,10 +83,10 @@ namespace KWin private: void realDeactivate(); bool checkParityByte(const char* data); + void setupGlobalShortcut(const BreezyShortcuts::Shortcut &shortcut, + std::function triggeredFunc); QTimer *m_shutdownTimer; - QAction *m_toggleAction = nullptr; - QList m_toggleShortcut; QString m_cursorImageSource; bool m_enabled = false; diff --git a/kwin/src/kcm/breezydesktopeffectkcm.cpp b/kwin/src/kcm/breezydesktopeffectkcm.cpp index 19b1e86..abe5946 100644 --- a/kwin/src/kcm/breezydesktopeffectkcm.cpp +++ b/kwin/src/kcm/breezydesktopeffectkcm.cpp @@ -1,9 +1,4 @@ -/* - SPDX-FileCopyrightText: 2022 Vlad Zahorodnii - - SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL -*/ - +#include "shortcuts.h" #include "breezydesktopeffectkcm.h" #include "breezydesktopconfig.h" @@ -15,8 +10,18 @@ #include #include + #include +void addShortcutAction(KActionCollection *collection, const BreezyShortcuts::Shortcut &shortcut) +{ + QAction *action = collection->addAction(shortcut.actionName); + action->setText(shortcut.actionText); + action->setProperty("isConfigurationAction", true); + KGlobalAccel::self()->setDefaultShortcut(action, {shortcut.shortcut}); + KGlobalAccel::self()->setShortcut(action, {shortcut.shortcut}); +} + K_PLUGIN_CLASS(BreezyDesktopEffectConfig) BreezyDesktopEffectConfig::BreezyDesktopEffectConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args) @@ -30,13 +35,8 @@ BreezyDesktopEffectConfig::BreezyDesktopEffectConfig(QObject *parent, const KPlu actionCollection->setConfigGroup(QStringLiteral("breezy_desktop_effect")); actionCollection->setConfigGlobal(true); - const QKeySequence defaultToggleShortcut = Qt::CTRL | Qt::META | Qt::Key_Backslash; - QAction *toggleAction = actionCollection->addAction(QStringLiteral("Breezy Desktop")); - toggleAction->setText(i18n("Toggle Breezy Desktop")); - toggleAction->setProperty("isConfigurationAction", true); - KGlobalAccel::self()->setDefaultShortcut(toggleAction, {defaultToggleShortcut}); - KGlobalAccel::self()->setShortcut(toggleAction, {defaultToggleShortcut}); - + addShortcutAction(actionCollection, BreezyShortcuts::TOGGLE); + addShortcutAction(actionCollection, BreezyShortcuts::RECENTER); ui.shortcutsEditor->addCollection(actionCollection); connect(ui.shortcutsEditor, &KShortcutsEditor::keyChange, this, &BreezyDesktopEffectConfig::markAsChanged); connect(ui.kcfg_FocusedDisplayDistance, &QSlider::valueChanged, this, &BreezyDesktopEffectConfig::save); diff --git a/kwin/src/kcm/shortcuts.h b/kwin/src/kcm/shortcuts.h new file mode 100644 index 0000000..1eb8c75 --- /dev/null +++ b/kwin/src/kcm/shortcuts.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +namespace BreezyShortcuts { + struct Shortcut { + QKeySequence shortcut; + QString actionName; + QString actionText; + }; + + const Shortcut TOGGLE = { + Qt::CTRL | Qt::META | Qt::Key_Backslash, + QStringLiteral("Toggle XR Effect"), + QStringLiteral("Toggle XR Effect") + }; + + const Shortcut RECENTER = { + Qt::CTRL | Qt::META | Qt::Key_Space, + QStringLiteral("Recenter"), + QStringLiteral("Recenter") + }; +}