+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;
+ gint 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
+proccookies(SoupMessage *m, Client *c) {
+ GSList *l;
+ SoupCookie *co;
+ long t;
+
+ rereadcookies();
+ for (l = soup_cookies_from_response(m); l; l = l->next){
+ co = (SoupCookie *)l->data;
+ t = co->expires ? soup_date_to_time_t(co->expires) : 0;
+ setcookie(co->name, co->value, co->domain, co->value, t);
+ }
+ g_slist_free(l);
+}
+
+void
+progresschange(WebKitWebView* view, gint p, Client *c) {
+ c->progress = p;
+ update(c);
+}
+
+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(void) {
+ const gchar *filename, *home;
+
+ home = g_get_home_dir();
+ filename = g_build_filename(home, ".surf", "cookies", NULL);
+}
+
+void
+scroll(Client *c, const Arg *arg) {
+ gdouble v;
+ GtkAdjustment *a;
+
+ a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(c->scroll));
+ v = gtk_adjustment_get_value(a);
+ v += gtk_adjustment_get_step_increment(a) * arg->i;
+ v = MAX(v, 0.0);
+ v = MIN(v, gtk_adjustment_get_upper(a) - gtk_adjustment_get_page_size(a));
+ gtk_adjustment_set_value(a, v);
+}
+
+void
+setcookie(char *name, char *val, char *dom, char *path, long exp) {
+
+}
+
+void
+setup(void) {
+ 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
+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, c->source);*/
+ 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 TRUE;
+}
+
+void
+usage(void) {
+ fputs("surf - simple browser\n", stderr);
+ die("usage: surf [-e] [-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
+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);
+}
+