aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-02-17 13:25:01 +0800
committerPo Lu2022-02-17 13:25:01 +0800
commit5df33cfcaf379455857f2aefa5ca0ab39cb9fc6f (patch)
treea6f0b09674677be931675225a0bd0f08276e1502 /src
parent99d6536c326a4df3bfb964f421edc2a005deb851 (diff)
downloademacs-5df33cfcaf379455857f2aefa5ca0ab39cb9fc6f.tar.gz
emacs-5df33cfcaf379455857f2aefa5ca0ab39cb9fc6f.zip
Improve handling of XI2 wheel movement
* src/xterm.c (handle_one_xevent): Process movement in all directions and send it as a single event.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c107
1 files changed, 50 insertions, 57 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 57e06f6c7e1..b0d3adca0e2 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -10968,13 +10968,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
10968 case XI_Motion: 10968 case XI_Motion:
10969 { 10969 {
10970 struct xi_device_t *device; 10970 struct xi_device_t *device;
10971 bool touch_end_event_seen = false;
10972 10971
10973 states = &xev->valuators; 10972 states = &xev->valuators;
10974 values = states->values; 10973 values = states->values;
10975 device = xi_device_from_id (dpyinfo, xev->deviceid); 10974 device = xi_device_from_id (dpyinfo, xev->deviceid);
10976 10975
10977 if (!device || !device->master_p) 10976 if (!device)
10978 goto XI_OTHER; 10977 goto XI_OTHER;
10979 10978
10980#ifdef XI_TouchBegin 10979#ifdef XI_TouchBegin
@@ -10988,6 +10987,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
10988 double xv_total_x = 0.0; 10987 double xv_total_x = 0.0;
10989 double xv_total_y = 0.0; 10988 double xv_total_y = 0.0;
10990#endif 10989#endif
10990 double total_x = 0.0;
10991 double total_y = 0.0;
10991 10992
10992 for (int i = 0; i < states->mask_len * 8; i++) 10993 for (int i = 0; i < states->mask_len * 8; i++)
10993 { 10994 {
@@ -11029,7 +11030,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
11029 } 11030 }
11030#endif 11031#endif
11031 11032
11032 found_valuator = true; 11033 if (delta == 0.0)
11034 found_valuator = true;
11033 11035
11034 if (signbit (delta) != signbit (val->emacs_value)) 11036 if (signbit (delta) != signbit (val->emacs_value))
11035 val->emacs_value = 0; 11037 val->emacs_value = 0;
@@ -11041,26 +11043,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
11041 && (fabs (delta) > 0)) 11043 && (fabs (delta) > 0))
11042 continue; 11044 continue;
11043 11045
11044 bool s = signbit (val->emacs_value);
11045 inev.ie.kind = (fabs (delta) > 0
11046 ? (val->horizontal
11047 ? HORIZ_WHEEL_EVENT
11048 : WHEEL_EVENT)
11049 : TOUCH_END_EVENT);
11050 inev.ie.timestamp = xev->time;
11051
11052 XSETINT (inev.ie.x, lrint (xev->event_x));
11053 XSETINT (inev.ie.y, lrint (xev->event_y));
11054 XSETFRAME (inev.ie.frame_or_window, f);
11055
11056 if (fabs (delta) > 0)
11057 {
11058 inev.ie.modifiers = !s ? up_modifier : down_modifier;
11059 inev.ie.modifiers
11060 |= x_x_to_emacs_modifiers (dpyinfo,
11061 xev->mods.effective);
11062 }
11063
11064 window = window_from_coordinates (f, xev->event_x, 11046 window = window_from_coordinates (f, xev->event_x,
11065 xev->event_y, NULL, 11047 xev->event_y, NULL,
11066 false, false); 11048 false, false);
@@ -11078,40 +11060,15 @@ handle_one_xevent (struct x_display_info *dpyinfo,
11078 if (NUMBERP (Vx_scroll_event_delta_factor)) 11060 if (NUMBERP (Vx_scroll_event_delta_factor))
11079 scroll_unit *= XFLOATINT (Vx_scroll_event_delta_factor); 11061 scroll_unit *= XFLOATINT (Vx_scroll_event_delta_factor);
11080 11062
11081 if (fabs (delta) > 0) 11063 if (val->horizontal)
11082 { 11064 total_x += delta * scroll_unit;
11083 if (val->horizontal)
11084 {
11085 inev.ie.arg
11086 = list3 (Qnil,
11087 make_float (val->emacs_value
11088 * scroll_unit),
11089 make_float (0));
11090 }
11091 else
11092 {
11093 inev.ie.arg = list3 (Qnil, make_float (0),
11094 make_float (val->emacs_value
11095 * scroll_unit));
11096 }
11097 }
11098 else 11065 else
11099 { 11066 total_y += delta * scroll_unit;
11100 inev.ie.arg = Qnil;
11101 }
11102
11103 if (inev.ie.kind != TOUCH_END_EVENT
11104 || !touch_end_event_seen)
11105 {
11106 kbd_buffer_store_event_hold (&inev.ie, hold_quit);
11107 touch_end_event_seen = inev.ie.kind == TOUCH_END_EVENT;
11108 }
11109 11067
11068 found_valuator = true;
11110 val->emacs_value = 0; 11069 val->emacs_value = 0;
11111 } 11070 }
11112 } 11071 }
11113
11114 inev.ie.kind = NO_EVENT;
11115 } 11072 }
11116 11073
11117#ifdef HAVE_XWIDGETS 11074#ifdef HAVE_XWIDGETS
@@ -11141,15 +11098,51 @@ handle_one_xevent (struct x_display_info *dpyinfo,
11141 11098
11142 goto XI_OTHER; 11099 goto XI_OTHER;
11143 } 11100 }
11144#endif 11101 else
11145 if (found_valuator)
11146 { 11102 {
11103#endif
11104 if (found_valuator)
11105 {
11106 if (fabs (total_x) > 0 || fabs (total_y) > 0)
11107 {
11108 inev.ie.kind = (fabs (total_y) >= fabs (total_x)
11109 ? WHEEL_EVENT : HORIZ_WHEEL_EVENT);
11110 inev.ie.timestamp = xev->time;
11111
11112 XSETINT (inev.ie.x, lrint (xev->event_x));
11113 XSETINT (inev.ie.y, lrint (xev->event_y));
11114 XSETFRAME (inev.ie.frame_or_window, f);
11115
11116 inev.ie.modifiers = (signbit (fabs (total_y) >= fabs (total_x)
11117 ? total_y : total_x)
11118 ? down_modifier : up_modifier);
11119 inev.ie.modifiers
11120 |= x_x_to_emacs_modifiers (dpyinfo,
11121 xev->mods.effective);
11122 inev.ie.arg = list3 (Qnil,
11123 make_float (total_x),
11124 make_float (total_y));
11125
11147#ifdef USE_GTK 11126#ifdef USE_GTK
11148 if (f && xg_event_is_for_scrollbar (f, event)) 11127 if (f && xg_event_is_for_scrollbar (f, event))
11149 *finish = X_EVENT_DROP; 11128 *finish = X_EVENT_DROP;
11150#endif 11129#endif
11151 goto XI_OTHER; 11130 }
11131 else
11132 {
11133 inev.ie.kind = TOUCH_END_EVENT;
11134 inev.ie.timestamp = xev->time;
11135
11136 XSETINT (inev.ie.x, lrint (xev->event_x));
11137 XSETINT (inev.ie.y, lrint (xev->event_y));
11138 XSETFRAME (inev.ie.frame_or_window, f);
11139 }
11140
11141 goto XI_OTHER;
11142 }
11143#ifdef HAVE_XWIDGETS
11152 } 11144 }
11145#endif
11153 11146
11154 ev.x = lrint (xev->event_x); 11147 ev.x = lrint (xev->event_x);
11155 ev.y = lrint (xev->event_y); 11148 ev.y = lrint (xev->event_y);