From d5c87baa3860855208b4f2c198961655474f7992 Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Thu, 24 Mar 2022 12:08:59 -0400 Subject: [PATCH] Make X11Extras conditional on autotype again After 404fd941e8e5 ("Move global shortcut handling into OSUtils (#5566)"), X11Extras was made mandatory, even though it is only used for autotype. Make it conditional on autotype again. --- CMakeLists.txt | 5 ++++- src/CMakeLists.txt | 5 ++++- src/gui/osutils/nixutils/NixUtils.cpp | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe436d351a..3a5dfc789f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -440,7 +440,10 @@ include(CLangFormat) set(QT_COMPONENTS Core Network Concurrent Gui Svg Widgets Test LinguistTools) if(UNIX AND NOT APPLE) - find_package(Qt5 COMPONENTS ${QT_COMPONENTS} DBus X11Extras REQUIRED) + find_package(Qt5 COMPONENTS ${QT_COMPONENTS} DBus REQUIRED) + if(WITH_XC_AUTOTYPE) + find_package(Qt5 COMPONENTS ${QT_COMPONENTS} X11Extras REQUIRED) + endif() elseif(APPLE) find_package(Qt5 COMPONENTS ${QT_COMPONENTS} REQUIRED HINTS /usr/local/opt/qt/lib/cmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 38d162ec85..8c6f635e55 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -360,7 +360,10 @@ if(HAIKU) target_link_libraries(keepassx_core network) endif() if(UNIX AND NOT APPLE) - target_link_libraries(keepassx_core Qt5::DBus Qt5::X11Extras X11) + target_link_libraries(keepassx_core Qt5::DBus X11) + if(WITH_XC_AUTOTYPE) + target_link_libraries(keepassx_core Qt5::X11Extras) + endif() include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) endif() if(WIN32) diff --git a/src/gui/osutils/nixutils/NixUtils.cpp b/src/gui/osutils/nixutils/NixUtils.cpp index d0fa84f3c7..a522253037 100644 --- a/src/gui/osutils/nixutils/NixUtils.cpp +++ b/src/gui/osutils/nixutils/NixUtils.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include @@ -32,6 +31,9 @@ #include #include +#ifdef WITH_XC_AUTOTYPE +#include + namespace { Display* dpy; @@ -44,6 +46,7 @@ namespace return 1; } } // namespace +#endif QPointer NixUtils::m_instance = nullptr; @@ -59,8 +62,10 @@ NixUtils* NixUtils::instance() NixUtils::NixUtils(QObject* parent) : OSUtilsBase(parent) { +#ifdef WITH_XC_AUTOTYPE dpy = QX11Info::display(); rootWindow = QX11Info::appRootWindow(); +#endif // notify about system color scheme changes QDBusConnection sessionBus = QDBusConnection::sessionBus(); @@ -214,6 +219,7 @@ bool NixUtils::triggerGlobalShortcut(uint keycode, uint modifiers) bool NixUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::KeyboardModifiers modifiers, QString* error) { +#ifdef WITH_XC_AUTOTYPE auto keycode = XKeysymToKeycode(dpy, qcharToNativeKeyCode(key)); auto modifierscode = qtToNativeModifiers(modifiers); @@ -255,6 +261,13 @@ bool NixUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::Keyb gs->nativeModifiers = modifierscode; m_globalShortcuts.insert(name, gs); return true; +#else + (void)name; + (void)key; + (void)modifiers; + *error = tr("Auto-Type disabled at compile time"); + return false; +#endif } bool NixUtils::unregisterGlobalShortcut(const QString& name) @@ -263,6 +276,7 @@ bool NixUtils::unregisterGlobalShortcut(const QString& name) return false; } +#ifdef WITH_XC_AUTOTYPE auto gs = m_globalShortcuts.value(name); XUngrabKey(dpy, gs->nativeKeyCode, gs->nativeModifiers, rootWindow); XUngrabKey(dpy, gs->nativeKeyCode, gs->nativeModifiers | Mod2Mask, rootWindow); @@ -270,6 +284,7 @@ bool NixUtils::unregisterGlobalShortcut(const QString& name) XUngrabKey(dpy, gs->nativeKeyCode, gs->nativeModifiers | Mod2Mask | LockMask, rootWindow); m_globalShortcuts.remove(name); +#endif return true; }