diff --git a/src/backends/x11/windowed/CMakeLists.txt b/src/backends/x11/windowed/CMakeLists.txt index 2eefbd3f34..4dca1d274a 100644 --- a/src/backends/x11/windowed/CMakeLists.txt +++ b/src/backends/x11/windowed/CMakeLists.txt @@ -8,11 +8,10 @@ target_sources(kwin PRIVATE target_link_libraries(kwin PRIVATE - X11::XCB - X11::X11 + XCB::XCB XCB::DRI3 XCB::PRESENT ) -if (X11_Xi_FOUND) - target_link_libraries(kwin PRIVATE X11::Xi) +if (TARGET XCB::XINPUT) + target_link_libraries(kwin PRIVATE XCB::XINPUT) endif() diff --git a/src/backends/x11/windowed/x11_windowed_backend.cpp b/src/backends/x11/windowed/x11_windowed_backend.cpp index 0417fa9c90..4d717d0889 100644 --- a/src/backends/x11/windowed/x11_windowed_backend.cpp +++ b/src/backends/x11/windowed/x11_windowed_backend.cpp @@ -24,19 +24,12 @@ #include // xcb #include -#include #include #include -// X11 -#include -#include -#if HAVE_X11_XINPUT -#include -#include -#endif +#include +#include +#include // system -#include -#include #include #include #include @@ -178,15 +171,11 @@ X11WindowedBackend::~X11WindowedBackend() bool X11WindowedBackend::initialize() { - m_display = XOpenDisplay(m_options.display.toLatin1().constData()); - if (!m_display) { + m_connection = xcb_connect(m_options.display.toLatin1(), &m_screenNumber); + if (!m_connection) { return false; } - m_connection = XGetXCBConnection(m_display); - m_screenNumber = XDefaultScreen(m_display); - XSetEventQueueOwner(m_display, XCBOwnsEventQueue); - int screen = m_screenNumber; for (xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(m_connection)); it.rem; @@ -274,27 +263,27 @@ bool X11WindowedBackend::initialize() void X11WindowedBackend::initXInput() { #if HAVE_X11_XINPUT - int xi_opcode, event, error; - // init XInput extension - if (!XQueryExtension(m_display, "XInputExtension", &xi_opcode, &event, &error)) { + const xcb_query_extension_reply_t *xinputExtension = xcb_get_extension_data(m_connection, &xcb_input_id); + if (!xinputExtension || !xinputExtension->present) { qCDebug(KWIN_X11WINDOWED) << "XInputExtension not present"; return; } + m_xiOpcode = xinputExtension->major_opcode; // verify that the XInput extension is at at least version 2.0 - int major = 2, minor = 2; - int result = XIQueryVersion(m_display, &major, &minor); - if (result != Success) { + auto cookie = xcb_input_xi_query_version(m_connection, 2, 2); + UniqueCPtr reply(xcb_input_xi_query_version_reply( m_connection, cookie, nullptr)); + if (!reply) { qCDebug(KWIN_X11WINDOWED) << "Failed to init XInput 2.2, trying 2.0"; - minor = 0; - if (XIQueryVersion(m_display, &major, &minor) != Success) { + auto cookie = xcb_input_xi_query_version(m_connection, 2, 0); + reply.reset(xcb_input_xi_query_version_reply( m_connection, cookie, nullptr)); + if (!reply) { qCDebug(KWIN_X11WINDOWED) << "Failed to init XInput"; return; } } - m_xiOpcode = xi_opcode; - m_majorVersion = major; - m_minorVersion = minor; + m_majorVersion = reply->major_version; + m_minorVersion = reply->minor_version; m_hasXInput = m_majorVersion >= 2 && m_minorVersion >= 2; #endif } @@ -400,7 +389,7 @@ void X11WindowedBackend::createOutputs() #if HAVE_X11_XINPUT -static inline qreal fixed1616ToReal(FP1616 val) +static inline qreal fixed1616ToReal(xcb_input_fp1616_t val) { return (val)*1.0 / (1 << 16); } @@ -432,7 +421,7 @@ void X11WindowedBackend::handleEvent(xcb_generic_event_t *e) m_keySymbols = xcb_key_symbols_alloc(m_connection); } const xcb_keysym_t kc = xcb_key_symbols_get_keysym(m_keySymbols, event->detail, 0); - if (kc == XK_Control_R) { + if (kc == XKB_KEY_Control_R) { grabKeyboard(event->time); } Q_EMIT m_keyboardDevice->keyChanged(event->detail - 8, @@ -638,7 +627,7 @@ void X11WindowedBackend::updateSize(xcb_configure_notify_event_t *event) void X11WindowedBackend::handleXinputEvent(xcb_ge_generic_event_t *ge) { #if HAVE_X11_XINPUT - auto te = reinterpret_cast(ge); + auto te = reinterpret_cast(ge); const X11WindowedOutput *output = findOutput(te->event); if (!output) { return; @@ -647,24 +636,24 @@ void X11WindowedBackend::handleXinputEvent(xcb_ge_generic_event_t *ge) const QPointF position = output->mapFromGlobal(QPointF(fixed1616ToReal(te->root_x), fixed1616ToReal(te->root_y))); switch (ge->event_type) { - case XI_TouchBegin: { + case XCB_INPUT_TOUCH_BEGIN: { Q_EMIT m_touchDevice->touchDown(te->detail, position, std::chrono::milliseconds(te->time), m_touchDevice.get()); Q_EMIT m_touchDevice->touchFrame(m_touchDevice.get()); break; } - case XI_TouchUpdate: { + case XCB_INPUT_TOUCH_UPDATE: { Q_EMIT m_touchDevice->touchMotion(te->detail, position, std::chrono::milliseconds(te->time), m_touchDevice.get()); Q_EMIT m_touchDevice->touchFrame(m_touchDevice.get()); break; } - case XI_TouchEnd: { + case XCB_INPUT_TOUCH_END: { Q_EMIT m_touchDevice->touchUp(te->detail, std::chrono::milliseconds(te->time), m_touchDevice.get()); Q_EMIT m_touchDevice->touchFrame(m_touchDevice.get()); break; } - case XI_TouchOwnership: { - auto te = reinterpret_cast(ge); - XIAllowTouchEvents(m_display, te->deviceid, te->sourceid, te->touchid, XIAcceptTouch); + case XCB_INPUT_TOUCH_OWNERSHIP: { + auto *te = reinterpret_cast(ge); + xcb_input_xi_allow_events(m_connection, te->time, te->deviceid, XCB_INPUT_EVENT_MODE_ACCEPT_TOUCH, te->touchid, te->event); break; } } @@ -749,11 +738,6 @@ int X11WindowedBackend::screenNumer() const return m_screenNumber; } -::Display *X11WindowedBackend::display() const -{ - return m_display; -} - bool X11WindowedBackend::hasXInput() const { return m_hasXInput; diff --git a/src/backends/x11/windowed/x11_windowed_backend.h b/src/backends/x11/windowed/x11_windowed_backend.h index 10f84908f1..2d623cab91 100644 --- a/src/backends/x11/windowed/x11_windowed_backend.h +++ b/src/backends/x11/windowed/x11_windowed_backend.h @@ -22,8 +22,6 @@ #include #include -struct _XDisplay; -typedef struct _XDisplay Display; typedef struct _XCBKeySymbols xcb_key_symbols_t; class NETWinInfo; class QSocketNotifier; @@ -99,7 +97,6 @@ public: explicit X11WindowedBackend(const X11WindowedBackendOptions &options); ~X11WindowedBackend() override; - ::Display *display() const; xcb_connection_t *connection() const; xcb_screen_t *screen() const; int screenNumer() const; @@ -158,7 +155,6 @@ private: xcb_atom_t m_protocols = XCB_ATOM_NONE; xcb_atom_t m_deleteWindowProtocol = XCB_ATOM_NONE; - ::Display *m_display = nullptr; bool m_keyboardGrabbed = false; std::unique_ptr m_eventNotifier; diff --git a/src/backends/x11/windowed/x11_windowed_output.cpp b/src/backends/x11/windowed/x11_windowed_output.cpp index 11c1b1ecab..9469a6b49c 100644 --- a/src/backends/x11/windowed/x11_windowed_output.cpp +++ b/src/backends/x11/windowed/x11_windowed_output.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace KWin { @@ -281,18 +282,15 @@ void X11WindowedOutput::initXInputForWindow() return; } #if HAVE_X11_XINPUT - XIEventMask evmasks[1]; - unsigned char mask1[XIMaskLen(XI_LASTEVENT)]; - - memset(mask1, 0, sizeof(mask1)); - XISetMask(mask1, XI_TouchBegin); - XISetMask(mask1, XI_TouchUpdate); - XISetMask(mask1, XI_TouchOwnership); - XISetMask(mask1, XI_TouchEnd); - evmasks[0].deviceid = XIAllMasterDevices; - evmasks[0].mask_len = sizeof(mask1); - evmasks[0].mask = mask1; - XISelectEvents(m_backend->display(), m_window, evmasks, 1); + struct + { + xcb_input_event_mask_t head; + xcb_input_xi_event_mask_t mask; + } mask; + mask.head.deviceid = XCB_INPUT_DEVICE_ALL_MASTER; + mask.head.mask_len = 1; + mask.mask = static_cast(XCB_INPUT_XI_EVENT_MASK_RAW_TOUCH_BEGIN | XCB_INPUT_XI_EVENT_MASK_RAW_TOUCH_UPDATE | XCB_INPUT_XI_EVENT_MASK_TOUCH_END | XCB_INPUT_XI_EVENT_MASK_TOUCH_OWNERSHIP); + xcb_input_xi_select_events(m_backend->connection(), m_window, 1, &mask.head); #endif }