-GdkFilterReturn
-processx(GdkXEvent *e, GdkEvent *event, gpointer data) {
- XPropertyEvent *ev;
- 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((gchar *)buf);
- XFree(buf);
- return GDK_FILTER_REMOVE;
+void
+cleanup(void) {
+ while(clients)
+ destroyclient(clients);
+}
+
+void
+destroyclient(Client *c) {
+ Client *p;
+
+ gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new()));
+ gtk_widget_destroy(c->scroll);
+ gtk_widget_destroy(c->urlbar);
+ gtk_widget_destroy(c->searchbar);
+ gtk_widget_destroy(c->vbox);
+ gtk_widget_destroy(c->win);
+ for(p = clients; p && p->next != c; p = p->next);
+ if(p)
+ p->next = c->next;
+ else
+ clients = c->next;
+ free(c);
+ if(clients == NULL)
+ gtk_main_quit();
+}
+
+void
+destroywin(GtkWidget* w, gpointer d) {
+ Client *c = (Client *)d;
+
+ destroyclient(c);
+}
+
+void die(char *str) {
+ fputs(str, stderr);
+ exit(EXIT_FAILURE);
+}
+
+void
+download(WebKitDownload *o, GParamSpec *pspec, gpointer d) {
+ Client *c = (Client *) d;
+ WebKitDownloadStatus status;
+
+ status = webkit_download_get_status(c->download);
+ if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) {
+ c->progress = (int)(webkit_download_get_progress(c->download)*100);
+ }
+ else {
+ stop(c);
+ }
+ updatetitle(c, NULL);
+}
+
+gboolean
+initdownload(WebKitWebView *view, WebKitDownload *o, gpointer d) {
+ Client *c = (Client *) d;
+ const gchar *home, *filename;
+ gchar *uri, *path;
+ GString *html = g_string_new("");
+
+ stop(c);
+ c->download = o;
+ home = g_get_home_dir();
+ filename = webkit_download_get_suggested_filename(o);
+ path = g_build_filename(home, ".surf", "dl",
+ filename, NULL);
+ uri = g_strconcat("file://", path, NULL);
+ webkit_download_set_destination_uri(c->download, uri);
+ c->progress = 0;
+ g_free(uri);
+ html = g_string_append(html, "Downloading <b>");
+ html = g_string_append(html, filename);
+ html = g_string_append(html, "</b>...");
+ webkit_web_view_load_html_string(c->view, html->str,
+ webkit_download_get_uri(c->download));
+ g_signal_connect(c->download, "notify::progress", G_CALLBACK(download), c);
+ g_signal_connect(c->download, "notify::status", G_CALLBACK(download), c);
+ webkit_download_start(c->download);
+ updatetitle(c, filename);
+ return TRUE;
+}
+
+gchar *
+geturi(Client *c) {
+ gchar *uri;
+
+ if(!(uri = (gchar *)webkit_web_view_get_uri(c->view)))
+ uri = g_strdup("about:blank");
+ return uri;
+}
+
+void
+hidesearch(Client *c) {
+ gtk_widget_hide(c->searchbar);
+ gtk_widget_grab_focus(GTK_WIDGET(c->view));
+}
+
+void
+hideurl(Client *c) {
+ gtk_widget_hide(c->urlbar);
+ gtk_widget_grab_focus(GTK_WIDGET(c->view));
+}
+
+gboolean
+keypress(GtkWidget* w, GdkEventKey *ev, gpointer d) {
+ Client *c = (Client *)d;
+
+ if(ev->type != GDK_KEY_PRESS)
+ return FALSE;
+ if(GTK_WIDGET_HAS_FOCUS(c->searchbar)) {
+ switch(ev->keyval) {
+ case GDK_Escape:
+ hidesearch(c);
+ return TRUE;
+ case GDK_Return:
+ webkit_web_view_search_text(c->view,
+ gtk_entry_get_text(GTK_ENTRY(c->searchbar)),
+ FALSE,
+ !(ev->state & GDK_SHIFT_MASK),
+ TRUE);
+ return TRUE;
+ case GDK_Left:
+ case GDK_Right:
+ return FALSE;