12#include <config-kwin.h>
19#include <kglobalaccel_interface.h>
20#include <kglobalacceld.h>
33 if (
auto swipeGesture = std::get_if<RealtimeFeedbackSwipeShortcut>(&sc)) {
34 m_swipeGesture = std::make_unique<SwipeGesture>();
36 m_swipeGesture->setMinimumDelta(QPointF(200, 200));
37 m_swipeGesture->setMaximumFingerCount(
swipeGesture->fingerCount);
38 m_swipeGesture->setMinimumFingerCount(
swipeGesture->fingerCount);
39 QObject::connect(m_swipeGesture.get(), &
SwipeGesture::triggered, m_action, &QAction::trigger, Qt::QueuedConnection);
40 QObject::connect(m_swipeGesture.get(), &
SwipeGesture::cancelled, m_action, &QAction::trigger, Qt::QueuedConnection);
44 }
else if (
auto pinchGesture = std::get_if<RealtimeFeedbackPinchShortcut>(&sc)) {
45 m_pinchGesture = std::make_unique<PinchGesture>();
47 m_pinchGesture->setMaximumFingerCount(
pinchGesture->fingerCount);
48 m_pinchGesture->setMinimumFingerCount(
pinchGesture->fingerCount);
49 QObject::connect(m_pinchGesture.get(), &
PinchGesture::triggered, m_action, &QAction::trigger, Qt::QueuedConnection);
50 QObject::connect(m_pinchGesture.get(), &
PinchGesture::cancelled, m_action, &QAction::trigger, Qt::QueuedConnection);
68 QMetaObject::invokeMethod(m_action, &QAction::trigger, Qt::QueuedConnection);
78 return m_swipeGesture.get();
83 return m_pinchGesture.get();
99 if (kwinApp()->shouldUseWaylandForCompositing()) {
100 qputenv(
"KGLOBALACCELD_PLATFORM", QByteArrayLiteral(
"org.kde.kwin"));
101 m_kglobalAccel = std::make_unique<KGlobalAccelD>();
102 if (!m_kglobalAccel->init()) {
103 qCDebug(KWIN_CORE) <<
"Init of kglobalaccel failed";
104 m_kglobalAccel.reset();
106 qCDebug(KWIN_CORE) <<
"KGlobalAcceld inited";
111void GlobalShortcutsManager::objectDeleted(QObject *
object)
113 auto it = m_shortcuts.begin();
114 while (it != m_shortcuts.end()) {
115 if (it->action() ==
object) {
116 it = m_shortcuts.erase(it);
123bool GlobalShortcutsManager::add(GlobalShortcut sc,
DeviceType device)
125 const auto &recognizer = device ==
DeviceType::Touchpad ? m_touchpadGestureRecognizer : m_touchscreenGestureRecognizer;
126 if (std::holds_alternative<RealtimeFeedbackSwipeShortcut>(sc.shortcut())) {
127 recognizer->registerSwipeGesture(sc.swipeGesture());
128 }
else if (std::holds_alternative<RealtimeFeedbackPinchShortcut>(sc.shortcut())) {
129 recognizer->registerPinchGesture(sc.pinchGesture());
131 connect(sc.action(), &QAction::destroyed,
this, &GlobalShortcutsManager::objectDeleted);
132 m_shortcuts.push_back(std::move(sc));
164 const auto it = std::find_if(m_shortcuts.begin(), m_shortcuts.end(), [&shortcut](
const auto &s) {
165 return shortcut.shortcut() == s.shortcut();
167 if (it != m_shortcuts.end()) {
168 m_shortcuts.erase(it);
170 m_touchscreenGestureRecognizer->registerSwipeGesture(shortcut.swipeGesture());
171 connect(shortcut.action(), &QAction::destroyed,
this, &GlobalShortcutsManager::objectDeleted);
172 m_shortcuts.push_back(std::move(shortcut));
177 if (m_kglobalAccelInterface) {
178 if (!keyQt && !mods) {
181 auto check = [
this](Qt::KeyboardModifiers mods,
int keyQt) {
183 QMetaObject::invokeMethod(m_kglobalAccelInterface,
185 Qt::DirectConnection,
186 Q_RETURN_ARG(
bool, retVal),
187 Q_ARG(
int,
int(mods) | keyQt));
190 if (check(mods, keyQt)) {
192 }
else if (keyQt == Qt::Key_Backtab) {
200 if (check(mods | Qt::ShiftModifier, keyQt)) {
203 if (check(mods | Qt::ShiftModifier, Qt::Key_Tab)) {
213 if (m_kglobalAccelInterface) {
214 QMetaObject::invokeMethod(m_kglobalAccelInterface,
216 Qt::DirectConnection,
217 Q_ARG(
int,
int(mods) | keyQt));
222template<
typename ShortcutKind,
typename... Args>
223bool match(QList<GlobalShortcut> &shortcuts, Args... args)
225 for (
auto &sc : shortcuts) {
226 if (std::holds_alternative<ShortcutKind>(sc.shortcut())) {
227 if (std::get<ShortcutKind>(sc.shortcut()) == ShortcutKind{args...}) {
239 return match<PointerButtonShortcut>(m_shortcuts, mods, pointerButtons);
244 return match<PointerAxisShortcut>(m_shortcuts, mods, axis);
250 m_touchpadGestureRecognizer->startSwipeGesture(fingerCount);
252 m_touchscreenGestureRecognizer->startSwipeGesture(fingerCount);
259 m_touchpadGestureRecognizer->updateSwipeGesture(delta);
261 m_touchscreenGestureRecognizer->updateSwipeGesture(delta);
268 m_touchpadGestureRecognizer->cancelSwipeGesture();
270 m_touchscreenGestureRecognizer->cancelSwipeGesture();
277 m_touchpadGestureRecognizer->endSwipeGesture();
279 m_touchscreenGestureRecognizer->endSwipeGesture();
286 m_touchpadGestureRecognizer->startPinchGesture(fingerCount);
291 m_touchpadGestureRecognizer->updatePinchGesture(scale, angleDelta, delta);
296 m_touchpadGestureRecognizer->cancelPinchGesture();
301 m_touchpadGestureRecognizer->endPinchGesture();
306#include "moc_globalshortcuts.cpp"
const Shortcut & shortcut() const
GlobalShortcut(Shortcut &&shortcut, QAction *action)
PinchGesture * pinchGesture() const
SwipeGesture * swipeGesture() const
void registerTouchpadPinch(PinchDirection direction, uint32_t fingerCount, QAction *action, std::function< void(qreal)> progressCallback={})
void processSwipeEnd(DeviceType device)
void processPinchUpdate(qreal scale, qreal angleDelta, const QPointF &delta)
GlobalShortcutsManager(QObject *parent=nullptr)
void processSwipeUpdate(DeviceType device, const QPointF &delta)
void processPinchCancel()
void registerPointerShortcut(QAction *action, Qt::KeyboardModifiers modifiers, Qt::MouseButtons pointerButtons)
Registers an internal global pointer shortcut.
void processSwipeCancel(DeviceType device)
bool processKeyRelease(Qt::KeyboardModifiers modifiers, int keyQt)
void forceRegisterTouchscreenSwipe(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function< void(qreal)> progressCallback={})
bool processKey(Qt::KeyboardModifiers modifiers, int keyQt)
Processes a key event to decide whether a shortcut needs to be triggered.
~GlobalShortcutsManager() override
void registerTouchpadSwipe(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function< void(qreal)> progressCallback={})
bool processAxis(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis)
Processes a pointer axis event to decide whether a shortcut needs to be triggered.
bool processPointerPressed(Qt::KeyboardModifiers modifiers, Qt::MouseButtons pointerButtons)
void processPinchStart(uint fingerCount)
void processSwipeStart(DeviceType device, uint fingerCount)
void registerTouchscreenSwipe(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function< void(qreal)> progressCallback={})
void registerAxisShortcut(QAction *action, Qt::KeyboardModifiers modifiers, PointerAxisDirection axis)
Registers an internal global axis shortcut.
PinchDirection direction() const
SwipeDirection direction() const
std::variant< KeyboardShortcut, PointerButtonShortcut, PointerAxisShortcut, RealtimeFeedbackSwipeShortcut, RealtimeFeedbackPinchShortcut > Shortcut
PointerAxisDirection
The direction in which a pointer axis is moved.
SwipeDirection
Directions for swipe gestures.
bool match(QList< GlobalShortcut > &shortcuts, Args... args)