X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=e325126ae640de3fbc5ff31fc67a167e583aa211;hb=083ea8ecde50314cca961c7596a7ab43fc90223e;hp=ee4ab756135617f57ec459129d331e2f75101af2;hpb=c6fbbd9dc6c16b04fd6c59f891909f59474ee429;p=surf.git diff --git a/surf.c b/surf.c index ee4ab75..e325126 100644 --- a/surf.c +++ b/surf.c @@ -80,6 +80,7 @@ static gboolean usingproxy = 0; static char togglestat[6]; static char pagestat[3]; +static void addaccelgroup(Client *c); static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, WebKitNetworkRequest *req, WebKitNetworkResponse *resp, gpointer d); @@ -124,7 +125,9 @@ static gboolean inspector_show(WebKitWebInspector *i, Client *c); static gboolean inspector_close(WebKitWebInspector *i, Client *c); static void inspector_finished(WebKitWebInspector *i, Client *c); -static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c); +static gboolean keypress(GtkAccelGroup *group, + GObject *obj, guint key, GdkModifierType mods, + Client *c); static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c); static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, @@ -155,7 +158,7 @@ static void titlechange(WebKitWebView *v, WebKitWebFrame *frame, static void toggle(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, @@ -165,6 +168,20 @@ static void zoom(Client *c, const Arg *arg); /* configuration, allows nested code to access above variables */ #include "config.h" +static void +addaccelgroup(Client *c) { + int i; + GtkAccelGroup *group = gtk_accel_group_new(); + GClosure *closure; + + for(i = 0; i < LENGTH(keys); i++) { + closure = g_cclosure_new(G_CALLBACK(keypress), c, NULL); + gtk_accel_group_connect(group, keys[i].keyval, keys[i].mod, + 0, closure); + } + gtk_window_add_accel_group(GTK_WINDOW(c->win), group); +} + static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, WebKitNetworkRequest *req, WebKitNetworkResponse *resp, @@ -514,14 +531,17 @@ inspector_finished(WebKitWebInspector *i, Client *c) { } static gboolean -keypress(GtkWidget* w, GdkEventKey *ev, Client *c) { +keypress(GtkAccelGroup *group, GObject *obj, + guint key, GdkModifierType mods, Client *c) { guint i; gboolean processed = FALSE; + mods = CLEANMASK(mods); + key = gdk_keyval_to_lower(key); updatewinid(c); for(i = 0; i < LENGTH(keys); i++) { - if(gdk_keyval_to_lower(ev->keyval) == keys[i].keyval - && CLEANMASK(ev->state) == keys[i].mod + if(key == keys[i].keyval + && mods == keys[i].mod && keys[i].func) { keys[i].func(c, &(keys[i].arg)); processed = TRUE; @@ -539,7 +559,7 @@ linkhover(WebKitWebView *v, const char* t, const char* l, Client *c) { free(c->linkhover); c->linkhover = NULL; } - update(c); + updatetitle(c); } static void @@ -565,7 +585,7 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) { break; case WEBKIT_LOAD_FINISHED: c->progress = 100; - update(c); + updatetitle(c); break; default: break; @@ -577,12 +597,13 @@ loaduri(Client *c, const Arg *arg) { char *u, *rp; const char *uri = (char *)arg->v; Arg a = { .b = FALSE }; + struct stat st; if(strcmp(uri, "") == 0) return; /* In case it's a file path. */ - if(uri[0] == '/') { + if(stat(uri, &st) == 0) { rp = realpath(uri, NULL); u = g_strdup_printf("file://%s", rp); free(rp); @@ -599,7 +620,7 @@ loaduri(Client *c, const Arg *arg) { c->progress = 0; c->title = copystr(&c->title, u); g_free(u); - update(c); + updatetitle(c); } } @@ -644,11 +665,9 @@ newclient(void) { g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c); - if(!kioskmode) { - g_signal_connect(G_OBJECT(c->win), - "key-press-event", - G_CALLBACK(keypress), c); - } + + if(!kioskmode) + addaccelgroup(c); /* Pane */ c->pane = gtk_vpaned_new(); @@ -752,6 +771,8 @@ newclient(void) { enableinspector, NULL); g_object_set(G_OBJECT(settings), "enable-default-context-menu", kioskmode ^ 1, NULL); + g_object_set(G_OBJECT(settings), "default-font-size", + defaultfontsize, NULL); if(enableinspector) { c->inspector = WEBKIT_WEB_INSPECTOR( @@ -887,11 +908,12 @@ processx(GdkXEvent *e, GdkEvent *event, gpointer d) { if(ev->atom == atoms[AtomFind]) { arg.b = TRUE; find(c, &arg); + return GDK_FILTER_REMOVE; - } - else if(ev->atom == atoms[AtomGo]) { + } else if(ev->atom == atoms[AtomGo]) { arg.v = getatom(c, AtomGo); loaduri(c, &arg); + return GDK_FILTER_REMOVE; } } @@ -902,7 +924,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 @@ -1050,7 +1072,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 @@ -1115,7 +1137,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 @@ -1159,23 +1181,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); + 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); + } + + 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