This patch enables zooming text only, i.e. increase/decrease font size
and preserve other elements' sizes.

--s_
diff -r 51a6d05c2c84 config.def.h
--- a/config.def.h      Mon Mar 26 09:33:42 2012 +0200
+++ b/config.def.h      Thu May 31 19:30:14 2012 +0200
@@ -32,6 +32,9 @@
     { MODKEY|GDK_SHIFT_MASK,GDK_j,      zoom,       { .i = -1 } },
     { MODKEY|GDK_SHIFT_MASK,GDK_k,      zoom,       { .i = +1 } },
     { MODKEY|GDK_SHIFT_MASK,GDK_i,      zoom,       { .i = 0  } },
+    { MODKEY,               GDK_underscore,  zoomtext,   { .i = -1 } },
+    { MODKEY,               GDK_plus,        zoomtext,   { .i = +1 } },
+    { MODKEY,               GDK_parenright,  zoomtext,   { .i = 0 } },
     { MODKEY,               GDK_l,      navigate,   { .i = +1 } },
     { MODKEY,               GDK_h,      navigate,   { .i = -1 } },
     { MODKEY,               GDK_j,      scroll,     { .i = +1 } },
diff -r 51a6d05c2c84 surf.c
--- a/surf.c    Mon Mar 26 09:33:42 2012 +0200
+++ b/surf.c    Thu May 31 19:30:14 2012 +0200
@@ -111,6 +111,7 @@
 static void usage(void);
 static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, 
JSContextRef js, JSObjectRef win, Client *c);
 static void zoom(Client *c, const Arg *arg);
+static void zoomtext(Client *c, const Arg *arg);
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
@@ -828,6 +829,19 @@
 }
 
 void
+zoomtext(Client *c, const Arg *arg) {
+       WebKitWebSettings *settings;
+       gint fontsize;
+
+       settings = webkit_web_view_get_settings(c->view);
+       g_object_get(G_OBJECT(settings), "default-font-size", &fontsize, NULL);
+       //default size according to webkit docs is 12;
+       //FIXME: figure out how to get setting defaults
+       fontsize = (arg->i == 0 ?  12 : fontsize + arg->i);
+       g_object_set(G_OBJECT(settings), "default-font-size", fontsize, NULL);
+}
+
+void
 zoom(Client *c, const Arg *arg) {
        c->zoomed = TRUE;
        if(arg->i < 0)          /* zoom out */

Reply via email to