From 965b8b0fad617a6a1050ca850567726cb7197694 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 24 Dec 2021 14:22:21 +0800 Subject: [PATCH] Grab the server when warping the client pointer * src/xfns.c (Fx_set_mouse_absolute_pixel_position): * src/xterm.c (x_make_frame_invisible): Avoid race conditions where the client pointer is destroyed between when it is obtained and when XIWarpPointer is called. --- src/xfns.c | 2 ++ src/xterm.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/xfns.c b/src/xfns.c index 168debc8f33..b02996c0d3c 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -5648,6 +5648,7 @@ The coordinates X and Y are interpreted in pixels relative to a position if (FRAME_DISPLAY_INFO (f)->supports_xi2) { + XGrabServer (FRAME_X_DISPLAY (f)); if (XIGetClientPointer (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &deviceid)) { @@ -5655,6 +5656,7 @@ The coordinates X and Y are interpreted in pixels relative to a position DefaultRootWindow (FRAME_X_DISPLAY (f)), 0, 0, 0, 0, xval, yval); } + XUngrabServer (FRAME_X_DISPLAY (f)); } else #endif diff --git a/src/xterm.c b/src/xterm.c index aa88610961c..42001023b3b 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -13242,6 +13242,7 @@ frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) if (FRAME_DISPLAY_INFO (f)->supports_xi2) { + XGrabServer (FRAME_X_DISPLAY (f)); if (XIGetClientPointer (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &deviceid)) { @@ -13250,6 +13251,7 @@ frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) FRAME_X_WINDOW (f), 0, 0, 0, 0, pix_x, pix_y); } + XUngrabServer (FRAME_X_DISPLAY (f)); } else #endif -- 2.39.2