add a --config-file command line option, and OB_CONFIG_FILE root hint

This commit is contained in:
Dana Jansens 2008-02-02 09:22:50 -05:00
parent 674c042c68
commit bbad88aa21
6 changed files with 40 additions and 18 deletions

View file

@ -107,6 +107,7 @@ static KeyCode keys[OB_NUM_KEYS];
static gint exitcode = 0;
static guint remote_control = 0;
static gboolean being_replaced = FALSE;
static gchar *config_file = NULL;
static void signal_handler(gint signal, gpointer data);
static void remove_args(gint *argc, gchar **argv, gint index, gint num);
@ -246,17 +247,26 @@ gint main(gint argc, gchar **argv)
config_startup(i);
/* parse/load user options */
if (parse_load_rc(NULL, &doc, &node)) {
if (parse_load_rc(config_file, &doc, &node)) {
parse_tree(i, doc, node->xmlChildrenNode);
parse_close(doc);
} else
}
else {
g_message(_("Unable to find a valid config file, using some simple defaults"));
config_file = NULL;
}
/*
if (config_type != NULL)
if (config_file) {
gchar *p = g_filename_to_utf8(config_file, -1,
NULL, NULL, NULL);
if (p)
PROP_SETS(RootWindow(ob_display, ob_screen),
ob_config, config_type);
*/
ob_config_file, p);
g_free(p);
}
else
PROP_ERASE(RootWindow(ob_display, ob_screen),
ob_config_file);
/* we're done with parsing now, kill it */
parse_shutdown(i);
@ -489,6 +499,7 @@ static void print_help()
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"));
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"));
@ -566,6 +577,18 @@ 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 */
/* not translated cuz it's sekret */
g_printerr(_("--config-file requires an argument\n"));
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\n", config_file);
}
}
else if (!strcmp(argv[i], "--sm-save-file")) {
if (i == *argc - 1) /* no args left */
/* not translated cuz it's sekret */

View file

@ -172,6 +172,7 @@ void prop_startup(void)
CREATE(openbox_pid, "_OPENBOX_PID");
CREATE(ob_theme, "_OB_THEME");
CREATE(ob_config_file, "_OB_CONFIG_FILE");
CREATE(ob_wm_action_undecorate, "_OB_WM_ACTION_UNDECORATE");
CREATE(ob_wm_state_undecorated, "_OB_WM_STATE_UNDECORATED");
CREATE(ob_control, "_OB_CONTROL");

View file

@ -194,6 +194,7 @@ typedef struct Atoms {
Atom ob_wm_state_undecorated;
Atom openbox_pid; /* this is depreecated in favour of ob_control */
Atom ob_theme;
Atom ob_config_file;
Atom ob_control;
} Atoms;
extern Atoms prop_atoms;

View file

@ -300,6 +300,7 @@ gboolean screen_annex(void)
supported[i++] = prop_atoms.ob_wm_state_undecorated;
supported[i++] = prop_atoms.openbox_pid;
supported[i++] = prop_atoms.ob_theme;
supported[i++] = prop_atoms.ob_config_file;
supported[i++] = prop_atoms.ob_control;
g_assert(i == num_support);

View file

@ -79,25 +79,21 @@ void parse_register(ObParseInst *i, const gchar *tag,
g_hash_table_insert(i->callbacks, c->tag, c);
}
gboolean parse_load_rc(const gchar *type, xmlDocPtr *doc, xmlNodePtr *root)
gboolean parse_load_rc(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root)
{
GSList *it;
gboolean r = FALSE;
gchar *fname;
if (type == NULL)
fname = g_strdup("rc.xml");
else
fname = g_strdup_printf("rc-%s.xml", type);
if (file && parse_load(file, "openbox_config", doc, root))
return TRUE;
for (it = xdg_config_dir_paths; !r && it; it = g_slist_next(it)) {
gchar *path;
path = g_build_filename(it->data, "openbox", fname, NULL);
path = g_build_filename(it->data, "openbox", "rc.xml", NULL);
r = parse_load(path, "openbox_config", doc, root);
g_free(path);
}
g_free(fname);
return r;
}

View file

@ -35,10 +35,10 @@ ObParseInst* parse_startup();
void parse_shutdown(ObParseInst *inst);
/*! Loads Openbox's rc, from the normal paths
@type The configuration type to load, or NULL to use the default.
e.g. "gnome" would load rc-gnome.xml.
@param file The path of the config to try load. NULL to load from the
default path
*/
gboolean parse_load_rc(const gchar *type, xmlDocPtr *doc, xmlNodePtr *root);
gboolean parse_load_rc(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root);
/* Loads an Openbox menu, from the normal paths */
gboolean parse_load_menu(const gchar *file, xmlDocPtr *doc, xmlNodePtr *root);
/* Loads an Openbox theme, from the normal paths */