Fix fullscreen handling
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index 28bffef..035853a 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -154,7 +154,8 @@ static const char *getatom(Client *c, int a);
 static void gettogglestat(Client *c);
 static void getpagestat(Client *c);
 static char *geturi(Client *c);
-static gchar *getstyle(const char *uri);
+static const gchar *getstyle(const char *uri);
+static void setstyle(Client *c, const char *style);
 
 static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri);
 
@@ -645,20 +646,29 @@ geturi(Client *c)
        return uri;
 }
 
-gchar *
+const gchar *
 getstyle(const char *uri)
 {
        int i;
 
        if (stylefile != NULL)
-               return g_strconcat("file://", stylefile, NULL);
+               return stylefile;
 
        for (i = 0; i < LENGTH(styles); i++) {
                if (styles[i].regex && !regexec(&(styles[i].re), uri, 0,
                    NULL, 0))
-                       return g_strconcat("file://", styles[i].style, NULL);
+                       return styles[i].style;
        }
-       return g_strdup("");
+
+       return "";
+}
+
+void
+setstyle(Client *c, const char *style)
+{
+       WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
+
+       g_object_set(G_OBJECT(settings), "user-stylesheet-uri", style, NULL);
 }
 
 void
@@ -775,7 +785,6 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c)
        WebKitWebFrame *frame;
        WebKitWebDataSource *src;
        WebKitNetworkRequest *request;
-       WebKitWebSettings *set = webkit_web_view_get_settings(c->view);
        SoupMessage *msg;
        char *uri;
 
@@ -792,10 +801,8 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c)
                }
                setatom(c, AtomUri, uri);
 
-               if (enablestyles) {
-                       g_object_set(G_OBJECT(set), "user-stylesheet-uri",
-                                    getstyle(uri), NULL);
-               }
+               if (enablestyles)
+                       setstyle(c, getstyle(uri));
                break;
        case WEBKIT_LOAD_FINISHED:
                c->progress = 100;
@@ -996,11 +1003,6 @@ newclient(void)
        if (!(ua = getenv("SURF_USERAGENT")))
                ua = useragent;
        g_object_set(G_OBJECT(settings), "user-agent", ua, NULL);
-       if (enablestyles) {
-               g_object_set(G_OBJECT(settings),
-                            "user-stylesheet-uri", getstyle("about:blank"),
-                            NULL);
-       }
        g_object_set(G_OBJECT(settings),
                     "auto-load-images", loadimages, NULL);
        g_object_set(G_OBJECT(settings),
@@ -1017,6 +1019,8 @@ newclient(void)
                     "default-font-size", defaultfontsize, NULL);
        g_object_set(G_OBJECT(settings),
                     "resizable-text-areas", 1, NULL);
+       if (enablestyles)
+               setstyle(c, getstyle("about:blank"));
 
        /*
         * While stupid, CSS specifies that a pixel represents 1/96 of an inch.
@@ -1049,10 +1053,8 @@ newclient(void)
                c->isinspecting = false;
        }
 
-       if (runinfullscreen) {
-               c->fullscreen = 0;
+       if (runinfullscreen)
                fullscreen(c, NULL);
-       }
 
        setatom(c, AtomFind, "");
        setatom(c, AtomUri, "about:blank");
@@ -1285,8 +1287,8 @@ void
 setup(void)
 {
        int i;
-       char *proxy;
-       char *new_proxy;
+       char *proxy, *new_proxy;
+       char *styledirfile, *stylepath;
        SoupURI *puri;
        SoupSession *s;
        GError *error = NULL;
@@ -1306,8 +1308,8 @@ setup(void)
        cookiefile = buildfile(cookiefile);
        scriptfile = buildfile(scriptfile);
        cachefolder = buildpath(cachefolder);
-       styledir = buildpath(styledir);
        if (stylefile == NULL) {
+               styledir = buildpath(styledir);
                for (i = 0; i < LENGTH(styles); i++) {
                        if (regcomp(&(styles[i].re), styles[i].regex,
                            REG_EXTENDED)) {
@@ -1316,11 +1318,19 @@ setup(void)
                                        styles[i].regex);
                                styles[i].regex = NULL;
                        }
-                       styles[i].style = buildfile(g_strconcat(styledir, "/",
-                                                   styles[i].style, NULL));
+                       styledirfile    = g_strconcat(styledir, "/",
+                                                     styles[i].style, NULL);
+                       stylepath       = buildfile(styledirfile);
+                       styles[i].style = g_strconcat("file://", stylepath,
+                                                     NULL);
+                       g_free(styledirfile);
+                       g_free(stylepath);
                }
+               g_free(styledir);
        } else {
-               stylefile = buildfile(stylefile);
+               stylepath = buildfile(stylefile);
+               stylefile = g_strconcat("file://", stylepath, NULL);
+               g_free(stylepath);
        }
 
        /* request handler */
@@ -1522,12 +1532,8 @@ togglescrollbars(Client *c, const Arg *arg)
 void
 togglestyle(Client *c, const Arg *arg)
 {
-       WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
-       char *uri;
-
        enablestyles = !enablestyles;
-       uri = enablestyles ? getstyle(geturi(c)) : g_strdup("");
-       g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
+       setstyle(c, enablestyles ? getstyle(geturi(c)) : "");
 
        updatetitle(c);
 }
@@ -1677,10 +1683,10 @@ main(int argc, char *argv[])
                embed = strtol(EARGF(usage()), NULL, 0);
                break;
        case 'f':
-               runinfullscreen = 1;
+               runinfullscreen = 0;
                break;
        case 'F':
-               runinfullscreen = 0;
+               runinfullscreen = 1;
                break;
        case 'g':
                allowgeolocation = 0;