+WebKitWebView *
+newwindow(WebKitWebView *v, WebKitWebFrame *f, gpointer d) {
+ Client *c = newclient();
+ return c->view;
+}
+
+void
+progresschange(WebKitWebView* view, gint p, gpointer d) {
+ Client *c = (Client *)d;
+
+ c->progress = p;
+ updatetitle(c, NULL);
+}
+
+GdkFilterReturn
+processx(GdkXEvent *e, GdkEvent *event, gpointer d) {
+ XPropertyEvent *ev;
+ Client *c = (Client *)d;
+ Atom adummy;
+ int idummy;
+ unsigned long ldummy;
+ unsigned char *buf = NULL;
+ if(((XEvent *)e)->type == PropertyNotify) {
+ ev = &((XEvent *)e)->xproperty;
+ if(ignore_once == FALSE && ev->atom == urlprop && ev->state == PropertyNewValue) {
+ XGetWindowProperty(dpy, ev->window, urlprop, 0L, BUFSIZ, False, XA_STRING,
+ &adummy, &idummy, &ldummy, &ldummy, &buf);
+ loaduri(c, (gchar *)buf);
+ XFree(buf);
+ return GDK_FILTER_REMOVE;
+ }
+ }
+ return GDK_FILTER_CONTINUE;
+}
+
+void setup(void) {
+ dpy = GDK_DISPLAY();
+ urlprop = XInternAtom(dpy, "_SURF_URL", False);
+}
+
+void
+showsearch(Client *c) {
+ hideurl(c);
+ gtk_widget_show(c->searchbar);
+ gtk_widget_grab_focus(c->searchbar);
+}
+
+void
+showurl(Client *c) {
+ gchar *uri;
+
+ hidesearch(c);
+ 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) {
+ 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, gpointer d) {
+ Client *c = (Client *)d;
+
+ updatetitle(c, t);
+}
+
+void
+updatetitle(Client *c, const char *title) {
+ char t[512];
+
+ if(title) {
+ if(c->title)
+ g_free(c->title);
+ c->title = g_strdup(title);
+ }
+ if(c->progress == 100)
+ snprintf(t, LENGTH(t), "%s", c->title);
+ else
+ snprintf(t, LENGTH(t), "%s [%i%%]", c->title, c->progress);
+ gtk_window_set_title(GTK_WINDOW(c->win), t);
+}
+