Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make X11Extras conditional on autotype again #7635

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion src/gui/osutils/nixutils/NixUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
#include <QStandardPaths>
#include <QStyle>
#include <QTextStream>
#include <QX11Info>

#include <qpa/qplatformnativeinterface.h>

#include "X11Funcs.h"
#include <X11/XKBlib.h>
#include <xcb/xproto.h>

#ifdef WITH_XC_AUTOTYPE
#include <QX11Info>

namespace
{
Display* dpy;
Expand All @@ -44,6 +46,7 @@ namespace
return 1;
}
} // namespace
#endif

QPointer<NixUtils> NixUtils::m_instance = nullptr;

Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -263,13 +276,15 @@ 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);
XUngrabKey(dpy, gs->nativeKeyCode, gs->nativeModifiers | LockMask, rootWindow);
XUngrabKey(dpy, gs->nativeKeyCode, gs->nativeModifiers | Mod2Mask | LockMask, rootWindow);

m_globalShortcuts.remove(name);
#endif
return true;
}

Expand Down