]> git.eshelyaron.com Git - emacs.git/commitdiff
Enable pixel-precision scrolling on pgtk port
authorPo Lu <luangruo@yahoo.com>
Tue, 30 Nov 2021 01:01:26 +0000 (09:01 +0800)
committerPo Lu <luangruo@yahoo.com>
Tue, 30 Nov 2021 01:01:26 +0000 (09:01 +0800)
* src/pgtkterm.c (scroll_event): Generate enhanced wheel
events.
(x_coalesce_scroll_events): New variable.

src/pgtkterm.c

index f7aadec321cc0c762b0946517604509d4652ba0f..8353a9ca4dc926c2186a5c31b902083a57d37995 100644 (file)
@@ -6032,37 +6032,77 @@ scroll_event (GtkWidget * widget, GdkEvent * event, gpointer * user_data)
     {
       dpyinfo->scroll.acc_x += delta_x;
       dpyinfo->scroll.acc_y += delta_y;
-      if (dpyinfo->scroll.acc_y >= dpyinfo->scroll.y_per_line)
+      if (dpyinfo->scroll.acc_y >= dpyinfo->scroll.y_per_line
+         || !x_coalesce_scroll_events)
        {
          int nlines = dpyinfo->scroll.acc_y / dpyinfo->scroll.y_per_line;
          inev.ie.kind = WHEEL_EVENT;
          inev.ie.modifiers |= down_modifier;
-         inev.ie.arg = make_fixnum (nlines);
-         dpyinfo->scroll.acc_y -= dpyinfo->scroll.y_per_line * nlines;
+         inev.ie.arg = list3 (make_fixnum (nlines),
+                              make_float (-dpyinfo->scroll.acc_x * 10),
+                              make_float (-dpyinfo->scroll.acc_y * 10));
+         if (!x_coalesce_scroll_events)
+           {
+             dpyinfo->scroll.acc_y = 0;
+             dpyinfo->scroll.acc_x = 0;
+           }
+         else
+           {
+             dpyinfo->scroll.acc_y -= dpyinfo->scroll.y_per_line * nlines;
+           }
        }
-      else if (dpyinfo->scroll.acc_y <= -dpyinfo->scroll.y_per_line)
+      else if (dpyinfo->scroll.acc_y <= -dpyinfo->scroll.y_per_line
+              || !x_coalesce_scroll_events)
        {
          int nlines = -dpyinfo->scroll.acc_y / dpyinfo->scroll.y_per_line;
          inev.ie.kind = WHEEL_EVENT;
          inev.ie.modifiers |= up_modifier;
-         inev.ie.arg = make_fixnum (nlines);
-         dpyinfo->scroll.acc_y -= -dpyinfo->scroll.y_per_line * nlines;
+         inev.ie.arg = list3 (make_fixnum (nlines),
+                              make_float (-dpyinfo->scroll.acc_x * 10),
+                              make_float (-dpyinfo->scroll.acc_y * 10));
+
+         if (!x_coalesce_scroll_events)
+           {
+             dpyinfo->scroll.acc_y = 0;
+             dpyinfo->scroll.acc_x = 0;
+           }
+         else
+           dpyinfo->scroll.acc_y -= -dpyinfo->scroll.y_per_line * nlines;
        }
-      else if (dpyinfo->scroll.acc_x >= dpyinfo->scroll.x_per_char)
+      else if (dpyinfo->scroll.acc_x >= dpyinfo->scroll.x_per_char
+              || !x_coalesce_scroll_events)
        {
          int nchars = dpyinfo->scroll.acc_x / dpyinfo->scroll.x_per_char;
          inev.ie.kind = HORIZ_WHEEL_EVENT;
          inev.ie.modifiers |= up_modifier;
-         inev.ie.arg = make_fixnum (nchars);
-         dpyinfo->scroll.acc_x -= dpyinfo->scroll.x_per_char * nchars;
+         inev.ie.arg = list3 (make_fixnum (nchars),
+                              make_float (-dpyinfo->scroll.acc_x * 10),
+                              make_float (-dpyinfo->scroll.acc_y * 10));
+
+         if (x_coalesce_scroll_events)
+           dpyinfo->scroll.acc_x -= dpyinfo->scroll.x_per_char * nchars;
+         else
+           {
+             dpyinfo->scroll.acc_x = 0;
+             dpyinfo->scroll.acc_y = 0;
+           }
        }
       else if (dpyinfo->scroll.acc_x <= -dpyinfo->scroll.x_per_char)
        {
          int nchars = -dpyinfo->scroll.acc_x / dpyinfo->scroll.x_per_char;
          inev.ie.kind = HORIZ_WHEEL_EVENT;
          inev.ie.modifiers |= down_modifier;
-         inev.ie.arg = make_fixnum (nchars);
-         dpyinfo->scroll.acc_x -= -dpyinfo->scroll.x_per_char * nchars;
+         inev.ie.arg = list3 (make_fixnum (nchars),
+                              make_float (-dpyinfo->scroll.acc_x * 10),
+                              make_float (-dpyinfo->scroll.acc_y * 10));
+
+         if (x_coalesce_scroll_events)
+           dpyinfo->scroll.acc_x -= -dpyinfo->scroll.x_per_char * nchars;
+         else
+           {
+             dpyinfo->scroll.acc_x = 0;
+             dpyinfo->scroll.acc_y = 0;
+           }
        }
     }
 
@@ -6711,6 +6751,10 @@ If set to a non-float value, there will be no wait at all.  */);
   window_being_scrolled = Qnil;
   staticpro (&window_being_scrolled);
 
+  DEFVAR_BOOL ("x-coalesce-scroll-events", x_coalesce_scroll_events,
+              doc: /* SKIP: real doc in xterm.c.  */);
+  x_coalesce_scroll_events = true;
+
   /* Tell Emacs about this window system.  */
   Fprovide (Qpgtk, Qnil);
 }