X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=e0ad8ea89ad9fb92aba45357066d11ddbb3f3c59;hb=12101938d8df3da51871ed5d1da7c6144c2138cb;hp=214b9c7b6384ec33b88cde612260957c43e4c1a8;hpb=fe3bd631d4e163e15ab685c22ad70c67f8b94f83;p=surf.git diff --git a/surf.c b/surf.c index 214b9c7..e0ad8ea 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, @@ -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; @@ -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); @@ -644,9 +665,9 @@ newclient(void) { g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c); - g_signal_connect(G_OBJECT(c->win), - "key-press-event", - G_CALLBACK(keypress), c); + + if(!kioskmode) + addaccelgroup(c); /* Pane */ c->pane = gtk_vpaned_new(); @@ -748,6 +769,10 @@ newclient(void) { enablespatialbrowsing, NULL); g_object_set(G_OBJECT(settings), "enable-developer-extras", 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( @@ -790,7 +815,7 @@ newclient(void) { static void newwindow(Client *c, const Arg *arg, gboolean noembed) { guint i = 0; - const char *cmd[11], *uri; + const char *cmd[12], *uri; const Arg a = { .v = (void *)cmd }; char tmp[64]; @@ -804,6 +829,8 @@ newwindow(Client *c, const Arg *arg, gboolean noembed) { } if(!loadimages) cmd[i++] = "-i"; + if(kioskmode) + cmd[i++] = "-k"; if(!enableplugins) cmd[i++] = "-p"; if(!enablescripts) @@ -881,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; } } @@ -1180,7 +1208,7 @@ updatewinid(Client *c) { static void usage(void) { - die("usage: %s [-binpsvx] [-c cookiefile] [-e xid] [-r scriptfile]" + die("usage: %s [-biknpsvx] [-c cookiefile] [-e xid] [-r scriptfile]" " [-t stylefile] [-u useragent] [uri]\n", basename(argv0)); } @@ -1226,6 +1254,9 @@ main(int argc, char *argv[]) { case 'i': loadimages = 0; break; + case 'k': + kioskmode = 1; + break; case 'n': enableinspector = 0; break;