small cleanups
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index dca14de..5d2a30d 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -37,6 +37,7 @@ typedef struct Client {
        char *title, *linkhover;
        gint progress;
        struct Client *next;
+       gboolean zoomed;
 } Client;
 
 typedef struct {
@@ -106,6 +107,7 @@ static void print(Client *c, const Arg *arg);
 static void progresschange(WebKitWebView *v, gint p, Client *c);
 static void reloadcookies();
 static void reload(Client *c, const Arg *arg);
+static void resize(GtkWidget *w, GtkAllocation *a, Client *c);
 static void sigchld(int unused);
 static void setup(void);
 static void spawn(Client *c, const Arg *arg);
@@ -343,7 +345,7 @@ geturi(Client *c) {
        char *uri;
 
        if(!(uri = (char *)webkit_web_view_get_uri(c->view)))
-               uri = copystr(NULL, "about:blank");
+               uri = "about:blank";
        return uri;
 }
 
@@ -470,6 +472,7 @@ newclient(void) {
        gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
        g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
        g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
+       g_signal_connect(G_OBJECT(c->win), "size-allocate", G_CALLBACK(resize), c);
 
        if(!(c->items = calloc(1, sizeof(GtkWidget *) * LENGTH(items))))
                die("Cannot malloc!\n");
@@ -674,6 +677,19 @@ scroll(Client *c, const Arg *arg) {
        gtk_adjustment_set_value(a, v);
 }
 
+void
+resize(GtkWidget *w, GtkAllocation *a, Client *c) {
+       double zoom;
+
+       if(c->zoomed)
+               return;
+       zoom = webkit_web_view_get_zoom_level(c->view);
+       if(a->width * a->height < 300 * 400 && zoom != 0.2)
+               webkit_web_view_set_zoom_level(c->view, 0.2);
+       else if(zoom != 1.0)
+               webkit_web_view_set_zoom_level(c->view, 1.0);
+}
+
 void
 sigchld(int unused) {
        if(signal(SIGCHLD, sigchld) == SIG_ERR)
@@ -824,12 +840,15 @@ windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObje
 
 void
 zoom(Client *c, const Arg *arg) {
+       c->zoomed = TRUE;
        if(arg->i < 0)          /* zoom out */
                webkit_web_view_zoom_out(c->view);
        else if(arg->i > 0)     /* zoom in */
                webkit_web_view_zoom_in(c->view);
-       else                    /* reset */
+       else {                  /* reset */
+               c->zoomed = FALSE;
                webkit_web_view_set_zoom_level(c->view, 1.0);
+       }
 }
 
 int main(int argc, char *argv[]) {