Clean up how shortcuts are defined, add recenter shortcut
This commit is contained in:
parent
67c70532fd
commit
80c8f93c8e
|
|
@ -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 <functional>
|
||||
#include <QAction>
|
||||
#include <QFile>
|
||||
#include <QFileSystemWatcher>
|
||||
|
|
@ -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<void()> 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<QKeySequence> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "kcm/shortcuts.h"
|
||||
#include <effect/quickeffect.h>
|
||||
|
||||
#include <QAction>
|
||||
|
|
@ -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<void()> triggeredFunc);
|
||||
|
||||
QTimer *m_shutdownTimer;
|
||||
QAction *m_toggleAction = nullptr;
|
||||
QList<QKeySequence> m_toggleShortcut;
|
||||
QString m_cursorImageSource;
|
||||
|
||||
bool m_enabled = false;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
/*
|
||||
SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
|
||||
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 <KPluginFactory>
|
||||
|
||||
#include <QAction>
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <QKeySequence>
|
||||
#include <Qt>
|
||||
#include <QString>
|
||||
|
||||
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")
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue