From 12e601f9811479d657f6abd8f63099dc73dda471 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 8 Nov 2022 19:59:47 +0800 Subject: [PATCH] Clean up some duplicate event group conversion code * src/xterm.c (xi_convert_event_keyboard_state): New function. Move keyboard event state over. (handle_one_xevent): Use it where necessary. --- src/xterm.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/xterm.c b/src/xterm.c index 84438e85909..861cf5da549 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -5245,7 +5245,9 @@ xi_convert_button_state (XIButtonState *in, unsigned int *out) } } -/* Return the modifier state in XEV as a standard X modifier mask. */ +/* Return the modifier state in XEV as a standard X modifier mask. + This should be used for non-keyboard events, where the group does + not matter. */ #ifdef USE_GTK static @@ -5263,6 +5265,17 @@ xi_convert_event_state (XIDeviceEvent *xev) return mods | buttons; } +/* Like the above. However, buttons are not converted, while the + group is. This should be used for key events being passed to the + likes of input methods and Xt. */ + +static unsigned int +xi_convert_event_keyboard_state (XIDeviceEvent *xev) +{ + return ((xev->mods.effective & ~(1 << 13 | 1 << 14)) + | (xev->group.effective << 13)); +} + /* Free all XI2 devices on DPYINFO. */ static void x_free_xi_devices (struct x_display_info *dpyinfo) @@ -23092,8 +23105,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, copy.xkey.root = xev->root; copy.xkey.subwindow = xev->child; copy.xkey.time = xev->time; - copy.xkey.state = ((xev->mods.effective & ~(1 << 13 | 1 << 14)) - | (xev->group.effective << 13)); + copy.xkey.state = xi_convert_event_keyboard_state (xev); xi_convert_button_state (&xev->buttons, ©.xkey.state); copy.xkey.x = lrint (xev->event_x); @@ -23149,8 +23161,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, xkey.root = xev->root; xkey.subwindow = xev->child; xkey.time = xev->time; - xkey.state = ((xev->mods.effective & ~(1 << 13 | 1 << 14)) - | (xev->group.effective << 13)); + xkey.state = xi_convert_event_keyboard_state (xev); xkey.x = lrint (xev->event_x); xkey.y = lrint (xev->event_y); @@ -23568,8 +23579,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, xkey.root = xev->root; xkey.subwindow = xev->child; xkey.time = xev->time; - xkey.state = ((xev->mods.effective & ~(1 << 13 | 1 << 14)) - | (xev->group.effective << 13)); + xkey.state = xi_convert_event_keyboard_state (xev); xkey.x = lrint (xev->event_x); xkey.y = lrint (xev->event_y); xkey.x_root = lrint (xev->root_x); -- 2.39.2