From 0a17fe973c2cf655e301217baf618af73c20229a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fernando=20Tarl=C3=A1=20Cardoso=20Lemos?= Date: Fri, 26 Nov 2010 22:27:38 -0200 Subject: [PATCH] Make the restart path configurable. --- include/config.h | 1 + src/cfgparse.l | 1 + src/cfgparse.y | 9 +++++++++ src/config.c | 2 ++ src/tree.c | 8 ++++++-- src/util.c | 2 +- 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/config.h b/include/config.h index c9e8e1a4..abbee5e7 100644 --- a/include/config.h +++ b/include/config.h @@ -89,6 +89,7 @@ struct Config { const char *font; const char *ipc_socket_path; + const char *restart_state_path; int container_mode; int container_stack_limit; diff --git a/src/cfgparse.l b/src/cfgparse.l index eb9c25c7..93ce916c 100644 --- a/src/cfgparse.l +++ b/src/cfgparse.l @@ -91,6 +91,7 @@ assign { BEGIN(ASSIGN_COND); return TOKASSIGN; } set[^\n]* { return TOKCOMMENT; } ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; } ipc_socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; } +restart_state { BEGIN(BIND_AWS_COND); return TOKRESTARTSTATE; } new_container { return TOKNEWCONTAINER; } new_window { return TOKNEWWINDOW; } focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; } diff --git a/src/cfgparse.y b/src/cfgparse.y index c2227f67..eaed7c5d 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -217,6 +217,7 @@ void parse_file(const char *f) { %token TOKASSIGN "assign" %token TOKSET %token TOKIPCSOCKET "ipc_socket" +%token TOKRESTARTSTATE "restart_state" %token TOKEXEC "exec" %token TOKSINGLECOLOR %token TOKCOLOR @@ -248,6 +249,7 @@ line: | workspace | assign | ipcsocket + | restart_state | exec | single_color | color @@ -554,6 +556,13 @@ ipcsocket: } ; +restart_state: + TOKRESTARTSTATE WHITESPACE STR + { + config.restart_state_path = $3; + } + ; + exec: TOKEXEC WHITESPACE STR { diff --git a/src/config.c b/src/config.c index 93390b4a..c02d1c2a 100644 --- a/src/config.c +++ b/src/config.c @@ -364,6 +364,8 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath, INIT_COLOR(config.bar.unfocused, "#333333", "#222222", "#888888"); INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff"); + config.restart_state_path = "~/.i3/_restart.json"; + parse_configuration(override_configpath); if (reload) { diff --git a/src/tree.c b/src/tree.c index e37eb5f9..947a8daa 100644 --- a/src/tree.c +++ b/src/tree.c @@ -14,7 +14,7 @@ struct all_cons_head all_cons = TAILQ_HEAD_INITIALIZER(all_cons); * */ bool tree_restore() { - char *globbed = resolve_tilde("~/.i3/_restart.json"); + char *globbed = resolve_tilde(config.restart_state_path); if (!path_exists(globbed)) { LOG("%s does not exist, not restoring tree\n", globbed); @@ -27,7 +27,11 @@ bool tree_restore() { focused = croot; tree_append_json(globbed); - char *old_restart = resolve_tilde("~/.i3/_restart.json.old"); + + size_t path_len = strlen(config.restart_state_path); + char *old_restart = malloc(path_len + 5); + strncpy(old_restart, config.restart_state_path, path_len + 5); + strncat(old_restart, ".old", path_len + 5); unlink(old_restart); rename(globbed, old_restart); free(globbed); diff --git a/src/util.c b/src/util.c index 04ec1508..75203cfb 100644 --- a/src/util.c +++ b/src/util.c @@ -375,7 +375,7 @@ void store_restart_layout() { unsigned int length; y(get_buf, &payload, &length); - char *globbed = resolve_tilde("~/.i3/_restart.json"); + char *globbed = resolve_tilde(config.restart_state_path); int fd = open(globbed, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); free(globbed); if (fd == -1) { -- 2.39.5