From bc3ac17141620b9ae8cec104c34b279f195e7247 Mon Sep 17 00:00:00 2001 From: Jan Blackquill Date: Tue, 30 Mar 2021 09:32:32 -0400 Subject: [PATCH] GlobalShortcuts: clang-format --- src/globalshortcuts.cpp | 41 +++++++++++++++++++++-------------------- src/globalshortcuts.h | 25 ++++++++++++++----------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/globalshortcuts.cpp b/src/globalshortcuts.cpp index 68cb86b5ff..3e67318342 100644 --- a/src/globalshortcuts.cpp +++ b/src/globalshortcuts.cpp @@ -9,24 +9,25 @@ // own #include "globalshortcuts.h" // kwin -#include +#include "gestures.h" #include "kwinglobals.h" #include "main.h" -#include "gestures.h" #include "utils.h" +#include // KDE -#include #include +#include // Qt #include #include namespace KWin { - -GlobalShortcut::GlobalShortcut(Shortcut&& sc, QAction* action) : m_shortcut(sc), m_action(action) +GlobalShortcut::GlobalShortcut(Shortcut &&sc, QAction *action) + : m_shortcut(sc) + , m_action(action) { - static const QMap dirs = { + static const QMap dirs = { {SwipeDirection::Up, SwipeGesture::Direction::Up}, {SwipeDirection::Down, SwipeGesture::Direction::Down}, {SwipeDirection::Left, SwipeGesture::Direction::Left}, @@ -45,7 +46,7 @@ GlobalShortcut::~GlobalShortcut() { } -QAction* GlobalShortcut::action() const +QAction *GlobalShortcut::action() const { return m_action; } @@ -55,12 +56,12 @@ void GlobalShortcut::invoke() const QMetaObject::invokeMethod(m_action, "trigger", Qt::QueuedConnection); } -const Shortcut& GlobalShortcut::shortcut() const +const Shortcut &GlobalShortcut::shortcut() const { return m_shortcut; } -SwipeGesture* GlobalShortcut::swipeGesture() const +SwipeGesture *GlobalShortcut::swipeGesture() const { return m_gesture.get(); } @@ -104,7 +105,7 @@ void GlobalShortcutsManager::objectDeleted(QObject *object) bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc) { - for (const auto& cs : m_shortcuts) { + for (const auto &cs : m_shortcuts) { if (sc.shortcut() == cs.shortcut()) { return false; } @@ -120,17 +121,17 @@ bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc) 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) { - addIfNotExists(GlobalShortcut(PointerAxisShortcut{ modifiers, axis }, action)); + addIfNotExists(GlobalShortcut(PointerAxisShortcut{modifiers, axis}, action)); } 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) @@ -139,13 +140,13 @@ bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt) if (!keyQt && !mods) { return false; } - auto check = [this] (Qt::KeyboardModifiers mods, int keyQt) { + auto check = [this](Qt::KeyboardModifiers mods, int keyQt) { bool retVal = false; QMetaObject::invokeMethod(m_kglobalAccelInterface, - "checkKeyPressed", - Qt::DirectConnection, - Q_RETURN_ARG(bool, retVal), - Q_ARG(int, int(mods) | keyQt)); + "checkKeyPressed", + Qt::DirectConnection, + Q_RETURN_ARG(bool, retVal), + Q_ARG(int, int(mods) | keyQt)); return retVal; }; if (check(mods, keyQt)) { @@ -172,7 +173,7 @@ bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt) template bool match(QVector &shortcuts, Args... args) { - for (auto& sc : shortcuts) { + for (auto &sc : shortcuts) { if (std::holds_alternative(sc.shortcut())) { if (std::get(sc.shortcut()) == ShortcutKind{args...}) { sc.invoke(); @@ -183,7 +184,7 @@ bool match(QVector &shortcuts, Args... args) 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) { return match(m_shortcuts, mods, pointerButtons); diff --git a/src/globalshortcuts.h b/src/globalshortcuts.h index a0fb7b0069..fd3cdcf69d 100644 --- a/src/globalshortcuts.h +++ b/src/globalshortcuts.h @@ -20,7 +20,6 @@ class KGlobalAccelInterface; namespace KWin { - class GlobalShortcut; class SwipeGesture; class GestureRecognizer; @@ -92,7 +91,8 @@ public: void processSwipeCancel(); void processSwipeEnd(); - void setKGlobalAccelInterface(KGlobalAccelInterface *interface) { + void setKGlobalAccelInterface(KGlobalAccelInterface *interface) + { m_kglobalAccelInterface = interface; } @@ -110,7 +110,8 @@ private: struct KeyboardShortcut { QKeySequence sequence; - bool operator==(const KeyboardShortcut& rhs) const { + bool operator==(const KeyboardShortcut &rhs) const + { return sequence == rhs.sequence; } }; @@ -118,7 +119,8 @@ struct PointerButtonShortcut { Qt::KeyboardModifiers pointerModifiers; Qt::MouseButtons pointerButtons; - bool operator==(const PointerButtonShortcut& rhs) const { + bool operator==(const PointerButtonShortcut &rhs) const + { return pointerModifiers == rhs.pointerModifiers && pointerButtons == rhs.pointerButtons; } }; @@ -126,31 +128,32 @@ struct PointerAxisShortcut { Qt::KeyboardModifiers axisModifiers; PointerAxisDirection axisDirection; - bool operator==(const PointerAxisShortcut& rhs) const { + bool operator==(const PointerAxisShortcut &rhs) const + { return axisModifiers == rhs.axisModifiers && axisDirection == rhs.axisDirection; } }; struct FourFingerSwipeShortcut { SwipeDirection swipeDirection; - bool operator==(const FourFingerSwipeShortcut& rhs) const { + bool operator==(const FourFingerSwipeShortcut &rhs) const + { return swipeDirection == rhs.swipeDirection; } }; -using Shortcut = std::variant; +using Shortcut = std::variant; class GlobalShortcut { - public: - GlobalShortcut(Shortcut&& shortcut, QAction *action); + GlobalShortcut(Shortcut &&shortcut, QAction *action); ~GlobalShortcut(); void invoke() const; QAction *action() const; - const Shortcut& shortcut() const; - SwipeGesture* swipeGesture() const; + const Shortcut &shortcut() const; + SwipeGesture *swipeGesture() const; private: QSharedPointer m_gesture;