From: Albert Safin Date: Mon, 10 Dec 2018 14:51:30 +0000 (+0700) Subject: Preserve back_and_forth during restart X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;ds=sidebyside;h=64ab1f42b7f5612c906fdda4c1e1e51cf690d7b2;p=i3%2Fi3 Preserve back_and_forth during restart Add new key "previous_workspace_name" to the json dump of the root container. --- diff --git a/include/workspace.h b/include/workspace.h index 28d9eb66..db544ce8 100644 --- a/include/workspace.h +++ b/include/workspace.h @@ -24,6 +24,13 @@ #define NET_WM_DESKTOP_NONE 0xFFFFFFF0 #define NET_WM_DESKTOP_ALL 0xFFFFFFFF +/** + * Stores a copy of the name of the last used workspace for the workspace + * back-and-forth switching. + * + */ +extern char *previous_workspace_name; + /** * Returns the workspace with the given name or NULL if such a workspace does * not exist. diff --git a/src/ipc.c b/src/ipc.c index d0fb965c..2ad5ae0f 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -651,6 +651,11 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) { y(integer, con->depth); } + if (inplace_restart && con->type == CT_ROOT && previous_workspace_name) { + ystr("previous_workspace_name"); + ystr(previous_workspace_name); + } + y(map_close); } diff --git a/src/load_layout.c b/src/load_layout.c index 003affee..47daada1 100644 --- a/src/load_layout.c +++ b/src/load_layout.c @@ -420,6 +420,9 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) { else if (strcasecmp(buf, "changed") == 0) json_node->scratchpad_state = SCRATCHPAD_CHANGED; free(buf); + } else if (strcasecmp(last_key, "previous_workspace_name") == 0) { + FREE(previous_workspace_name); + previous_workspace_name = sstrndup((const char *)val, len); } } return 1; diff --git a/src/workspace.c b/src/workspace.c index f95073c9..2af88d73 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -11,9 +11,12 @@ #include "all.h" #include "yajl_utils.h" -/* Stores a copy of the name of the last used workspace for the workspace - * back-and-forth switching. */ -static char *previous_workspace_name = NULL; +/* + * Stores a copy of the name of the last used workspace for the workspace + * back-and-forth switching. + * + */ +char *previous_workspace_name = NULL; /* NULL-terminated list of workspace names (in order) extracted from * keybindings. */ diff --git a/testcases/t/176-workspace-baf.t b/testcases/t/176-workspace-baf.t index 01906e46..133e00fc 100644 --- a/testcases/t/176-workspace-baf.t +++ b/testcases/t/176-workspace-baf.t @@ -163,6 +163,14 @@ cmd 'scratchpad show'; cmd 'workspace back_and_forth'; is(focused_ws, '6: baz', 'workspace 6 now focused'); +################################################################################ +# See if BAF is preserved after restart +################################################################################ + +cmd 'restart'; +cmd 'workspace back_and_forth'; +is(focused_ws, '5: foo', 'workspace 5 focused after restart'); + exit_gracefully($pid); done_testing;