GlobalShortcuts: clang-format
This commit is contained in:
parent
ccca3b2af2
commit
bc3ac17141
2 changed files with 35 additions and 31 deletions
|
@ -9,24 +9,25 @@
|
||||||
// own
|
// own
|
||||||
#include "globalshortcuts.h"
|
#include "globalshortcuts.h"
|
||||||
// kwin
|
// kwin
|
||||||
#include <config-kwin.h>
|
#include "gestures.h"
|
||||||
#include "kwinglobals.h"
|
#include "kwinglobals.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "gestures.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <config-kwin.h>
|
||||||
// KDE
|
// KDE
|
||||||
#include <KGlobalAccel/private/kglobalacceld.h>
|
|
||||||
#include <KGlobalAccel/private/kglobalaccel_interface.h>
|
#include <KGlobalAccel/private/kglobalaccel_interface.h>
|
||||||
|
#include <KGlobalAccel/private/kglobalacceld.h>
|
||||||
// Qt
|
// Qt
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
GlobalShortcut::GlobalShortcut(Shortcut &&sc, QAction *action)
|
||||||
GlobalShortcut::GlobalShortcut(Shortcut&& sc, QAction* action) : m_shortcut(sc), m_action(action)
|
: m_shortcut(sc)
|
||||||
|
, m_action(action)
|
||||||
{
|
{
|
||||||
static const QMap<SwipeDirection,SwipeGesture::Direction> dirs = {
|
static const QMap<SwipeDirection, SwipeGesture::Direction> dirs = {
|
||||||
{SwipeDirection::Up, SwipeGesture::Direction::Up},
|
{SwipeDirection::Up, SwipeGesture::Direction::Up},
|
||||||
{SwipeDirection::Down, SwipeGesture::Direction::Down},
|
{SwipeDirection::Down, SwipeGesture::Direction::Down},
|
||||||
{SwipeDirection::Left, SwipeGesture::Direction::Left},
|
{SwipeDirection::Left, SwipeGesture::Direction::Left},
|
||||||
|
@ -45,7 +46,7 @@ GlobalShortcut::~GlobalShortcut()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction* GlobalShortcut::action() const
|
QAction *GlobalShortcut::action() const
|
||||||
{
|
{
|
||||||
return m_action;
|
return m_action;
|
||||||
}
|
}
|
||||||
|
@ -55,12 +56,12 @@ void GlobalShortcut::invoke() const
|
||||||
QMetaObject::invokeMethod(m_action, "trigger", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(m_action, "trigger", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Shortcut& GlobalShortcut::shortcut() const
|
const Shortcut &GlobalShortcut::shortcut() const
|
||||||
{
|
{
|
||||||
return m_shortcut;
|
return m_shortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwipeGesture* GlobalShortcut::swipeGesture() const
|
SwipeGesture *GlobalShortcut::swipeGesture() const
|
||||||
{
|
{
|
||||||
return m_gesture.get();
|
return m_gesture.get();
|
||||||
}
|
}
|
||||||
|
@ -104,7 +105,7 @@ void GlobalShortcutsManager::objectDeleted(QObject *object)
|
||||||
|
|
||||||
bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc)
|
bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc)
|
||||||
{
|
{
|
||||||
for (const auto& cs : m_shortcuts) {
|
for (const auto &cs : m_shortcuts) {
|
||||||
if (sc.shortcut() == cs.shortcut()) {
|
if (sc.shortcut() == cs.shortcut()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -120,17 +121,17 @@ bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc)
|
||||||
|
|
||||||
void GlobalShortcutsManager::registerPointerShortcut(QAction *action, Qt::KeyboardModifiers modifiers, Qt::MouseButtons pointerButtons)
|
void GlobalShortcutsManager::registerPointerShortcut(QAction *action, Qt::KeyboardModifiers modifiers, Qt::MouseButtons pointerButtons)
|
||||||
{
|
{
|
||||||
addIfNotExists(GlobalShortcut(PointerButtonShortcut{ modifiers, pointerButtons }, action));
|
addIfNotExists(GlobalShortcut(PointerButtonShortcut{modifiers, pointerButtons}, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalShortcutsManager::registerAxisShortcut(QAction *action, Qt::KeyboardModifiers modifiers, PointerAxisDirection axis)
|
void GlobalShortcutsManager::registerAxisShortcut(QAction *action, Qt::KeyboardModifiers modifiers, PointerAxisDirection axis)
|
||||||
{
|
{
|
||||||
addIfNotExists(GlobalShortcut(PointerAxisShortcut{ modifiers, axis }, action));
|
addIfNotExists(GlobalShortcut(PointerAxisShortcut{modifiers, axis}, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalShortcutsManager::registerTouchpadSwipe(QAction *action, SwipeDirection direction)
|
void GlobalShortcutsManager::registerTouchpadSwipe(QAction *action, SwipeDirection direction)
|
||||||
{
|
{
|
||||||
addIfNotExists(GlobalShortcut(FourFingerSwipeShortcut{ direction }, action));
|
addIfNotExists(GlobalShortcut(FourFingerSwipeShortcut{direction}, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt)
|
bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt)
|
||||||
|
@ -139,13 +140,13 @@ bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt)
|
||||||
if (!keyQt && !mods) {
|
if (!keyQt && !mods) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto check = [this] (Qt::KeyboardModifiers mods, int keyQt) {
|
auto check = [this](Qt::KeyboardModifiers mods, int keyQt) {
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
QMetaObject::invokeMethod(m_kglobalAccelInterface,
|
QMetaObject::invokeMethod(m_kglobalAccelInterface,
|
||||||
"checkKeyPressed",
|
"checkKeyPressed",
|
||||||
Qt::DirectConnection,
|
Qt::DirectConnection,
|
||||||
Q_RETURN_ARG(bool, retVal),
|
Q_RETURN_ARG(bool, retVal),
|
||||||
Q_ARG(int, int(mods) | keyQt));
|
Q_ARG(int, int(mods) | keyQt));
|
||||||
return retVal;
|
return retVal;
|
||||||
};
|
};
|
||||||
if (check(mods, keyQt)) {
|
if (check(mods, keyQt)) {
|
||||||
|
@ -172,7 +173,7 @@ bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt)
|
||||||
template<typename ShortcutKind, typename... Args>
|
template<typename ShortcutKind, typename... Args>
|
||||||
bool match(QVector<GlobalShortcut> &shortcuts, Args... args)
|
bool match(QVector<GlobalShortcut> &shortcuts, Args... args)
|
||||||
{
|
{
|
||||||
for (auto& sc : shortcuts) {
|
for (auto &sc : shortcuts) {
|
||||||
if (std::holds_alternative<ShortcutKind>(sc.shortcut())) {
|
if (std::holds_alternative<ShortcutKind>(sc.shortcut())) {
|
||||||
if (std::get<ShortcutKind>(sc.shortcut()) == ShortcutKind{args...}) {
|
if (std::get<ShortcutKind>(sc.shortcut()) == ShortcutKind{args...}) {
|
||||||
sc.invoke();
|
sc.invoke();
|
||||||
|
@ -183,7 +184,7 @@ bool match(QVector<GlobalShortcut> &shortcuts, Args... args)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(C++20): use ranges for a nicer way of filtering by shortcut type
|
// TODO(C++20): use ranges for a nicer way of filtering by shortcut type
|
||||||
bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Qt::MouseButtons pointerButtons)
|
bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Qt::MouseButtons pointerButtons)
|
||||||
{
|
{
|
||||||
return match<PointerButtonShortcut>(m_shortcuts, mods, pointerButtons);
|
return match<PointerButtonShortcut>(m_shortcuts, mods, pointerButtons);
|
||||||
|
|
|
@ -20,7 +20,6 @@ class KGlobalAccelInterface;
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
class GlobalShortcut;
|
class GlobalShortcut;
|
||||||
class SwipeGesture;
|
class SwipeGesture;
|
||||||
class GestureRecognizer;
|
class GestureRecognizer;
|
||||||
|
@ -92,7 +91,8 @@ public:
|
||||||
void processSwipeCancel();
|
void processSwipeCancel();
|
||||||
void processSwipeEnd();
|
void processSwipeEnd();
|
||||||
|
|
||||||
void setKGlobalAccelInterface(KGlobalAccelInterface *interface) {
|
void setKGlobalAccelInterface(KGlobalAccelInterface *interface)
|
||||||
|
{
|
||||||
m_kglobalAccelInterface = interface;
|
m_kglobalAccelInterface = interface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,8 @@ private:
|
||||||
struct KeyboardShortcut
|
struct KeyboardShortcut
|
||||||
{
|
{
|
||||||
QKeySequence sequence;
|
QKeySequence sequence;
|
||||||
bool operator==(const KeyboardShortcut& rhs) const {
|
bool operator==(const KeyboardShortcut &rhs) const
|
||||||
|
{
|
||||||
return sequence == rhs.sequence;
|
return sequence == rhs.sequence;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -118,7 +119,8 @@ struct PointerButtonShortcut
|
||||||
{
|
{
|
||||||
Qt::KeyboardModifiers pointerModifiers;
|
Qt::KeyboardModifiers pointerModifiers;
|
||||||
Qt::MouseButtons pointerButtons;
|
Qt::MouseButtons pointerButtons;
|
||||||
bool operator==(const PointerButtonShortcut& rhs) const {
|
bool operator==(const PointerButtonShortcut &rhs) const
|
||||||
|
{
|
||||||
return pointerModifiers == rhs.pointerModifiers && pointerButtons == rhs.pointerButtons;
|
return pointerModifiers == rhs.pointerModifiers && pointerButtons == rhs.pointerButtons;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -126,31 +128,32 @@ struct PointerAxisShortcut
|
||||||
{
|
{
|
||||||
Qt::KeyboardModifiers axisModifiers;
|
Qt::KeyboardModifiers axisModifiers;
|
||||||
PointerAxisDirection axisDirection;
|
PointerAxisDirection axisDirection;
|
||||||
bool operator==(const PointerAxisShortcut& rhs) const {
|
bool operator==(const PointerAxisShortcut &rhs) const
|
||||||
|
{
|
||||||
return axisModifiers == rhs.axisModifiers && axisDirection == rhs.axisDirection;
|
return axisModifiers == rhs.axisModifiers && axisDirection == rhs.axisDirection;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct FourFingerSwipeShortcut
|
struct FourFingerSwipeShortcut
|
||||||
{
|
{
|
||||||
SwipeDirection swipeDirection;
|
SwipeDirection swipeDirection;
|
||||||
bool operator==(const FourFingerSwipeShortcut& rhs) const {
|
bool operator==(const FourFingerSwipeShortcut &rhs) const
|
||||||
|
{
|
||||||
return swipeDirection == rhs.swipeDirection;
|
return swipeDirection == rhs.swipeDirection;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using Shortcut = std::variant<KeyboardShortcut,PointerButtonShortcut,PointerAxisShortcut,FourFingerSwipeShortcut>;
|
using Shortcut = std::variant<KeyboardShortcut, PointerButtonShortcut, PointerAxisShortcut, FourFingerSwipeShortcut>;
|
||||||
|
|
||||||
class GlobalShortcut
|
class GlobalShortcut
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlobalShortcut(Shortcut&& shortcut, QAction *action);
|
GlobalShortcut(Shortcut &&shortcut, QAction *action);
|
||||||
~GlobalShortcut();
|
~GlobalShortcut();
|
||||||
|
|
||||||
void invoke() const;
|
void invoke() const;
|
||||||
QAction *action() const;
|
QAction *action() const;
|
||||||
const Shortcut& shortcut() const;
|
const Shortcut &shortcut() const;
|
||||||
SwipeGesture* swipeGesture() const;
|
SwipeGesture *swipeGesture() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<SwipeGesture> m_gesture;
|
QSharedPointer<SwipeGesture> m_gesture;
|
||||||
|
|
Loading…
Reference in a new issue