From a218921172438a904168cae58142a42ab0d0dd0b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 4 Jul 2022 21:03:02 +0800 Subject: [PATCH] Avoid code duplication converting XI event state in toolkit menu code * src/xmenu.c (x_menu_translate_generic_event): (popup_get_selection): Use `xi_convert_event_state' instead. * src/xterm.c (xi_convert_event_state): Export on non-GTK builds. * src/xterm.h: Update prototypes. --- src/xmenu.c | 26 +++----------------------- src/xterm.c | 6 +++++- src/xterm.h | 3 +++ 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/xmenu.c b/src/xmenu.c index 7134bf22c83..c006d2bfe21 100644 --- a/src/xmenu.c +++ b/src/xmenu.c @@ -261,20 +261,10 @@ x_menu_translate_generic_event (XEvent *event) copy.xbutton.y = lrint (xev->event_y); copy.xbutton.x_root = lrint (xev->root_x); copy.xbutton.y_root = lrint (xev->root_y); - copy.xbutton.state = xev->mods.effective; + copy.xbutton.state = xi_convert_event_state (xev); copy.xbutton.button = xev->detail; copy.xbutton.same_screen = True; - if (xev->buttons.mask_len) - { - if (XIMaskIsSet (xev->buttons.mask, 1)) - copy.xbutton.state |= Button1Mask; - if (XIMaskIsSet (xev->buttons.mask, 2)) - copy.xbutton.state |= Button2Mask; - if (XIMaskIsSet (xev->buttons.mask, 3)) - copy.xbutton.state |= Button3Mask; - } - XPutBackEvent (dpyinfo->display, ©); break; @@ -397,7 +387,7 @@ popup_get_selection (XEvent *initial_event, struct x_display_info *dpyinfo, copy.xbutton.y = lrint (xev->event_y); copy.xbutton.x_root = lrint (xev->root_x); copy.xbutton.y_root = lrint (xev->root_y); - copy.xbutton.state = xev->mods.effective; + copy.xbutton.state = xi_convert_event_state (xev); copy.xbutton.button = xev->detail; copy.xbutton.same_screen = True; @@ -412,16 +402,6 @@ popup_get_selection (XEvent *initial_event, struct x_display_info *dpyinfo, copy.xbutton.state = 0; #endif - if (xev->buttons.mask_len) - { - if (XIMaskIsSet (xev->buttons.mask, 1)) - copy.xbutton.state |= Button1Mask; - if (XIMaskIsSet (xev->buttons.mask, 2)) - copy.xbutton.state |= Button2Mask; - if (XIMaskIsSet (xev->buttons.mask, 3)) - copy.xbutton.state |= Button3Mask; - } - break; } case XI_KeyPress: @@ -442,7 +422,7 @@ popup_get_selection (XEvent *initial_event, struct x_display_info *dpyinfo, copy.xkey.y = lrint (xev->event_y); copy.xkey.x_root = lrint (xev->root_x); copy.xkey.y_root = lrint (xev->root_y); - copy.xkey.state = xev->mods.effective; + copy.xkey.state = xi_convert_event_state (xev); copy.xkey.keycode = xev->detail; copy.xkey.same_screen = True; diff --git a/src/xterm.c b/src/xterm.c index e242768c95d..82a20ad1a97 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -5077,7 +5077,11 @@ xi_convert_button_state (XIButtonState *in, unsigned int *out) } /* Return the modifier state in XEV as a standard X modifier mask. */ -static unsigned int + +#ifdef USE_GTK +static +#endif +unsigned int xi_convert_event_state (XIDeviceEvent *xev) { unsigned int mods, buttons; diff --git a/src/xterm.h b/src/xterm.h index 26d6e4b3d03..b0f9200eeaf 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1689,6 +1689,9 @@ extern int x_error_message_count; #ifdef HAVE_XINPUT2 extern struct xi_device_t *xi_device_from_id (struct x_display_info *, int); extern bool xi_frame_selected_for (struct frame *, unsigned long); +#ifndef USE_GTK +extern unsigned int xi_convert_event_state (XIDeviceEvent *); +#endif #endif extern void mark_xterm (void); -- 2.39.5