diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-29 11:06:07 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-09-29 11:08:19 +1000 |
commit | 415a48ac6387a62a59adb8ed1168e851509a0ce3 (patch) | |
tree | fd0027a67439414e164318182be29a3529805543 /sway/commands/workspace.c | |
parent | Merge pull request #2724 from RedSoxFan/update-man-pages (diff) | |
download | sway-415a48ac6387a62a59adb8ed1168e851509a0ce3.tar.gz sway-415a48ac6387a62a59adb8ed1168e851509a0ce3.tar.zst sway-415a48ac6387a62a59adb8ed1168e851509a0ce3.zip |
Make gaps implementation consistent with i3-gaps
This changes our gaps implementation to behave like i3-gaps.
Our previous implementation allowed you to set gaps on a per container
basis. This isn't supported by i3-gaps and doesn't seem to have a
practical use case. The gaps_outer and gaps_inner properties on
containers are now removed as they just read the gaps_inner from the
workspace.
`gaps inner|outer <px>` no longer changes the gaps for all workspaces.
It only sets defaults for new workspaces.
`gaps inner|outer current|workspace|all set|plus|minus <px>` is now
runtime only, and the workspace option is now removed. `current` now
sets gaps for the current workspace as opposed to the current container.
`workspace <ws> gaps inner|outer <px>` is now implemented. This sets
defaults for a workspace.
This also fixes a bug where changing the layout of a split container
from linear to tabbed would cause gaps to not be applied to it until you
switch to another workspace and back.
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r-- | sway/commands/workspace.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 2ce7872d..63f29641 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -20,6 +20,8 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) { | |||
20 | return NULL; | 20 | return NULL; |
21 | } | 21 | } |
22 | wsc->workspace = strdup(ws_name); | 22 | wsc->workspace = strdup(ws_name); |
23 | wsc->gaps_inner = -1; | ||
24 | wsc->gaps_outer = -1; | ||
23 | list_add(config->workspace_configs, wsc); | 25 | list_add(config->workspace_configs, wsc); |
24 | return wsc; | 26 | return wsc; |
25 | } | 27 | } |
@@ -37,6 +39,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
37 | } | 39 | } |
38 | 40 | ||
39 | int output_location = -1; | 41 | int output_location = -1; |
42 | int gaps_location = -1; | ||
40 | 43 | ||
41 | for (int i = 0; i < argc; ++i) { | 44 | for (int i = 0; i < argc; ++i) { |
42 | if (strcasecmp(argv[i], "output") == 0) { | 45 | if (strcasecmp(argv[i], "output") == 0) { |
@@ -44,6 +47,12 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
44 | break; | 47 | break; |
45 | } | 48 | } |
46 | } | 49 | } |
50 | for (int i = 0; i < argc; ++i) { | ||
51 | if (strcasecmp(argv[i], "gaps") == 0) { | ||
52 | gaps_location = i; | ||
53 | break; | ||
54 | } | ||
55 | } | ||
47 | if (output_location >= 0) { | 56 | if (output_location >= 0) { |
48 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { | 57 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) { |
49 | return error; | 58 | return error; |
@@ -57,6 +66,35 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
57 | } | 66 | } |
58 | free(wsc->output); | 67 | free(wsc->output); |
59 | wsc->output = strdup(argv[output_location + 1]); | 68 | wsc->output = strdup(argv[output_location + 1]); |
69 | } else if (gaps_location >= 0) { | ||
70 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, gaps_location + 3))) { | ||
71 | return error; | ||
72 | } | ||
73 | char *ws_name = join_args(argv, argc - 3); | ||
74 | struct workspace_config *wsc = workspace_config_find_or_create(ws_name); | ||
75 | free(ws_name); | ||
76 | if (!wsc) { | ||
77 | return cmd_results_new(CMD_FAILURE, "workspace gaps", | ||
78 | "Unable to allocate workspace output"); | ||
79 | } | ||
80 | int *prop = NULL; | ||
81 | if (strcasecmp(argv[gaps_location + 1], "inner") == 0) { | ||
82 | prop = &wsc->gaps_inner; | ||
83 | } else if (strcasecmp(argv[gaps_location + 1], "outer") == 0) { | ||
84 | prop = &wsc->gaps_outer; | ||
85 | } else { | ||
86 | return cmd_results_new(CMD_FAILURE, "workspace gaps", | ||
87 | "Expected 'workspace <ws> gaps inner|outer <px>'"); | ||
88 | } | ||
89 | char *end; | ||
90 | int val = strtol(argv[gaps_location + 2], &end, 10); | ||
91 | |||
92 | if (strlen(end)) { | ||
93 | free(end); | ||
94 | return cmd_results_new(CMD_FAILURE, "workspace gaps", | ||
95 | "Expected 'workspace <ws> gaps inner|outer <px>'"); | ||
96 | } | ||
97 | *prop = val >= 0 ? val : 0; | ||
60 | } else { | 98 | } else { |
61 | if (config->reading || !config->active) { | 99 | if (config->reading || !config->active) { |
62 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | 100 | return cmd_results_new(CMD_DEFER, "workspace", NULL); |