diff options
author | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2022-11-12 17:32:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-12 17:32:30 +0100 |
commit | 96614a2f32ae5f0a8f39e49d98a4d2183a379516 (patch) | |
tree | b218f24e0af21d4dda7f9c7958f6cb5f394a5319 | |
parent | 1ba0eaca2298afda86fecc17549b2d5881aca5fe (diff) | |
download | i3-96614a2f32ae5f0a8f39e49d98a4d2183a379516.tar.gz i3-96614a2f32ae5f0a8f39e49d98a4d2183a379516.zip |
apply updated workspace gap assignments after reload (#5279)
Fixes https://github.com/i3/i3/issues/5257
-rw-r--r-- | include/gaps.h | 13 | ||||
-rw-r--r-- | src/config.c | 4 | ||||
-rw-r--r-- | src/gaps.c | 51 | ||||
-rw-r--r-- | src/workspace.c | 39 | ||||
-rw-r--r-- | testcases/t/319-gaps.t | 50 |
5 files changed, 119 insertions, 38 deletions
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; @@ -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 = <<EOT; # i3 config file (v4) @@ -233,4 +234,53 @@ is_deeply(scalar $floating->rect, $orig_rect, 'floating window position unchange exit_gracefully($pid); +################################################################################ +# Ensure existing workspaces pick up changes in gap assignments (issue #5257). +################################################################################ + +$config = <<EOT; +# i3 config file (v4) +font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 + +gaps inner 10 + +default_border pixel 0 +EOT + +$pid = launch_with_config($config); + +cmd 'workspace 2'; + +$left = open_window; +$right = open_window; +sync_with_i3; + +is_gaps(); + +my $version = i3()->get_version()->recv; +open(my $configfh, '>', $version->{'loaded_config_file_name'}); +say $configfh <<EOT; +# i3 config file (v4) +font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 + +# Increase gaps for (existing) workspace 2 to 16px +workspace 2 gaps inner 16 +gaps inner 10 + +default_border pixel 0 +EOT +close($configfh); + +cmd 'reload'; + +sync_with_i3; + +$inner_gaps = 16; +$outer_gaps = 0; +$total_gaps = $outer_gaps + $inner_gaps; + +is_gaps(); + +exit_gracefully($pid); + done_testing; |