From 2744fefc32dbe9b59a570f6515d51121b8fcfbe3 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Tue, 15 Sep 2009 23:14:39 -0500 Subject: [PATCH] Fix scrolling functionality 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 | 13 +++++++++++++ plugins/Vimish.cs | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/WebThing.cs b/WebThing.cs index 8bc589a..ff51354 100644 --- a/WebThing.cs +++ b/WebThing.cs @@ -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); + } } } diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs index 51c2cfc..22f2532 100644 --- a/plugins/Vimish.cs +++ b/plugins/Vimish.cs @@ -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(); -- 2.25.1