all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Robert Pluim <rpluim@gmail.com>
Cc: 51891@debbugs.gnu.org
Subject: bug#51891: 29.0.50; [PATCH] Pixel delta support for wheel events on X
Date: Wed, 17 Nov 2021 10:38:41 +0800	[thread overview]
Message-ID: <871r3ftsjy.fsf@yahoo.com> (raw)
In-Reply-To: <875ysrtyak.fsf@yahoo.com> (Po Lu's message of "Wed, 17 Nov 2021 08:34:43 +0800")

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

Po Lu <luangruo@yahoo.com> writes:

> Because other systems (such as GDK) have different methods of reporting
> scroll deltas.  While it makes sense in the context of the XInput 2 code
> to report them one at a time, it does not in the context of GDK, as it
> reports both deltas to Emacs at the same time.
>
> Which means the pure GTK port will report both delta-y and delta-x at
> the same time.
>
> Thanks.

And here's a new version of the patch with the fixes to documentation,
and an extra option to prevent motion events from being sent too
rapidly.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Expose-pixel-wise-wheel-events-to-Lisp.patch --]
[-- Type: text/x-patch, Size: 6367 bytes --]

From cf9a4a28cd44077e7682c0deccda9d1fbc98344d Mon Sep 17 00:00:00 2001
From: Po Lu <luangruo@yahoo.com>
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.
(x_coalesce_scroll_events): New user option.
---
 doc/lispref/commands.texi |  6 +++++-
 src/keyboard.c            |  5 ++++-
 src/termhooks.h           |  6 +++++-
 src/xfns.c                |  3 +++
 src/xterm.c               | 37 ++++++++++++++++++++++++++-----------
 5 files changed, 43 insertions(+), 14 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..19a6cc82da 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -119,7 +119,11 @@ #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
+				   X and 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..74f0cefb7b 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -556,6 +556,7 @@ xi_reset_scroll_valuators_for_device_id (struct x_display_info *dpyinfo, int id)
     {
       valuator = &device->valuators[i];
       valuator->invalid_p = true;
+      valuator->emacs_value = 0.0;
     }
 
   return;
@@ -9921,8 +9922,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 #endif
 	    goto XI_OTHER;
 	  case XI_Motion:
-	    /* First test if there is some kind of scroll event
-	       here! */
 	    states = &xev->valuators;
 	    values = states->values;
 
@@ -9932,10 +9931,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 	      {
 		if (XIMaskIsSet (states->mask, i))
 		  {
-		    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 +9940,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))
@@ -9950,15 +9948,16 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 
 			val->emacs_value += delta;
 
+			if (x_coalesce_scroll_events
+			    && (fabs (val->emacs_value) < 1))
+			  continue;
+
 			if (!f)
 			  {
 			    f = x_any_window_to_frame (dpyinfo, xev->event);
 
 			    if (!f)
-			      {
-				unblock_input ();
-				goto XI_OTHER;
-			      }
+			      goto XI_OTHER;
 			  }
 
 			bool s = signbit (val->emacs_value);
@@ -9975,13 +9974,22 @@ 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 (val->emacs_value
+							   * scroll_unit),
+					       QCdelta_y, make_float (0));
+			else
+			  inev.ie.arg = list5 (Qnil, QCdelta_x, make_float (0),
+					       QCdelta_y,
+					       make_float (val->emacs_value
+							   * scroll_unit));
 
 			kbd_buffer_store_event_hold (&inev.ie, hold_quit);
 
 			val->emacs_value = 0;
 		      }
-		    unblock_input ();
 		    values++;
 		  }
 
@@ -15048,4 +15056,11 @@ syms_of_xterm (void)
 consuming frame position adjustments.  In newer versions of GTK, Emacs
 always uses gtk_window_move and ignores the value of this variable.  */);
   x_gtk_use_window_move = true;
+
+  DEFVAR_BOOL ("x-coalesce-scroll-events", x_coalesce_scroll_events,
+	       doc: /* Non-nil means to only send one wheel event for each scroll unit.
+Otherwise, a wheel event will be sent every time the mouse wheel is
+moved.  This option is only effective when Emacs is built with XInput
+2.  */);
+  x_coalesce_scroll_events = true;
 }
-- 
2.31.1


  reply	other threads:[~2021-11-17  2:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87zgq4uvh0.fsf.ref@yahoo.com>
2021-11-16 12:38 ` bug#51891: 29.0.50; [PATCH] Pixel delta support for wheel events on X Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-16 13:39   ` Robert Pluim
2021-11-17  0:34     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-17  2:38       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-11-17 13:33         ` Eli Zaretskii
2021-11-18  0:15           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-18  7:33             ` Eli Zaretskii
2021-11-18  9:17               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-18 10:27                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-19 13:05                   ` Eli Zaretskii
2021-11-19 13:10                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-19 13:23                       ` Eli Zaretskii
2021-11-20  0:30                         ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-20  7:06                           ` Eli Zaretskii
2021-11-19 13:09                 ` Eli Zaretskii
2021-11-19 13:24                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-19 13:55                     ` Eli Zaretskii
2021-11-20 10:28                       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871r3ftsjy.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=51891@debbugs.gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=rpluim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.