+
+ dpy = GDK_DISPLAY();
+ session = webkit_get_default_session();
+ urlprop = XInternAtom(dpy, "_SURF_URL", False);
+
+ /* create dirs and files */
+ cookiefile = buildpath(cookiefile);
+ dldir = buildpath(dldir);
+ scriptfile = buildpath(scriptfile);
+ stylefile = buildpath(stylefile);
+
+ /* cookie persistance */
+ s = webkit_get_default_session();
+ cookiejar = soup_cookie_jar_text_new(cookiefile, FALSE);
+ soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
+}
+
+void
+showsearch(Client *c, const Arg *arg) {
+ hideurl(c, NULL);
+ gtk_widget_show(c->searchbar);
+ gtk_widget_grab_focus(c->searchbar);
+}
+
+void
+source(Client *c, const Arg *arg) {
+ Arg a = { .b = FALSE };
+ gboolean s;
+
+ s = webkit_web_view_get_view_source_mode(c->view);
+ webkit_web_view_set_view_source_mode(c->view, !s);
+ reload(c, &a);
+}
+
+void
+searchtext(Client *c, const Arg *arg) {
+ gboolean forward = *(gboolean *)arg;
+ webkit_web_view_search_text(c->view,
+ gtk_entry_get_text(GTK_ENTRY(c->searchbar)),
+ FALSE,
+ forward,
+ TRUE);
+}
+
+void
+showurl(Client *c, const Arg *arg) {
+ gchar *uri;
+
+ hidesearch(c, NULL);
+ uri = geturi(c);
+ gtk_entry_set_text(GTK_ENTRY(c->urlbar), uri);
+ gtk_widget_show(c->urlbar);
+ gtk_widget_grab_focus(c->urlbar);
+}
+
+void
+stop(Client *c, const Arg *arg) {
+ if(c->download)
+ webkit_download_cancel(c->download);
+ else
+ webkit_web_view_stop_loading(c->view);
+ c->download = NULL;
+}
+
+void
+titlechange(WebKitWebView *v, WebKitWebFrame *f, const gchar *t, Client *c) {
+ c->title = copystr(&c->title, t);
+ update(c);
+}
+
+gboolean
+unfocusbar(GtkWidget *w, GdkEventFocus *e, Client *c) {
+ hidesearch(c, NULL);
+ hideurl(c, NULL);
+ return FALSE;
+}
+
+void
+usage(void) {
+ fputs("surf - simple browser\n", stderr);
+ die("usage: surf [-e Window] [-x] [uri]\n");
+}
+
+void
+update(Client *c) {
+ gchar *t;
+
+ if(c->progress == 100)
+ t = g_strdup(c->title);
+ else
+ t = g_strdup_printf("%s [%i%%]", c->title, c->progress);
+ drawindicator(c);
+ gtk_window_set_title(GTK_WINDOW(c->win), t);
+ g_free(t);
+
+}
+
+void
+windowobjectcleared(GtkWidget *w, WebKitWebFrame *frame, JSContextRef js, JSObjectRef win, Client *c) {
+ JSStringRef jsscript;
+ gchar *script;
+ JSValueRef exception = NULL;
+ GError *error;
+
+ if(g_file_get_contents(scriptfile, &script, NULL, &error)) {
+ jsscript = JSStringCreateWithUTF8CString(script);
+ JSEvaluateScript(js, jsscript, JSContextGetGlobalObject(js), NULL, 0, &exception);
+ }
+}
+
+void
+zoom(Client *c, const Arg *arg) {
+ if(arg->i < 0) /* zoom out */
+ webkit_web_view_zoom_out(c->view);
+ else if(arg->i > 0) /* zoom in */
+ webkit_web_view_zoom_in(c->view);
+ else /* reset */
+ webkit_web_view_set_zoom_level(c->view, 1.0);
+}
+
+int main(int argc, char *argv[]) {
+ int i;
+ Arg arg;
+
+ /* command line args */
+ for(i = 1, arg.v = NULL; i < argc; i++) {
+ if(!strcmp(argv[i], "-x"))