X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=da84e1c56a6fdf13e5f0a13ae8e78cc80d2ac0fd;hb=067c313e6ce1ab19116088d7e0b1618080c9b4a7;hp=e0ad8ea89ad9fb92aba45357066d11ddbb3f3c59;hpb=12101938d8df3da51871ed5d1da7c6144c2138cb;p=surf.git diff --git a/surf.c b/surf.c index e0ad8ea..da84e1c 100644 --- a/surf.c +++ b/surf.c @@ -77,7 +77,7 @@ static GdkNativeWindow embed = 0; static gboolean showxid = FALSE; static char winid[64]; static gboolean usingproxy = 0; -static char togglestat[6]; +static char togglestat[7]; static char pagestat[3]; static void addaccelgroup(Client *c); @@ -106,12 +106,16 @@ static gboolean decidedownload(WebKitWebView *v, WebKitWebFrame *f, static gboolean decidewindow(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, WebKitWebNavigationAction *n, WebKitWebPolicyDecision *p, Client *c); +static gboolean deletion_interface(WebKitWebView *view, + WebKitDOMHTMLElement *arg1, Client *c); static void destroyclient(Client *c); static void destroywin(GtkWidget* w, Client *c); static void die(const char *errstr, ...); static void eval(Client *c, const Arg *arg); static void find(Client *c, const Arg *arg); static void fullscreen(Client *c, const Arg *arg); +static void geopolicyrequested(WebKitWebView *v, WebKitWebFrame *f, + WebKitGeolocationPolicyDecision *d, Client *c); static const char *getatom(Client *c, int a); static void gettogglestat(Client *c); static void getpagestat(Client *c); @@ -156,9 +160,10 @@ static void stop(Client *c, const Arg *arg); static void titlechange(WebKitWebView *v, WebKitWebFrame *frame, const char *title, Client *c); static void toggle(Client *c, const Arg *arg); +static void togglegeolocation(Client *c, const Arg *arg); static void togglescrollbars(Client *c, const Arg *arg); static void togglestyle(Client *c, const Arg *arg); -static void update(Client *c); +static void updatetitle(Client *c); static void updatewinid(Client *c); static void usage(void); static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, @@ -386,6 +391,12 @@ decidewindow(WebKitWebView *view, WebKitWebFrame *f, WebKitNetworkRequest *r, return FALSE; } +static gboolean +deletion_interface(WebKitWebView *view, + WebKitDOMHTMLElement *arg1, Client *c) { + return FALSE; +} + static void destroyclient(Client *c) { Client *p; @@ -441,6 +452,16 @@ fullscreen(Client *c, const Arg *arg) { c->fullscreen = !c->fullscreen; } +static void +geopolicyrequested(WebKitWebView *v, WebKitWebFrame *f, + WebKitGeolocationPolicyDecision *d, Client *c) { + if(allowgeolocation) { + webkit_geolocation_policy_allow(d); + } else { + webkit_geolocation_policy_deny(d); + } +} + static const char * getatom(Client *c, int a) { static char buf[BUFSIZ]; @@ -559,7 +580,7 @@ linkhover(WebKitWebView *v, const char* t, const char* l, Client *c) { free(c->linkhover); c->linkhover = NULL; } - update(c); + updatetitle(c); } static void @@ -585,7 +606,7 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { break; case WEBKIT_LOAD_FINISHED: c->progress = 100; - update(c); + updatetitle(c); break; default: break; @@ -620,7 +641,7 @@ loaduri(Client *c, const Arg *arg) { c->progress = 0; c->title = copystr(&c->title, u); g_free(u); - update(c); + updatetitle(c); } } @@ -685,6 +706,9 @@ newclient(void) { g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c); + g_signal_connect(G_OBJECT(c->view), + "geolocation-policy-decision-requested", + G_CALLBACK(geopolicyrequested), c); g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(createwindow), c); @@ -715,6 +739,9 @@ newclient(void) { g_signal_connect(G_OBJECT(c->view), "resource-request-starting", G_CALLBACK(beforerequest), c); + g_signal_connect(G_OBJECT(c->view), + "should-show-delete-interface-for-element", + G_CALLBACK(deletion_interface), c); /* Scrolled Window */ c->scroll = gtk_scrolled_window_new(NULL, NULL); @@ -924,7 +951,7 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) { static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { c->progress = webkit_web_view_get_progress(c->view) * 100; - update(c); + updatetitle(c); } static void @@ -1072,7 +1099,7 @@ stop(Client *c, const Arg *arg) { static void titlechange(WebKitWebView *v, WebKitWebFrame *f, const char *t, Client *c) { c->title = copystr(&c->title, t); - update(c); + updatetitle(c); } static void @@ -1086,7 +1113,7 @@ toggle(Client *c, const Arg *arg) { g_object_get(G_OBJECT(settings), name, &value, NULL); g_object_set(G_OBJECT(settings), name, !value, NULL); - reload(c,&a); + reload(c, &a); } static void @@ -1107,6 +1134,15 @@ twitch(Client *c, const Arg *arg) { gtk_adjustment_set_value(a, v); } +static void +togglegeolocation(Client *c, const Arg *arg) { + Arg a = { .b = FALSE }; + + allowgeolocation ^= 1; + + reload(c, &a); +} + static void togglescrollbars(Client *c, const Arg *arg) { GtkPolicyType vspolicy; @@ -1137,7 +1173,7 @@ togglestyle(Client *c, const Arg *arg) { uri = uri[0] ? g_strdup("") : g_strconcat("file://", stylefile, NULL); g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL); - update(c); + updatetitle(c); } static void @@ -1150,19 +1186,21 @@ gettogglestat(Client *c){ &value, NULL); togglestat[0] = value? 'C': 'c'; + togglestat[1] = allowgeolocation? 'G': 'g'; + g_object_get(G_OBJECT(settings), "auto-load-images", &value, NULL); - togglestat[1] = value? 'I': 'i'; + togglestat[2] = value? 'I': 'i'; g_object_get(G_OBJECT(settings), "enable-scripts", &value, NULL); - togglestat[2] = value? 'S': 's'; + togglestat[3] = value? 'S': 's'; g_object_get(G_OBJECT(settings), "enable-plugins", &value, NULL); - togglestat[3] = value? 'V': 'v'; + togglestat[4] = value? 'V': 'v'; g_object_get(G_OBJECT(settings), "user-stylesheet-uri", &uri, NULL); - togglestat[4] = uri[0] ? 'M': 'm'; + togglestat[5] = uri[0] ? 'M': 'm'; - togglestat[5] = '\0'; + togglestat[6] = '\0'; } static void @@ -1181,23 +1219,29 @@ getpagestat(Client *c) { } static void -update(Client *c) { +updatetitle(Client *c) { char *t; - gettogglestat(c); - getpagestat(c); + 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); + } else { + t = g_strdup_printf("%s:%s | %s", togglestat, pagestat, + c->title); + } - 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); + gtk_window_set_title(GTK_WINDOW(c->win), t); + g_free(t); } else { - t = g_strdup_printf("%s:%s | %s", togglestat, pagestat, c->title); + gtk_window_set_title(GTK_WINDOW(c->win), c->title); } - - gtk_window_set_title(GTK_WINDOW(c->win), t); - g_free(t); } static void @@ -1251,6 +1295,9 @@ main(int argc, char *argv[]) { case 'e': embed = strtol(EARGF(usage()), NULL, 0); break; + case 'g': + allowgeolocation = 0; + break; case 'i': loadimages = 0; break;