]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid code duplication converting XI event state in toolkit menu code
authorPo Lu <luangruo@yahoo.com>
Mon, 4 Jul 2022 13:03:02 +0000 (21:03 +0800)
committerPo Lu <luangruo@yahoo.com>
Mon, 4 Jul 2022 13:13:29 +0000 (21:13 +0800)
* 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
src/xterm.c
src/xterm.h

index 7134bf22c8352bd449385312848335db5dd49fbd..c006d2bfe211dffd28ecfd205392f9111fecfb79 100644 (file)
@@ -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, &copy);
 
              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;
 
index e242768c95dfe54861b1bf3c2d87da1fbec573e2..82a20ad1a97805cf1c7463ac13dc59ef2c0c307e 100644 (file)
@@ -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;
index 26d6e4b3d03a22c94797f5e43707051843d8669c..b0f9200eeaf4181a6acbff4105348f4b81b3cff4 100644 (file)
@@ -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);