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 <victoria.fischer@mbition.io>
This commit is contained in:
Aleix Pol Gonzalez 2024-06-25 11:18:01 +02:00
parent a7470f4b4a
commit 2601d06f5b
5 changed files with 19 additions and 10 deletions

View file

@ -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()

View file

@ -16,8 +16,10 @@
#include "main.h"
#include "utils/common.h"
// KDE
#if KWIN_BUILD_GLOBALSHORTCUTS
#include <kglobalaccel_interface.h>
#include <kglobalacceld.h>
#endif
// Qt
#include <QAction>
// 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<KGlobalAccelD>();
@ -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<GlobalShortcut> &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<PointerButtonShortcut>(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<PointerAxisShortcut>(m_shortcuts, mods, axis);
}

View file

@ -15,9 +15,10 @@
#include <memory>
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<GlobalShortcut> m_shortcuts;
#if KWIN_BUILD_GLOBALSHORTCUTS
std::unique_ptr<KGlobalAccelD> m_kglobalAccel;
KGlobalAccelInterface *m_kglobalAccelInterface = nullptr;
#endif
std::unique_ptr<GestureRecognizer> m_touchpadGestureRecognizer;
std::unique_ptr<GestureRecognizer> m_touchscreenGestureRecognizer;
};

View file

@ -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<std::unique_ptr<InputBackend>> m_inputBackends;
QList<InputDevice *> m_inputDevices;

View file

@ -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