From f703232b7ff3453640179c6c1e9415e9ff1af987 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 22 Dec 2021 11:13:23 +0800 Subject: [PATCH] Use XI2 calls to warp the client pointer * src/xfns.c (Fx_set_mouse_absolute_pixel_position): * src/xterm.c (frame_set_mouse_pixel_position): Replace calls to XWarpPointer with calls to XIWarpPointer with the client pointer explictly specified. This avoids the odd situation where the client pointer of the root window is not the client pointer of the frame. --- src/xfns.c | 19 +++++++++++++++++-- src/xterm.c | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/xfns.c b/src/xfns.c index 30ed358fb28..168debc8f33 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -5643,8 +5643,23 @@ The coordinates X and Y are interpreted in pixels relative to a position int yval = check_integer_range (y, INT_MIN, INT_MAX); block_input (); - XWarpPointer (FRAME_X_DISPLAY (f), None, DefaultRootWindow (FRAME_X_DISPLAY (f)), - 0, 0, 0, 0, xval, yval); +#ifdef HAVE_XINPUT2 + int deviceid; + + if (FRAME_DISPLAY_INFO (f)->supports_xi2) + { + if (XIGetClientPointer (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + &deviceid)) + { + XIWarpPointer (FRAME_X_DISPLAY (f), deviceid, None, + DefaultRootWindow (FRAME_X_DISPLAY (f)), + 0, 0, 0, 0, xval, yval); + } + } + else +#endif + XWarpPointer (FRAME_X_DISPLAY (f), None, DefaultRootWindow (FRAME_X_DISPLAY (f)), + 0, 0, 0, 0, xval, yval); unblock_input (); return Qnil; diff --git a/src/xterm.c b/src/xterm.c index 33396cc9ab4..070ee7d671e 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -13223,9 +13223,24 @@ void frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) { block_input (); +#ifdef HAVE_XINPUT2 + int deviceid; - XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), - 0, 0, 0, 0, pix_x, pix_y); + if (FRAME_DISPLAY_INFO (f)->supports_xi2) + { + if (XIGetClientPointer (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + &deviceid)) + { + XIWarpPointer (FRAME_X_DISPLAY (f), + deviceid, None, + FRAME_X_WINDOW (f), + 0, 0, 0, 0, pix_x, pix_y); + } + } + else +#endif + XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), + 0, 0, 0, 0, pix_x, pix_y); unblock_input (); } -- 2.39.2