+static void sigchld(int unused);
+static void source(Client *c, const Arg *arg);
+static void spawn(Client *c, const Arg *arg);
+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 updatetitle(Client *c);
+static void updatewinid(Client *c);
+static void usage(void);
+static void windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame,
+ JSContextRef js, JSObjectRef win, Client *c);
+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,
+ gpointer d) {
+ const gchar *uri = webkit_network_request_get_uri(req);
+
+ if(g_str_has_suffix(uri, "/favicon.ico"))
+ webkit_network_request_set_uri(req, "about:blank");
+}
+
+static char *
+buildpath(const char *path) {
+ char *apath, *p;
+ FILE *f;
+
+ /* creating directory */
+ if(path[0] == '/') {
+ apath = g_strdup(path);
+ } else if(path[0] == '~') {
+ if(path[1] == '/') {
+ apath = g_strconcat(g_get_home_dir(), &path[1], NULL);
+ } else {
+ apath = g_strconcat(g_get_home_dir(), "/",
+ &path[1], NULL);
+ }
+ } else {
+ apath = g_strconcat(g_get_current_dir(), "/", path, NULL);
+ }
+
+ if((p = strrchr(apath, '/'))) {
+ *p = '\0';
+ g_mkdir_with_parents(apath, 0700);
+ g_chmod(apath, 0700); /* in case it existed */
+ *p = '/';
+ }
+ /* creating file (gives error when apath ends with "/") */
+ if((f = fopen(apath, "a"))) {
+ g_chmod(apath, 0600); /* always */
+ fclose(f);
+ }
+
+ return apath;
+}
+
+static gboolean
+buttonrelease(WebKitWebView *web, GdkEventButton *e, GList *gl) {
+ WebKitHitTestResultContext context;
+ WebKitHitTestResult *result = webkit_web_view_get_hit_test_result(web,
+ e);
+ Arg arg;
+
+ g_object_get(result, "context", &context, NULL);
+ if(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
+ if(e->button == 2) {
+ g_object_get(result, "link-uri", &arg.v, NULL);
+ newwindow(NULL, &arg, e->state & GDK_CONTROL_MASK);
+ return true;
+ }
+ }
+ return false;
+}
+
+static void