aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorYuuki Harano2020-11-28 21:55:18 +0900
committerYuuki Harano2020-11-28 21:55:18 +0900
commitfc68127ce8b273834bed951510d5bb39d12e5615 (patch)
tree280c005a71293a4e09e9f2352681c7c9343a34ad /src
parent197b37c7689578bf3b08fd690c97df122e8d3547 (diff)
downloademacs-fc68127ce8b273834bed951510d5bb39d12e5615.tar.gz
emacs-fc68127ce8b273834bed951510d5bb39d12e5615.zip
Improve smooth scroll
* src/pgtkterm.c (scroll_event): Accumulate deltas and calculate the number of lines. (pgtk_term_init): Set smooth scroll parameters. * src/pgtkterm.h (scroll): New members to store parameters.
Diffstat (limited to 'src')
-rw-r--r--src/pgtkterm.c80
-rw-r--r--src/pgtkterm.h6
2 files changed, 56 insertions, 30 deletions
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 0cf9bb84e76..f3675b49fb7 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -6530,6 +6530,8 @@ scroll_event (GtkWidget * widget, GdkEvent * event, gpointer * user_data)
6530 union buffered_input_event inev; 6530 union buffered_input_event inev;
6531 struct frame *f, *frame; 6531 struct frame *f, *frame;
6532 struct pgtk_display_info *dpyinfo; 6532 struct pgtk_display_info *dpyinfo;
6533 GdkScrollDirection dir;
6534 double delta_x, delta_y;
6533 6535
6534 EVENT_INIT (inev.ie); 6536 EVENT_INIT (inev.ie);
6535 inev.ie.kind = NO_EVENT; 6537 inev.ie.kind = NO_EVENT;
@@ -6543,7 +6545,7 @@ scroll_event (GtkWidget * widget, GdkEvent * event, gpointer * user_data)
6543 else 6545 else
6544 f = pgtk_any_window_to_frame (gtk_widget_get_window (widget)); 6546 f = pgtk_any_window_to_frame (gtk_widget_get_window (widget));
6545 6547
6546 inev.ie.kind = WHEEL_EVENT; 6548 inev.ie.kind = NO_EVENT;
6547 inev.ie.timestamp = event->scroll.time; 6549 inev.ie.timestamp = event->scroll.time;
6548 inev.ie.modifiers = 6550 inev.ie.modifiers =
6549 pgtk_gtk_to_emacs_modifiers (FRAME_DISPLAY_INFO (f), event->scroll.state); 6551 pgtk_gtk_to_emacs_modifiers (FRAME_DISPLAY_INFO (f), event->scroll.state);
@@ -6552,50 +6554,64 @@ scroll_event (GtkWidget * widget, GdkEvent * event, gpointer * user_data)
6552 XSETFRAME (inev.ie.frame_or_window, f); 6554 XSETFRAME (inev.ie.frame_or_window, f);
6553 inev.ie.arg = Qnil; 6555 inev.ie.arg = Qnil;
6554 6556
6555 switch (event->scroll.direction) 6557 if (gdk_event_get_scroll_direction (event, &dir))
6556 { 6558 {
6557 case GDK_SCROLL_UP: 6559 switch (dir)
6558 inev.ie.kind = WHEEL_EVENT;
6559 inev.ie.modifiers |= up_modifier;
6560 break;
6561 case GDK_SCROLL_DOWN:
6562 inev.ie.kind = WHEEL_EVENT;
6563 inev.ie.modifiers |= down_modifier;
6564 break;
6565 case GDK_SCROLL_LEFT:
6566 inev.ie.kind = HORIZ_WHEEL_EVENT;
6567 inev.ie.modifiers |= up_modifier;
6568 break;
6569 case GDK_SCROLL_RIGHT:
6570 inev.ie.kind = HORIZ_WHEEL_EVENT;
6571 inev.ie.modifiers |= down_modifier;
6572 break;
6573 case GDK_SCROLL_SMOOTH:
6574 if (event->scroll.delta_y >= 0.5)
6575 { 6560 {
6561 case GDK_SCROLL_UP:
6562 inev.ie.kind = WHEEL_EVENT;
6563 inev.ie.modifiers |= up_modifier;
6564 break;
6565 case GDK_SCROLL_DOWN:
6576 inev.ie.kind = WHEEL_EVENT; 6566 inev.ie.kind = WHEEL_EVENT;
6577 inev.ie.modifiers |= down_modifier; 6567 inev.ie.modifiers |= down_modifier;
6568 break;
6569 case GDK_SCROLL_LEFT:
6570 inev.ie.kind = HORIZ_WHEEL_EVENT;
6571 inev.ie.modifiers |= up_modifier;
6572 break;
6573 case GDK_SCROLL_RIGHT:
6574 inev.ie.kind = HORIZ_WHEEL_EVENT;
6575 inev.ie.modifiers |= down_modifier;
6576 break;
6578 } 6577 }
6579 else if (event->scroll.delta_y <= -0.5) 6578 }
6579 else if (gdk_event_get_scroll_deltas (event, &delta_x, &delta_y))
6580 {
6581 dpyinfo->scroll.acc_x += delta_x;
6582 dpyinfo->scroll.acc_y += delta_y;
6583 if (dpyinfo->scroll.acc_y >= dpyinfo->scroll.y_per_line)
6580 { 6584 {
6585 int nlines = dpyinfo->scroll.acc_y / dpyinfo->scroll.y_per_line;
6586 inev.ie.kind = WHEEL_EVENT;
6587 inev.ie.modifiers |= down_modifier;
6588 inev.ie.arg = make_fixnum(nlines);
6589 dpyinfo->scroll.acc_y -= dpyinfo->scroll.y_per_line * nlines;
6590 }
6591 else if (dpyinfo->scroll.acc_y <= -dpyinfo->scroll.y_per_line)
6592 {
6593 int nlines = -dpyinfo->scroll.acc_y / dpyinfo->scroll.y_per_line;
6581 inev.ie.kind = WHEEL_EVENT; 6594 inev.ie.kind = WHEEL_EVENT;
6582 inev.ie.modifiers |= up_modifier; 6595 inev.ie.modifiers |= up_modifier;
6596 inev.ie.arg = make_fixnum(nlines);
6597 dpyinfo->scroll.acc_y -= -dpyinfo->scroll.y_per_line * nlines;
6583 } 6598 }
6584 else if (event->scroll.delta_x >= 0.5) 6599 else if (dpyinfo->scroll.acc_x >= dpyinfo->scroll.x_per_char)
6585 { 6600 {
6601 int nchars = dpyinfo->scroll.acc_x / dpyinfo->scroll.x_per_char;
6586 inev.ie.kind = HORIZ_WHEEL_EVENT; 6602 inev.ie.kind = HORIZ_WHEEL_EVENT;
6587 inev.ie.modifiers |= down_modifier; 6603 inev.ie.modifiers |= up_modifier;
6604 inev.ie.arg = make_fixnum(nchars);
6605 dpyinfo->scroll.acc_x -= dpyinfo->scroll.x_per_char * nchars;
6588 } 6606 }
6589 else if (event->scroll.delta_x <= -0.5) 6607 else if (dpyinfo->scroll.acc_x <= -dpyinfo->scroll.x_per_char)
6590 { 6608 {
6609 int nchars = -dpyinfo->scroll.acc_x / dpyinfo->scroll.x_per_char;
6591 inev.ie.kind = HORIZ_WHEEL_EVENT; 6610 inev.ie.kind = HORIZ_WHEEL_EVENT;
6592 inev.ie.modifiers |= up_modifier; 6611 inev.ie.modifiers |= down_modifier;
6612 inev.ie.arg = make_fixnum(nchars);
6613 dpyinfo->scroll.acc_x -= -dpyinfo->scroll.x_per_char * nchars;
6593 } 6614 }
6594 else
6595 return TRUE;
6596 break;
6597 default:
6598 return TRUE;
6599 } 6615 }
6600 6616
6601 if (inev.ie.kind != NO_EVENT) 6617 if (inev.ie.kind != NO_EVENT)
@@ -6943,6 +6959,10 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name)
6943 dpyinfo->resy = dpi; 6959 dpyinfo->resy = dpi;
6944 } 6960 }
6945 6961
6962 /* smooth scroll setting */
6963 dpyinfo->scroll.x_per_char = 2;
6964 dpyinfo->scroll.y_per_line = 2;
6965
6946 x_setup_pointer_blanking (dpyinfo); 6966 x_setup_pointer_blanking (dpyinfo);
6947 6967
6948 xsettings_initialize (dpyinfo); 6968 xsettings_initialize (dpyinfo);
diff --git a/src/pgtkterm.h b/src/pgtkterm.h
index 09b3b21b170..5e71f939987 100644
--- a/src/pgtkterm.h
+++ b/src/pgtkterm.h
@@ -246,6 +246,12 @@ struct pgtk_display_info
246 GtkIMContext *context; 246 GtkIMContext *context;
247 struct frame *focused_frame; 247 struct frame *focused_frame;
248 } im; 248 } im;
249
250 struct
251 {
252 double acc_x, acc_y;
253 double x_per_char, y_per_line;
254 } scroll;
249}; 255};
250 256
251/* This is a chain of structures for all the PGTK displays currently in use. */ 257/* This is a chain of structures for all the PGTK displays currently in use. */