10 #include <gdk/gdkkeysyms.h>
12 #include <webkit/webkit.h>
15 static void adblock(WebKitWebView *, WebKitWebFrame *, WebKitWebResource *,
16 WebKitNetworkRequest *, WebKitNetworkResponse *, gpointer);
17 static void adblock_load(void);
18 static void client_destroy(GtkWidget *obj, gpointer data);
19 static gboolean client_destroy_request(WebKitWebView *, gpointer);
20 static WebKitWebView *client_new(const gchar *uri);
21 static WebKitWebView *client_new_request(WebKitWebView *, WebKitWebFrame *,
23 static void cooperation_setup(void);
24 static void changed_load_progress(GObject *obj, GParamSpec *pspec,
26 static void changed_title(GObject *, GParamSpec *, gpointer);
27 static void changed_uri(GObject *, GParamSpec *, gpointer);
28 static gboolean download_handle(WebKitWebView *, WebKitDownload *, gpointer);
29 static gboolean download_reset_indicator(gpointer);
30 static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
31 WebKitNetworkRequest *, gchar *,
32 WebKitWebPolicyDecision *, gpointer);
33 static void downloadmanager_cancel(GtkToolButton *, gpointer data);
34 static void downloadmanager_progress(GObject *obj, GParamSpec *pspec,
36 static void downloadmanager_setup(void);
37 static gchar *ensure_url_scheme(const gchar *);
38 static void grab_environment_configuration(void);
39 static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer);
40 static gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
41 static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
42 static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
43 static void keywords_load(void);
44 static gboolean keywords_try_search(WebKitWebView *, const gchar *);
45 static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
46 static void search(gpointer, gint);
47 static Window tabbed_launch(void);
48 static void usage(void);
63 struct DownloadManager
71 static gchar *accepted_language = "en-US";
72 static GSList *adblock_patterns = NULL;
73 static gint clients = 0;
74 static gboolean cooperative_alone = TRUE;
75 static gboolean cooperative_instances = TRUE;
76 static int cooperative_pipe_fp = 0;
77 static gchar *download_dir = "/tmp";
78 static gint downloads_indicated = 0;
79 static Window embed = 0;
80 static gchar *first_uri = NULL;
81 static gdouble global_zoom = 1.0;
82 static GHashTable *keywords = NULL;
83 static gboolean language_is_set = FALSE;
84 static gchar *search_text = NULL;
85 static gboolean show_all_requests = FALSE;
86 static gboolean tabbed_automagic = TRUE;
90 adblock(WebKitWebView *web_view, WebKitWebFrame *frame,
91 WebKitWebResource *resource, WebKitNetworkRequest *request,
92 WebKitNetworkResponse *response, gpointer data)
94 GSList *it = adblock_patterns;
103 uri = webkit_network_request_get_uri(request);
104 if (show_all_requests)
105 fprintf(stderr, " -> %s\n", uri);
109 if (g_regex_match((GRegex *)(it->data), uri, 0, NULL))
111 webkit_network_request_set_uri(request, "about:blank");
112 if (show_all_requests)
113 fprintf(stderr, " BLOCKED!\n");
116 it = g_slist_next(it);
125 GIOChannel *channel = NULL;
126 gchar *path = NULL, *buf = NULL;
128 path = g_build_filename(g_get_user_config_dir(), __NAME__, "adblock.black",
130 channel = g_io_channel_new_file(path, "r", &err);
133 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
134 == G_IO_STATUS_NORMAL)
139 re = g_regex_new(buf,
140 G_REGEX_CASELESS | G_REGEX_OPTIMIZE,
141 G_REGEX_MATCH_PARTIAL, &err);
144 fprintf(stderr, __NAME__": Could not compile regex: %s\n", buf);
149 adblock_patterns = g_slist_append(adblock_patterns, re);
154 g_io_channel_shutdown(channel, FALSE, NULL);
159 client_destroy(GtkWidget *obj, gpointer data)
161 struct Client *c = (struct Client *)data;
174 client_destroy_request(WebKitWebView *web_view, gpointer data)
176 struct Client *c = (struct Client *)data;
180 gtk_widget_destroy(c->win);
186 client_new(const gchar *uri)
191 if (uri != NULL && cooperative_instances && !cooperative_alone)
193 write(cooperative_pipe_fp, uri, strlen(uri));
194 write(cooperative_pipe_fp, "\n", 1);
198 c = malloc(sizeof(struct Client));
201 fprintf(stderr, __NAME__": fatal: malloc failed\n");
208 c->win = gtk_plug_new(embed);
209 if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
211 fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
212 gtk_widget_destroy(c->win);
220 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
221 gtk_window_set_wmclass(GTK_WINDOW(c->win), __NAME__, __NAME_CAPITALIZED__);
224 /* When using Gtk2, it only shows a white area when run in suckless'
225 * tabbed. It appears we need to set a default window size for this
226 * to work. This is not needed when using Gtk3. */
227 gtk_window_set_default_size(GTK_WINDOW(c->win), 1024, 768);
229 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
230 gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
232 c->web_view = webkit_web_view_new();
234 /* XXX I really do want to enable this option. However, I get
235 * reproducable crashes with it enabled. I've seen bug reports from
236 * 2010 about this... WebKit crashes in libpixman, so maybe it's not
238 * Yeah, well. I'll turn it off for now. */
239 /*webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(c->web_view), TRUE);*/
241 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
242 g_signal_connect(G_OBJECT(c->web_view), "notify::title",
243 G_CALLBACK(changed_title), c);
244 g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
245 G_CALLBACK(changed_uri), c);
246 g_signal_connect(G_OBJECT(c->web_view), "notify::progress",
247 G_CALLBACK(changed_load_progress), c);
248 g_signal_connect(G_OBJECT(c->web_view), "create-web-view",
249 G_CALLBACK(client_new_request), NULL);
250 g_signal_connect(G_OBJECT(c->web_view), "close-web-view",
251 G_CALLBACK(client_destroy_request), c);
252 g_signal_connect(G_OBJECT(c->web_view),
253 "mime-type-policy-decision-requested",
254 G_CALLBACK(download_request), NULL);
255 g_signal_connect(G_OBJECT(c->web_view), "download-requested",
256 G_CALLBACK(download_handle), c);
257 g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
258 G_CALLBACK(key_web_view), c);
259 g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
260 G_CALLBACK(key_web_view), c);
261 g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
262 G_CALLBACK(key_web_view), c);
263 g_signal_connect(G_OBJECT(c->web_view), "hovering-over-link",
264 G_CALLBACK(hover_web_view), c);
265 g_signal_connect(G_OBJECT(c->web_view), "resource-request-starting",
266 G_CALLBACK(adblock), NULL);
268 if (!language_is_set)
270 g_object_set(webkit_get_default_session(), "accept-language",
271 accepted_language, NULL);
272 language_is_set = TRUE;
275 c->scroll = gtk_scrolled_window_new(NULL, NULL);
277 gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
279 c->location = gtk_entry_new();
280 g_signal_connect(G_OBJECT(c->location), "key-press-event",
281 G_CALLBACK(key_location), c);
283 c->progress = gtk_progress_bar_new();
284 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), 0);
286 c->status = gtk_progress_bar_new();
287 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
288 gtk_widget_set_size_request(c->status, 20, -1);
290 c->top_box = gtk_hbox_new(FALSE, 0);
291 gtk_box_pack_start(GTK_BOX(c->top_box), c->status, FALSE, FALSE, 2);
292 gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
293 gtk_box_pack_end(GTK_BOX(c->top_box), c->progress, FALSE, TRUE, 2);
295 c->vbox = gtk_vbox_new(FALSE, 0);
296 gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 2);
297 gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
299 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
301 gtk_widget_grab_focus(c->web_view);
302 gtk_widget_show_all(c->win);
306 f = ensure_url_scheme(uri);
307 if (show_all_requests)
308 fprintf(stderr, "====> %s\n", uri);
309 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
315 return WEBKIT_WEB_VIEW(c->web_view);
319 client_new_request(WebKitWebView *web_view, WebKitWebFrame *frame, gpointer data)
325 return client_new(NULL);
329 cooperation_setup(void)
333 gchar *fifofilename, *fifopath;
335 e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
337 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", e);
339 fifofilename = g_strdup(__NAME__".fifo");
340 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
341 g_free(fifofilename);
343 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
344 mkfifo(fifopath, 0600);
346 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
347 if (!cooperative_pipe_fp)
349 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
353 if (write(cooperative_pipe_fp, "", 0) == -1)
355 /* Could not do an empty write to the FIFO which means there's
356 * no one listening. */
357 close(cooperative_pipe_fp);
358 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
359 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
362 cooperative_alone = FALSE;
369 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
371 struct Client *c = (struct Client *)data;
377 p = webkit_web_view_get_progress(WEBKIT_WEB_VIEW(c->web_view));
378 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), p);
382 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
385 struct Client *c = (struct Client *)data;
390 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
391 gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
395 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
398 struct Client *c = (struct Client *)data;
403 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
404 gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
408 download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
410 struct Client *c = (struct Client *)data;
411 gchar *path, *path2 = NULL, *uri;
419 path = g_build_filename(download_dir,
420 webkit_download_get_suggested_filename(download),
422 path2 = g_strdup(path);
423 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
427 path2 = g_strdup_printf("%s.%d", path, suffix);
433 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
438 uri = g_filename_to_uri(path2, NULL, NULL);
439 webkit_download_set_destination_uri(download, uri);
443 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 1);
444 downloads_indicated++;
445 g_timeout_add(500, download_reset_indicator, c);
447 tb = gtk_tool_button_new_from_stock(GTK_STOCK_DELETE);
448 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb),
449 webkit_download_get_suggested_filename(download));
450 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
451 gtk_widget_show_all(dm.toolbar);
453 g_signal_connect(G_OBJECT(download), "notify::progress",
454 G_CALLBACK(downloadmanager_progress), tb);
456 g_object_ref(download);
457 g_signal_connect(G_OBJECT(tb), "clicked",
458 G_CALLBACK(downloadmanager_cancel), download);
468 download_reset_indicator(gpointer data)
470 struct Client *c = (struct Client *)data;
472 downloads_indicated--;
473 if (downloads_indicated == 0)
474 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
480 download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
481 WebKitNetworkRequest *request, gchar *mime_type,
482 WebKitWebPolicyDecision *policy_decision, gpointer data)
488 if (!webkit_web_view_can_show_mime_type(web_view, mime_type))
490 webkit_web_policy_decision_download(policy_decision);
497 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
499 WebKitDownload *download = WEBKIT_DOWNLOAD(data);
501 webkit_download_cancel(download);
502 g_object_unref(download);
504 gtk_widget_destroy(GTK_WIDGET(tb));
508 downloadmanager_progress(GObject *obj, GParamSpec *pspec, gpointer data)
510 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
511 GtkToolItem *tb = GTK_TOOL_ITEM(data);
517 p = webkit_download_get_progress(download) * 100;
518 t = g_strdup_printf("%s (%.0f%%)",
519 webkit_download_get_suggested_filename(download),
521 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
526 downloadmanager_setup(void)
528 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
529 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
530 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
531 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
532 g_signal_connect(G_OBJECT(dm.win), "delete-event",
533 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
534 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
535 G_CALLBACK(key_downloadmanager), NULL);
537 dm.toolbar = gtk_toolbar_new();
538 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
539 GTK_ORIENTATION_VERTICAL);
540 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
541 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
543 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
544 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
545 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
546 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(dm.scroll),
549 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
553 ensure_url_scheme(const gchar *t)
557 f = g_ascii_strdown(t, -1);
558 if (!g_str_has_prefix(f, "http:") &&
559 !g_str_has_prefix(f, "https:") &&
560 !g_str_has_prefix(f, "file:") &&
561 !g_str_has_prefix(f, "about:"))
564 f = g_strdup_printf("http://%s", t);
572 grab_environment_configuration(void)
576 e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
578 accepted_language = g_strdup(e);
580 e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
582 download_dir = g_strdup(e);
584 e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
586 global_zoom = atof(e);
590 hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri, gpointer data)
592 struct Client *c = (struct Client *)data;
597 if (!gtk_widget_is_focus(c->location))
600 gtk_entry_set_text(GTK_ENTRY(c->location),
601 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
603 gtk_entry_set_text(GTK_ENTRY(c->location), uri);
608 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
613 if (event->type == GDK_KEY_PRESS)
615 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
617 switch (((GdkEventKey *)event)->keyval)
619 case GDK_KEY_q: /* close window (left hand) */
620 gtk_widget_hide(dm.win);
630 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
632 struct Client *c = (struct Client *)data;
638 if (event->type == GDK_KEY_PRESS)
640 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
642 switch (((GdkEventKey *)event)->keyval)
644 case GDK_KEY_q: /* close window (left hand) */
645 gtk_widget_destroy(c->win);
647 case GDK_KEY_d: /* download manager (left hand) */
648 gtk_widget_show_all(dm.win);
650 case GDK_KEY_r: /* reload (left hand) */
651 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
654 case GDK_KEY_k: /* initiate search (BOTH hands) */
655 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
656 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
662 switch (((GdkEventKey *)event)->keyval)
665 gtk_widget_grab_focus(c->web_view);
666 t = gtk_entry_get_text(GTK_ENTRY(c->location));
667 if (t != NULL && t[0] == '/')
669 if (search_text != NULL)
671 search_text = g_strdup(t + 1); /* XXX whacky */
674 else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
676 f = ensure_url_scheme(t);
677 if (show_all_requests)
678 fprintf(stderr, "====> %s\n", f);
679 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
684 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
685 gtk_entry_set_text(GTK_ENTRY(c->location),
686 (t == NULL ? __NAME__ : t));
696 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
698 struct Client *c = (struct Client *)data;
699 WebKitHitTestResultContext ht_context;
700 WebKitHitTestResult *ht_result = NULL;
701 gchar *ht_uri = NULL, *f;
706 if (event->type == GDK_KEY_PRESS)
708 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
710 switch (((GdkEventKey *)event)->keyval)
712 case GDK_KEY_q: /* close window (left hand) */
713 gtk_widget_destroy(c->win);
715 case GDK_KEY_w: /* home (left hand) */
716 f = ensure_url_scheme(first_uri);
717 if (show_all_requests)
718 fprintf(stderr, "====> %s\n", f);
719 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
722 case GDK_KEY_e: /* new tab (left hand) */
723 f = ensure_url_scheme(first_uri);
724 if (show_all_requests)
725 fprintf(stderr, "====> %s\n", f);
729 case GDK_KEY_r: /* reload (left hand) */
730 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
733 case GDK_KEY_d: /* download manager (left hand) */
734 gtk_widget_show_all(dm.win);
736 case GDK_KEY_2: /* search forward (left hand) */
737 case GDK_KEY_n: /* search forward (maybe both hands) */
740 case GDK_KEY_3: /* search backward (left hand) */
743 case GDK_KEY_l: /* location (BOTH hands) */
744 gtk_widget_grab_focus(c->location);
746 case GDK_KEY_k: /* initiate search (BOTH hands) */
747 gtk_widget_grab_focus(c->location);
748 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
749 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
753 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
755 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
756 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), 0);
759 else if (event->type == GDK_BUTTON_PRESS)
761 switch (((GdkEventButton *)event)->button)
764 ht_result = webkit_web_view_get_hit_test_result(
765 WEBKIT_WEB_VIEW(c->web_view),
766 (GdkEventButton *)event);
767 g_object_get(ht_result, "context", &ht_context, NULL);
768 if (ht_context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
770 g_object_get(ht_result, "link-uri", &ht_uri, NULL);
772 g_object_unref(ht_result);
775 g_object_unref(ht_result);
778 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
781 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
785 else if (event->type == GDK_SCROLL)
787 if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
788 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
790 switch (((GdkEventScroll *)event)->direction)
793 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(
796 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
799 case GDK_SCROLL_DOWN:
800 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(
803 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
819 GIOChannel *channel = NULL;
820 gchar *path = NULL, *buf = NULL;
821 gchar **tokens = NULL;
823 keywords = g_hash_table_new(g_str_hash, g_str_equal);
825 path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
827 channel = g_io_channel_new_file(path, "r", &err);
830 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
831 == G_IO_STATUS_NORMAL)
836 tokens = g_strsplit(buf, " ", 2);
837 if (tokens[0] != NULL && tokens[1] != NULL)
838 g_hash_table_insert(keywords, tokens[0], tokens[1]);
845 g_io_channel_shutdown(channel, FALSE, NULL);
850 keywords_try_search(WebKitWebView *web_view, const gchar *t)
852 gboolean ret = FALSE;
853 gchar **tokens = NULL;
854 gchar *val = NULL, *uri = NULL;
856 tokens = g_strsplit(t, " ", 2);
857 if (tokens[0] != NULL && tokens[1] != NULL)
859 val = g_hash_table_lookup(keywords, tokens[0]);
862 uri = g_strdup_printf((gchar *)val, tokens[1]);
863 if (show_all_requests)
864 fprintf(stderr, "====> %s\n", uri);
865 webkit_web_view_load_uri(web_view, uri);
876 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
883 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
894 search(gpointer data, gint direction)
896 struct Client *c = (struct Client *)data;
898 if (search_text == NULL)
901 webkit_web_view_search_text(WEBKIT_WEB_VIEW(c->web_view), search_text,
902 FALSE, direction == 1, TRUE);
909 GIOChannel *tabbed_stdout_channel;
911 gchar *output = NULL;
912 char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
915 if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
916 NULL, NULL, NULL, &tabbed_stdout, NULL,
919 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
924 tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
925 g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
928 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
932 g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
935 plug_into = strtol(output, NULL, 16);
943 fprintf(stderr, "Usage: "__NAME__" [OPTION]... <URI>...\n");
949 main(int argc, char **argv)
953 gtk_init(&argc, &argv);
955 grab_environment_configuration();
957 while ((opt = getopt(argc, argv, "e:rCT")) != -1)
962 embed = atol(optarg);
963 tabbed_automagic = FALSE;
966 show_all_requests = TRUE;
969 cooperative_instances = FALSE;
972 tabbed_automagic = FALSE;
985 downloadmanager_setup();
987 if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
988 embed = tabbed_launch();
990 first_uri = g_strdup(argv[optind]);
991 for (i = optind; i < argc; i++)
993 if (!cooperative_instances || cooperative_alone)