+static void destroywin(GtkWidget* w, Client *c);
+static void die(char *str);
+static void drawindicator(Client *c);
+static gboolean exposeindicator(GtkWidget *w, GdkEventExpose *e, Client *c);
+static void find(Client *c, const Arg *arg);
+static const char *getatom(Client *c, int a);
+static char *geturi(Client *c);
+static gboolean initdownload(WebKitWebView *v, WebKitDownload *o, Client *c);
+static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
+static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
+static void loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
+static void loaduri(Client *c, const Arg *arg);
+static void navigate(Client *c, const Arg *arg);
+static Client *newclient(void);
+static void newwindow(Client *c, const Arg *arg, gboolean noembed);
+static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d);
+static void populatepopup(WebKitWebView *web, GtkMenu *menu, Client *c);
+static void popupactivate(GtkMenuItem *menu, Client *);
+static void print(Client *c, const Arg *arg);
+static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
+static void progresschange(WebKitWebView *view, GParamSpec *pspec, Client *c);
+static void reload(Client *c, const Arg *arg);
+static void scroll_h(Client *c, const Arg *arg);
+static void scroll_v(Client *c, const Arg *arg);
+static void scroll(GtkAdjustment *a, const Arg *arg);
+static void setatom(Client *c, int a, const char *v);
+static void setup(void);
+static void sigchld(int unused);
+static void source(Client *c, const Arg *arg);
+static void spawn(Client *c, const Arg *arg);
+static void eval(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 update(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"
+
+char *
+buildpath(const char *path) {
+ char *apath, *p;
+ FILE *f;
+
+ /* creating directory */
+ if(path[0] == '/')
+ apath = g_strdup(path);
+ else
+ apath = g_strconcat(g_get_home_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;
+}