- if(!(c = calloc(1, sizeof(Client))))
- die("Cannot malloc!\n");
- /* Window */
- if(embed) {
- c->win = gtk_plug_new(embed);
- }
- 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(createwindow), c);
- g_signal_connect(G_OBJECT(c->view), "new-window-policy-decision-requested", G_CALLBACK(decidewindow), c);
- g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
- g_signal_connect(G_OBJECT(c->view), "window-object-cleared", G_CALLBACK(windowobjectcleared), c);
- g_signal_connect_after(session, "request-started", G_CALLBACK(request), c);
- g_signal_connect(G_OBJECT(c->view), "focus-in-event", G_CALLBACK(focusview), c);
-
- /* urlbar */
- c->urlbar = gtk_entry_new();
- gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE);
-
- /* searchbar */
- c->searchbar = gtk_entry_new();
- gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
-
- /* 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);
-
- /* 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);
- settings = webkit_web_view_get_settings(c->view);
- g_object_set(G_OBJECT(settings), "user-agent", useragent, NULL);
- uri = g_strconcat("file://", stylefile, NULL);
- g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
- g_free(uri);
-
- 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);