Removed .gitignore from .gitignore
[uzbl-mobile] / uzbl.c
1 // Original code taken from the example webkit-gtk+ application. see notice below.
2 // Modified code is licensed under the GPL 3.  See LICENSE file.
3
4
5 /*
6  * Copyright (C) 2006, 2007 Apple Inc.
7  * Copyright (C) 2007 Alp Toker <alp@atoker.com>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31
32 #define LENGTH(x) (sizeof x / sizeof x[0])
33
34 #include <gtk/gtk.h>
35 #include <gdk/gdkx.h>
36 #include <gdk/gdkkeysyms.h>
37 #include <webkit/webkit.h>
38 #include <pthread.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <sys/stat.h>
42 #include <sys/types.h>
43 #include <unistd.h>
44 #include <stdlib.h>
45
46 /* housekeeping / internal variables */
47 static GtkWidget* main_window;
48 static GtkWidget* mainbar;
49 static GtkWidget* mainbar_label;
50 static WebKitWebView* web_view;
51 static gchar* main_title;
52 static gchar selected_url[500];
53 static gint load_progress;
54 static Window xwin = 0;
55 static char fifopath[64];
56
57 /* state variables (initial values coming from command line arguments but may be changed later) */
58 static gchar*   uri         = NULL;
59 static gchar*   config_file = NULL;
60 static gboolean verbose     = FALSE;
61
62 /* settings from config: group behaviour */
63 static gchar*   history_handler    = NULL;
64 static gchar*   fifodir            = NULL;
65 static gchar*   download_handler   = NULL;
66 static gboolean always_insert_mode = FALSE;
67 static gboolean show_status        = FALSE;
68 static gboolean insert_mode        = FALSE;
69 static gboolean status_top         = FALSE;
70 static gchar*   modkey             = NULL;
71 static guint    modmask            = 0;
72
73 typedef struct {
74     const char *binding;
75     const char *action;
76 } Binding;
77
78 /* settings from config: group bindings_internal */
79 static Binding internal_bindings[256];
80 static int     num_internal_bindings = 0;
81
82 /* settings from config: group bindings_external */
83 static Binding external_bindings[256];
84 static int     num_external_bindings = 0;
85
86 /* commandline arguments (set initial values for the state variables) */
87 static GOptionEntry entries[] =
88 {
89     { "uri",     'u', 0, G_OPTION_ARG_STRING, &uri,         "Uri to load", NULL },
90     { "verbose", 'v', 0, G_OPTION_ARG_NONE,   &verbose,     "Be verbose",  NULL },
91     { "config",  'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file", NULL },
92     { NULL,      0, 0, 0, NULL, NULL, NULL }
93 };
94
95 /* for internal list of commands */
96 typedef struct
97 {
98     const char *command;
99     void (*func_1_param)(WebKitWebView*);
100     void (*func_2_params)(WebKitWebView*, const gchar *);
101 } Command;
102
103 /* XDG stuff */
104 char *XDG_CONFIG_HOME_default[256];
105 char *XDG_CONFIG_DIRS_default = "/etc/xdg";
106
107 static void
108 update_title (GtkWindow* window);
109
110 static gboolean
111 run_command(const char *command, const char *args);
112
113
114 /* --- CALLBACKS --- */
115 static void
116 go_back_cb (WebKitWebView* page) {
117     (void) page;
118     webkit_web_view_go_back (web_view);
119 }
120
121 static void
122 go_forward_cb (WebKitWebView* page) {
123     (void) page;
124     webkit_web_view_go_forward (web_view);
125 }
126
127 static void
128 toggle_status_cb (WebKitWebView* page) {
129     (void) page;
130     if (show_status) {
131         gtk_widget_hide(mainbar);
132     } else {
133         gtk_widget_show(mainbar);
134     }
135     show_status = !show_status;
136     update_title (GTK_WINDOW (main_window));
137 }
138
139 static void
140 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) {
141     (void) page;
142     (void) title;
143     (void) data;    
144     //ADD HOVER URL TO WINDOW TITLE
145     selected_url[0] = '\0';
146     if (link) {
147         strcpy (selected_url, link);
148     }
149     update_title (GTK_WINDOW (main_window));
150 }
151
152 static void
153 title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data) {
154     (void) web_view;
155     (void) web_frame;
156     (void) data;
157     if (main_title)
158         g_free (main_title);
159     main_title = g_strdup (title);
160     update_title (GTK_WINDOW (main_window));
161 }
162
163 static void
164 progress_change_cb (WebKitWebView* page, gint progress, gpointer data) {
165     (void) page;
166     (void) data;
167     load_progress = progress;
168     update_title (GTK_WINDOW (main_window));
169 }
170
171 static void
172 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) {
173     (void) page;
174     (void) data;
175     strcpy (uri, webkit_web_frame_get_uri (frame));
176 }
177
178 static void
179 destroy_cb (GtkWidget* widget, gpointer data) {
180     (void) widget;
181     (void) data;
182     gtk_main_quit ();
183 }
184
185 static void
186 log_history_cb () {
187    if (history_handler) {
188        time_t rawtime;
189        struct tm * timeinfo;
190        char date [80];
191        time ( &rawtime );
192        timeinfo = localtime ( &rawtime );
193        strftime (date, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
194        GString* args = g_string_new ("");
195        g_string_printf (args, "'%s' '%s' '%s'", uri, "TODO:page title here", date);
196        run_command(history_handler, args->str);
197    }
198 }
199
200 /* -- command to callback/function map for things we cannot attach to any signals */
201 // TODO: reload, home, quit
202 static Command commands[] =
203 {
204     { "back",          &go_back_cb,                    NULL },
205     { "forward",       &go_forward_cb,                 NULL },
206     { "refresh",       &webkit_web_view_reload,        NULL }, //Buggy
207     { "stop",          &webkit_web_view_stop_loading,  NULL },
208     { "zoom_in",       &webkit_web_view_zoom_in,       NULL }, //Can crash (when max zoom reached?).
209     { "zoom_out",      &webkit_web_view_zoom_out,      NULL },
210     { "uri",           NULL, &webkit_web_view_load_uri      },
211     { "toggle_status", &toggle_status_cb,              NULL }
212 //{ "get uri",  &webkit_web_view_get_uri},
213 };
214
215 /* -- CORE FUNCTIONS -- */
216
217 static bool
218 file_exists (const char * filename)
219 {
220     FILE *file = fopen (filename, "r");
221     if (file) {
222         fclose (file);
223         return true;
224     }
225     return false;
226 }
227
228 // make sure to put '' around args, so that if there is whitespace we can still keep arguments together.
229 static gboolean
230 run_command(const char *command, const char *args) {
231    //command <uzbl conf> <uzbl pid> <uzbl win id> <uzbl fifo file> [args]
232     GString* to_execute = g_string_new ("");
233     gboolean result;
234     g_string_printf (to_execute, "%s '%s' '%i' '%i' '%s' %s", command, config_file, (int) getpid() , (int) xwin, "/tmp/uzbl_25165827", args);
235     result = g_spawn_command_line_async (to_execute->str, NULL);
236     printf("Called %s.  Result: %s\n", to_execute->str, (result ? "TRUE" : "FALSE" ));
237     return result;
238 }
239
240 static void
241 parse_command(const char *cmd) {
242     unsigned int i;
243     Command *c = NULL;
244     char buffer[512];
245     strcpy (buffer, cmd);
246     char * command_name  = strtok (buffer, " ");
247     char * command_param = strtok (NULL,  " ,");
248
249     Command *c_tmp = NULL;
250     for (i = 0; i < LENGTH (commands); i++) {
251         c_tmp = &commands[i];
252         if (strncmp (command_name, c_tmp->command, strlen (c_tmp->command)) == 0) {
253             c = c_tmp;
254         }
255     }
256     if (c != NULL) {
257         if (c->func_2_params != NULL) {
258             if (command_param != NULL) {
259                 printf ("command executing: \"%s %s\"\n", command_name, command_param);
260                 c->func_2_params (web_view, command_param);
261             } else {
262                 if (c->func_1_param != NULL) {
263                     printf ("command executing: \"%s\"\n", command_name);
264                     c->func_1_param (web_view);
265                 } else {
266                     fprintf (stderr, "command needs a parameter. \"%s\" is not complete\n", command_name);
267                 }
268             }
269         } else if (c->func_1_param != NULL) {
270             printf ("command executing: \"%s\"\n", command_name);
271             c->func_1_param (web_view);
272         }
273     } else {
274         fprintf (stderr, "command \"%s\" not understood. ignoring.\n", cmd);
275     }
276 }
277  
278 static void
279 *control_fifo() {
280     if (fifodir) {
281         sprintf (fifopath, "%s/uzbl_%d", fifodir, (int) xwin);
282     } else {
283         sprintf (fifopath, "/tmp/uzbl_%d", (int) xwin);
284     }
285  
286     if (mkfifo (fifopath, 0666) == -1) {
287         printf ("Possible error creating fifo\n");
288     }
289  
290     printf ("Control fifo opened in %s\n", fifopath);
291  
292     while (true) {
293         FILE *fifo = fopen (fifopath, "r");
294         if (!fifo) {
295             printf ("Could not open %s for reading\n", fifopath);
296             return NULL;
297         }
298         
299         char buffer[256];
300         memset (buffer, 0, sizeof (buffer));
301         while (!feof (fifo) && fgets (buffer, sizeof (buffer), fifo)) {
302             if (strcmp (buffer, "\n")) {
303                 buffer[strlen (buffer) - 1] = '\0'; // Remove newline
304                 parse_command (buffer);
305             }
306         }
307     }
308     
309     return NULL;
310
311  
312 static void
313 setup_threading () {
314     pthread_t control_thread;
315     pthread_create(&control_thread, NULL, control_fifo, NULL);
316 }
317
318 static void
319 update_title (GtkWindow* window) {
320     GString* string_long = g_string_new ("");
321     GString* string_short = g_string_new ("");
322     if (!always_insert_mode)
323         g_string_append (string_long, (insert_mode ? "[I] " : "[C] "));
324     g_string_append (string_long, main_title);
325     g_string_append (string_short, main_title);
326     g_string_append (string_long, " - Uzbl browser");
327     g_string_append (string_short, " - Uzbl browser");
328     if (load_progress < 100)
329         g_string_append_printf (string_long, " (%d%%)", load_progress);
330
331     if (selected_url[0]!=0) {
332         g_string_append_printf (string_long, " -> (%s)", selected_url);
333     }
334
335     gchar* title_long = g_string_free (string_long, FALSE);
336     gchar* title_short = g_string_free (string_short, FALSE);
337
338     if (show_status) {
339         gtk_window_set_title (window, title_short);
340         gtk_label_set_text(GTK_LABEL(mainbar_label), title_long);
341     } else {
342         gtk_window_set_title (window, title_long);
343     }
344
345     g_free (title_long);
346     g_free (title_short);
347 }
348  
349 static gboolean
350 key_press_cb (WebKitWebView* page, GdkEventKey* event)
351 {
352     (void) page;
353     int i;
354     gboolean result=FALSE; //TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
355     if (event->type != GDK_KEY_PRESS) 
356         return result;
357
358     //TURN OFF/ON INSERT MODE
359     if (!always_insert_mode && ((insert_mode && (event->keyval == GDK_Escape)) || (!insert_mode && (event->string[0] == 'i')))) {
360         insert_mode = !insert_mode;
361         update_title (GTK_WINDOW (main_window));
362         return TRUE;
363     }
364
365     //INTERNAL BINDINGS
366     for (i = 0; i < num_internal_bindings; i++) {
367         if (strcmp(event->string, internal_bindings[i].binding) == 0) {
368             if (!insert_mode || (event->state == modmask)) {
369                 parse_command (internal_bindings[i].action);
370                 result = TRUE;
371             }
372         }       
373     }
374
375     //EXTERNAL BINDINGS
376     for (i = 0; i < num_external_bindings; i++) {
377         if (strcmp(event->string, external_bindings[i].binding) == 0) {
378             if (!insert_mode || (event->state == modmask)) {
379                 run_command(external_bindings[i].action, NULL);
380                 result = TRUE;
381             }
382         }       
383     }
384
385     if (!result)
386         result = (insert_mode ? FALSE : TRUE);      
387
388     return result;
389 }
390
391 static GtkWidget*
392 create_browser () {
393     GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
394     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_NEVER); //todo: some sort of display of position/total length. like what emacs does
395
396     web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
397     gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
398
399     g_signal_connect (G_OBJECT (web_view), "title-changed", G_CALLBACK (title_change_cb), web_view);
400     g_signal_connect (G_OBJECT (web_view), "load-progress-changed", G_CALLBACK (progress_change_cb), web_view);
401     g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (load_commit_cb), web_view);
402     g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (log_history_cb), web_view);
403     g_signal_connect (G_OBJECT (web_view), "hovering-over-link", G_CALLBACK (link_hover_cb), web_view);
404     g_signal_connect (G_OBJECT (web_view), "key-press-event", G_CALLBACK (key_press_cb), web_view);
405
406     return scrolled_window;
407 }
408
409 static GtkWidget*
410 create_mainbar () {
411     mainbar = gtk_hbox_new (FALSE, 0);
412     mainbar_label = gtk_label_new ("");  
413     gtk_misc_set_alignment (GTK_MISC(mainbar_label), 0, 0);
414     gtk_misc_set_padding (GTK_MISC(mainbar_label), 2, 2);
415     gtk_box_pack_start (GTK_BOX (mainbar), mainbar_label, TRUE, TRUE, 0);
416     return mainbar;
417 }
418
419 static
420 GtkWidget* create_window () {
421     GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
422     gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
423     gtk_widget_set_name (window, "Uzbl browser");
424     g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy_cb), NULL);
425
426     return window;
427 }
428
429 static void
430 add_binding (char *binding, char *action, bool internal) {
431     Binding bind = {binding, action};
432     if (internal) {
433         internal_bindings[num_internal_bindings] = bind;
434         num_internal_bindings ++;
435     } else {
436         external_bindings[num_external_bindings] = bind;
437         num_external_bindings ++;
438     }
439 }
440
441 static void
442 settings_init () {
443     GKeyFile* config;
444     gboolean res  = FALSE;
445     gchar** keysi = NULL;
446     gchar** keyse = NULL;
447
448     if (! config_file) {
449         const char* XDG_CONFIG_HOME = getenv ("XDG_CONFIG_HOME");
450         char conf[256];
451         if (! XDG_CONFIG_HOME || ! strcmp (XDG_CONFIG_HOME, "")) {
452           XDG_CONFIG_HOME = (char *)XDG_CONFIG_HOME_default;
453         }
454         printf("XDG_CONFIG_HOME: %s\n", XDG_CONFIG_HOME);
455     
456         strcpy (conf, XDG_CONFIG_HOME);
457         strcat (conf, "/uzbl");
458         if (file_exists (conf)) {
459           printf ("Config file %s found.\n", conf);
460           config_file = &conf[0];
461         } else {
462             // Now we check $XDG_CONFIG_DIRS
463             char *XDG_CONFIG_DIRS = getenv ("XDG_CONFIG_DIRS");
464             if (! XDG_CONFIG_DIRS || ! strcmp (XDG_CONFIG_DIRS, ""))
465                 XDG_CONFIG_DIRS = XDG_CONFIG_DIRS_default;
466
467             printf("XDG_CONFIG_DIRS: %s\n", XDG_CONFIG_DIRS);
468
469             char *dirs = XDG_CONFIG_DIRS;
470             char *dir = (char *)strtok (dirs, ":");
471             while (dir && ! file_exists (conf)) {
472                 strcpy (conf, dir);
473                 strcat (conf, "/uzbl");
474                 if (file_exists (conf)) {
475                     printf ("Config file %s found.\n", conf);
476                     config_file = &conf[0];
477                 }
478                 dir = (char *)strtok (NULL, ":");
479             }
480         }
481     }
482
483     if (config_file) {
484         config = g_key_file_new ();
485         res = g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL);
486           if(res) {
487             printf ("Config %s loaded\n", config_file);
488           } else {
489             fprintf (stderr, "Config %s loading failed\n", config_file);
490         }
491     } else {
492         printf ("No configuration.\n");
493     }
494
495     if (res) {
496         history_handler    = g_key_file_get_value   (config, "behavior", "history_handler", NULL);
497         download_handler   = g_key_file_get_value   (config, "behavior", "download_handler", NULL);
498         always_insert_mode = g_key_file_get_boolean (config, "behavior", "always_insert_mode", NULL);
499         show_status        = g_key_file_get_boolean (config, "behavior", "show_status", NULL);
500         modkey             = g_key_file_get_value   (config, "behavior", "modkey", NULL);
501         keysi              = g_key_file_get_keys    (config, "bindings_internal", NULL, NULL);
502         keyse              = g_key_file_get_keys    (config, "bindings_external", NULL, NULL);
503         status_top         = g_key_file_get_boolean (config, "behavior", "status_top", NULL);
504         if (! fifodir)
505             fifodir        = g_key_file_get_value   (config, "behavior", "fifodir", NULL);
506     }
507         
508     if (history_handler) {
509         printf ("History handler: %s\n", history_handler);
510     } else {
511         printf ("History handler disabled\n");
512     }
513
514     if (download_handler) {
515         printf ("Download manager: %s\n", download_handler);
516     } else {
517         printf ("Download manager disabled\n");
518     }
519
520     if (fifodir) {
521         printf ("Fifo directory: %s\n", fifodir);
522     } else {
523         printf ("Fifo directory: /tmp\n");
524     }
525
526     printf ("Always insert mode: %s\n", (always_insert_mode ? "TRUE" : "FALSE"));
527
528     printf ("Show status: %s\n", (show_status ? "TRUE" : "FALSE"));
529
530     printf ("Status top: %s\n", (status_top ? "TRUE" : "FALSE"));
531
532     if (modkey) {
533         printf ("Modkey: %s\n", modkey);
534     } else {
535         printf ("Modkey disabled\n");   
536         modkey = "";
537     }
538     //POSSIBLE MODKEY VALUES (COMBINATIONS CAN BE USED)
539     gchar* modkeyup = g_utf8_strup (modkey, -1);
540     if (g_strrstr (modkeyup,"SHIFT") != NULL)    modmask |= GDK_SHIFT_MASK;    //the Shift key.
541     if (g_strrstr (modkeyup,"LOCK") != NULL)     modmask |= GDK_LOCK_MASK;     //a Lock key (depending on the modifier mapping of the X server this may either be CapsLock or ShiftLock).
542     if (g_strrstr (modkeyup,"CONTROL") != NULL)  modmask |= GDK_CONTROL_MASK;  //the Control key.
543     if (g_strrstr (modkeyup,"MOD1") != NULL)     modmask |= GDK_MOD1_MASK;     //the fourth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier, but normally it is the Alt key).
544     if (g_strrstr (modkeyup,"MOD2") != NULL)     modmask |= GDK_MOD2_MASK;     //the fifth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier).
545     if (g_strrstr (modkeyup,"MOD3") != NULL)     modmask |= GDK_MOD3_MASK;     //the sixth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier).
546     if (g_strrstr (modkeyup,"MOD4") != NULL)     modmask |= GDK_MOD4_MASK;     //the seventh modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier).
547     if (g_strrstr (modkeyup,"MOD5") != NULL)     modmask |= GDK_MOD5_MASK;     //the eighth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier).
548     if (g_strrstr (modkeyup,"BUTTON1") != NULL)  modmask |= GDK_BUTTON1_MASK;  //the first mouse button.
549     if (g_strrstr (modkeyup,"BUTTON2") != NULL)  modmask |= GDK_BUTTON2_MASK;  //the second mouse button.
550     if (g_strrstr (modkeyup,"BUTTON3") != NULL)  modmask |= GDK_BUTTON3_MASK;  //the third mouse button.
551     if (g_strrstr (modkeyup,"BUTTON4") != NULL)  modmask |= GDK_BUTTON4_MASK;  //the fourth mouse button.
552     if (g_strrstr (modkeyup,"BUTTON5") != NULL)  modmask |= GDK_BUTTON5_MASK;  //the fifth mouse button.
553     if (g_strrstr (modkeyup,"SUPER") != NULL)    modmask |= GDK_SUPER_MASK;    //the Super modifier. Since 2.10
554     if (g_strrstr (modkeyup,"HYPER") != NULL)    modmask |= GDK_HYPER_MASK;    //the Hyper modifier. Since 2.10
555     if (g_strrstr (modkeyup,"META") != NULL)     modmask |= GDK_META_MASK;     //the Meta modifier. Since 2.10  */
556     free (modkeyup);
557
558     if (keysi) {
559               int i = 0;
560         for (i = 0; keysi[i]; i++) {
561             gchar *binding = g_key_file_get_string (config, "bindings_internal", keysi[i], NULL);
562             printf ("Action: %s, Binding: %s (internal)\n", g_strdup (keysi[i]), binding);
563             add_binding (binding, g_strdup (keysi[i]), true);
564         }
565     }
566     if (keyse) {
567               int i = 0;
568         for (i = 0; keyse[i]; i++) {
569             gchar *binding = g_key_file_get_string (config, "bindings_external", keyse[i], NULL);
570             printf ("Action: %s, Binding: %s (external)\n", g_strdup (keyse[i]), binding);
571             add_binding (binding, g_strdup (keyse[i]), false);
572         }
573     }
574 }
575
576 int
577 main (int argc, char* argv[]) {
578     gtk_init (&argc, &argv);
579     if (!g_thread_supported ())
580         g_thread_init (NULL);
581
582     strcat ((char *) XDG_CONFIG_HOME_default, getenv ("HOME"));
583     strcat ((char *) XDG_CONFIG_HOME_default, "/.config");
584
585     GError *error = NULL;
586     GOptionContext* context = g_option_context_new ("- some stuff here maybe someday");
587     g_option_context_add_main_entries (context, entries, NULL);
588     g_option_context_add_group (context, gtk_get_option_group (TRUE));
589     g_option_context_parse (context, &argc, &argv, &error);
590
591     settings_init ();
592     if (always_insert_mode)
593         insert_mode = TRUE;
594
595     GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
596     if (status_top)
597         gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);
598     gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
599     if (!status_top)
600         gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);
601
602     main_window = create_window ();
603     gtk_container_add (GTK_CONTAINER (main_window), vbox);
604
605     webkit_web_view_load_uri (web_view, uri);
606
607     gtk_widget_grab_focus (GTK_WIDGET (web_view));
608     gtk_widget_show_all (main_window);
609     xwin = GDK_WINDOW_XID (GTK_WIDGET (main_window)->window);
610     printf("window_id %i\n",(int) xwin);
611     printf("pid %i\n", getpid ());
612
613     if (!show_status)
614         gtk_widget_hide(mainbar);
615
616     setup_threading ();
617
618     gtk_main ();
619
620     unlink (fifopath);
621     return 0;
622 }