+Client *
+newclient(void) {
+ Client *c;
+ if(!(c = calloc(1, sizeof(Client))))
+ die("Cannot malloc!\n");
+ /* Window */
+ if(embed) {
+ c->win = gtk_plug_new(0);
+ }
+ else {
+ c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf");
+ }
+ gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
+ g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
+ g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
+
+ /* VBox */
+ c->vbox = gtk_vbox_new(FALSE, 0);
+
+ /* scrolled window */
+ c->scroll = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll),
+ GTK_POLICY_NEVER, GTK_POLICY_NEVER);
+
+ /* webview */
+ c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c);
+ g_signal_connect(G_OBJECT(c->view), "load-progress-changed", G_CALLBACK(progresschange), c);
+ g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c);
+ g_signal_connect(G_OBJECT(c->view), "load-started", G_CALLBACK(loadstart), c);
+ g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
+ g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
+ g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
+ g_signal_connect_after(session, "request-started", G_CALLBACK(request), c);
+
+ /* urlbar */
+ c->urlbar = gtk_entry_new();
+ gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE);
+ g_signal_connect(G_OBJECT(c->urlbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
+
+ /* searchbar */
+ c->searchbar = gtk_entry_new();
+ gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
+ g_signal_connect(G_OBJECT(c->searchbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
+
+ /* indicator */
+ c->indicator = gtk_drawing_area_new();
+ gtk_widget_set_size_request(c->indicator, 0, 2);
+ g_signal_connect (G_OBJECT (c->indicator), "expose_event",
+ G_CALLBACK (exposeindicator), c);
+
+ /* downloadbar */
+
+ /* Arranging */
+ gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
+ gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
+ gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
+ gtk_container_add(GTK_CONTAINER(c->vbox), c->searchbar);
+ gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);
+ gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
+
+ /* Setup */
+ gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
+ gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);
+ gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START);
+ gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
+ gtk_widget_grab_focus(GTK_WIDGET(c->view));
+ gtk_widget_hide_all(c->searchbar);
+ gtk_widget_hide_all(c->urlbar);
+ gtk_widget_show(c->vbox);
+ gtk_widget_show(c->indicator);
+ gtk_widget_show(c->scroll);
+ gtk_widget_show(GTK_WIDGET(c->view));
+ gtk_widget_show(c->win);
+ gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK);
+ gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c);
+ webkit_web_view_set_full_content_zoom(c->view, TRUE);
+ c->download = NULL;
+ c->title = NULL;
+ c->next = clients;
+ clients = c;
+ if(showxid) {
+ gdk_display_sync(gtk_widget_get_display(c->win));
+ printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
+ fflush(NULL);
+ }
+ return c;
+}
+
+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;