+static void
+add_binding (char *binding, char *action, bool internal) {
+ Binding bind = {binding, action};
+ if (internal) {
+ internal_bindings[num_internal_bindings] = bind;
+ num_internal_bindings ++;
+ } else {
+ external_bindings[num_external_bindings] = bind;
+ num_external_bindings ++;
+ }
+}
+
+static void
+settings_init () {
+ GKeyFile* config;
+ gboolean res = FALSE;
+ gchar** keysi = NULL;
+ gchar** keyse = NULL;
+
+ if (! config_file) {
+ const char* xdg = getenv ("XDG_CONFIG_HOME");
+ char conf[256];
+ if (xdg) {
+ printf("XDG_CONFIG_DIR: %s\n", xdg);
+ strcpy (conf, xdg);
+ strcat (conf, "/uzbl");
+ if (file_exists (conf)) {
+ printf ("Config file %s found.\n", conf);
+ config_file = &conf[0];
+ }
+ }
+ }
+
+ if (config_file) {
+ config = g_key_file_new ();
+ res = g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL);
+ if(res) {
+ printf ("Config %s loaded\n", config_file);
+ } else {
+ fprintf (stderr, "Config %s loading failed\n", config_file);
+ }
+ } else {
+ printf ("No configuration.\n");
+ }
+
+ if (res) {
+ history_handler = g_key_file_get_value (config, "behavior", "history_handler", NULL);
+ download_handler = g_key_file_get_value (config, "behavior", "download_handler", NULL);
+ always_insert_mode = g_key_file_get_boolean (config, "behavior", "always_insert_mode", NULL);
+ show_status = g_key_file_get_boolean (config, "behavior", "show_status", NULL);
+ modkey = g_key_file_get_value (config, "behavior", "modkey", NULL);
+ keysi = g_key_file_get_keys (config, "bindings_internal", NULL, NULL);
+ keyse = g_key_file_get_keys (config, "bindings_external", NULL, NULL);
+ status_top = g_key_file_get_boolean (config, "behavior", "status_top", NULL);
+ if (! fifodir)
+ fifodir = g_key_file_get_value (config, "behavior", "fifodir", NULL);
+ }
+
+ if (history_handler) {
+ printf ("History handler: %s\n", history_handler);
+ } else {
+ printf ("History handler disabled\n");
+ }
+
+ if (download_handler) {
+ printf ("Download manager: %s\n", download_handler);
+ } else {
+ printf ("Download manager disabled\n");
+ }
+
+ if (fifodir) {
+ printf ("Fifo directory: %s\n", fifodir);
+ } else {
+ printf ("Fifo directory: /tmp\n");
+ }
+
+ printf ("Always insert mode: %s\n", (always_insert_mode ? "TRUE" : "FALSE"));
+
+ printf ("Show status: %s\n", (show_status ? "TRUE" : "FALSE"));
+
+ printf ("Status top: %s\n", (status_top ? "TRUE" : "FALSE"));
+
+ if (modkey) {
+ printf ("Modkey: %s\n", modkey);
+ } else {
+ printf ("Modkey disabled\n");
+ modkey = "";
+ }
+ //POSSIBLE MODKEY VALUES (COMBINATIONS CAN BE USED)
+ gchar* modkeyup = g_utf8_strup(modkey, -1);
+ if (g_strrstr(modkeyup,"SHIFT") != NULL) modmask |= GDK_SHIFT_MASK; //the Shift key.
+ 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).
+ if (g_strrstr(modkeyup,"CONTROL") != NULL) modmask |= GDK_CONTROL_MASK; //the Control key.
+ 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).
+ 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).
+ 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).
+ 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).
+ 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).
+ if (g_strrstr(modkeyup,"BUTTON1") != NULL) modmask |= GDK_BUTTON1_MASK; //the first mouse button.
+ if (g_strrstr(modkeyup,"BUTTON2") != NULL) modmask |= GDK_BUTTON2_MASK; //the second mouse button.
+ if (g_strrstr(modkeyup,"BUTTON3") != NULL) modmask |= GDK_BUTTON3_MASK; //the third mouse button.
+ if (g_strrstr(modkeyup,"BUTTON4") != NULL) modmask |= GDK_BUTTON4_MASK; //the fourth mouse button.
+ if (g_strrstr(modkeyup,"BUTTON5") != NULL) modmask |= GDK_BUTTON5_MASK; //the fifth mouse button.
+ if (g_strrstr(modkeyup,"SUPER") != NULL) modmask |= GDK_SUPER_MASK; //the Super modifier. Since 2.10
+ if (g_strrstr(modkeyup,"HYPER") != NULL) modmask |= GDK_HYPER_MASK; //the Hyper modifier. Since 2.10
+ if (g_strrstr(modkeyup,"META") != NULL) modmask |= GDK_META_MASK; //the Meta modifier. Since 2.10 */
+ free (modkeyup);
+
+ if (keysi) {
+ int i = 0;
+ for (i = 0; keysi[i]; i++) {
+ gchar *binding = g_key_file_get_string (config, "bindings_internal", keysi[i], NULL);
+ printf ("Action: %s, Binding: %s (internal)\n", g_strdup (keysi[i]), binding);
+ add_binding (binding, g_strdup (keysi[i]), true);
+ }
+ }
+ if (keyse) {
+ int i = 0;
+ for (i = 0; keyse[i]; i++) {
+ gchar *binding = g_key_file_get_string (config, "bindings_external", keyse[i], NULL);
+ printf ("Action: %s, Binding: %s (external)\n", g_strdup (keyse[i]), binding);
+ add_binding (binding, g_strdup (keyse[i]), false);
+ }
+ }
+}
+
+int
+main (int argc, char* argv[]) {