scroll stuff, thx to jouz, with slight changes
authorPremysl 'Anydot' Hruby <dfenze@gmail.com>
Fri, 1 May 2009 12:35:32 +0000 (14:35 +0200)
committerPremysl 'Anydot' Hruby <dfenze@gmail.com>
Fri, 1 May 2009 12:35:32 +0000 (14:35 +0200)
examples/configs/sampleconfig
examples/configs/sampleconfig-dev
uzbl.c

index 230ef30..2f9df6f 100644 (file)
@@ -21,6 +21,10 @@ show_status = 1
 status_top = 0
 
 [bindings]
+j = scroll_down
+k = scroll_up
+h = scroll_left
+l = scroll_right
 b = back
 m = forward
 s = stop
@@ -33,10 +37,11 @@ w = follow_link_new_window
 + = zoom_in
 - = zoom_out
 t = toggle_status
-k = exit
+ZZ = exit
 i = insert_mode
 B = spawn /bin/bash /usr/share/uzbl/examples/scripts/insert_bookmark.sh
 u = spawn /bin/bash /usr/share/uzbl/examples/scripts/load_url_from_history.sh
 U = spawn /bin/bash /usr/share/uzbl/examples/scripts/load_url_from_bookmarks.sh
 
+
 [network]
index 35e7746..9fcc906 100644 (file)
@@ -21,6 +21,10 @@ show_status = 1
 status_top = 0
 
 [bindings]
+j = scroll_down
+k = scroll_up
+h = scroll_left
+l = scroll_right
 b = back
 m = forward
 s = stop
@@ -33,7 +37,7 @@ w = follow_link_new_window
 + = zoom_in
 - = zoom_out
 t = toggle_status
-k = exit
+ZZ = exit
 i = insert_mode
 B = spawn /bin/bash ./examples/scripts/insert_bookmark.sh
 u = spawn /bin/bash ./examples/scripts/load_url_from_history.sh
diff --git a/uzbl.c b/uzbl.c
index b767f4d..ca6c6ae 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
 static GtkWidget* main_window;
 static GtkWidget* mainbar;
 static GtkWidget* mainbar_label;
+static GtkScrollbar* scbar_v;   // Horizontal and Vertical Scrollbar 
+static GtkScrollbar* scbar_h;   // (These are still hidden)
+static GtkAdjustment* bar_v; // Information about document length
+static GtkAdjustment* bar_h; // and scrolling position
 static WebKitWebView* web_view;
 static gchar* main_title;
 static gchar selected_url[500] = "\0";
@@ -80,6 +84,8 @@ static gboolean insert_mode        = FALSE;
 static gboolean status_top         = FALSE;
 static gchar*   modkey             = NULL;
 static guint    modmask            = 0;
+static gdouble   hscroll            = 20;
+static gdouble   vscroll            = 20;
 
 /* settings from config: group bindings, key -> action */
 static GHashTable *bindings;
@@ -177,10 +183,45 @@ download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) {
     return (FALSE);
 }
 
+/* scroll a bar in a given direction */
+static void
+scroll (double i, GtkAdjustment* bar) {
+    gtk_adjustment_set_value (bar, gtk_adjustment_get_value(bar)+i);
+}
+
+static void scroll_up (WebKitWebView* page, const char *param) {
+    (void) page;
+    (void) param;
+
+    scroll (-vscroll, bar_v);
+}
+
+static void scroll_left (WebKitWebView* page, const char *param) {
+    (void) page;
+    (void) param;
+
+    scroll (-hscroll, bar_h);
+}
+
+static void scroll_down (WebKitWebView* page, const char *param) {
+    (void) page;
+    (void) param;
+
+    scroll (vscroll, bar_v);
+}
+
+static void scroll_right (WebKitWebView* page, const char *param) {
+    (void) page;
+    (void) param;
+
+    scroll (hscroll, bar_h);
+}
+
 static void
 toggle_status_cb (WebKitWebView* page, const char *param) {
     (void)page;
     (void)param;
+
     if (show_status) {
         gtk_widget_hide(mainbar);
     } else {
@@ -272,6 +313,10 @@ static struct {char *name; Command command;} cmdlist[] =
 {
     { "back",          view_go_back       },
     { "forward",       view_go_forward    },
+    { "scroll_down",   scroll_down        },
+    { "scroll_up",     scroll_up          },
+    { "scroll_left",   scroll_left        },
+    { "scroll_right",  scroll_right       },
     { "reload",        view_reload,       }, //Buggy
     { "refresh",       view_reload,       }, /* for convenience, will change */
     { "stop",          view_stop_loading, },
@@ -825,6 +870,12 @@ main (int argc, char* argv[]) {
     printf("window_id %i\n",(int) xwin);
     printf("pid %i\n", getpid ());
 
+    scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
+    bar_v = gtk_range_get_adjustment((GtkRange*) scbar_v);
+    scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
+    bar_h = gtk_range_get_adjustment((GtkRange*) scbar_h);
+    gtk_widget_set_scroll_adjustments ((GtkWidget*) web_view, bar_h, bar_v);
+
     if (!show_status)
         gtk_widget_hide(mainbar);