[gtk+/gtk-3-16] scrolled window: Use shift to modify scroll direction



commit 539caa897a39549a0f72bb1785f584b8773f1750
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 17 08:54:45 2015 -0400

    scrolled window: Use shift to modify scroll direction
    
    It has been a long-standing request to interpret scroll events
    with Shift held down as horizontal instead of vertical, and
    some applications are already doing this on their own.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=132197

 gtk/gtkscrolledwindow.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index c0acdd9..a9eabef 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -2908,7 +2908,10 @@ gtk_scrolled_window_scroll_event (GtkWidget      *widget,
   gboolean handled = FALSE;
   gdouble delta_x;
   gdouble delta_y;
-  gdouble delta;
+  GdkScrollDirection direction;
+  gboolean shifted;
+
+  shifted = (event->state & GDK_SHIFT_MASK) != 0;
 
   scrolled_window = GTK_SCROLLED_WINDOW (widget);
   priv = scrolled_window->priv;
@@ -2917,6 +2920,15 @@ gtk_scrolled_window_scroll_event (GtkWidget      *widget,
 
   if (gdk_event_get_scroll_deltas ((GdkEvent *) event, &delta_x, &delta_y))
     {
+      if (shifted)
+        {
+          gdouble delta;
+
+          delta = delta_x;
+          delta_x = delta_y;
+          delta_y = delta;
+        }
+
       if (delta_x != 0.0 &&
           may_hscroll (scrolled_window))
         {
@@ -2963,12 +2975,13 @@ gtk_scrolled_window_scroll_event (GtkWidget      *widget,
           handled = TRUE;
         }
     }
-  else
+  else if (gdk_event_get_scroll_direction ((GdkEvent *)event, &direction))
     {
       GtkWidget *range;
       gboolean may_scroll;
 
-      if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
+      if ((!shifted && (direction == GDK_SCROLL_UP || direction == GDK_SCROLL_DOWN)) ||
+          (shifted && (direction == GDK_SCROLL_LEFT || direction == GDK_SCROLL_RIGHT)))
         {
           range = priv->vscrollbar;
           may_scroll = may_vscroll (scrolled_window);
@@ -2983,6 +2996,7 @@ gtk_scrolled_window_scroll_event (GtkWidget      *widget,
         {
           GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (range));
           gdouble new_value;
+          gdouble delta;
 
           delta = _gtk_range_get_wheel_delta (GTK_RANGE (range), event);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]