diff --git a/include/gaps.h b/include/gaps.h index 3652a478..cb4d0093 100644 --- a/include/gaps.h +++ b/include/gaps.h @@ -26,3 +26,16 @@ bool gaps_should_inset_con(Con *con, int children); * the container is not touching the edge of the screen in that direction. */ bool gaps_has_adjacent_container(Con *con, direction_t direction); + +/** + * Returns the configured gaps for this workspace based on the workspace name, + * number, and configured workspace gap assignments. + */ +gaps_t gaps_for_workspace(Con *ws); + +/** + * Re-applies all workspace gap assignments to existing workspaces after + * reloading the configuration file. + * + */ +void gaps_reapply_workspace_assignments(void); diff --git a/src/config.c b/src/config.c index 7cbdad1f..f06a3f8d 100644 --- a/src/config.c +++ b/src/config.c @@ -296,11 +296,11 @@ bool load_configuration(const char *override_configpath, config_load_t load_type translate_keysyms(); grab_all_keys(conn); regrab_all_buttons(conn); + gaps_reapply_workspace_assignments(); /* Redraw the currently visible decorations on reload, so that the * possibly new drawing parameters changed. */ - x_deco_recurse(croot); - xcb_flush(conn); + tree_render(); } return result == 0; diff --git a/src/gaps.c b/src/gaps.c index a67e8ceb..59c25a34 100644 --- a/src/gaps.c +++ b/src/gaps.c @@ -110,3 +110,54 @@ bool gaps_has_adjacent_container(Con *con, direction_t direction) { /* For fullscreen containers, only consider the adjacent container if it is also fullscreen. */ return con_has_parent(con, fullscreen) && con_has_parent(second, fullscreen); } + +/* + * Returns the configured gaps for this workspace based on the workspace name, + * number, and configured workspace gap assignments. + */ +gaps_t gaps_for_workspace(Con *ws) { + gaps_t gaps = (gaps_t){0, 0, 0, 0, 0}; + struct Workspace_Assignment *assignment; + TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) { + if (strcmp(assignment->name, ws->name) == 0) { + gaps = assignment->gaps; + break; + } else if (ws->num != -1 && name_is_digits(assignment->name) && ws_name_to_number(assignment->name) == ws->num) { + gaps = assignment->gaps; + } + } + + if (gaps.inner != 0) { + gaps.inner -= config.gaps.inner; + } + if (gaps.top != 0) { + gaps.top -= config.gaps.top; + } + if (gaps.right != 0) { + gaps.right -= config.gaps.right; + } + if (gaps.bottom != 0) { + gaps.bottom -= config.gaps.bottom; + } + if (gaps.left != 0) { + gaps.left -= config.gaps.left; + } + + return gaps; +} + +/* + * Re-applies all workspace gap assignments to existing workspaces after + * reloading the configuration file. + * + */ +void gaps_reapply_workspace_assignments(void) { + Con *output, *workspace = NULL; + TAILQ_FOREACH (output, &(croot->nodes_head), nodes) { + Con *content = output_get_content(output); + TAILQ_FOREACH (workspace, &(content->nodes_head), nodes) { + DLOG("updating gap assignments for workspace %s\n", workspace->name); + workspace->gaps = gaps_for_workspace(workspace); + } + } +} diff --git a/src/workspace.c b/src/workspace.c index 9d8fd8bd..1bf1225c 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -135,38 +135,11 @@ Con *workspace_get(const char *num) { } LOG("Creating new workspace \"%s\"\n", num); - gaps_t gaps = (gaps_t){0, 0, 0, 0, 0}; /* We set workspace->num to the number if this workspace’s name begins with * a positive number. Otherwise it’s a named ws and num will be 1. */ const int parsed_num = ws_name_to_number(num); - struct Workspace_Assignment *assignment; - TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) { - if (strcmp(assignment->name, num) == 0) { - gaps = assignment->gaps; - break; - } else if (parsed_num != -1 && name_is_digits(assignment->name) && ws_name_to_number(assignment->name) == parsed_num) { - gaps = assignment->gaps; - } - } - - if (gaps.inner != 0) { - gaps.inner -= config.gaps.inner; - } - if (gaps.top != 0) { - gaps.top -= config.gaps.top; - } - if (gaps.right != 0) { - gaps.right -= config.gaps.right; - } - if (gaps.bottom != 0) { - gaps.bottom -= config.gaps.bottom; - } - if (gaps.left != 0) { - gaps.left -= config.gaps.left; - } - Con *output = get_assigned_output(num, parsed_num); /* if an assignment is not found, we create this workspace on the current output */ if (!output) { @@ -187,7 +160,7 @@ Con *workspace_get(const char *num) { workspace->workspace_layout = config.default_layout; workspace->num = parsed_num; workspace->type = CT_WORKSPACE; - workspace->gaps = gaps; + workspace->gaps = gaps_for_workspace(workspace); con_attach(workspace, output_get_content(output), false); _workspace_apply_default_orientation(workspace); @@ -314,14 +287,6 @@ Con *create_workspace_on_output(Output *output, Con *content) { sasprintf(&(ws->name), "%d", c); } - struct Workspace_Assignment *assignment; - TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) { - if (strcmp(assignment->name, ws->name) == 0) { - ws->gaps = assignment->gaps; - break; - } - } - con_attach(ws, content, false); char *name; @@ -329,6 +294,8 @@ Con *create_workspace_on_output(Output *output, Con *content) { x_set_name(ws, name); free(name); + ws->gaps = gaps_for_workspace(ws); + ws->fullscreen_mode = CF_OUTPUT; ws->workspace_layout = config.default_layout; diff --git a/testcases/t/319-gaps.t b/testcases/t/319-gaps.t index eefb9281..903a4845 100644 --- a/testcases/t/319-gaps.t +++ b/testcases/t/319-gaps.t @@ -18,6 +18,7 @@ # Ticket: #3724 use i3test i3_autostart => 0; +use i3test::Util qw(slurp); my $config = <rect, $orig_rect, 'floating window position unchange exit_gracefully($pid); +################################################################################ +# Ensure existing workspaces pick up changes in gap assignments (issue #5257). +################################################################################ + +$config = <get_version()->recv; +open(my $configfh, '>', $version->{'loaded_config_file_name'}); +say $configfh <