From b904fe5acd8398a27728913cc0cac35a04a9d74e Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Wed, 22 Jul 2015 20:32:11 +0200 Subject: [PATCH] Adapt X11 auto-type plugin to handle xcb instead of xlib events. --- src/autotype/CMakeLists.txt | 3 +- src/autotype/x11/AutoTypeX11.cpp | 47 +++++++++++++++++++++++--------- src/autotype/x11/CMakeLists.txt | 2 +- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/autotype/CMakeLists.txt b/src/autotype/CMakeLists.txt index fff368642..d332a2392 100644 --- a/src/autotype/CMakeLists.txt +++ b/src/autotype/CMakeLists.txt @@ -1,8 +1,9 @@ if(UNIX AND NOT APPLE) find_package(X11) find_package(Qt5X11Extras) + add_feature_info(libXi X11_Xi_FOUND "The X11 Xi Protocol library is required for auto-type") add_feature_info(libXtest X11_XTest_FOUND "The X11 XTEST Protocol library is required for auto-type") - add_feature_info(libXtest Qt5X11Extras_FOUND "The Qt5X11Extras library is required for auto-type") + add_feature_info(Qt5X11Extras Qt5X11Extras_FOUND "The Qt5X11Extras library is required for auto-type") if(X11_FOUND AND X11_XTest_FOUND AND Qt5X11Extras_FOUND) add_subdirectory(x11) diff --git a/src/autotype/x11/AutoTypeX11.cpp b/src/autotype/x11/AutoTypeX11.cpp index 646d6f0cd..71316e772 100644 --- a/src/autotype/x11/AutoTypeX11.cpp +++ b/src/autotype/x11/AutoTypeX11.cpp @@ -20,6 +20,7 @@ #include "KeySymMap.h" #include +#include bool AutoTypePlatformX11::m_catchXErrors = false; bool AutoTypePlatformX11::m_xErrorOccured = false; @@ -176,22 +177,42 @@ void AutoTypePlatformX11::unregisterGlobalShortcut(Qt::Key key, Qt::KeyboardModi int AutoTypePlatformX11::platformEventFilter(void* event) { - XEvent* xevent = static_cast(event); + xcb_generic_event_t* genericEvent = static_cast(event); + quint8 type = genericEvent->response_type & 0x7f; - if ((xevent->type == KeyPress || xevent->type == KeyRelease) - && m_currentGlobalKey - && xevent->xkey.keycode == m_currentGlobalKeycode - && (xevent->xkey.state & m_modifierMask) == m_currentGlobalNativeModifiers - && !QApplication::focusWidget() - && m_loaded) { - if (xevent->type == KeyPress) { - Q_EMIT globalShortcutTriggered(); + if (type == XCB_KEY_PRESS || type == XCB_KEY_RELEASE) { + xcb_key_press_event_t* keyPressEvent = static_cast(event); + if (keyPressEvent->detail == m_currentGlobalKeycode + && (keyPressEvent->state & m_modifierMask) == m_currentGlobalNativeModifiers + && !QApplication::focusWidget() + && m_loaded) { + if (type == XCB_KEY_PRESS) { + Q_EMIT globalShortcutTriggered(); + } + + return 1; } - return 1; } - if (xevent->type == MappingNotify && m_loaded) { - XRefreshKeyboardMapping(reinterpret_cast(xevent)); - updateKeymap(); + else if (type == XCB_MAPPING_NOTIFY) { + xcb_mapping_notify_event_t* mappingNotifyEvent = static_cast(event); + if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD + || mappingNotifyEvent->request == XCB_MAPPING_MODIFIER) + { + XMappingEvent xMappingEvent; + memset(&xMappingEvent, 0, sizeof(xMappingEvent)); + xMappingEvent.type = MappingNotify; + xMappingEvent.display = m_dpy; + if (mappingNotifyEvent->request == XCB_MAPPING_KEYBOARD) { + xMappingEvent.request = MappingKeyboard; + } + else { + xMappingEvent.request = MappingModifier; + } + xMappingEvent.first_keycode = mappingNotifyEvent->first_keycode; + xMappingEvent.count = mappingNotifyEvent->count; + XRefreshKeyboardMapping(&xMappingEvent); + updateKeymap(); + } } return -1; diff --git a/src/autotype/x11/CMakeLists.txt b/src/autotype/x11/CMakeLists.txt index 5361571af..cff19167e 100644 --- a/src/autotype/x11/CMakeLists.txt +++ b/src/autotype/x11/CMakeLists.txt @@ -5,7 +5,7 @@ set(autotype_X11_SOURCES ) add_library(keepassx-autotype-x11 MODULE ${autotype_X11_SOURCES}) -target_link_libraries(keepassx-autotype-x11 Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_X11_LIB} ${X11_XTest_LIB}) +target_link_libraries(keepassx-autotype-x11 Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB}) install(TARGETS keepassx-autotype-x11 BUNDLE DESTINATION . COMPONENT Runtime LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime)