X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=601887a8ed4932119cdbdc0dfeaebd94e8fff11a;hb=5bca2223399bb18bada2a48db7411d181e3186e6;hp=52d9cddfa5a66d1b09db2a54bcf7e79688074d41;hpb=84611a5d29d9522fab954625349e5c5ee5572abb;p=surf.git diff --git a/surf.c b/surf.c index 52d9cdd..601887a 100644 --- a/surf.c +++ b/surf.c @@ -107,11 +107,12 @@ static Client *clients = NULL; static Window embed = 0; static gboolean showxid = FALSE; static char winid[64]; -static char togglestat[9]; -static char pagestat[3]; +static char togglestats[10]; +static char pagestats[2]; static GTlsDatabase *tlsdb; static int cookiepolicy; static char *stylefile = NULL; +static const char *useragent; static void addaccelgroup(Client *c); static char *buildfile(const char *path); @@ -142,8 +143,8 @@ static void togglefullscreen(Client *c, const Arg *a); static gboolean permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c); static const char *getatom(Client *c, int a); -static void gettogglestat(Client *c); -static void getpagestat(Client *c); +static void gettogglestats(Client *c); +static void getpagestats(Client *c); static char *geturi(Client *c); static const gchar *getstyle(const char *uri); static void setstyle(Client *c, const char *stylefile); @@ -899,7 +900,6 @@ newview(Client *c, WebKitWebView *rv) WebKitSettings *settings; WebKitUserContentManager *contentmanager; WebKitWebContext *context; - char *ua; /* Webview */ if (rv) { @@ -918,12 +918,17 @@ newview(Client *c, WebKitWebView *rv) "enable-javascript", enablescripts, "enable-plugins", enableplugins, NULL); - if (!(ua = getenv("SURF_USERAGENT"))) - ua = useragent; - webkit_settings_set_user_agent(settings, ua); /* Have a look at http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html * for more interesting settings */ + if (strcmp(fulluseragent, "")) { + webkit_settings_set_user_agent(settings, fulluseragent); + } else if (surfuseragent) { + webkit_settings_set_user_agent_with_application_details( + settings, "Surf", VERSION); + } + useragent = webkit_settings_get_user_agent(settings); + contentmanager = webkit_user_content_manager_new(); context = webkit_web_context_new_with_website_data_manager( @@ -1389,72 +1394,52 @@ togglestyle(Client *c, const Arg *arg) } void -gettogglestat(Client *c) +gettogglestats(Client *c) { - gboolean value; - int p = 0; - WebKitWebSettings *settings = webkit_web_view_get_settings(c->view); - - togglestat[p++] = cookiepolicy_set(cookiepolicy_get()); - - g_object_get(G_OBJECT(settings), "enable-caret-browsing", &value, - NULL); - togglestat[p++] = value? 'C': 'c'; - - togglestat[p++] = allowgeolocation? 'G': 'g'; - - togglestat[p++] = enablecache? 'D': 'd'; - - g_object_get(G_OBJECT(settings), "auto-load-images", &value, NULL); - togglestat[p++] = value? 'I': 'i'; - - g_object_get(G_OBJECT(settings), "enable-scripts", &value, NULL); - togglestat[p++] = value? 'S': 's'; - - g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL); - togglestat[p++] = value? 'V': 'v'; - - togglestat[p++] = enablestyle ? 'M': 'm'; - - togglestat[p] = '\0'; + togglestats[0] = cookiepolicy_set(cookiepolicy_get()); + togglestats[1] = enablecaretbrowsing ? 'C' : 'c'; + togglestats[2] = allowgeolocation ? 'G' : 'g'; + togglestats[3] = enablecache ? 'D' : 'd'; + togglestats[4] = loadimages ? 'I' : 'i'; + togglestats[5] = enablescripts ? 'S': 's'; + togglestats[6] = enableplugins ? 'V' : 'v'; + togglestats[7] = enablestyle ? 'M' : 'm'; + togglestats[8] = enableframeflattening ? 'F' : 'f'; + togglestats[9] = '\0'; } void -getpagestat(Client *c) +getpagestats(Client *c) { - const char *uri = geturi(c); - pagestats[0] = c->tlsflags > G_TLS_CERTIFICATE_VALIDATE_ALL ? '-' : c->tlsflags > 0 ? 'U' : 'T'; - pagestat[1] = '\0'; + pagestats[1] = '\0'; } void updatetitle(Client *c) { - char *t; + char *title; if (showindicators) { - gettogglestat(c); - getpagestat(c); - - if (c->linkhover) { - t = g_strdup_printf("%s:%s | %s", togglestat, pagestat, - c->linkhover); - } else if (c->progress != 100) { - t = g_strdup_printf("[%i%%] %s:%s | %s", c->progress, - togglestat, pagestat, - c->title == NULL ? "" : c->title); + gettogglestats(c); + getpagestats(c); + + if (c->progress != 100) { + title = g_strdup_printf("[%i%%] %s:%s | %s", + c->progress, togglestats, pagestats, + c->targeturi ? c->targeturi : c->title); } else { - t = g_strdup_printf("%s:%s | %s", togglestat, pagestat, - c->title == NULL ? "" : c->title); + title = g_strdup_printf("%s:%s | %s", + togglestats, pagestats, + c->targeturi ? c->targeturi : c->title); } - gtk_window_set_title(GTK_WINDOW(c->win), t); - g_free(t); + gtk_window_set_title(GTK_WINDOW(c->win), title); + g_free(title); } else { - gtk_window_set_title(GTK_WINDOW(c->win), (c->title == NULL) ? - "" : c->title); + gtk_window_set_title(GTK_WINDOW(c->win), c->title ? + c->title : ""); } }