Fix scrolling functionality
authorChip Black <bytex64@bytex64.net>
Wed, 16 Sep 2009 04:14:39 +0000 (23:14 -0500)
committerChip Black <bytex64@bytex64.net>
Wed, 16 Sep 2009 04:14:39 +0000 (23:14 -0500)
Added Scroll(x, y) and Bump(x, y) functions to WebThing.  Scroll moves
in pixels (or whatever unit measure Gtk uses), and Bump moves in default
scroll increments (like what you'd get if you used the arrow keys).

WebThing.cs
plugins/Vimish.cs

index 8bc589a..ff51354 100644 (file)
@@ -225,5 +225,18 @@ namespace bytex64.WebThing {
             wtv.WebView.Open(uri);
             return true;
         }
+
+        public void Scroll(double x, double y) {
+            ScrolledWindow.Hadjustment.Value += x;
+            if (ScrolledWindow.Hadjustment.Value > ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize)
+                ScrolledWindow.Hadjustment.Value = ScrolledWindow.Hadjustment.Upper - ScrolledWindow.Hadjustment.PageSize;
+            ScrolledWindow.Vadjustment.Value += y;
+            if (ScrolledWindow.Vadjustment.Value > ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize)
+                ScrolledWindow.Vadjustment.Value = ScrolledWindow.Vadjustment.Upper - ScrolledWindow.Vadjustment.PageSize;
+        }
+
+        public void Bump(int x, int y) {
+            Scroll(x * ScrolledWindow.Hadjustment.StepIncrement, y * ScrolledWindow.Vadjustment.StepIncrement);
+        }
     }
 }
index 51c2cfc..22f2532 100644 (file)
@@ -66,16 +66,16 @@ public class Vimish : WebThingPlugin {
         if (e.Event.State == Gdk.ModifierType.None) {
             switch(e.Event.Key) {
             case Gdk.Key.j:
-                wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement;
+                wt.Bump(0, 1);
                 break;
             case Gdk.Key.k:
-                wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement;
+                wt.Bump(0, -1);
                 break;
             case Gdk.Key.l:
-                wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement;
+                wt.Bump(1, 0);
                 break;
             case Gdk.Key.h:
-                wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement;
+                wt.Bump(-1, 0);
                 break;
             case Gdk.Key.r:
                 wv.Reload();