+WebKitWebView *
+newwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c) {
+ Client *n = newclient();
+ return n->view;
+}
+
+
+void
+pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d) {
+ Arg arg = {.v = text };
+ if(text != NULL)
+ loaduri((Client *) d, &arg);
+}
+
+GdkFilterReturn
+processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
+ Client *c = (Client *)d;
+ XPropertyEvent *ev;
+ Atom adummy;
+ int idummy;
+ unsigned long ldummy;
+ unsigned char *buf = NULL;
+ Arg arg;
+
+ if(((XEvent *)e)->type == PropertyNotify) {
+ ev = &((XEvent *)e)->xproperty;
+ if(ev->atom == urlprop && ev->state == PropertyNewValue) {
+ if(ignore_once)
+ ignore_once = FALSE;
+ else {
+ XGetWindowProperty(dpy, ev->window, urlprop, 0L, BUFSIZ, False, XA_STRING,
+ &adummy, &idummy, &ldummy, &ldummy, &buf);
+ arg.v = buf;
+ loaduri(c, &arg);
+ XFree(buf);
+ }
+ return GDK_FILTER_REMOVE;
+ }
+ }
+ return GDK_FILTER_CONTINUE;
+}
+
+void
+print(Client *c, const Arg *arg) {
+ webkit_web_frame_print(webkit_web_view_get_main_frame(c->view));
+}
+
+void
+progresschange(WebKitWebView* view, gint p, Client *c) {
+ c->progress = p;
+ update(c, NULL);
+}
+
+void
+request(SoupSession *s, SoupMessage *m, Client *c) {
+ soup_message_add_header_handler(m, "got-headers", "Set-Cookie",
+ G_CALLBACK(proccookies), c);
+}
+
+void
+reload(Client *c, const Arg *arg) {
+ gboolean nocache = *(gboolean *)arg;
+ if(nocache)
+ webkit_web_view_reload_bypass_cache(c->view);
+ else
+ webkit_web_view_reload(c->view);
+}
+
+void
+rereadcookies() {
+ const gchar *filename, *home;
+
+ home = g_get_home_dir();
+ filename = g_build_filename(home, ".surf", "cookies", NULL);
+}
+
+void
+setcookie(char *name, char *val, char *dom, char *path, long exp) {
+
+}
+
+void
+setup() {
+ dpy = GDK_DISPLAY();
+ session = webkit_get_default_session();
+ urlprop = XInternAtom(dpy, "_SURF_URL", False);
+}
+
+void
+showsearch(Client *c, const Arg *arg) {
+ hideurl(c, NULL);
+ gtk_widget_show(c->searchbar);
+ gtk_widget_grab_focus(c->searchbar);
+}
+
+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) {
+ update(c, t);
+}
+
+void
+usage() {
+ fputs("surf - simple browser\n", stderr);
+ die("usage: surf [-e] [-x] [uri]\n");
+}
+
+void
+update(Client *c, const char *title) {
+ gchar *t;
+
+ if(title) {
+ if(c->title)
+ g_free(c->title);
+ c->title = g_strdup(title);
+ }
+ 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
+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);
+}
+