apply updated workspace gap assignments after reload (#5279)

Fixes https://github.com/i3/i3/issues/5257
This commit is contained in:
Michael Stapelberg 2022-11-12 17:32:30 +01:00 committed by GitHub
parent 1ba0eaca22
commit 96614a2f32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 119 additions and 38 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -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 workspaces name begins with
* a positive number. Otherwise its 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;

View File

@ -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;