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 *fifo_suffix = "main";
81 static gchar *first_uri = NULL;
82 static gdouble global_zoom = 1.0;
83 static GHashTable *keywords = NULL;
84 static gboolean language_is_set = FALSE;
85 static gchar *search_text = NULL;
86 static gboolean show_all_requests = FALSE;
87 static gboolean tabbed_automagic = TRUE;
91 adblock(WebKitWebView *web_view, WebKitWebFrame *frame,
92 WebKitWebResource *resource, WebKitNetworkRequest *request,
93 WebKitNetworkResponse *response, gpointer data)
95 GSList *it = adblock_patterns;
98 uri = webkit_network_request_get_uri(request);
99 if (show_all_requests)
100 fprintf(stderr, " -> %s\n", uri);
104 if (g_regex_match((GRegex *)(it->data), uri, 0, NULL))
106 webkit_network_request_set_uri(request, "about:blank");
107 if (show_all_requests)
108 fprintf(stderr, " BLOCKED!\n");
111 it = g_slist_next(it);
120 GIOChannel *channel = NULL;
121 gchar *path = NULL, *buf = NULL;
123 path = g_build_filename(g_get_user_config_dir(), __NAME__, "adblock.black",
125 channel = g_io_channel_new_file(path, "r", &err);
128 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
129 == G_IO_STATUS_NORMAL)
134 re = g_regex_new(buf,
135 G_REGEX_CASELESS | G_REGEX_OPTIMIZE,
136 G_REGEX_MATCH_PARTIAL, &err);
139 fprintf(stderr, __NAME__": Could not compile regex: %s\n", buf);
144 adblock_patterns = g_slist_append(adblock_patterns, re);
149 g_io_channel_shutdown(channel, FALSE, NULL);
154 client_destroy(GtkWidget *obj, gpointer data)
156 struct Client *c = (struct Client *)data;
166 client_destroy_request(WebKitWebView *web_view, gpointer data)
168 struct Client *c = (struct Client *)data;
170 gtk_widget_destroy(c->win);
176 client_new(const gchar *uri)
181 if (uri != NULL && cooperative_instances && !cooperative_alone)
183 write(cooperative_pipe_fp, uri, strlen(uri));
184 write(cooperative_pipe_fp, "\n", 1);
188 c = malloc(sizeof(struct Client));
191 fprintf(stderr, __NAME__": fatal: malloc failed\n");
198 c->win = gtk_plug_new(embed);
199 if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
201 fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
202 gtk_widget_destroy(c->win);
210 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
211 gtk_window_set_wmclass(GTK_WINDOW(c->win), __NAME__, __NAME_CAPITALIZED__);
214 /* When using Gtk2, it only shows a white area when run in suckless'
215 * tabbed. It appears we need to set a default window size for this
216 * to work. This is not needed when using Gtk3. */
217 gtk_window_set_default_size(GTK_WINDOW(c->win), 1024, 768);
219 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
220 gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
222 c->web_view = webkit_web_view_new();
224 /* XXX I really do want to enable this option. However, I get
225 * reproducable crashes with it enabled. I've seen bug reports from
226 * 2010 about this... WebKit crashes in libpixman, so maybe it's not
228 * Yeah, well. I'll turn it off for now. */
229 /*webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(c->web_view), TRUE);*/
231 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
232 g_signal_connect(G_OBJECT(c->web_view), "notify::title",
233 G_CALLBACK(changed_title), c);
234 g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
235 G_CALLBACK(changed_uri), c);
236 g_signal_connect(G_OBJECT(c->web_view), "notify::progress",
237 G_CALLBACK(changed_load_progress), c);
238 g_signal_connect(G_OBJECT(c->web_view), "create-web-view",
239 G_CALLBACK(client_new_request), NULL);
240 g_signal_connect(G_OBJECT(c->web_view), "close-web-view",
241 G_CALLBACK(client_destroy_request), c);
242 g_signal_connect(G_OBJECT(c->web_view),
243 "mime-type-policy-decision-requested",
244 G_CALLBACK(download_request), NULL);
245 g_signal_connect(G_OBJECT(c->web_view), "download-requested",
246 G_CALLBACK(download_handle), c);
247 g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
248 G_CALLBACK(key_web_view), c);
249 g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
250 G_CALLBACK(key_web_view), c);
251 g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
252 G_CALLBACK(key_web_view), c);
253 g_signal_connect(G_OBJECT(c->web_view), "hovering-over-link",
254 G_CALLBACK(hover_web_view), c);
255 g_signal_connect(G_OBJECT(c->web_view), "resource-request-starting",
256 G_CALLBACK(adblock), NULL);
258 if (!language_is_set)
260 g_object_set(webkit_get_default_session(), "accept-language",
261 accepted_language, NULL);
262 language_is_set = TRUE;
265 c->scroll = gtk_scrolled_window_new(NULL, NULL);
267 gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
269 c->location = gtk_entry_new();
270 g_signal_connect(G_OBJECT(c->location), "key-press-event",
271 G_CALLBACK(key_location), c);
273 c->progress = gtk_progress_bar_new();
274 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), 0);
276 c->status = gtk_progress_bar_new();
277 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
278 gtk_widget_set_size_request(c->status, 20, -1);
280 c->top_box = gtk_hbox_new(FALSE, 0);
281 gtk_box_pack_start(GTK_BOX(c->top_box), c->status, FALSE, FALSE, 2);
282 gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
283 gtk_box_pack_end(GTK_BOX(c->top_box), c->progress, FALSE, TRUE, 2);
285 c->vbox = gtk_vbox_new(FALSE, 0);
286 gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 2);
287 gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
289 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
291 gtk_widget_grab_focus(c->web_view);
292 gtk_widget_show_all(c->win);
296 f = ensure_url_scheme(uri);
297 if (show_all_requests)
298 fprintf(stderr, "====> %s\n", uri);
299 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
305 return WEBKIT_WEB_VIEW(c->web_view);
309 client_new_request(WebKitWebView *web_view, WebKitWebFrame *frame, gpointer data)
311 return client_new(NULL);
315 cooperation_setup(void)
318 gchar *fifofilename, *fifopath;
320 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", fifo_suffix);
321 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
322 g_free(fifofilename);
324 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
325 mkfifo(fifopath, 0600);
327 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
328 if (!cooperative_pipe_fp)
330 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
334 if (write(cooperative_pipe_fp, "", 0) == -1)
336 /* Could not do an empty write to the FIFO which means there's
337 * no one listening. */
338 close(cooperative_pipe_fp);
339 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
340 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
343 cooperative_alone = FALSE;
350 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
352 struct Client *c = (struct Client *)data;
355 p = webkit_web_view_get_progress(WEBKIT_WEB_VIEW(c->web_view));
356 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), p);
360 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
363 struct Client *c = (struct Client *)data;
365 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
366 gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
370 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
373 struct Client *c = (struct Client *)data;
375 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
376 gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
380 download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
382 struct Client *c = (struct Client *)data;
383 gchar *path, *path2 = NULL, *uri;
388 path = g_build_filename(download_dir,
389 webkit_download_get_suggested_filename(download),
391 path2 = g_strdup(path);
392 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
396 path2 = g_strdup_printf("%s.%d", path, suffix);
402 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
407 uri = g_filename_to_uri(path2, NULL, NULL);
408 webkit_download_set_destination_uri(download, uri);
412 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 1);
413 downloads_indicated++;
414 g_timeout_add(500, download_reset_indicator, c);
416 tb = gtk_tool_button_new_from_stock(GTK_STOCK_DELETE);
417 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb),
418 webkit_download_get_suggested_filename(download));
419 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
420 gtk_widget_show_all(dm.toolbar);
422 g_signal_connect(G_OBJECT(download), "notify::progress",
423 G_CALLBACK(downloadmanager_progress), tb);
425 g_object_ref(download);
426 g_signal_connect(G_OBJECT(tb), "clicked",
427 G_CALLBACK(downloadmanager_cancel), download);
437 download_reset_indicator(gpointer data)
439 struct Client *c = (struct Client *)data;
441 downloads_indicated--;
442 if (downloads_indicated == 0)
443 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
449 download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
450 WebKitNetworkRequest *request, gchar *mime_type,
451 WebKitWebPolicyDecision *policy_decision, gpointer data)
453 if (!webkit_web_view_can_show_mime_type(web_view, mime_type))
455 webkit_web_policy_decision_download(policy_decision);
462 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
464 WebKitDownload *download = WEBKIT_DOWNLOAD(data);
466 webkit_download_cancel(download);
467 g_object_unref(download);
469 gtk_widget_destroy(GTK_WIDGET(tb));
473 downloadmanager_progress(GObject *obj, GParamSpec *pspec, gpointer data)
475 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
476 GtkToolItem *tb = GTK_TOOL_ITEM(data);
479 gchar *t, *filename, *base;
481 p = webkit_download_get_progress(download) * 100;
483 uri = webkit_download_get_destination_uri(download);
484 filename = g_filename_from_uri(uri, NULL, NULL);
485 if (filename == NULL)
487 /* This really should not happen because WebKit uses that URI to
488 * write to a file... */
489 fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
490 t = g_strdup_printf("%s (%.0f%%)",
491 webkit_download_get_suggested_filename(download), p);
495 base = g_path_get_basename(filename);
496 t = g_strdup_printf("%s (%.0f%%)", base, p);
500 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
505 downloadmanager_setup(void)
507 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
508 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
509 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
510 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
511 g_signal_connect(G_OBJECT(dm.win), "delete-event",
512 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
513 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
514 G_CALLBACK(key_downloadmanager), NULL);
516 dm.toolbar = gtk_toolbar_new();
517 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
518 GTK_ORIENTATION_VERTICAL);
519 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
520 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
522 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
523 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
524 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
525 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(dm.scroll),
528 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
532 ensure_url_scheme(const gchar *t)
536 f = g_ascii_strdown(t, -1);
537 if (!g_str_has_prefix(f, "http:") &&
538 !g_str_has_prefix(f, "https:") &&
539 !g_str_has_prefix(f, "file:") &&
540 !g_str_has_prefix(f, "about:"))
543 f = g_strdup_printf("http://%s", t);
551 grab_environment_configuration(void)
555 e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
557 accepted_language = g_strdup(e);
559 e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
561 download_dir = g_strdup(e);
563 e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
565 fifo_suffix = g_strdup(e);
567 e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
569 global_zoom = atof(e);
573 hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri, gpointer data)
575 struct Client *c = (struct Client *)data;
577 if (!gtk_widget_is_focus(c->location))
580 gtk_entry_set_text(GTK_ENTRY(c->location),
581 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
583 gtk_entry_set_text(GTK_ENTRY(c->location), uri);
588 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
590 if (event->type == GDK_KEY_PRESS)
592 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
594 switch (((GdkEventKey *)event)->keyval)
596 case GDK_KEY_q: /* close window (left hand) */
597 gtk_widget_hide(dm.win);
607 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
609 struct Client *c = (struct Client *)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_destroy(c->win);
622 case GDK_KEY_d: /* download manager (left hand) */
623 gtk_widget_show_all(dm.win);
625 case GDK_KEY_r: /* reload (left hand) */
626 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
629 case GDK_KEY_k: /* initiate search (BOTH hands) */
630 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
631 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
637 switch (((GdkEventKey *)event)->keyval)
640 gtk_widget_grab_focus(c->web_view);
641 t = gtk_entry_get_text(GTK_ENTRY(c->location));
642 if (t != NULL && t[0] == '/')
644 if (search_text != NULL)
646 search_text = g_strdup(t + 1); /* XXX whacky */
649 else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
651 f = ensure_url_scheme(t);
652 if (show_all_requests)
653 fprintf(stderr, "====> %s\n", f);
654 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
659 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
660 gtk_entry_set_text(GTK_ENTRY(c->location),
661 (t == NULL ? __NAME__ : t));
671 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
673 struct Client *c = (struct Client *)data;
674 WebKitHitTestResultContext ht_context;
675 WebKitHitTestResult *ht_result = NULL;
676 gchar *ht_uri = NULL, *f;
680 if (event->type == GDK_KEY_PRESS)
682 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
684 switch (((GdkEventKey *)event)->keyval)
686 case GDK_KEY_q: /* close window (left hand) */
687 gtk_widget_destroy(c->win);
689 case GDK_KEY_w: /* home (left hand) */
690 f = ensure_url_scheme(first_uri);
691 if (show_all_requests)
692 fprintf(stderr, "====> %s\n", f);
693 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
696 case GDK_KEY_e: /* new tab (left hand) */
697 f = ensure_url_scheme(first_uri);
698 if (show_all_requests)
699 fprintf(stderr, "====> %s\n", f);
703 case GDK_KEY_r: /* reload (left hand) */
704 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
707 case GDK_KEY_s: /* toggle source view (left hand) */
708 b = webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(
711 webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(
713 webkit_web_view_reload(WEBKIT_WEB_VIEW(c->web_view));
715 case GDK_KEY_d: /* download manager (left hand) */
716 gtk_widget_show_all(dm.win);
718 case GDK_KEY_2: /* search forward (left hand) */
719 case GDK_KEY_n: /* search forward (maybe both hands) */
722 case GDK_KEY_3: /* search backward (left hand) */
725 case GDK_KEY_l: /* location (BOTH hands) */
726 gtk_widget_grab_focus(c->location);
728 case GDK_KEY_k: /* initiate search (BOTH hands) */
729 gtk_widget_grab_focus(c->location);
730 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
731 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
735 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
737 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
738 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), 0);
741 else if (event->type == GDK_BUTTON_PRESS)
743 switch (((GdkEventButton *)event)->button)
746 ht_result = webkit_web_view_get_hit_test_result(
747 WEBKIT_WEB_VIEW(c->web_view),
748 (GdkEventButton *)event);
749 g_object_get(ht_result, "context", &ht_context, NULL);
750 if (ht_context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
752 g_object_get(ht_result, "link-uri", &ht_uri, NULL);
754 g_object_unref(ht_result);
757 g_object_unref(ht_result);
760 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
763 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
767 else if (event->type == GDK_SCROLL)
769 if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
770 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
772 switch (((GdkEventScroll *)event)->direction)
775 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(
778 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
781 case GDK_SCROLL_DOWN:
782 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(
785 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
801 GIOChannel *channel = NULL;
802 gchar *path = NULL, *buf = NULL;
803 gchar **tokens = NULL;
805 keywords = g_hash_table_new(g_str_hash, g_str_equal);
807 path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
809 channel = g_io_channel_new_file(path, "r", &err);
812 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
813 == G_IO_STATUS_NORMAL)
818 tokens = g_strsplit(buf, " ", 2);
819 if (tokens[0] != NULL && tokens[1] != NULL)
820 g_hash_table_insert(keywords, tokens[0], tokens[1]);
827 g_io_channel_shutdown(channel, FALSE, NULL);
832 keywords_try_search(WebKitWebView *web_view, const gchar *t)
834 gboolean ret = FALSE;
835 gchar **tokens = NULL;
836 gchar *val = NULL, *uri = NULL;
838 tokens = g_strsplit(t, " ", 2);
839 if (tokens[0] != NULL && tokens[1] != NULL)
841 val = g_hash_table_lookup(keywords, tokens[0]);
844 uri = g_strdup_printf((gchar *)val, tokens[1]);
845 if (show_all_requests)
846 fprintf(stderr, "====> %s\n", uri);
847 webkit_web_view_load_uri(web_view, uri);
858 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
862 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
873 search(gpointer data, gint direction)
875 struct Client *c = (struct Client *)data;
877 if (search_text == NULL)
880 webkit_web_view_search_text(WEBKIT_WEB_VIEW(c->web_view), search_text,
881 FALSE, direction == 1, TRUE);
888 GIOChannel *tabbed_stdout_channel;
890 gchar *output = NULL;
891 char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
894 if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
895 NULL, NULL, NULL, &tabbed_stdout, NULL,
898 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
903 tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
904 g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
907 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
911 g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
914 plug_into = strtol(output, NULL, 16);
922 fprintf(stderr, "Usage: "__NAME__" [OPTION]... <URI>...\n");
928 main(int argc, char **argv)
932 gtk_init(&argc, &argv);
934 grab_environment_configuration();
936 while ((opt = getopt(argc, argv, "e:rCT")) != -1)
941 embed = atol(optarg);
942 tabbed_automagic = FALSE;
945 show_all_requests = TRUE;
948 cooperative_instances = FALSE;
951 tabbed_automagic = FALSE;
964 downloadmanager_setup();
966 if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
967 embed = tabbed_launch();
969 first_uri = g_strdup(argv[optind]);
970 for (i = optind; i < argc; i++)
972 if (!cooperative_instances || cooperative_alone)