diff options
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r-- | sway/tree/workspace.c | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 16031e87..e9e5dfa2 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -20,17 +20,23 @@ | |||
20 | #include "log.h" | 20 | #include "log.h" |
21 | #include "util.h" | 21 | #include "util.h" |
22 | 22 | ||
23 | struct workspace_config *workspace_find_config(const char *ws_name) { | ||
24 | for (int i = 0; i < config->workspace_configs->length; ++i) { | ||
25 | struct workspace_config *wsc = config->workspace_configs->items[i]; | ||
26 | if (strcmp(wsc->workspace, ws_name) == 0) { | ||
27 | return wsc; | ||
28 | } | ||
29 | } | ||
30 | return NULL; | ||
31 | } | ||
32 | |||
23 | struct sway_output *workspace_get_initial_output(const char *name) { | 33 | struct sway_output *workspace_get_initial_output(const char *name) { |
24 | // Search for workspace<->output pair | 34 | // Check workspace configs for a workspace<->output pair |
25 | for (int i = 0; i < config->workspace_outputs->length; ++i) { | 35 | struct workspace_config *wsc = workspace_find_config(name); |
26 | struct workspace_output *wso = config->workspace_outputs->items[i]; | 36 | if (wsc && wsc->output) { |
27 | if (strcasecmp(wso->workspace, name) == 0) { | 37 | struct sway_output *output = output_by_name(wsc->output); |
28 | // Find output to use if it exists | 38 | if (output) { |
29 | struct sway_output *output = output_by_name(wso->output); | 39 | return output; |
30 | if (output) { | ||
31 | return output; | ||
32 | } | ||
33 | break; | ||
34 | } | 40 | } |
35 | } | 41 | } |
36 | // Otherwise put it on the focused output | 42 | // Otherwise put it on the focused output |
@@ -62,6 +68,20 @@ struct sway_workspace *workspace_create(struct sway_output *output, | |||
62 | ws->output_priority = create_list(); | 68 | ws->output_priority = create_list(); |
63 | workspace_output_add_priority(ws, output); | 69 | workspace_output_add_priority(ws, output); |
64 | 70 | ||
71 | ws->gaps_outer = config->gaps_outer; | ||
72 | ws->gaps_inner = config->gaps_inner; | ||
73 | if (name) { | ||
74 | struct workspace_config *wsc = workspace_find_config(name); | ||
75 | if (wsc) { | ||
76 | if (wsc->gaps_outer != -1) { | ||
77 | ws->gaps_outer = wsc->gaps_outer; | ||
78 | } | ||
79 | if (wsc->gaps_inner != -1) { | ||
80 | ws->gaps_inner = wsc->gaps_inner; | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | |||
65 | output_add_workspace(output, ws); | 85 | output_add_workspace(output, ws); |
66 | output_sort_workspaces(output); | 86 | output_sort_workspaces(output); |
67 | 87 | ||
@@ -121,17 +141,8 @@ void next_name_map(struct sway_container *ws, void *data) { | |||
121 | 141 | ||
122 | static bool workspace_valid_on_output(const char *output_name, | 142 | static bool workspace_valid_on_output(const char *output_name, |
123 | const char *ws_name) { | 143 | const char *ws_name) { |
124 | int i; | 144 | struct workspace_config *wsc = workspace_find_config(ws_name); |
125 | for (i = 0; i < config->workspace_outputs->length; ++i) { | 145 | return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0; |
126 | struct workspace_output *wso = config->workspace_outputs->items[i]; | ||
127 | if (strcasecmp(wso->workspace, ws_name) == 0) { | ||
128 | if (strcasecmp(wso->output, output_name) != 0) { | ||
129 | return false; | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | |||
134 | return true; | ||
135 | } | 146 | } |
136 | 147 | ||
137 | static void workspace_name_from_binding(const struct sway_binding * binding, | 148 | static void workspace_name_from_binding(const struct sway_binding * binding, |
@@ -231,13 +242,13 @@ char *workspace_next_name(const char *output_name) { | |||
231 | workspace_name_from_binding(mode->keycode_bindings->items[i], | 242 | workspace_name_from_binding(mode->keycode_bindings->items[i], |
232 | output_name, &order, &target); | 243 | output_name, &order, &target); |
233 | } | 244 | } |
234 | for (int i = 0; i < config->workspace_outputs->length; ++i) { | 245 | for (int i = 0; i < config->workspace_configs->length; ++i) { |
235 | // Unlike with bindings, this does not guarantee order | 246 | // Unlike with bindings, this does not guarantee order |
236 | const struct workspace_output *wso = config->workspace_outputs->items[i]; | 247 | const struct workspace_config *wsc = config->workspace_configs->items[i]; |
237 | if (strcmp(wso->output, output_name) == 0 | 248 | if (wsc->output && strcmp(wsc->output, output_name) == 0 |
238 | && workspace_by_name(wso->workspace) == NULL) { | 249 | && workspace_by_name(wsc->workspace) == NULL) { |
239 | free(target); | 250 | free(target); |
240 | target = strdup(wso->workspace); | 251 | target = strdup(wsc->workspace); |
241 | break; | 252 | break; |
242 | } | 253 | } |
243 | } | 254 | } |
@@ -629,19 +640,25 @@ void workspace_add_gaps(struct sway_workspace *ws) { | |||
629 | if (ws->current_gaps > 0) { | 640 | if (ws->current_gaps > 0) { |
630 | return; | 641 | return; |
631 | } | 642 | } |
632 | bool should_apply = | 643 | if (!config->edge_gaps) { |
633 | config->edge_gaps || (config->smart_gaps && ws->tiling->length > 1); | ||
634 | if (!should_apply) { | ||
635 | return; | 644 | return; |
636 | } | 645 | } |
646 | if (config->smart_gaps) { | ||
647 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | ||
648 | struct sway_container *focus = | ||
649 | seat_get_focus_inactive_view(seat, &ws->node); | ||
650 | if (focus && focus->view && view_is_only_visible(focus->view)) { | ||
651 | return; | ||
652 | } | ||
653 | } | ||
637 | 654 | ||
638 | ws->current_gaps = ws->has_gaps ? ws->gaps_outer : config->gaps_outer; | 655 | ws->current_gaps = ws->gaps_outer; |
639 | 656 | ||
640 | if (ws->layout == L_TABBED || ws->layout == L_STACKED) { | 657 | if (ws->layout == L_TABBED || ws->layout == L_STACKED) { |
641 | // We have to add inner gaps for this, because children of tabbed and | 658 | // We have to add inner gaps for this, because children of tabbed and |
642 | // stacked containers don't apply their own gaps - they assume the | 659 | // stacked containers don't apply their own gaps - they assume the |
643 | // tabbed/stacked container is using gaps. | 660 | // tabbed/stacked container is using gaps. |
644 | ws->current_gaps += ws->has_gaps ? ws->gaps_inner : config->gaps_inner; | 661 | ws->current_gaps += ws->gaps_inner; |
645 | } | 662 | } |
646 | 663 | ||
647 | ws->x += ws->current_gaps; | 664 | ws->x += ws->current_gaps; |