Make the restart path configurable.

This commit is contained in:
Fernando Tarlá Cardoso Lemos 2010-11-26 22:27:38 -02:00 committed by Michael Stapelberg
parent 622b51a1ea
commit 0a17fe973c
6 changed files with 20 additions and 3 deletions

View File

@ -89,6 +89,7 @@ struct Config {
const char *font; const char *font;
const char *ipc_socket_path; const char *ipc_socket_path;
const char *restart_state_path;
int container_mode; int container_mode;
int container_stack_limit; int container_stack_limit;

View File

@ -91,6 +91,7 @@ assign { BEGIN(ASSIGN_COND); return TOKASSIGN; }
set[^\n]* { return TOKCOMMENT; } set[^\n]* { return TOKCOMMENT; }
ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; } ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
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_container { return TOKNEWCONTAINER; }
new_window { return TOKNEWWINDOW; } new_window { return TOKNEWWINDOW; }
focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; } focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }

View File

@ -217,6 +217,7 @@ void parse_file(const char *f) {
%token TOKASSIGN "assign" %token TOKASSIGN "assign"
%token TOKSET %token TOKSET
%token TOKIPCSOCKET "ipc_socket" %token TOKIPCSOCKET "ipc_socket"
%token TOKRESTARTSTATE "restart_state"
%token TOKEXEC "exec" %token TOKEXEC "exec"
%token TOKSINGLECOLOR %token TOKSINGLECOLOR
%token TOKCOLOR %token TOKCOLOR
@ -248,6 +249,7 @@ line:
| workspace | workspace
| assign | assign
| ipcsocket | ipcsocket
| restart_state
| exec | exec
| single_color | single_color
| color | color
@ -554,6 +556,13 @@ ipcsocket:
} }
; ;
restart_state:
TOKRESTARTSTATE WHITESPACE STR
{
config.restart_state_path = $<string>3;
}
;
exec: exec:
TOKEXEC WHITESPACE STR TOKEXEC WHITESPACE STR
{ {

View File

@ -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.unfocused, "#333333", "#222222", "#888888");
INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff"); INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff");
config.restart_state_path = "~/.i3/_restart.json";
parse_configuration(override_configpath); parse_configuration(override_configpath);
if (reload) { if (reload) {

View File

@ -14,7 +14,7 @@ struct all_cons_head all_cons = TAILQ_HEAD_INITIALIZER(all_cons);
* *
*/ */
bool tree_restore() { bool tree_restore() {
char *globbed = resolve_tilde("~/.i3/_restart.json"); char *globbed = resolve_tilde(config.restart_state_path);
if (!path_exists(globbed)) { if (!path_exists(globbed)) {
LOG("%s does not exist, not restoring tree\n", globbed); LOG("%s does not exist, not restoring tree\n", globbed);
@ -27,7 +27,11 @@ bool tree_restore() {
focused = croot; focused = croot;
tree_append_json(globbed); 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); unlink(old_restart);
rename(globbed, old_restart); rename(globbed, old_restart);
free(globbed); free(globbed);

View File

@ -375,7 +375,7 @@ void store_restart_layout() {
unsigned int length; unsigned int length;
y(get_buf, &payload, &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); int fd = open(globbed, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
free(globbed); free(globbed);
if (fd == -1) { if (fd == -1) {