From aee86e1d2f94dff95644a817cad072a1de9a88bf Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 16 Nov 2021 19:39:50 +0800 Subject: [PATCH 2/2] Expose pixel-wise wheel events to Lisp * doc/lispref/commands.texi (Misc Events): Document changes to wheel events. * src/keyboard.c (make_lispy_event): Handle wheel events with pixel delta data. * src/termhooks.h (WHEEL_EVENT): Document changes to WHEEL_EVENT args. * src/xfns.c (syms_of_xfns): Declare new symbols. * src/xterm.c (handle_one_xevent): Give wheel events pixel delta data. --- doc/lispref/commands.texi | 6 +++++- src/keyboard.c | 5 ++++- src/termhooks.h | 7 ++++++- src/xfns.c | 3 +++ src/xterm.c | 13 +++++++++++-- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index 1509c200e0..be0f4189ee 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi @@ -1985,7 +1985,11 @@ Misc Events These kinds of event are generated by moving a mouse wheel. The @var{position} element is a mouse position list (@pxref{Click Events}), specifying the position of the mouse cursor when the event -occurred. +occurred. The event may have additional arguments after +@var{position}. The third argument after @var{position}, if present, +is a property list of the form @w{@code{(:delta-x @var{x} :delta-y +@var{y})}}, where @var{x} and @var{y} are the number of pixels to +scroll by in each axis. @vindex mouse-wheel-up-event @vindex mouse-wheel-down-event diff --git a/src/keyboard.c b/src/keyboard.c index de9805df32..276fd8c5aa 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -5980,7 +5980,10 @@ make_lispy_event (struct input_event *event) ASIZE (wheel_syms)); } - if (NUMBERP (event->arg)) + if (CONSP (event->arg)) + return list5 (head, position, make_fixnum (double_click_count), + XCAR (event->arg), XCDR (event->arg)); + else if (NUMBERP (event->arg)) return list4 (head, position, make_fixnum (double_click_count), event->arg); else if (event->modifiers & (double_modifier | triple_modifier)) diff --git a/src/termhooks.h b/src/termhooks.h index e7539bbce2..43a9fc2f22 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -119,7 +119,12 @@ #define EMACS_TERMHOOKS_H .timestamp gives a timestamp (in milliseconds) for the event. .arg may contain the number of - lines to scroll. */ + lines to scroll, or a list of + the form (NUMBER-OF-LINES . + (:DELTA-X :DELTA-Y Y)) where + DELTA-X and DELTA-Y are the number + of pixels on each axis to scroll + by. */ HORIZ_WHEEL_EVENT, /* A wheel event generated by a second horizontal wheel that is present on some mice. See WHEEL_EVENT. */ diff --git a/src/xfns.c b/src/xfns.c index b33b40b330..9d70ba479b 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -8085,6 +8085,9 @@ syms_of_xfns (void) #ifdef HAVE_XINPUT2 DEFSYM (Qxinput2, "xinput2"); + DEFSYM (QCdelta_x, ":delta-x"); + DEFSYM (QCdelta_y, ":delta-y"); + Fprovide (Qxinput2, Qnil); #endif diff --git a/src/xterm.c b/src/xterm.c index 63754a2cb6..6eb361efca 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -9935,7 +9935,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, block_input (); struct xi_scroll_valuator_t *val; - double delta; + double delta, scroll_unit; delta = x_get_scroll_valuator_delta (dpyinfo, xev->deviceid, i, *values, &val); @@ -9943,6 +9943,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, if (delta != DBL_MAX) { f = mouse_or_wdesc_frame (dpyinfo, xev->event); + scroll_unit = pow (FRAME_PIXEL_HEIGHT (f), 2.0 / 3.0); found_valuator = true; if (signbit (delta) != signbit (val->emacs_value)) @@ -9975,7 +9976,15 @@ handle_one_xevent (struct x_display_info *dpyinfo, inev.ie.modifiers |= x_x_to_emacs_modifiers (dpyinfo, xev->mods.effective); - inev.ie.arg = Qnil; + + if (val->horizontal) + inev.ie.arg = list5 (Qnil, QCdelta_x, + make_float (delta * scroll_unit), + QCdelta_y, make_float (0)); + else + inev.ie.arg = list5 (Qnil, QCdelta_x, make_float (0), + QCdelta_y, + make_float (delta * scroll_unit)); kbd_buffer_store_event_hold (&inev.ie, hold_quit); -- 2.31.1