aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-06-24 09:49:14 +0800
committerPo Lu2022-06-24 09:49:14 +0800
commitab203b0ce26f4989c7fc80185207c6c40bbfa5fe (patch)
treeb1f012d44e31b49b94bb3208fa5f68bd6a5d176b /src
parentf7e73716316d0256ac1584348009a79c81d11e56 (diff)
downloademacs-ab203b0ce26f4989c7fc80185207c6c40bbfa5fe.tar.gz
emacs-ab203b0ce26f4989c7fc80185207c6c40bbfa5fe.zip
Simplify XI event state conversion
* src/xterm.c (xi_convert_button_state, xi_convert_event_state): New functions. (handle_one_xevent): Reduce duplicate code for converting XI state and button state into X state.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c140
1 files changed, 44 insertions, 96 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 23cee3c5472..6375b71666b 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -4960,7 +4960,38 @@ x_extension_initialize (struct x_display_info *dpyinfo)
4960 4960
4961#ifdef HAVE_XINPUT2 4961#ifdef HAVE_XINPUT2
4962 4962
4963/* Free all XI2 devices on dpyinfo. */ 4963/* Convert XI2 button state IN to a standard X button modifier
4964 mask, and place it in OUT. */
4965static void
4966xi_convert_button_state (XIButtonState *in, unsigned int *out)
4967{
4968 int i;
4969
4970 if (in->mask_len)
4971 {
4972 for (i = 1; i <= 8; ++i)
4973 {
4974 if (XIMaskIsSet (in->mask, i))
4975 *out |= (Button1Mask << (i - 1));
4976 }
4977 }
4978}
4979
4980/* Return the modifier state in XEV as a standard X modifier mask. */
4981static unsigned int
4982xi_convert_event_state (XIDeviceEvent *xev)
4983{
4984 unsigned int mods, buttons;
4985
4986 mods = xev->mods.effective;
4987 buttons = 0;
4988
4989 xi_convert_button_state (&xev->buttons, &buttons);
4990
4991 return mods | buttons;
4992}
4993
4994/* Free all XI2 devices on DPYINFO. */
4964static void 4995static void
4965x_free_xi_devices (struct x_display_info *dpyinfo) 4996x_free_xi_devices (struct x_display_info *dpyinfo)
4966{ 4997{
@@ -19462,7 +19493,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
19462 xm_top_level_leave_message lmsg; 19493 xm_top_level_leave_message lmsg;
19463 xm_top_level_enter_message emsg; 19494 xm_top_level_enter_message emsg;
19464 xm_drag_motion_message dmsg; 19495 xm_drag_motion_message dmsg;
19465 int dnd_state; 19496 unsigned int dnd_state;
19466 19497
19467 source = xi_device_from_id (dpyinfo, xev->sourceid); 19498 source = xi_device_from_id (dpyinfo, xev->sourceid);
19468 19499
@@ -19628,20 +19659,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
19628#ifdef HAVE_XWIDGETS 19659#ifdef HAVE_XWIDGETS
19629 if (xv) 19660 if (xv)
19630 { 19661 {
19631 uint state = xev->mods.effective; 19662 unsigned int state;
19663
19664 state = xi_convert_event_state (xev);
19632 x_display_set_last_user_time (dpyinfo, xev->time, 19665 x_display_set_last_user_time (dpyinfo, xev->time,
19633 xev->send_event); 19666 xev->send_event);
19634 19667
19635 if (xev->buttons.mask_len)
19636 {
19637 if (XIMaskIsSet (xev->buttons.mask, 1))
19638 state |= Button1Mask;
19639 if (XIMaskIsSet (xev->buttons.mask, 2))
19640 state |= Button2Mask;
19641 if (XIMaskIsSet (xev->buttons.mask, 3))
19642 state |= Button3Mask;
19643 }
19644
19645 if (found_valuator) 19668 if (found_valuator)
19646 xwidget_scroll (xv, xev->event_x, xev->event_y, 19669 xwidget_scroll (xv, xev->event_x, xev->event_y,
19647 -xv_total_x, -xv_total_y, state, 19670 -xv_total_x, -xv_total_y, state,
@@ -19748,17 +19771,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
19748 copy.xmotion.y = lrint (xev->event_y); 19771 copy.xmotion.y = lrint (xev->event_y);
19749 copy.xmotion.x_root = lrint (xev->root_x); 19772 copy.xmotion.x_root = lrint (xev->root_x);
19750 copy.xmotion.y_root = lrint (xev->root_y); 19773 copy.xmotion.y_root = lrint (xev->root_y);
19751 copy.xmotion.state = 0; 19774 copy.xmotion.state = xi_convert_event_state (xev);
19752
19753 if (xev->buttons.mask_len)
19754 {
19755 if (XIMaskIsSet (xev->buttons.mask, 1))
19756 copy.xmotion.state |= Button1Mask;
19757 if (XIMaskIsSet (xev->buttons.mask, 2))
19758 copy.xmotion.state |= Button2Mask;
19759 if (XIMaskIsSet (xev->buttons.mask, 3))
19760 copy.xmotion.state |= Button3Mask;
19761 }
19762 19775
19763 copy.xmotion.is_hint = False; 19776 copy.xmotion.is_hint = False;
19764 copy.xmotion.same_screen = True; 19777 copy.xmotion.same_screen = True;
@@ -19962,17 +19975,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
19962 xev->root_x, xev->root_y); 19975 xev->root_x, xev->root_y);
19963 else if (x_dnd_last_protocol_version != -1 && target != None) 19976 else if (x_dnd_last_protocol_version != -1 && target != None)
19964 { 19977 {
19965 dnd_state = xev->mods.effective; 19978 dnd_state = xi_convert_event_state (xev);
19966
19967 if (xev->buttons.mask_len)
19968 {
19969 if (XIMaskIsSet (xev->buttons.mask, 1))
19970 dnd_state |= Button1Mask;
19971 if (XIMaskIsSet (xev->buttons.mask, 2))
19972 dnd_state |= Button2Mask;
19973 if (XIMaskIsSet (xev->buttons.mask, 3))
19974 dnd_state |= Button3Mask;
19975 }
19976 19979
19977 x_dnd_send_position (x_dnd_frame, target, 19980 x_dnd_send_position (x_dnd_frame, target,
19978 x_dnd_last_protocol_version, 19981 x_dnd_last_protocol_version,
@@ -20156,17 +20159,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
20156 && x_dnd_last_seen_window != None 20159 && x_dnd_last_seen_window != None
20157 && x_dnd_last_protocol_version != -1) 20160 && x_dnd_last_protocol_version != -1)
20158 { 20161 {
20159 dnd_state = xev->mods.effective; 20162 dnd_state = xi_convert_event_state (xev);
20160
20161 if (xev->buttons.mask_len)
20162 {
20163 if (XIMaskIsSet (xev->buttons.mask, 1))
20164 dnd_state |= Button1Mask;
20165 if (XIMaskIsSet (xev->buttons.mask, 2))
20166 dnd_state |= Button2Mask;
20167 if (XIMaskIsSet (xev->buttons.mask, 3))
20168 dnd_state |= Button3Mask;
20169 }
20170 20163
20171 x_dnd_send_position (x_dnd_frame, x_dnd_last_seen_window, 20164 x_dnd_send_position (x_dnd_frame, x_dnd_last_seen_window,
20172 x_dnd_last_protocol_version, xev->root_x, 20165 x_dnd_last_protocol_version, xev->root_x,
@@ -20339,19 +20332,10 @@ handle_one_xevent (struct x_display_info *dpyinfo,
20339 copy.xbutton.y = lrint (xev->event_y); 20332 copy.xbutton.y = lrint (xev->event_y);
20340 copy.xbutton.x_root = lrint (xev->root_x); 20333 copy.xbutton.x_root = lrint (xev->root_x);
20341 copy.xbutton.y_root = lrint (xev->root_y); 20334 copy.xbutton.y_root = lrint (xev->root_y);
20342 copy.xbutton.state = xev->mods.effective; 20335 copy.xbutton.state = xi_convert_event_state (xev);
20343 copy.xbutton.button = xev->detail; 20336 copy.xbutton.button = xev->detail;
20344 copy.xbutton.same_screen = True; 20337 copy.xbutton.same_screen = True;
20345 20338
20346 if (xev->buttons.mask_len)
20347 {
20348 if (XIMaskIsSet (xev->buttons.mask, 1))
20349 copy.xbutton.state |= Button1Mask;
20350 if (XIMaskIsSet (xev->buttons.mask, 2))
20351 copy.xbutton.state |= Button2Mask;
20352 if (XIMaskIsSet (xev->buttons.mask, 3))
20353 copy.xbutton.state |= Button3Mask;
20354 }
20355#elif defined USE_GTK && !defined HAVE_GTK3 20339#elif defined USE_GTK && !defined HAVE_GTK3
20356 copy = gdk_event_new (xev->evtype == XI_ButtonPress 20340 copy = gdk_event_new (xev->evtype == XI_ButtonPress
20357 ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE); 20341 ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE);
@@ -20363,19 +20347,9 @@ handle_one_xevent (struct x_display_info *dpyinfo,
20363 copy->button.y = xev->event_y; 20347 copy->button.y = xev->event_y;
20364 copy->button.x_root = xev->root_x; 20348 copy->button.x_root = xev->root_x;
20365 copy->button.y_root = xev->root_y; 20349 copy->button.y_root = xev->root_y;
20366 copy->button.state = xev->mods.effective; 20350 copy->button.state = xi_convert_event_state (xev);
20367 copy->button.button = xev->detail; 20351 copy->button.button = xev->detail;
20368 20352
20369 if (xev->buttons.mask_len)
20370 {
20371 if (XIMaskIsSet (xev->buttons.mask, 1))
20372 copy->button.state |= GDK_BUTTON1_MASK;
20373 if (XIMaskIsSet (xev->buttons.mask, 2))
20374 copy->button.state |= GDK_BUTTON2_MASK;
20375 if (XIMaskIsSet (xev->buttons.mask, 3))
20376 copy->button.state |= GDK_BUTTON3_MASK;
20377 }
20378
20379 if (!copy->button.window) 20353 if (!copy->button.window)
20380 emacs_abort (); 20354 emacs_abort ();
20381 20355
@@ -20738,22 +20712,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
20738 copy.xkey.time = xev->time; 20712 copy.xkey.time = xev->time;
20739 copy.xkey.state = ((xev->mods.effective & ~(1 << 13 | 1 << 14)) 20713 copy.xkey.state = ((xev->mods.effective & ~(1 << 13 | 1 << 14))
20740 | (xev->group.effective << 13)); 20714 | (xev->group.effective << 13));
20715 xi_convert_button_state (&xev->buttons, &copy.xkey.state);
20741 20716
20742 copy.xkey.x = lrint (xev->event_x); 20717 copy.xkey.x = lrint (xev->event_x);
20743 copy.xkey.y = lrint (xev->event_y); 20718 copy.xkey.y = lrint (xev->event_y);
20744 copy.xkey.x_root = lrint (xev->root_x); 20719 copy.xkey.x_root = lrint (xev->root_x);
20745 copy.xkey.y_root = lrint (xev->root_y); 20720 copy.xkey.y_root = lrint (xev->root_y);
20746
20747 if (xev->buttons.mask_len)
20748 {
20749 if (XIMaskIsSet (xev->buttons.mask, 1))
20750 copy.xkey.state |= Button1Mask;
20751 if (XIMaskIsSet (xev->buttons.mask, 2))
20752 copy.xkey.state |= Button2Mask;
20753 if (XIMaskIsSet (xev->buttons.mask, 3))
20754 copy.xkey.state |= Button3Mask;
20755 }
20756
20757 copy.xkey.keycode = xev->detail; 20721 copy.xkey.keycode = xev->detail;
20758 copy.xkey.same_screen = True; 20722 copy.xkey.same_screen = True;
20759#endif 20723#endif
@@ -20789,15 +20753,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
20789 20753
20790 /* Some input methods react differently depending on the 20754 /* Some input methods react differently depending on the
20791 buttons that are pressed. */ 20755 buttons that are pressed. */
20792 if (xev->buttons.mask_len) 20756 xi_convert_button_state (&xev->buttons, &xkey.state);
20793 {
20794 if (XIMaskIsSet (xev->buttons.mask, 1))
20795 xkey.state |= Button1Mask;
20796 if (XIMaskIsSet (xev->buttons.mask, 2))
20797 xkey.state |= Button2Mask;
20798 if (XIMaskIsSet (xev->buttons.mask, 3))
20799 xkey.state |= Button3Mask;
20800 }
20801 20757
20802 xkey.keycode = xev->detail; 20758 xkey.keycode = xev->detail;
20803 xkey.same_screen = True; 20759 xkey.same_screen = True;
@@ -21228,15 +21184,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
21228 21184
21229 /* Some input methods react differently depending on the 21185 /* Some input methods react differently depending on the
21230 buttons that are pressed. */ 21186 buttons that are pressed. */
21231 if (xev->buttons.mask_len) 21187 xi_convert_button_state (&xev->buttons, &xkey.state);
21232 {
21233 if (XIMaskIsSet (xev->buttons.mask, 1))
21234 xkey.state |= Button1Mask;
21235 if (XIMaskIsSet (xev->buttons.mask, 2))
21236 xkey.state |= Button2Mask;
21237 if (XIMaskIsSet (xev->buttons.mask, 3))
21238 xkey.state |= Button3Mask;
21239 }
21240 21188
21241 xkey.keycode = xev->detail; 21189 xkey.keycode = xev->detail;
21242 xkey.same_screen = True; 21190 xkey.same_screen = True;