From cd85f0d6a09b8a73ab26eeff230521ed316ba6b6 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 8 Aug 2011 16:40:09 -0400 Subject: [PATCH] Change where config settings, key and mouse bindings, and perapp settings are loaded from. Load settings from ~/.cache/openbox/config Load key binds from ~/.config/openbox/keys Load mouse binds from ~/.config/openbox/mouse Load per app rules from ~/.config/openbox/applications Split the rc.xsd file into keys.xsd, mouse.xsd and windows.xsd. Didn't keep the stuff for "config" since that will be written by openbox, not by people. --- Makefile.am | 12 +- data/applications | 83 +++++ data/applications.xsd | 101 ++++++ data/keys | 118 +++++++ data/keys.xsd | 36 ++ data/{menu.xml => menu} | 0 data/mouse | 293 ++++++++++++++++ data/mouse.xsd | 79 +++++ data/rc.xml | 730 ---------------------------------------- data/rc.xsd | 551 ------------------------------ openbox/config.c | 234 ++++++++----- openbox/config.h | 7 +- openbox/menu.c | 4 +- openbox/openbox.c | 61 +--- 14 files changed, 890 insertions(+), 1419 deletions(-) create mode 100644 data/applications create mode 100644 data/applications.xsd create mode 100644 data/keys create mode 100644 data/keys.xsd rename data/{menu.xml => menu} (100%) create mode 100644 data/mouse create mode 100644 data/mouse.xsd delete mode 100644 data/rc.xml delete mode 100644 data/rc.xsd diff --git a/Makefile.am b/Makefile.am index 082016b3..961f4066 100644 --- a/Makefile.am +++ b/Makefile.am @@ -492,8 +492,10 @@ dist_pixmap_DATA = \ data/openbox.png dist_rc_DATA = \ - data/rc.xml \ - data/menu.xml + data/keys \ + data/mouse \ + data/applications \ + data/menu edit = $(SED) \ -e 's!@version\@!$(VERSION)!' \ @@ -539,8 +541,6 @@ nodist_xsessions_DATA = \ data/xsession/openbox-kde.desktop dist_noinst_DATA = \ - data/rc.xsd \ - data/menu.xsd \ data/autostart/autostart.in \ data/autostart/openbox-autostart.in \ data/xsession/openbox.desktop.in \ @@ -587,7 +587,9 @@ dist_doc_DATA = \ AUTHORS \ CHANGELOG \ COPYING \ - data/rc.xsd \ + data/keys.xsd \ + data/mouse.xsd \ + data/applications.xsd \ data/menu.xsd \ doc/rc-mouse-focus.xml diff --git a/data/applications b/data/applications new file mode 100644 index 00000000..08ed70aa --- /dev/null +++ b/data/applications @@ -0,0 +1,83 @@ + + + diff --git a/data/applications.xsd b/data/applications.xsd new file mode 100644 index 00000000..6030c4a6 --- /dev/null +++ b/data/applications.xsd @@ -0,0 +1,101 @@ + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/keys b/data/keys new file mode 100644 index 00000000..ed5ae84c --- /dev/null +++ b/data/keys @@ -0,0 +1,118 @@ + + + + leftno + + + rightno + + + upno + + + downno + + + leftno + + + rightno + + + upno + + + downno + + + 1 + + + 2 + + + 3 + + + 4 + + + + + + + + + + + + + + + + client-menu + + + + + + + + + + + + + + + + + + + + + + + + yesyes + + + + + + + + + + + + right + + + + + left + + + + + up + + + + + down + + + + + + + + true + Konqueror + + kfmclient openProfile filemanagement + + + diff --git a/data/keys.xsd b/data/keys.xsd new file mode 100644 index 00000000..289adaa1 --- /dev/null +++ b/data/keys.xsd @@ -0,0 +1,36 @@ + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + diff --git a/data/menu.xml b/data/menu similarity index 100% rename from data/menu.xml rename to data/menu diff --git a/data/mouse b/data/mouse new file mode 100644 index 00000000..a512aed0 --- /dev/null +++ b/data/mouse @@ -0,0 +1,293 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + previous + + + next + + + previous + + + next + + + previous + + + next + + + + + + + + + + + + + + no + + + + + + + + + + + yes + + + + + + + + + + + + + + + + + + + + + + + + + client-menu + + + + + + top + + + + + + left + + + + + + right + + + + + + bottom + + + + + + client-menu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + client-menu + + + + + client-menu + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + vertical + + + horizontal + + + + + + + + + + + + + + + + + previous + + + next + + + + previous + + + next + + + previous + + + next + + + + + + + + + + + + + + + + client-list-combined-menu + + + root-menu + + + + + + previous + + + next + + + previous + + + next + + + diff --git a/data/mouse.xsd b/data/mouse.xsd new file mode 100644 index 00000000..9918a65c --- /dev/null +++ b/data/mouse.xsd @@ -0,0 +1,79 @@ + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/rc.xml b/data/rc.xml deleted file mode 100644 index 7598a72c..00000000 --- a/data/rc.xml +++ /dev/null @@ -1,730 +0,0 @@ - - - - - - - - 10 - 20 - - - - yes - - no - - yes - - no - - 200 - - no - - - - - Smart - -
yes
- - Primary - - 1 - -
- - - Clearlooks - NLIMC - - yes - yes - - sans - 8 - - bold - - normal - - - - sans - 8 - - bold - - normal - - - - sans - 9 - - normal - - normal - - - - sans - 9 - - normal - - normal - - - - sans - 9 - - bold - - normal - - - - sans - 9 - - bold - - normal - - - - - - - 4 - 1 - - - - 875 - - - - - yes - Nonpixel - - Center - - - - - 10 - - 10 - - - - - - - 0 - 0 - 0 - 0 - - - - TopLeft - - 0 - 0 - no - Above - - Vertical - - no - 300 - - 300 - - Middle - - - - - C-g - - - - leftno - - - rightno - - - upno - - - downno - - - leftno - - - rightno - - - upno - - - downno - - - 1 - - - 2 - - - 3 - - - 4 - - - - - - - - - - - - - - - - client-menu - - - - - - - - - - - - - - - - - - - - - - - - yesyes - - - - - - - - - - - - right - - - - - left - - - - - up - - - - - down - - - - - - - - true - Konqueror - - kfmclient openProfile filemanagement - - - - - - 1 - - 200 - - 400 - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - previous - - - next - - - previous - - - next - - - previous - - - next - - - - - - - - - - - - - - no - - - - - - - - - - - yes - - - - - - - - - - - - - - - - - - - - - - - - - client-menu - - - - - - top - - - - - - left - - - - - - right - - - - - - bottom - - - - - - client-menu - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - client-menu - - - - - client-menu - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - vertical - - - horizontal - - - - - - - - - - - - - - - - - previous - - - next - - - - previous - - - next - - - previous - - - next - - - - - - - - - - - - - - - - client-list-combined-menu - - - root-menu - - - - - - previous - - - next - - - previous - - - next - - - - - - - - - menu.xml - 200 - - no - - 100 - - 400 - - if this is a negative value, then the delay is infinite and the - submenu will not be hidden until a different submenu is opened --> - yes - - yes - - - - - - - -
diff --git a/data/rc.xsd b/data/rc.xsd deleted file mode 100644 index ad96994a..00000000 --- a/data/rc.xsd +++ /dev/null @@ -1,551 +0,0 @@ - - - - - - - -]> - - - - - - all these elements are expected in a openbox config file - - - - - - - - - - - - - - - - - - - - - - defines behaviour of windows when close to each other or the screen edge - - - - - - - - - defines aspects of window focus - - - - - - - - - - - - - - defines how new windows are placed - - - - - - - - - - - defines desktop margins - - - - - - - - - - - - - - - - - - - - - - - - - - - - - defines the number and names of desktops - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/openbox/config.c b/openbox/config.c index 9dd803be..5f4d9c1e 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -370,7 +370,7 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d) */ -static void parse_key(xmlNodePtr node, GList *keylist) +static void parse_keybind(xmlNodePtr node, GList *keylist) { gchar *keystring, **keys, **key; xmlNodePtr n; @@ -387,7 +387,7 @@ static void parse_key(xmlNodePtr node, GList *keylist) if ((n = obt_xml_find_sibling(node->children, "keybind"))) { while (n) { - parse_key(n, keylist); + parse_keybind(n, keylist); n = obt_xml_find_sibling(n->next, "keybind"); } } @@ -426,20 +426,12 @@ static void parse_keyboard(xmlNodePtr node, gpointer d) xmlNodePtr n; gchar *key; - keyboard_unbind_all(); - if ((n = obt_xml_find_sibling(node->children, "chainQuitKey"))) { key = obt_xml_node_string(n); translate_key(key, &config_keyboard_reset_state, &config_keyboard_reset_keycode); g_free(key); } - - if ((n = obt_xml_find_sibling(node->children, "keybind"))) - while (n) { - parse_key(n, NULL); - n = obt_xml_find_sibling(n->next, "keybind"); - } } /* @@ -454,10 +446,7 @@ static void parse_keyboard(xmlNodePtr node, gpointer d) static void parse_mouse(xmlNodePtr node, gpointer d) { - xmlNodePtr n, nbut, nact; - gchar *buttonstr; - gchar *cxstr; - ObMouseAction mact; + xmlNodePtr n; mouse_unbind_all(); @@ -476,70 +465,72 @@ static void parse_mouse(xmlNodePtr node, gpointer d) } if ((n = obt_xml_find_sibling(node, "screenEdgeWarpMouse"))) config_mouse_screenedgewarp = obt_xml_node_bool(n); +} - n = obt_xml_find_sibling(node, "context"); - while (n) { - gchar *modcxstr; - ObFrameContext cx; - - if (!obt_xml_attr_string(n, "name", &cxstr)) - goto next_n; - - modcxstr = g_strdup(cxstr); /* make a copy to mutilate */ - while (frame_next_context_from_string(modcxstr, &cx)) { - if (!cx) { - gchar *s = strchr(modcxstr, ' '); - if (s) { - *s = '\0'; - g_message(_("Invalid context \"%s\" in mouse binding"), - modcxstr); - *s = ' '; - } - continue; +static void parse_context(xmlNodePtr n, gpointer d) +{ + xmlNodePtr nbut, nact; + gchar *buttonstr; + gchar *cxstr; + ObMouseAction mact; + gchar *modcxstr; + ObFrameContext cx; + + if (!obt_xml_attr_string(n, "name", &cxstr)) + return; + + modcxstr = g_strdup(cxstr); /* make a copy to mutilate */ + while (frame_next_context_from_string(modcxstr, &cx)) { + if (!cx) { + gchar *s = strchr(modcxstr, ' '); + if (s) { + *s = '\0'; + g_message(_("Invalid context \"%s\" in mouse binding"), + modcxstr); + *s = ' '; } + continue; + } - nbut = obt_xml_find_sibling(n->children, "mousebind"); - while (nbut) { - if (!obt_xml_attr_string(nbut, "button", &buttonstr)) - goto next_nbut; - if (obt_xml_attr_contains(nbut, "action", "press")) - mact = OB_MOUSE_ACTION_PRESS; - else if (obt_xml_attr_contains(nbut, "action", "release")) - mact = OB_MOUSE_ACTION_RELEASE; - else if (obt_xml_attr_contains(nbut, "action", "click")) - mact = OB_MOUSE_ACTION_CLICK; - else if (obt_xml_attr_contains(nbut, "action","doubleclick")) - mact = OB_MOUSE_ACTION_DOUBLE_CLICK; - else if (obt_xml_attr_contains(nbut, "action", "drag")) - mact = OB_MOUSE_ACTION_MOTION; - else - goto next_nbut; - - nact = obt_xml_find_sibling(nbut->children, "action"); - while (nact) { - ObActionList *actions; - ObActionParser *p; - xmlChar *c; - - c = xmlNodeGetContent(nact); - p = action_parser_new(); - if ((actions = action_parser_read_string(p, (gchar*)c))) - mouse_bind(buttonstr, cx, mact, actions); - nact = obt_xml_find_sibling(nact->next, "action"); - action_list_unref(actions); - xmlFree(c); - action_parser_unref(p); - } + nbut = obt_xml_find_sibling(n->children, "mousebind"); + while (nbut) { + if (!obt_xml_attr_string(nbut, "button", &buttonstr)) + goto next_nbut; + if (obt_xml_attr_contains(nbut, "action", "press")) + mact = OB_MOUSE_ACTION_PRESS; + else if (obt_xml_attr_contains(nbut, "action", "release")) + mact = OB_MOUSE_ACTION_RELEASE; + else if (obt_xml_attr_contains(nbut, "action", "click")) + mact = OB_MOUSE_ACTION_CLICK; + else if (obt_xml_attr_contains(nbut, "action","doubleclick")) + mact = OB_MOUSE_ACTION_DOUBLE_CLICK; + else if (obt_xml_attr_contains(nbut, "action", "drag")) + mact = OB_MOUSE_ACTION_MOTION; + else + goto next_nbut; + + nact = obt_xml_find_sibling(nbut->children, "action"); + while (nact) { + ObActionList *actions; + ObActionParser *p; + xmlChar *c; + + c = xmlNodeGetContent(nact); + p = action_parser_new(); + if ((actions = action_parser_read_string(p, (gchar*)c))) + mouse_bind(buttonstr, cx, mact, actions); + nact = obt_xml_find_sibling(nact->next, "action"); + action_list_unref(actions); + xmlFree(c); + action_parser_unref(p); + } g_free(buttonstr); - next_nbut: + next_nbut: nbut = obt_xml_find_sibling(nbut->next, "mousebind"); - } } - g_free(modcxstr); - g_free(cxstr); - next_n: - n = obt_xml_find_sibling(n->next, "context"); } + g_free(modcxstr); + g_free(cxstr); } static void parse_focus(xmlNodePtr node, gpointer d) @@ -919,9 +910,6 @@ static void bind_default_keyboard(void) { ObDefKeyBind *it; ObDefKeyBind binds[] = { - { "Left", - "Execute startupnotify:yes name:Konqueror \\\n" - " command:(kfmclient openProfile filemanagement)" }, { "A-Tab", "NextWindow" }, { "S-A-Tab", "PreviousWindow" }, { "A-F4", "Close" }, @@ -1013,8 +1001,37 @@ static void bind_default_mouse(void) action_parser_unref(p); } -void config_startup(ObtXmlInst *i) +void config_startup() +{ +} + +enum ObConfigType { + CONFIG_FILE, + CACHE_FILE +}; + +static gboolean load_file(ObtXmlInst *i, enum ObConfigType type, + const gchar *domain, const gchar *file) { + gboolean load = FALSE; + + switch (type) { + case CONFIG_FILE: + load = obt_xml_load_config_file(i, domain, file, file); + break; + case CACHE_FILE: + load = obt_xml_load_cache_file(i, domain, file, file); + break; + } + + return load; +} + +gboolean config_load_config(void) +{ + ObtXmlInst *i = obt_xml_instance_new(); + gboolean ok; + config_focus_new = TRUE; config_focus_follow = FALSE; config_focus_delay = 0; @@ -1087,8 +1104,6 @@ void config_startup(ObtXmlInst *i) translate_key("C-g", &config_keyboard_reset_state, &config_keyboard_reset_keycode); - bind_default_keyboard(); - obt_xml_register(i, "keyboard", parse_keyboard, NULL); config_mouse_threshold = 8; @@ -1096,8 +1111,6 @@ void config_startup(ObtXmlInst *i) config_mouse_screenedgetime = 400; config_mouse_screenedgewarp = FALSE; - bind_default_mouse(); - obt_xml_register(i, "mouse", parse_mouse, NULL); config_resist_win = 10; @@ -1115,9 +1128,70 @@ void config_startup(ObtXmlInst *i) obt_xml_register(i, "menu", parse_menu, NULL); - config_per_app_settings = NULL; + ok = load_file(i, CACHE_FILE, "openbox", "config"); + if (ok) { + obt_xml_tree_from_root(i); + obt_xml_close(i); + } + obt_xml_instance_unref(i); + return ok; +} +gboolean config_load_keys(void) +{ + ObtXmlInst *i = obt_xml_instance_new(); + gboolean ok; + + ok = load_file(i, CONFIG_FILE, "openbox", "keys"); + if (!ok) + bind_default_keyboard(); + else { + xmlNodePtr n, r; + + r = obt_xml_root(i); + if ((n = obt_xml_find_sibling(r->children, "keybind"))) + while (n) { + parse_keybind(n, NULL); + n = obt_xml_find_sibling(n->next, "keybind"); + } + } + obt_xml_instance_unref(i); + return ok; +} + +gboolean config_load_mouse(void) +{ + ObtXmlInst *i = obt_xml_instance_new(); + gboolean ok; + + obt_xml_register(i, "context", parse_context, NULL); + + ok = load_file(i, CONFIG_FILE, "openbox", "mouse"); + if (!ok) + bind_default_mouse(); + else { + obt_xml_tree_from_root(i); + obt_xml_close(i); + } + obt_xml_instance_unref(i); + return ok; +} + +gboolean config_load_windows(void) +{ + ObtXmlInst *i = obt_xml_instance_new(); + gboolean ok; + + config_per_app_settings = NULL; obt_xml_register(i, "applications", parse_per_app_settings, NULL); + + ok = load_file(i, CONFIG_FILE, "openbox", "applications"); + if (ok) { + obt_xml_tree_from_root(i); + obt_xml_close(i); + } + obt_xml_instance_unref(i); + return ok; } void config_shutdown(void) diff --git a/openbox/config.h b/openbox/config.h index 90b6581a..aef0f06b 100644 --- a/openbox/config.h +++ b/openbox/config.h @@ -206,9 +206,14 @@ extern GSList *config_menu_files; /*! Per app settings */ extern GSList *config_per_app_settings; -void config_startup(ObtXmlInst *i); +void config_startup(void); void config_shutdown(void); +gboolean config_load_config(void); +gboolean config_load_keys(void); +gboolean config_load_mouse(void); +gboolean config_load_windows(void); + /*! Create an ObAppSettings structure with the default values */ ObAppSettings* config_create_app_settings(void); /*! Copies any settings in src to dest, if they are their default value in diff --git a/openbox/menu.c b/openbox/menu.c index 54875d85..16e8448b 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -101,14 +101,14 @@ void menu_startup(gboolean reconfig) if (!loaded) { if (obt_xml_load_config_file(menu_parse_inst, "openbox", - "menu.xml", + "menu", "openbox_menu")) { obt_xml_tree_from_root(menu_parse_inst); obt_xml_close(menu_parse_inst); } else g_message(_("Unable to find a valid menu file \"%s\""), - "menu.xml"); + "menu"); } g_assert(menu_parse_state.parent == NULL); diff --git a/openbox/openbox.c b/openbox/openbox.c index 14d0bd27..8cd9c878 100644 --- a/openbox/openbox.c +++ b/openbox/openbox.c @@ -105,7 +105,6 @@ static Cursor cursors[OB_NUM_CURSORS]; static gint exitcode = 0; static guint remote_control = 0; static gboolean being_replaced = FALSE; -static gchar *config_file = NULL; static gchar *startup_cmd = NULL; static void signal_handler(gint signal, gpointer data); @@ -229,45 +228,22 @@ gint main(gint argc, gchar **argv) if (reconfigure) obt_keyboard_reload(); - { - ObtXmlInst *i; - - /* startup the parsing so everything can register sections - of the rc */ - i = obt_xml_instance_new(); + config_startup(); + { /* register all the available actions and filters */ action_startup(reconfigure); action_filter_startup(reconfigure); - /* start up config which sets up with the parser */ - config_startup(i); - - /* parse/load user options */ - if ((config_file && - obt_xml_load_file(i, config_file, "openbox_config")) || - obt_xml_load_config_file(i, "openbox", "rc", - "openbox_config")) - { - obt_xml_tree_from_root(i); - obt_xml_close(i); - } - else { - g_message(_("Unable to find a valid config file, using some simple defaults")); - config_file = NULL; - } - - if (config_file) { - gchar *p = g_filename_to_utf8(config_file, -1, - NULL, NULL, NULL); - if (p) - OBT_PROP_SETS(obt_root(ob_screen), OB_CONFIG_FILE, p); - g_free(p); - } - else - OBT_PROP_ERASE(obt_root(ob_screen), OB_CONFIG_FILE); - /* we're done with parsing now, kill it */ - obt_xml_instance_unref(i); + /* set up the various file loaders */ + config_load_config(); + if (!config_load_keys()) + g_message(_("Unable to find a valid \"%s\" file, using some simple defaults"), "keys"); + if (!config_load_mouse()) + g_message(_("Unable to find a valid \"%s\" file, using some simple defaults"), "mouse"); + if (!config_load_windows()) + g_message(_("No \"%s\" file found, not using any rules"), + "windows"); } /* load the theme specified in the rc file */ @@ -533,10 +509,6 @@ static void print_help(void) g_print(_(" --help Display this help and exit\n")); g_print(_(" --version Display the version and exit\n")); g_print(_(" --replace Replace the currently running window manager\n")); - /* TRANSLATORS: if you translate "FILE" here, make sure to keep the "Specify..." - aligned still, if you have to, make a new line with \n and 22 spaces. It's - fine to leave it as FILE though. */ - g_print(_(" --config-file FILE Specify the path to the config file to use\n")); g_print(_(" --sm-disable Disable connection to the session manager\n")); g_print(_("\nPassing messages to a running Openbox instance:\n")); g_print(_(" --reconfigure Reload Openbox's configuration\n")); @@ -664,17 +636,6 @@ static void parse_args(gint *argc, gchar **argv) else if (!strcmp(argv[i], "--exit")) { remote_control = 3; } - else if (!strcmp(argv[i], "--config-file")) { - if (i == *argc - 1) /* no args left */ - g_printerr(_("%s requires an argument\n"), "--config-file"); - else { - /* this will be in the current locale encoding, which is - what we want */ - config_file = argv[i+1]; - ++i; /* skip the argument */ - ob_debug("--config-file %s", config_file); - } - } else if (!strcmp(argv[i], "--sm-save-file")) { if (i == *argc - 1) /* no args left */ /* not translated cuz it's sekret */ -- 2.34.1