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.
6 * Copyright (C) 2006, 2007 Apple Inc.
7 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
32 #define LENGTH(x) (sizeof x / sizeof x[0])
33 #define MAX_BINDINGS 256
37 #include <gdk/gdkkeysyms.h>
38 #include <webkit/webkit.h>
43 #include <sys/types.h>
48 #include <sys/types.h>
50 #include <sys/socket.h>
53 /* housekeeping / internal variables */
54 static GtkWidget* main_window;
55 static GtkWidget* mainbar;
56 static GtkWidget* mainbar_label;
57 static GtkScrollbar* scbar_v; // Horizontal and Vertical Scrollbar
58 static GtkScrollbar* scbar_h; // (These are still hidden)
59 static GtkAdjustment* bar_v; // Information about document length
60 static GtkAdjustment* bar_h; // and scrolling position
61 static WebKitWebView* web_view;
62 static gchar* main_title;
63 static gchar selected_url[500] = "\0";
64 static gint load_progress;
65 static Window xwin = 0;
66 static char fifo_path[64];
67 static char socket_path[108];
68 static GString *keycmd;
70 /* state variables (initial values coming from command line arguments but may be changed later) */
71 static gchar* uri = NULL;
72 static gchar* config_file = NULL;
73 static gchar config_file_path[500];
74 static gboolean verbose = FALSE;
76 /* settings from config: group behaviour */
77 static gchar* history_handler = NULL;
78 static gchar* fifo_dir = NULL;
79 static gchar* socket_dir = NULL;
80 static gchar* download_handler = NULL;
81 static gboolean always_insert_mode = FALSE;
82 static gboolean show_status = FALSE;
83 static gboolean insert_mode = FALSE;
84 static gboolean status_top = FALSE;
85 static gchar* modkey = NULL;
86 static guint modmask = 0;
87 static gdouble hscroll = 20;
88 static gdouble vscroll = 20;
90 /* settings from config: group bindings, key -> action */
91 static GHashTable *bindings;
93 /* command list: name -> Command */
94 static GHashTable *commands;
101 /* commandline arguments (set initial values for the state variables) */
102 static GOptionEntry entries[] =
104 { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL },
105 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
106 { "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file", NULL },
107 { NULL, 0, 0, 0, NULL, NULL, NULL }
110 typedef void (*Command)(WebKitWebView*, const char *);
113 static char *XDG_CONFIG_HOME_default[256];
114 static char *XDG_CONFIG_DIRS_default = "/etc/xdg";
120 load_uri ( WebKitWebView * web_view, const gchar * uri);
123 new_window_load_uri (const gchar * uri);
126 close_uzbl (WebKitWebView *page, const char *param);
129 run_command(const char *command, const char *args);
132 spawn(WebKitWebView *web_view, const char *param);
135 free_action(gpointer action);
138 new_action(const gchar *name, const gchar *param);
141 set_insert_mode(WebKitWebView *page, const gchar *param);
145 /* --- CALLBACKS --- */
148 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data) {
151 (void) navigation_action;
152 (void) policy_decision;
154 const gchar* uri = webkit_network_request_get_uri (request);
155 printf("New window requested -> %s \n", uri);
156 new_window_load_uri(uri);
161 create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data) {
165 if (selected_url[0]!=0) {
166 printf("\nNew web view -> %s\n",selected_url);
167 new_window_load_uri(selected_url);
169 printf("New web view -> %s\n","Nothing to open, exiting");
175 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) {
178 if (download_handler) {
179 const gchar* uri = webkit_download_get_uri ((WebKitDownload*)download);
180 printf("Download -> %s\n",uri);
181 run_command(download_handler, uri);
186 /* scroll a bar in a given direction */
188 scroll (double i, GtkAdjustment* bar) {
189 gtk_adjustment_set_value (bar, gtk_adjustment_get_value(bar)+i);
192 static void scroll_up (WebKitWebView* page, const char *param) {
196 scroll (-vscroll, bar_v);
199 static void scroll_left (WebKitWebView* page, const char *param) {
203 scroll (-hscroll, bar_h);
206 static void scroll_down (WebKitWebView* page, const char *param) {
210 scroll (vscroll, bar_v);
213 static void scroll_right (WebKitWebView* page, const char *param) {
217 scroll (hscroll, bar_h);
221 toggle_status_cb (WebKitWebView* page, const char *param) {
226 gtk_widget_hide(mainbar);
228 gtk_widget_show(mainbar);
230 show_status = !show_status;
235 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) {
239 //ADD HOVER URL TO WINDOW TITLE
240 selected_url[0] = '\0';
242 strcpy (selected_url, link);
248 title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data) {
254 main_title = g_strdup (title);
259 progress_change_cb (WebKitWebView* page, gint progress, gpointer data) {
262 load_progress = progress;
267 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) {
271 GString* newuri = g_string_new (webkit_web_frame_get_uri (frame));
272 uri = g_string_free (newuri, FALSE);
276 destroy_cb (GtkWidget* widget, gpointer data) {
284 if (history_handler) {
286 struct tm * timeinfo;
289 timeinfo = localtime ( &rawtime );
290 strftime (date, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
291 GString* args = g_string_new ("");
292 g_string_printf (args, "'%s' '%s' '%s'", uri, "TODO:page title here", date);
293 run_command(history_handler, args->str);
294 g_string_free (args, TRUE);
298 /* VIEW funcs (little webkit wrappers) */
300 #define VIEWFUNC(name) static void view_##name(WebKitWebView *page, const char *param){(void)param; webkit_web_view_##name(page);}
302 VIEWFUNC(stop_loading)
309 /* -- command to callback/function map for things we cannot attach to any signals */
312 static struct {char *name; Command command;} cmdlist[] =
314 { "back", view_go_back },
315 { "forward", view_go_forward },
316 { "scroll_down", scroll_down },
317 { "scroll_up", scroll_up },
318 { "scroll_left", scroll_left },
319 { "scroll_right", scroll_right },
320 { "reload", view_reload, }, //Buggy
321 { "refresh", view_reload, }, /* for convenience, will change */
322 { "stop", view_stop_loading, },
323 { "zoom_in", view_zoom_in, }, //Can crash (when max zoom reached?).
324 { "zoom_out", view_zoom_out, },
326 { "toggle_status", toggle_status_cb },
328 { "exit", close_uzbl },
329 { "insert_mode", set_insert_mode }
336 commands = g_hash_table_new(g_str_hash, g_str_equal);
338 for (i = 0; i < LENGTH(cmdlist); i++)
339 g_hash_table_insert(commands, cmdlist[i].name, cmdlist[i].command);
342 /* -- CORE FUNCTIONS -- */
345 free_action(gpointer act) {
346 Action *action = (Action*)act;
347 g_free(action->name);
349 g_free(action->param);
354 new_action(const gchar *name, const gchar *param) {
355 Action *action = g_new(Action, 1);
357 action->name = g_strdup(name);
359 action->param = g_strdup(param);
361 action->param = NULL;
367 file_exists (const char * filename) {
368 FILE *file = fopen (filename, "r");
377 set_insert_mode(WebKitWebView *page, const gchar *param) {
386 load_uri (WebKitWebView * web_view, const gchar *param) {
388 GString* newuri = g_string_new (param);
389 if (g_strrstr (param, "://") == NULL)
390 g_string_prepend (newuri, "http://");
391 webkit_web_view_load_uri (web_view, newuri->str);
392 g_string_free (newuri, TRUE);
397 new_window_load_uri (const gchar * uri) {
398 GString* to_execute = g_string_new ("");
400 g_string_printf (to_execute, "uzbl --uri '%s'", uri);
402 g_string_printf (to_execute, "uzbl --uri '%s' --config '%s'", uri, config_file);
404 printf("Spawning %s\n",to_execute->str);
405 if (!g_spawn_command_line_async (to_execute->str, NULL)) {
407 g_string_printf (to_execute, "./uzbl --uri '%s'", uri);
409 g_string_printf (to_execute, "./uzbl --uri '%s' --config '%s'", uri, config_file);
411 printf("Spawning %s\n",to_execute->str);
412 g_spawn_command_line_async (to_execute->str, NULL);
414 g_string_free (to_execute, TRUE);
418 close_uzbl (WebKitWebView *page, const char *param) {
424 // make sure to put '' around args, so that if there is whitespace we can still keep arguments together.
426 run_command(const char *command, const char *args) {
427 //command <uzbl conf> <uzbl pid> <uzbl win id> <uzbl fifo file> <uzbl socket file> [args]
428 GString* to_execute = g_string_new ("");
430 g_string_printf (to_execute, "%s '%s' '%i' '%i' '%s' '%s'", command, config_file, (int) getpid() , (int) xwin, fifo_path, socket_path);
432 g_string_append_printf (to_execute, " %s", args);
434 result = g_spawn_command_line_async (to_execute->str, NULL);
435 printf("Called %s. Result: %s\n", to_execute->str, (result ? "TRUE" : "FALSE" ));
436 g_string_free (to_execute, TRUE);
441 spawn(WebKitWebView *web_view, const char *param) {
443 run_command(param, NULL);
447 parse_command(const char *cmd, const char *param) {
450 if ((c = g_hash_table_lookup(commands, cmd)))
453 fprintf (stderr, "command \"%s\" not understood. ignoring.\n", cmd);
457 parse_line(char *line) {
462 parts = g_strsplit(line, " ", 2);
467 parse_command(parts[0], parts[1]);
473 control_fifo(GIOChannel *fd) {
480 g_io_channel_read_line(fd, &ctl_line, NULL, &term_pos, NULL);
481 ctl_line[term_pos] ='\0';
483 parse_line(ctl_line);
492 GIOChannel *chan = NULL;
495 sprintf (fifo_path, "%s/uzbl_fifo_%d", fifo_dir, (int) xwin);
497 sprintf (fifo_path, "/tmp/uzbl_fifo_%d", (int) xwin);
499 printf ("Control fifo opened in %s\n", fifo_path);
500 if (mkfifo (fifo_path, 0666) == -1) {
501 printf ("Possible error creating fifo\n");
504 if( (chan = g_io_channel_new_file((gchar *) fifo_path, "r+", NULL)) )
505 g_io_add_watch(chan, G_IO_IN|G_IO_HUP, (GIOFunc) control_fifo, chan);
512 sprintf (socket_path, "%s/uzbl_socket_%d", socket_dir, (int) xwin);
514 sprintf (socket_path, "/tmp/uzbl_socket_%d", (int) xwin);
517 int sock, clientsock, len;
519 struct sockaddr_un local, remote;
521 sock = socket (AF_UNIX, SOCK_STREAM, 0);
523 local.sun_family = AF_UNIX;
524 strcpy (local.sun_path, socket_path);
525 unlink (local.sun_path);
527 len = strlen (local.sun_path) + sizeof (local.sun_family);
528 bind (sock, (struct sockaddr *) &local, len);
531 printf ("A problem occurred when opening a socket in %s\n", socket_path);
533 printf ("Control socket opened in %s\n", socket_path);
542 memset (buffer, 0, sizeof (buffer));
545 clientsock = accept (sock, (struct sockaddr *) &remote, &t);
546 printf ("Connected to client\n");
550 memset (temp, 0, sizeof (temp));
551 n = recv (clientsock, temp, 128, 0);
553 buffer[strlen (buffer)] = '\0';
558 strcat (buffer, temp);
561 if (strcmp (buffer, "\n") < 0) {
562 buffer[strlen (buffer) - 1] = '\0';
564 buffer[strlen (buffer)] = '\0';
576 pthread_t control_thread;
577 pthread_create(&control_thread, NULL, control_socket, NULL);
578 pthread_detach(control_thread);
582 update_title (void) {
583 GString* string_long = g_string_new ("");
584 GString* string_short = g_string_new ("");
586 g_string_append_printf(string_long, "%s ", keycmd->str);
587 if (!always_insert_mode)
588 g_string_append (string_long, (insert_mode ? "[I] " : "[C] "));
590 g_string_append (string_long, main_title);
591 g_string_append (string_short, main_title);
593 g_string_append (string_long, " - Uzbl browser");
594 g_string_append (string_short, " - Uzbl browser");
595 if (load_progress < 100)
596 g_string_append_printf (string_long, " (%d%%)", load_progress);
598 if (selected_url[0]!=0) {
599 g_string_append_printf (string_long, " -> (%s)", selected_url);
602 gchar* title_long = g_string_free (string_long, FALSE);
603 gchar* title_short = g_string_free (string_short, FALSE);
606 gtk_window_set_title (GTK_WINDOW(main_window), title_short);
607 gtk_label_set_text(GTK_LABEL(mainbar_label), title_long);
609 gtk_window_set_title (GTK_WINDOW(main_window), title_long);
613 g_free (title_short);
617 key_press_cb (WebKitWebView* page, GdkEventKey* event)
619 //TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
624 if (event->type != GDK_KEY_PRESS || event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down
625 || event->keyval == GDK_Up || event->keyval == GDK_Down || event->keyval == GDK_Left || event->keyval == GDK_Right)
628 /* turn off insert mode (if always_insert_mode is not used) */
629 if (insert_mode && (event->keyval == GDK_Escape)) {
630 insert_mode = always_insert_mode;
635 if (insert_mode && event->state != modmask)
639 if (event->keyval == GDK_Escape) {
640 g_string_truncate(keycmd, 0);
647 g_string_append(keycmd, event->string);
649 if ((action = g_hash_table_lookup(bindings, keycmd->str))) {
650 g_string_truncate(keycmd, 0);
652 parse_command(action->name, action->param);
662 GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
663 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
665 web_view = WEBKIT_WEB_VIEW (webkit_web_view_new ());
666 gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
668 g_signal_connect (G_OBJECT (web_view), "title-changed", G_CALLBACK (title_change_cb), web_view);
669 g_signal_connect (G_OBJECT (web_view), "load-progress-changed", G_CALLBACK (progress_change_cb), web_view);
670 g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (load_commit_cb), web_view);
671 g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (log_history_cb), web_view);
672 g_signal_connect (G_OBJECT (web_view), "hovering-over-link", G_CALLBACK (link_hover_cb), web_view);
673 g_signal_connect (G_OBJECT (web_view), "key-press-event", G_CALLBACK (key_press_cb), web_view);
674 g_signal_connect (G_OBJECT (web_view), "new-window-policy-decision-requested", G_CALLBACK (new_window_cb), web_view);
675 g_signal_connect (G_OBJECT (web_view), "download-requested", G_CALLBACK (download_cb), web_view);
676 g_signal_connect (G_OBJECT (web_view), "create-web-view", G_CALLBACK (create_web_view_cb), web_view);
678 return scrolled_window;
683 mainbar = gtk_hbox_new (FALSE, 0);
684 mainbar_label = gtk_label_new ("");
685 gtk_misc_set_alignment (GTK_MISC(mainbar_label), 0, 0);
686 gtk_misc_set_padding (GTK_MISC(mainbar_label), 2, 2);
687 gtk_box_pack_start (GTK_BOX (mainbar), mainbar_label, TRUE, TRUE, 0);
692 GtkWidget* create_window () {
693 GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
694 gtk_window_set_default_size (GTK_WINDOW (window), 800, 600);
695 gtk_widget_set_name (window, "Uzbl browser");
696 g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy_cb), NULL);
702 add_binding (const gchar *key, const gchar *act) {
703 char **parts = g_strsplit(act, " ", 2);
709 action = new_action(parts[0], parts[1]);
710 g_hash_table_insert(bindings, g_strdup(key), action);
718 gboolean res = FALSE;
723 const char* XDG_CONFIG_HOME = getenv ("XDG_CONFIG_HOME");
724 if (! XDG_CONFIG_HOME || ! strcmp (XDG_CONFIG_HOME, "")) {
725 XDG_CONFIG_HOME = (char*)XDG_CONFIG_HOME_default;
727 printf("XDG_CONFIG_HOME: %s\n", XDG_CONFIG_HOME);
729 strcpy (config_file_path, XDG_CONFIG_HOME);
730 strcat (config_file_path, "/uzbl/config");
731 if (file_exists (config_file_path)) {
732 printf ("Config file %s found.\n", config_file_path);
733 config_file = &config_file_path[0];
735 // Now we check $XDG_CONFIG_DIRS
736 char *XDG_CONFIG_DIRS = getenv ("XDG_CONFIG_DIRS");
737 if (! XDG_CONFIG_DIRS || ! strcmp (XDG_CONFIG_DIRS, ""))
738 XDG_CONFIG_DIRS = XDG_CONFIG_DIRS_default;
740 printf("XDG_CONFIG_DIRS: %s\n", XDG_CONFIG_DIRS);
743 strcpy (buffer, XDG_CONFIG_DIRS);
744 const gchar* dir = (char *) strtok_r (buffer, ":", &saveptr);
745 while (dir && ! file_exists (config_file_path)) {
746 strcpy (config_file_path, dir);
747 strcat (config_file_path, "/uzbl/config_file_pathig");
748 if (file_exists (config_file_path)) {
749 printf ("Config file %s found.\n", config_file_path);
750 config_file = &config_file_path[0];
752 dir = (char * ) strtok_r (NULL, ":", &saveptr);
758 config = g_key_file_new ();
759 res = g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL);
761 printf ("Config %s loaded\n", config_file);
763 fprintf (stderr, "Config %s loading failed\n", config_file);
766 printf ("No configuration.\n");
770 history_handler = g_key_file_get_value (config, "behavior", "history_handler", NULL);
771 download_handler = g_key_file_get_value (config, "behavior", "download_handler", NULL);
772 always_insert_mode = g_key_file_get_boolean (config, "behavior", "always_insert_mode", NULL);
773 show_status = g_key_file_get_boolean (config, "behavior", "show_status", NULL);
774 modkey = g_key_file_get_value (config, "behavior", "modkey", NULL);
775 status_top = g_key_file_get_boolean (config, "behavior", "status_top", NULL);
777 fifo_dir = g_key_file_get_value (config, "behavior", "fifodir", NULL);
779 socket_dir = g_key_file_get_value (config, "behavior", "socket_dir", NULL);
780 keys = g_key_file_get_keys (config, "bindings", NULL, NULL);
783 printf ("History handler: %s\n", (history_handler ? history_handler : "disabled"));
784 printf ("Download manager: %s\n", (download_handler ? download_handler : "disabled"));
785 printf ("Fifo directory: %s\n", (fifo_dir ? fifo_dir : "/tmp"));
786 printf ("Socket directory: %s\n", (socket_dir ? socket_dir : "/tmp"));
787 printf ("Always insert mode: %s\n", (always_insert_mode ? "TRUE" : "FALSE"));
788 printf ("Show status: %s\n", (show_status ? "TRUE" : "FALSE"));
789 printf ("Status top: %s\n", (status_top ? "TRUE" : "FALSE"));
790 printf ("Modkey: %s\n", (modkey ? modkey : "disabled"));
795 //POSSIBLE MODKEY VALUES (COMBINATIONS CAN BE USED)
796 gchar* modkeyup = g_utf8_strup (modkey, -1);
797 if (g_strrstr (modkeyup,"SHIFT") != NULL) modmask |= GDK_SHIFT_MASK; //the Shift key.
798 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).
799 if (g_strrstr (modkeyup,"CONTROL") != NULL) modmask |= GDK_CONTROL_MASK; //the Control key.
800 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).
801 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).
802 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).
803 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).
804 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).
805 if (g_strrstr (modkeyup,"BUTTON1") != NULL) modmask |= GDK_BUTTON1_MASK; //the first mouse button.
806 if (g_strrstr (modkeyup,"BUTTON2") != NULL) modmask |= GDK_BUTTON2_MASK; //the second mouse button.
807 if (g_strrstr (modkeyup,"BUTTON3") != NULL) modmask |= GDK_BUTTON3_MASK; //the third mouse button.
808 if (g_strrstr (modkeyup,"BUTTON4") != NULL) modmask |= GDK_BUTTON4_MASK; //the fourth mouse button.
809 if (g_strrstr (modkeyup,"BUTTON5") != NULL) modmask |= GDK_BUTTON5_MASK; //the fifth mouse button.
810 if (g_strrstr (modkeyup,"SUPER") != NULL) modmask |= GDK_SUPER_MASK; //the Super modifier. Since 2.10
811 if (g_strrstr (modkeyup,"HYPER") != NULL) modmask |= GDK_HYPER_MASK; //the Hyper modifier. Since 2.10
812 if (g_strrstr (modkeyup,"META") != NULL) modmask |= GDK_META_MASK; //the Meta modifier. Since 2.10 */
817 for (i = 0; keys[i]; i++) {
818 gchar *value = g_key_file_get_string (config, "bindings", keys[i], NULL);
820 add_binding(g_strstrip(keys[i]), value);
829 main (int argc, char* argv[]) {
830 gtk_init (&argc, &argv);
831 if (!g_thread_supported ())
832 g_thread_init (NULL);
834 printf("Uzbl start location: %s\n", argv[0]);
836 strcat ((char *) XDG_CONFIG_HOME_default, getenv ("HOME"));
837 strcat ((char *) XDG_CONFIG_HOME_default, "/.config");
839 GError *error = NULL;
840 GOptionContext* context = g_option_context_new ("- some stuff here maybe someday");
841 g_option_context_add_main_entries (context, entries, NULL);
842 g_option_context_add_group (context, gtk_get_option_group (TRUE));
843 g_option_context_parse (context, &argc, &argv, &error);
844 /* initialize hash table */
845 bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action);
847 keycmd = g_string_new("");
852 if (always_insert_mode)
855 GtkWidget* vbox = gtk_vbox_new (FALSE, 0);
857 gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);
858 gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0);
860 gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0);
862 main_window = create_window ();
863 gtk_container_add (GTK_CONTAINER (main_window), vbox);
865 load_uri (web_view, uri);
867 gtk_widget_grab_focus (GTK_WIDGET (web_view));
868 gtk_widget_show_all (main_window);
869 xwin = GDK_WINDOW_XID (GTK_WIDGET (main_window)->window);
870 printf("window_id %i\n",(int) xwin);
871 printf("pid %i\n", getpid ());
873 scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
874 bar_v = gtk_range_get_adjustment((GtkRange*) scbar_v);
875 scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
876 bar_h = gtk_range_get_adjustment((GtkRange*) scbar_h);
877 gtk_widget_set_scroll_adjustments ((GtkWidget*) web_view, bar_h, bar_v);
880 gtk_widget_hide(mainbar);
887 g_string_free(keycmd, TRUE);
889 unlink (socket_path);
892 g_hash_table_destroy(bindings);
893 g_hash_table_destroy(commands);
897 /* vi: set et ts=4: */