X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=d36053e93506d25f440dba9ac6a166f417142f20;hb=9b1e1873b0929ff397abf5ba523390c9f01f807f;hp=55ffd841f76987b1bc462456319a67274197d342;hpb=d84fe71094e5eb2598344da5c6a1d6f64381142c;p=surf.git diff --git a/surf.c b/surf.c index 55ffd84..d36053e 100644 --- a/surf.c +++ b/surf.c @@ -155,6 +155,7 @@ static void gettogglestat(Client *c); static void getpagestat(Client *c); static char *geturi(Client *c); 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); @@ -272,6 +273,7 @@ buildfile(const char *path) g_free(dname); fpath = g_build_filename(bpath, bname, NULL); + g_free(bpath); g_free(bname); if (!(f = fopen(fpath, "a"))) @@ -662,6 +664,14 @@ getstyle(const char *uri) 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 handleplumb(Client *c, WebKitWebView *w, const gchar *uri) { @@ -686,10 +696,12 @@ initdownload(WebKitWebView *view, WebKitDownload *o, Client *c) void inspector(Client *c, const Arg *arg) { - if (c->isinspecting) - webkit_web_inspector_close(c->inspector); - else - webkit_web_inspector_show(c->inspector); + if (enableinspector) { + if (c->isinspecting) + webkit_web_inspector_close(c->inspector); + else + webkit_web_inspector_show(c->inspector); + } } WebKitWebView * @@ -776,7 +788,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; @@ -793,10 +804,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 (enablestyle) + setstyle(c, getstyle(uri)); break; case WEBKIT_LOAD_FINISHED: c->progress = 100; @@ -997,11 +1006,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), @@ -1018,6 +1022,8 @@ newclient(void) "default-font-size", defaultfontsize, NULL); g_object_set(G_OBJECT(settings), "resizable-text-areas", 1, NULL); + if (enablestyle) + setstyle(c, getstyle("about:blank")); /* * While stupid, CSS specifies that a pixel represents 1/96 of an inch. @@ -1050,10 +1056,8 @@ newclient(void) c->isinspecting = false; } - if (runinfullscreen) { - c->fullscreen = 0; + if (runinfullscreen) fullscreen(c, NULL); - } setatom(c, AtomFind, ""); setatom(c, AtomUri, "about:blank"); @@ -1531,11 +1535,8 @@ togglescrollbars(Client *c, const Arg *arg) void togglestyle(Client *c, const Arg *arg) { - WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); - - enablestyles = !enablestyles; - g_object_set(G_OBJECT(settings), "user-stylesheet-uri", - enablestyles ? getstyle(geturi(c)) : "", NULL); + enablestyle = !enablestyle; + setstyle(c, enablestyle ? getstyle(geturi(c)) : ""); updatetitle(c); } @@ -1566,7 +1567,7 @@ gettogglestat(Client *c) g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL); togglestat[p++] = value? 'V': 'v'; - togglestat[p++] = enablestyles ? 'M': 'm'; + togglestat[p++] = enablestyle ? 'M': 'm'; togglestat[p] = '\0'; } @@ -1624,7 +1625,7 @@ updatewinid(Client *c) void usage(void) { - die("usage: %s [-bBfFgGiIkKnNpPsSvx] [-a cookiepolicies ] " + die("usage: %s [-bBdDfFgGiIkKmMnNpPsSvx] [-a cookiepolicies ] " "[-c cookiefile] [-e xid] [-r scriptfile] [-t stylefile] " "[-u useragent] [-z zoomlevel] [uri]\n", basename(argv0)); } @@ -1685,10 +1686,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; @@ -1709,10 +1710,10 @@ main(int argc, char *argv[]) kioskmode = 1; break; case 'm': - enablestyles = 0; + enablestyle = 0; break; case 'M': - enablestyles = 1; + enablestyle = 1; break; case 'n': enableinspector = 0;