From: Po Lu Date: Tue, 16 Aug 2022 13:11:03 +0000 (+0800) Subject: Fix XInput hierarchy events not being delivered in daemon mode X-Git-Tag: emacs-29.0.90~1447^2~118 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b4879603fd8f9c8e82e30c5fbb65fa63d8166ee4;p=emacs.git Fix XInput hierarchy events not being delivered in daemon mode * src/xfns.c (setup_xi_event_mask): Stop selecting for device hierarchy events. * src/xterm.c (xi_select_hierarchy_events, x_term_init): Select those here instead, on the default root window. --- diff --git a/src/xfns.c b/src/xfns.c index 6ed93ee42ca..a275e3e11a8 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -3773,14 +3773,11 @@ setup_xi_event_mask (struct frame *f) memset (m, 0, l); #endif - mask.deviceid = XIAllDevices; - - XISetMask (m, XI_PropertyEvent); - XISetMask (m, XI_HierarchyChanged); - XISetMask (m, XI_DeviceChanged); #ifdef HAVE_XINPUT2_2 if (FRAME_DISPLAY_INFO (f)->xi2_version >= 2) { + mask.deviceid = XIAllDevices; + XISetMask (m, XI_TouchBegin); XISetMask (m, XI_TouchUpdate); XISetMask (m, XI_TouchEnd); @@ -3792,11 +3789,12 @@ setup_xi_event_mask (struct frame *f) XISetMask (m, XI_GesturePinchEnd); } #endif + + XISelectEvents (FRAME_X_DISPLAY (f), + FRAME_X_WINDOW (f), + &mask, 1); } #endif - XISelectEvents (FRAME_X_DISPLAY (f), - FRAME_X_WINDOW (f), - &mask, 1); #ifndef HAVE_XINPUT2_1 FRAME_X_OUTPUT (f)->xi_masks = selected; diff --git a/src/xterm.c b/src/xterm.c index ee0035234b5..7487450d649 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -27634,6 +27634,33 @@ my_log_handler (const gchar *log_domain, GLogLevelFlags log_level, connection established. */ static unsigned x_display_id; +#if defined HAVE_XINPUT2 && !defined HAVE_GTK3 + +/* Select for device change events on the root window of DPYINFO. + These include device change and hierarchy change notifications. */ + +static void +xi_select_hierarchy_events (struct x_display_info *dpyinfo) +{ + XIEventMask mask; + ptrdiff_t l; + unsigned char *m; + + l = XIMaskLen (XI_LASTEVENT); + mask.mask = m = alloca (l); + memset (m, 0, l); + mask.mask_len = l; + + XISetMask (m, XI_PropertyEvent); + XISetMask (m, XI_HierarchyChanged); + XISetMask (m, XI_DeviceChanged); + + XISelectEvents (dpyinfo->display, dpyinfo->root_window, + &mask, 1); +} + +#endif + /* Open a connection to X display DISPLAY_NAME, and return the structure that describes the open display. If we cannot contact the display, return null. */ @@ -28263,6 +28290,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) if (rc == Success) { dpyinfo->supports_xi2 = true; +#ifndef HAVE_GTK3 + /* Select for hierarchy events on the root window. GTK 3.x + does this itself. */ + xi_select_hierarchy_events (dpyinfo); +#endif + x_cache_xi_devices (dpyinfo); } }