From 7078af622b05971496bf07712775d19b3980a628 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 24 Dec 2021 11:10:09 +0800 Subject: [PATCH] Fix menu grabs on XI2 Motif builds * src/xmenu.c (x_activate_menubar) [USE_MOTIF]: Clear XI grab. * src/xterm.c (xi_grab_or_ungrab_device) [USE_MOTIF]: Always ungrab if a popup is active. --- src/xmenu.c | 16 ++++++++++++++++ src/xterm.c | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/xmenu.c b/src/xmenu.c index 07255911f97..4d969fa25f8 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -51,6 +51,10 @@ along with GNU Emacs. If not, see . */ #include "msdos.h" #endif +#ifdef HAVE_XINPUT2 +#include +#endif + #ifdef HAVE_X_WINDOWS /* This may include sys/types.h, and that somehow loses if this is not done before the other system files. */ @@ -444,6 +448,18 @@ x_activate_menubar (struct frame *f) XPutBackEvent (f->output_data.x->display_info->display, f->output_data.x->saved_menu_event); #else +#ifdef USE_MOTIF + struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); + /* Clear the XI2 grab so Motif can set a core grab. Otherwise some + versions of Motif will emit a warning and hang. */ + + if (dpyinfo->num_devices) + { + for (int i = 0; i < dpyinfo->num_devices; ++i) + XIUngrabDevice (dpyinfo->display, dpyinfo->devices[i].device_id, + CurrentTime); + } +#endif XtDispatchEvent (f->output_data.x->saved_menu_event); #endif unblock_input (); diff --git a/src/xterm.c b/src/xterm.c index b8cf637f436..aa88610961c 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -637,7 +637,11 @@ xi_grab_or_ungrab_device (struct xi_device_t *device, XISetMask (m, XI_Enter); XISetMask (m, XI_Leave); - if (device->grab) + if (device->grab +#ifdef USE_MOTIF + && !popup_activated () +#endif + ) { XIGrabDevice (dpyinfo->display, device->device_id, window, CurrentTime, None, GrabModeAsync, -- 2.39.2