From 2601d06f5bd0030a81c101450472bf44fcc3c398 Mon Sep 17 00:00:00 2001 From: Aleix Pol Gonzalez Date: Tue, 25 Jun 2024 11:18:01 +0200 Subject: [PATCH] Fix !KWIN_BUILD_GLOBALSHORTCUTS builds Makes it so the GlobalShortucts object gets built and its KGlobalAccelD parts get disabled. Addresses the TODO in GestureHandler. Signed-off-by: Victoria Fischer --- src/CMakeLists.txt | 2 +- src/globalshortcuts.cpp | 12 ++++++++++++ src/globalshortcuts.h | 7 ++++++- src/input.h | 4 ---- src/scripting/gesturehandler.cpp | 4 ---- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2142e17bd4..ada9a6cc94 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -99,6 +99,7 @@ target_sources(kwin PRIVATE focuschain.cpp ftrace.cpp gestures.cpp + globalshortcuts.cpp hide_cursor_spy.cpp idle_inhibition.cpp idledetector.cpp @@ -258,7 +259,6 @@ target_link_libraries(kwin ) if (TARGET K::KGlobalAccelD) - target_sources(kwin PRIVATE globalshortcuts.cpp) target_link_libraries(kwin PRIVATE K::KGlobalAccelD) endif() diff --git a/src/globalshortcuts.cpp b/src/globalshortcuts.cpp index 2a65ae65f9..5682e2a797 100644 --- a/src/globalshortcuts.cpp +++ b/src/globalshortcuts.cpp @@ -16,8 +16,10 @@ #include "main.h" #include "utils/common.h" // KDE +#if KWIN_BUILD_GLOBALSHORTCUTS #include #include +#endif // Qt #include // system @@ -96,6 +98,7 @@ GlobalShortcutsManager::~GlobalShortcutsManager() void GlobalShortcutsManager::init() { +#if KWIN_BUILD_GLOBALSHORTCUTS if (kwinApp()->shouldUseWaylandForCompositing()) { qputenv("KGLOBALACCELD_PLATFORM", QByteArrayLiteral("org.kde.kwin")); m_kglobalAccel = std::make_unique(); @@ -106,6 +109,7 @@ void GlobalShortcutsManager::init() qCDebug(KWIN_CORE) << "KGlobalAcceld inited"; } } +#endif } void GlobalShortcutsManager::objectDeleted(QObject *object) @@ -189,6 +193,7 @@ void GlobalShortcutsManager::forceRegisterTouchscreenSwipe(SwipeDirection direct bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt) { +#if KWIN_BUILD_GLOBALSHORTCUTS if (m_kglobalAccelInterface) { auto check = [this](Qt::KeyboardModifiers mods, int keyQt) { bool retVal = false; @@ -217,17 +222,20 @@ bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, int keyQt) } } } +#endif return false; } bool GlobalShortcutsManager::processKeyRelease(Qt::KeyboardModifiers mods, int keyQt) { +#if KWIN_BUILD_GLOBALSHORTCUTS if (m_kglobalAccelInterface) { QMetaObject::invokeMethod(m_kglobalAccelInterface, "checkKeyReleased", Qt::DirectConnection, Q_ARG(int, int(mods) | keyQt)); } +#endif return false; } @@ -248,6 +256,7 @@ bool match(QList &shortcuts, Args... args) // TODO(C++20): use ranges for a nicer way of filtering by shortcut type bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Qt::MouseButtons pointerButtons) { +#if KWIN_BUILD_GLOBALSHORTCUTS // currently only used to better support modifier only shortcuts // modifier-only shortcuts are not triggered if a pointer button is pressed if (m_kglobalAccelInterface) { @@ -256,11 +265,13 @@ bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Q Qt::DirectConnection, Q_ARG(Qt::MouseButtons, pointerButtons)); } +#endif return match(m_shortcuts, mods, pointerButtons); } bool GlobalShortcutsManager::processAxis(Qt::KeyboardModifiers mods, PointerAxisDirection axis) { +#if KWIN_BUILD_GLOBALSHORTCUTS // currently only used to better support modifier only shortcuts // modifier-only shortcuts are not triggered if a pointer axis is used if (m_kglobalAccelInterface) { @@ -269,6 +280,7 @@ bool GlobalShortcutsManager::processAxis(Qt::KeyboardModifiers mods, PointerAxis Qt::DirectConnection, Q_ARG(int, axis)); } +#endif return match(m_shortcuts, mods, axis); } diff --git a/src/globalshortcuts.h b/src/globalshortcuts.h index 9fdea26473..13c4239cae 100644 --- a/src/globalshortcuts.h +++ b/src/globalshortcuts.h @@ -15,9 +15,10 @@ #include class QAction; +#if KWIN_BUILD_GLOBALSHORTCUTS class KGlobalAccelD; class KGlobalAccelInterface; - +#endif namespace KWin { class GlobalShortcut; @@ -109,10 +110,12 @@ public: void processPinchCancel(); void processPinchEnd(); +#if KWIN_BUILD_GLOBALSHORTCUTS void setKGlobalAccelInterface(KGlobalAccelInterface *interface) { m_kglobalAccelInterface = interface; } +#endif private: void objectDeleted(QObject *object); @@ -120,8 +123,10 @@ private: QList m_shortcuts; +#if KWIN_BUILD_GLOBALSHORTCUTS std::unique_ptr m_kglobalAccel; KGlobalAccelInterface *m_kglobalAccelInterface = nullptr; +#endif std::unique_ptr m_touchpadGestureRecognizer; std::unique_ptr m_touchscreenGestureRecognizer; }; diff --git a/src/input.h b/src/input.h index 9a8c123743..9494e3194c 100644 --- a/src/input.h +++ b/src/input.h @@ -166,12 +166,10 @@ public: void removeIdleInhibitor(Window *inhibitor); Window *findToplevel(const QPointF &pos); -#if KWIN_BUILD_GLOBALSHORTCUTS GlobalShortcutsManager *shortcuts() const { return m_shortcuts; } -#endif /** * Sends an event through all InputFilters. @@ -322,9 +320,7 @@ private: TouchInputRedirection *m_touch; QObject *m_lastInputDevice = nullptr; -#if KWIN_BUILD_GLOBALSHORTCUTS GlobalShortcutsManager *m_shortcuts; -#endif std::vector> m_inputBackends; QList m_inputDevices; diff --git a/src/scripting/gesturehandler.cpp b/src/scripting/gesturehandler.cpp index cba33d1edf..6dc018f3c0 100644 --- a/src/scripting/gesturehandler.cpp +++ b/src/scripting/gesturehandler.cpp @@ -37,7 +37,6 @@ void SwipeGestureHandler::componentComplete() connect(m_gesture.get(), &SwipeGesture::cancelled, this, &SwipeGestureHandler::cancelled); connect(m_gesture.get(), &SwipeGesture::progress, this, &SwipeGestureHandler::setProgress); -#if KWIN_BUILD_GLOBALSHORTCUTS // TODO: input()->shortcuts() should be built even when building without KGlobalAccelD switch (m_deviceType) { case Device::Touchpad: input()->shortcuts()->registerTouchpadSwipe(m_gesture.get()); @@ -46,7 +45,6 @@ void SwipeGestureHandler::componentComplete() input()->shortcuts()->registerTouchscreenSwipe(m_gesture.get()); break; } -#endif } SwipeGestureHandler::Direction SwipeGestureHandler::direction() const @@ -125,13 +123,11 @@ void PinchGestureHandler::componentComplete() connect(m_gesture.get(), &PinchGesture::cancelled, this, &PinchGestureHandler::cancelled); connect(m_gesture.get(), &PinchGesture::progress, this, &PinchGestureHandler::setProgress); -#if KWIN_BUILD_GLOBALSHORTCUTS // TODO: input()->shortcuts() should be built even when building without KGlobalAccelD switch (m_deviceType) { case Device::Touchpad: input()->shortcuts()->registerTouchpadPinch(m_gesture.get()); break; } -#endif } PinchGestureHandler::Direction PinchGestureHandler::direction() const