]> git.armaanb.net Git - chorizo.git/blob - browser.c
Open new windows on middle click
[chorizo.git] / browser.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <string.h>
7
8 #include <gtk/gtk.h>
9 #include <gdk/gdkx.h>
10 #include <gdk/gdkkeysyms.h>
11 #include <gio/gio.h>
12 #include <webkit/webkit.h>
13
14
15 #define DOWNLOAD_DIR "/tmp/tmp"
16 #define LANGUAGE "en-US"
17
18
19 static void adblock(WebKitWebView *, WebKitWebFrame *, WebKitWebResource *,
20                     WebKitNetworkRequest *, WebKitNetworkResponse *, gpointer);
21 static void adblock_load(void);
22 static void client_destroy(GtkWidget *, gpointer);
23 static void client_new(const gchar *uri);
24 static gboolean client_new_request(WebKitWebView *, WebKitWebFrame *,
25                                    WebKitNetworkRequest *,
26                                    WebKitWebNavigationAction *,
27                                    WebKitWebPolicyDecision *, gpointer);
28 static void cooperation_setup(void);
29 static void changed_load_status(GObject *obj, GParamSpec *pspec,
30                                 gpointer data);
31 static void changed_title(GObject *, GParamSpec *, gpointer);
32 static void changed_uri(GObject *, GParamSpec *, gpointer);
33 static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
34                                  WebKitNetworkRequest *, gchar *,
35                                  WebKitWebPolicyDecision *, gpointer);
36 static gboolean download_wget(WebKitWebView *, WebKitDownload *, gpointer);
37 static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer);
38 static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
39 static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
40 static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
41 static void search(gpointer, gint);
42 static void scroll(GtkAdjustment *, gint, gdouble);
43 static Window tabbed_launch(void);
44 static void usage(void);
45
46
47 struct Client
48 {
49         GtkWidget *win;
50         GtkWidget *vbox;
51         GtkWidget *location;
52         GtkWidget *status;
53         GtkWidget *scroll;
54         GtkWidget *web_view;
55 };
56
57
58 static GSList *adblock_patterns = NULL;
59 static gint clients = 0;
60 static gboolean cooperative_alone = TRUE;
61 static gboolean cooperative_instances = TRUE;
62 static int cooperative_pipe_fp = 0;
63 static Window embed = 0;
64 static gchar *first_uri = NULL;
65 static gdouble global_zoom = 1.0;
66 static gboolean language_is_set = FALSE;
67 static gchar *search_text = NULL;
68 static gboolean show_all_requests = FALSE;
69 static gboolean tabbed_automagic = TRUE;
70
71
72 void
73 adblock(WebKitWebView *web_view, WebKitWebFrame *frame,
74         WebKitWebResource *resource, WebKitNetworkRequest *request,
75         WebKitNetworkResponse *response, gpointer data)
76 {
77         GSList *it = adblock_patterns;
78         const gchar *uri;
79
80         (void)web_view;
81         (void)frame;
82         (void)resource;
83         (void)response;
84         (void)data;
85
86         uri = webkit_network_request_get_uri(request);
87         if (show_all_requests)
88                 fprintf(stderr, "-> %s\n", uri);
89
90         while (it)
91         {
92                 if (g_regex_match((GRegex *)(it->data), uri, 0, NULL))
93                 {
94                         webkit_network_request_set_uri(request, "about:blank");
95                         if (show_all_requests)
96                                 fprintf(stderr, "\tBLOCKED!\n");
97                         return;
98                 }
99                 it = g_slist_next(it);
100         }
101 }
102
103 void
104 adblock_load(void)
105 {
106         GRegex *re = NULL;
107         GError *err = NULL;
108         GIOChannel *channel = NULL;
109         gchar *path = NULL;
110         gchar *buf = NULL;
111
112         path = g_build_filename(g_get_user_config_dir(), __NAME__, "adblock.black",
113                                 NULL);
114         channel = g_io_channel_new_file(path, "r", &err);
115         if (channel != NULL)
116         {
117                 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
118                        == G_IO_STATUS_NORMAL)
119                 {
120                         g_strstrip(buf);
121                         re = g_regex_new(buf,
122                                          G_REGEX_CASELESS | G_REGEX_OPTIMIZE,
123                                          G_REGEX_MATCH_PARTIAL, &err);
124                         if (err != NULL)
125                         {
126                                 fprintf(stderr, __NAME__": Could not compile regex: %s\n", buf);
127                                 g_error_free(err);
128                                 err = NULL;
129                         }
130                         adblock_patterns = g_slist_append(adblock_patterns, re);
131
132                         g_free(buf);
133                 }
134         }
135         g_free(path);
136 }
137
138 void
139 client_destroy(GtkWidget *obj, gpointer data)
140 {
141         struct Client *c = (struct Client *)data;
142
143         (void)obj;
144
145         webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
146         gtk_widget_destroy(c->web_view);
147         gtk_widget_destroy(c->scroll);
148         gtk_widget_destroy(c->status);
149         gtk_widget_destroy(c->location);
150         gtk_widget_destroy(c->vbox);
151         gtk_widget_destroy(c->win);
152         free(c);
153
154         clients--;
155         if (clients == 0)
156                 gtk_main_quit();
157 }
158
159 void
160 client_new(const gchar *uri)
161 {
162         struct Client *c;
163         gchar *capitalized_name = NULL;
164
165         if (cooperative_instances && !cooperative_alone)
166         {
167                 write(cooperative_pipe_fp, uri, strlen(uri));
168                 write(cooperative_pipe_fp, "\n", 1);
169                 return;
170         }
171
172         c = malloc(sizeof(struct Client));
173         if (!c)
174         {
175                 fprintf(stderr, __NAME__": fatal: malloc failed\n");
176                 exit(EXIT_FAILURE);
177         }
178
179         c->win = NULL;
180         if (embed != 0)
181         {
182                 c->win = gtk_plug_new(embed);
183                 if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
184                 {
185                         fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
186                         gtk_widget_destroy(c->win);
187                         c->win = NULL;
188                         embed = 0;
189                 }
190         }
191
192         if (c->win == NULL)
193         {
194                 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
195
196                 capitalized_name = g_strdup(__NAME__);
197                 capitalized_name[0] = g_ascii_toupper(capitalized_name[0]);
198                 gtk_window_set_wmclass(GTK_WINDOW(c->win), __NAME__, capitalized_name);
199                 g_free(capitalized_name);
200         }
201
202         /* When using Gtk2, it only shows a white area when run in suckless'
203          * tabbed. It appears we need to set a default window size for this
204          * to work. This is not needed when using Gtk3. */
205         gtk_window_set_default_size(GTK_WINDOW(c->win), 1024, 768);
206
207         g_signal_connect(G_OBJECT(c->win), "destroy",
208                          G_CALLBACK(client_destroy), c);
209         gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
210
211         c->web_view = webkit_web_view_new();
212         webkit_web_view_set_full_content_zoom(WEBKIT_WEB_VIEW(c->web_view), TRUE);
213         webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
214         g_signal_connect(G_OBJECT(c->web_view), "notify::title",
215                          G_CALLBACK(changed_title), c);
216         g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
217                          G_CALLBACK(changed_uri), c);
218         g_signal_connect(G_OBJECT(c->web_view), "notify::load-status",
219                          G_CALLBACK(changed_load_status), c);
220         g_signal_connect(G_OBJECT(c->web_view),
221                          "new-window-policy-decision-requested",
222                          G_CALLBACK(client_new_request), NULL);
223         g_signal_connect(G_OBJECT(c->web_view),
224                          "mime-type-policy-decision-requested",
225                          G_CALLBACK(download_request), NULL);
226         g_signal_connect(G_OBJECT(c->web_view), "download-requested",
227                          G_CALLBACK(download_wget), NULL);
228         g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
229                          G_CALLBACK(key_web_view), c);
230         g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
231                          G_CALLBACK(key_web_view), c);
232         g_signal_connect(G_OBJECT(c->web_view), "hovering-over-link",
233                          G_CALLBACK(hover_web_view), c);
234         g_signal_connect(G_OBJECT(c->web_view), "resource-request-starting",
235                          G_CALLBACK(adblock), NULL);
236
237         if (!language_is_set)
238         {
239                 g_object_set(webkit_get_default_session(), "accept-language", LANGUAGE,
240                              NULL);
241                 language_is_set = TRUE;
242         }
243
244         c->scroll = gtk_scrolled_window_new(NULL, NULL);
245
246         gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
247
248         c->location = gtk_entry_new();
249         g_signal_connect(G_OBJECT(c->location), "key-press-event",
250                          G_CALLBACK(key_location), c);
251
252         c->status = gtk_statusbar_new();
253         gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(c->status), FALSE);
254
255         c->vbox = gtk_vbox_new(FALSE, 2);
256         gtk_box_pack_start(GTK_BOX(c->vbox), c->location, FALSE, FALSE, 0);
257         gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
258         gtk_box_pack_end(GTK_BOX(c->vbox), c->status, FALSE, FALSE, 0);
259
260         gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
261
262         gtk_widget_grab_focus(c->web_view);
263         gtk_widget_show_all(c->win);
264
265         webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), uri);
266
267         clients++;
268 }
269
270 gboolean
271 client_new_request(WebKitWebView *web_view, WebKitWebFrame *frame,
272                    WebKitNetworkRequest *request,
273                    WebKitWebNavigationAction *navigation_action,
274                    WebKitWebPolicyDecision *policy_decision, gpointer user_data)
275 {
276         (void)web_view;
277         (void)frame;
278         (void)navigation_action;
279         (void)user_data;
280
281         webkit_web_policy_decision_ignore(policy_decision);
282         client_new(webkit_network_request_get_uri(request));
283
284         return TRUE;
285 }
286
287 void
288 cooperation_setup(void)
289 {
290         GIOChannel *towatch;
291         gchar *fifopath;
292
293         fifopath = g_build_filename(g_get_user_runtime_dir(), __NAME__".fifo", NULL);
294
295         if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
296                 mkfifo(fifopath, 0600);
297
298         cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
299         if (!cooperative_pipe_fp)
300         {
301                 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
302         }
303         else
304         {
305                 if (write(cooperative_pipe_fp, "", 0) == -1)
306                 {
307                         /* Could not do an empty write to the FIFO which means there's
308                          * no one listening. */
309                         close(cooperative_pipe_fp);
310                         towatch = g_io_channel_new_file(fifopath, "r+", NULL);
311                         g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
312                 }
313                 else
314                         cooperative_alone = FALSE;
315         }
316
317         g_free(fifopath);
318 }
319
320 void
321 changed_load_status(GObject *obj, GParamSpec *pspec, gpointer data)
322 {
323         struct Client *c = (struct Client *)data;
324
325         (void)obj;
326         (void)pspec;
327
328         if (webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(c->web_view))
329             == WEBKIT_LOAD_FINISHED)
330         {
331                 gtk_statusbar_pop(GTK_STATUSBAR(c->status), 1);
332                 gtk_statusbar_push(GTK_STATUSBAR(c->status), 1, "Finished.");
333         }
334         else
335         {
336                 gtk_statusbar_pop(GTK_STATUSBAR(c->status), 1);
337                 gtk_statusbar_push(GTK_STATUSBAR(c->status), 1, "Loading...");
338         }
339 }
340
341 void
342 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
343 {
344         const gchar *t;
345         struct Client *c = (struct Client *)data;
346
347         (void)obj;
348         (void)pspec;
349
350         t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
351         gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
352 }
353
354 void
355 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
356 {
357         const gchar *t;
358         struct Client *c = (struct Client *)data;
359
360         (void)obj;
361         (void)pspec;
362
363         t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
364         gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
365 }
366
367 gboolean
368 download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
369                  WebKitNetworkRequest *request, gchar *mime_type,
370                  WebKitWebPolicyDecision *policy_decision, gpointer data)
371 {
372         (void)frame;
373         (void)request;
374         (void)data;
375
376         if (!webkit_web_view_can_show_mime_type(web_view, mime_type))
377         {
378                 webkit_web_policy_decision_download(policy_decision);
379                 return TRUE;
380         }
381         return FALSE;
382 }
383
384 gboolean
385 download_wget(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
386 {
387         const gchar *uri;
388         char id[16] = "";
389         gint ret;
390
391         (void)web_view;
392         (void)data;
393
394         uri = webkit_download_get_uri(download);
395         if (fork() == 0)
396         {
397                 chdir(DOWNLOAD_DIR);
398                 if (embed == 0)
399                         ret = execlp("xterm", "xterm", "-hold", "-e", "wget", uri, NULL);
400                 else
401                 {
402                         if (snprintf(id, 16, "%ld", embed) >= 16)
403                         {
404                                 fprintf(stderr, __NAME__": id for xterm embed truncated!\n");
405                                 exit(EXIT_FAILURE);
406                         }
407                         ret = execlp("xterm", "xterm", "-hold", "-into", id, "-e", "wget",
408                                      uri, NULL);
409                 }
410
411                 if (ret == -1)
412                 {
413                         fprintf(stderr, __NAME__": exec'ing xterm for download");
414                         perror(" failed");
415                         exit(EXIT_FAILURE);
416                 }
417         }
418
419         return FALSE;
420 }
421
422 void
423 hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri,
424                    gpointer data)
425 {
426         struct Client *c = (struct Client *)data;
427
428         (void)web_view;
429         (void)title;
430
431         gtk_statusbar_pop(GTK_STATUSBAR(c->status), 0);
432         if (uri != NULL)
433                 gtk_statusbar_push(GTK_STATUSBAR(c->status), 0, uri);
434 }
435
436 gboolean
437 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
438 {
439         struct Client *c = (struct Client *)data;
440         const gchar *t;
441
442         (void)widget;
443
444         if (event->type == GDK_KEY_PRESS)
445         {
446                 if (((GdkEventKey *)event)->keyval == GDK_KEY_Return)
447                 {
448                         gtk_widget_grab_focus(c->web_view);
449                         t = gtk_entry_get_text(GTK_ENTRY(c->location));
450                         if (t != NULL && t[0] == '/')
451                         {
452                                 if (search_text != NULL)
453                                         g_free(search_text);
454                                 search_text = g_strdup(t + 1);  /* XXX whacky */
455                                 search(c, 1);
456                         }
457                         else
458                                 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), t);
459                         return TRUE;
460                 }
461         }
462
463         return FALSE;
464 }
465
466 gboolean
467 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
468 {
469         struct Client *c = (struct Client *)data;
470         WebKitHitTestResultContext ht_context;
471         WebKitHitTestResult *ht_result = NULL;
472         char *ht_uri =  NULL;
473
474         (void)widget;
475
476         if (event->type == GDK_KEY_PRESS)
477         {
478                 if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK)
479                 {
480                         switch (((GdkEventKey *)event)->keyval)
481                         {
482                                 case GDK_KEY_o:
483                                         gtk_widget_grab_focus(c->location);
484                                         return TRUE;
485                                 case GDK_KEY_h:
486                                         scroll(gtk_scrolled_window_get_hadjustment(
487                                                GTK_SCROLLED_WINDOW(c->scroll)), 0, -1);
488                                         return TRUE;
489                                 case GDK_KEY_j:
490                                         scroll(gtk_scrolled_window_get_vadjustment(
491                                                GTK_SCROLLED_WINDOW(c->scroll)), 0, 1);
492                                         return TRUE;
493                                 case GDK_KEY_k:
494                                         scroll(gtk_scrolled_window_get_vadjustment(
495                                                GTK_SCROLLED_WINDOW(c->scroll)), 0, -1);
496                                         return TRUE;
497                                 case GDK_KEY_l:
498                                         scroll(gtk_scrolled_window_get_hadjustment(
499                                                GTK_SCROLLED_WINDOW(c->scroll)), 0, 1);
500                                         return TRUE;
501                                 case GDK_KEY_f:
502                                         scroll(gtk_scrolled_window_get_vadjustment(
503                                                GTK_SCROLLED_WINDOW(c->scroll)), 1, 0.5);
504                                         return TRUE;
505                                 case GDK_KEY_b:
506                                         scroll(gtk_scrolled_window_get_vadjustment(
507                                                GTK_SCROLLED_WINDOW(c->scroll)), 1, -0.5);
508                                         return TRUE;
509                                 case GDK_KEY_n:
510                                         search(c, 1);
511                                         return TRUE;
512                                 case GDK_KEY_p:
513                                         search(c, -1);
514                                         return TRUE;
515                                 case GDK_KEY_g:
516                                         webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view),
517                                                                  first_uri);
518                                         return TRUE;
519                         }
520                 }
521                 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
522                 {
523                         webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
524                         gtk_statusbar_pop(GTK_STATUSBAR(c->status), 1);
525                         gtk_statusbar_push(GTK_STATUSBAR(c->status), 1, "Aborted.");
526                 }
527         }
528         else if (event->type == GDK_BUTTON_PRESS)
529         {
530                 switch (((GdkEventButton *)event)->button)
531                 {
532                         case 2:
533                                 ht_result = webkit_web_view_get_hit_test_result(
534                                                                    WEBKIT_WEB_VIEW(c->web_view),
535                                                                        (GdkEventButton *)event);
536                                 g_object_get(ht_result, "context", &ht_context, NULL);
537                                 if (ht_context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
538                                 {
539                                         g_object_get(ht_result, "link-uri", &ht_uri, NULL);
540                                         client_new(ht_uri);
541                                         g_object_unref(ht_result);
542                                         return TRUE;
543                                 }
544                                 g_object_unref(ht_result);
545                                 return FALSE;
546                         case 8:
547                                 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
548                                 return TRUE;
549                         case 9:
550                                 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
551                                 return TRUE;
552                 }
553         }
554
555         return FALSE;
556 }
557
558 gboolean
559 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
560 {
561         gchar *uri = NULL;
562
563         (void)condition;
564         (void)data;
565
566         g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
567         if (uri)
568         {
569                 g_strstrip(uri);
570                 client_new(uri);
571                 g_free(uri);
572         }
573         return TRUE;
574 }
575
576 void
577 search(gpointer data, gint direction)
578 {
579         struct Client *c = (struct Client *)data;
580
581         if (search_text == NULL)
582                 return;
583
584         webkit_web_view_search_text(WEBKIT_WEB_VIEW(c->web_view), search_text,
585                                     FALSE, direction == 1, TRUE);
586 }
587
588 void
589 scroll(GtkAdjustment *a, gint step_type, gdouble factor)
590 {
591         gdouble new, lower, upper, step;
592         lower = gtk_adjustment_get_lower(a);
593         upper = gtk_adjustment_get_upper(a) - gtk_adjustment_get_page_size(a) + lower;
594         if (step_type == 0)
595                 step = gtk_adjustment_get_step_increment(a);
596         else
597                 step = gtk_adjustment_get_page_increment(a);
598         new = gtk_adjustment_get_value(a) + factor * step;
599         new = new < lower ? lower : new;
600         new = new > upper ? upper : new;
601         gtk_adjustment_set_value(a, new);
602 }
603
604 Window
605 tabbed_launch(void)
606 {
607         gint tabbed_stdout;
608         GIOChannel *tabbed_stdout_channel;
609         GError *err = NULL;
610         gchar *output = NULL;
611         char *argv[] = { "tabbed", "-c", "-d", "-n", __NAME__, NULL };
612         Window plug_into;
613
614         if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
615                                       NULL, NULL, NULL, &tabbed_stdout, NULL,
616                                       &err))
617         {
618                 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
619                 g_error_free(err);
620                 return 0;
621         }
622
623         tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
624         g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
625         if (output == NULL)
626         {
627                 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
628                 return 0;
629         }
630
631         g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
632
633         g_strstrip(output);
634         plug_into = strtol(output, NULL, 16);
635         g_free(output);
636         return plug_into;
637 }
638
639 void
640 usage(void)
641 {
642         fprintf(stderr, "Usage: "__NAME__" [OPTION]... <URI>...\n");
643         exit(EXIT_FAILURE);
644 }
645
646
647 int
648 main(int argc, char **argv)
649 {
650         int opt, i;
651
652         gtk_init(&argc, &argv);
653
654         while ((opt = getopt(argc, argv, "z:e:rCT")) != -1)
655         {
656                 switch (opt)
657                 {
658                         case 'z':
659                                 global_zoom = atof(optarg);
660                                 break;
661                         case 'e':
662                                 embed = atol(optarg);
663                                 tabbed_automagic = FALSE;
664                                 break;
665                         case 'r':
666                                 show_all_requests = TRUE;
667                                 break;
668                         case 'C':
669                                 cooperative_instances = FALSE;
670                                 break;
671                         case 'T':
672                                 tabbed_automagic = FALSE;
673                                 break;
674                         default:
675                                 usage();
676                 }
677         }
678
679         if (optind >= argc)
680                 usage();
681
682         adblock_load();
683         cooperation_setup();
684
685         if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
686                 embed = tabbed_launch();
687
688         first_uri = g_strdup(argv[optind]);
689         for (i = optind; i < argc; i++)
690                 client_new(argv[i]);
691         if (!cooperative_instances || cooperative_alone)
692                 gtk_main();
693         exit(EXIT_SUCCESS);
694 }