From 4f9af2eb779ac540b8ca557acdb2182c4b036f27 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 17 Feb 2022 10:25:37 +0600 Subject: [PATCH] Xi2: Warp mouse cursor only on Xi2 thread --- src/qt/xinput2_mouse.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/qt/xinput2_mouse.cpp b/src/qt/xinput2_mouse.cpp index ff67b6a2c..b8af6f309 100644 --- a/src/qt/xinput2_mouse.cpp +++ b/src/qt/xinput2_mouse.cpp @@ -120,6 +120,14 @@ void xinput2_proc() prev_rel_coords[0] = relative_coords[0]; prev_rel_coords[1] = relative_coords[1]; prev_time = rawev->time; + if (!mouse_capture) break; + XWindowAttributes winattrib{}; + if (XGetWindowAttributes(disp, main_window->winId(), &winattrib)) { + auto globalPoint = main_window->mapToGlobal(QPoint(main_window->width() / 2, main_window->height() / 2)); + XWarpPointer(disp, XRootWindow(disp, XScreenNumberOfScreen(winattrib.screen)), XRootWindow(disp, XScreenNumberOfScreen(winattrib.screen)), 0, 0, 0, 0, globalPoint.x(), globalPoint.y()); + XFlush(disp); + } + } case XI_Motion: { if (XKeysymToKeycode(disp, XK_Home) == 69) { @@ -175,13 +183,6 @@ void xinput2_poll() { mouse_x = xi2_mouse_x; mouse_y = xi2_mouse_y; - XWindowAttributes winattrib{}; - if (XGetWindowAttributes(disp, main_window->winId(), &winattrib)) - { - auto globalPoint = main_window->mapToGlobal(QPoint(main_window->width() / 2, main_window->height() / 2)); - XWarpPointer(disp, XRootWindow(disp, XScreenNumberOfScreen(winattrib.screen)), XRootWindow(disp, XScreenNumberOfScreen(winattrib.screen)), 0, 0, 0, 0, globalPoint.x(), globalPoint.y()); - XFlush(disp); - } } xi2_mouse_x = 0; xi2_mouse_y = 0;