diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-03-29 23:41:33 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-03-29 23:41:33 -0400 |
commit | dc8c9fbeb664518c76066cc28ee29452c6c30128 (patch) | |
tree | 88c2de0d08e00b2a30cb20cdfadfa6e53f5c59b4 /sway/tree/workspace.c | |
parent | Merge pull request #1653 from swaywm/revert-1647-refactor-tree (diff) | |
download | sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.tar.gz sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.tar.zst sway-dc8c9fbeb664518c76066cc28ee29452c6c30128.zip |
Revert "Merge pull request #1653 from swaywm/revert-1647-refactor-tree"
This reverts commit 472e81f35d689d67cda241acafda91c688d61046, reversing
changes made to 6b7841b11ff4cd35f54d69dc92029855893e5ce0.
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r-- | sway/tree/workspace.c | 92 |
1 files changed, 51 insertions, 41 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 861fda4d..ba04c55c 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -3,10 +3,10 @@ | |||
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <strings.h> | 5 | #include <strings.h> |
6 | #include "sway/container.h" | 6 | #include "sway/tree/container.h" |
7 | #include "sway/input/input-manager.h" | 7 | #include "sway/input/input-manager.h" |
8 | #include "sway/input/seat.h" | 8 | #include "sway/input/seat.h" |
9 | #include "sway/workspace.h" | 9 | #include "sway/tree/workspace.h" |
10 | #include "log.h" | 10 | #include "log.h" |
11 | #include "util.h" | 11 | #include "util.h" |
12 | 12 | ||
@@ -17,7 +17,7 @@ struct workspace_by_number_data { | |||
17 | const char *name; | 17 | const char *name; |
18 | }; | 18 | }; |
19 | 19 | ||
20 | void next_name_map(swayc_t *ws, void *data) { | 20 | void next_name_map(struct sway_container *ws, void *data) { |
21 | int *count = data; | 21 | int *count = data; |
22 | ++count; | 22 | ++count; |
23 | } | 23 | } |
@@ -37,7 +37,7 @@ char *workspace_next_name(const char *output_name) { | |||
37 | return name; | 37 | return name; |
38 | } | 38 | } |
39 | 39 | ||
40 | static bool _workspace_by_number(swayc_t *view, void *data) { | 40 | static bool _workspace_by_number(struct sway_container *view, void *data) { |
41 | if (view->type != C_WORKSPACE) { | 41 | if (view->type != C_WORKSPACE) { |
42 | return false; | 42 | return false; |
43 | } | 43 | } |
@@ -46,27 +46,28 @@ static bool _workspace_by_number(swayc_t *view, void *data) { | |||
46 | return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; | 46 | return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; |
47 | } | 47 | } |
48 | 48 | ||
49 | swayc_t *workspace_by_number(const char* name) { | 49 | struct sway_container *workspace_by_number(const char* name) { |
50 | struct workspace_by_number_data wbnd = {0, "1234567890", name}; | 50 | struct workspace_by_number_data wbnd = {0, "1234567890", name}; |
51 | wbnd.len = strspn(name, wbnd.cset); | 51 | wbnd.len = strspn(name, wbnd.cset); |
52 | if (wbnd.len <= 0) { | 52 | if (wbnd.len <= 0) { |
53 | return NULL; | 53 | return NULL; |
54 | } | 54 | } |
55 | return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd); | 55 | return container_find(&root_container, |
56 | _workspace_by_number, (void *) &wbnd); | ||
56 | } | 57 | } |
57 | 58 | ||
58 | static bool _workspace_by_name(swayc_t *view, void *data) { | 59 | static bool _workspace_by_name(struct sway_container *view, void *data) { |
59 | return (view->type == C_WORKSPACE) && | 60 | return (view->type == C_WORKSPACE) && |
60 | (strcasecmp(view->name, (char *) data) == 0); | 61 | (strcasecmp(view->name, (char *) data) == 0); |
61 | } | 62 | } |
62 | 63 | ||
63 | swayc_t *workspace_by_name(const char *name) { | 64 | struct sway_container *workspace_by_name(const char *name) { |
64 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 65 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
65 | swayc_t *current_workspace = NULL, *current_output = NULL; | 66 | struct sway_container *current_workspace = NULL, *current_output = NULL; |
66 | swayc_t *focus = sway_seat_get_focus(seat); | 67 | struct sway_container *focus = sway_seat_get_focus(seat); |
67 | if (focus) { | 68 | if (focus) { |
68 | current_workspace = swayc_parent_by_type(focus, C_WORKSPACE); | 69 | current_workspace = container_parent(focus, C_WORKSPACE); |
69 | current_output = swayc_parent_by_type(focus, C_OUTPUT); | 70 | current_output = container_parent(focus, C_OUTPUT); |
70 | } | 71 | } |
71 | if (strcmp(name, "prev") == 0) { | 72 | if (strcmp(name, "prev") == 0) { |
72 | return workspace_prev(current_workspace); | 73 | return workspace_prev(current_workspace); |
@@ -79,12 +80,13 @@ swayc_t *workspace_by_name(const char *name) { | |||
79 | } else if (strcmp(name, "current") == 0) { | 80 | } else if (strcmp(name, "current") == 0) { |
80 | return current_workspace; | 81 | return current_workspace; |
81 | } else { | 82 | } else { |
82 | return swayc_by_test(&root_container, _workspace_by_name, (void *) name); | 83 | return container_find(&root_container, _workspace_by_name, |
84 | (void *)name); | ||
83 | } | 85 | } |
84 | } | 86 | } |
85 | 87 | ||
86 | swayc_t *workspace_create(const char *name) { | 88 | struct sway_container *workspace_create(const char *name) { |
87 | swayc_t *parent; | 89 | struct sway_container *parent; |
88 | // Search for workspace<->output pair | 90 | // Search for workspace<->output pair |
89 | int i, e = config->workspace_outputs->length; | 91 | int i, e = config->workspace_outputs->length; |
90 | for (i = 0; i < e; ++i) { | 92 | for (i = 0; i < e; ++i) { |
@@ -95,7 +97,7 @@ swayc_t *workspace_create(const char *name) { | |||
95 | for (i = 0; i < e; ++i) { | 97 | for (i = 0; i < e; ++i) { |
96 | parent = root_container.children->items[i]; | 98 | parent = root_container.children->items[i]; |
97 | if (strcmp(parent->name, wso->output) == 0) { | 99 | if (strcmp(parent->name, wso->output) == 0) { |
98 | return new_workspace(parent, name); | 100 | return container_workspace_create(parent, name); |
99 | } | 101 | } |
100 | } | 102 | } |
101 | break; | 103 | break; |
@@ -103,10 +105,11 @@ swayc_t *workspace_create(const char *name) { | |||
103 | } | 105 | } |
104 | // Otherwise create a new one | 106 | // Otherwise create a new one |
105 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 107 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
106 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 108 | struct sway_container *focus = |
109 | sway_seat_get_focus_inactive(seat, &root_container); | ||
107 | parent = focus; | 110 | parent = focus; |
108 | parent = swayc_parent_by_type(parent, C_OUTPUT); | 111 | parent = container_parent(parent, C_OUTPUT); |
109 | return new_workspace(parent, name); | 112 | return container_workspace_create(parent, name); |
110 | } | 113 | } |
111 | 114 | ||
112 | /** | 115 | /** |
@@ -114,17 +117,18 @@ swayc_t *workspace_create(const char *name) { | |||
114 | * the end and beginning. If next is false, the previous workspace is returned, | 117 | * the end and beginning. If next is false, the previous workspace is returned, |
115 | * otherwise the next one is returned. | 118 | * otherwise the next one is returned. |
116 | */ | 119 | */ |
117 | swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { | 120 | struct sway_container *workspace_output_prev_next_impl( |
121 | struct sway_container *output, bool next) { | ||
118 | if (!sway_assert(output->type == C_OUTPUT, | 122 | if (!sway_assert(output->type == C_OUTPUT, |
119 | "Argument must be an output, is %d", output->type)) { | 123 | "Argument must be an output, is %d", output->type)) { |
120 | return NULL; | 124 | return NULL; |
121 | } | 125 | } |
122 | 126 | ||
123 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 127 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
124 | swayc_t *focus = sway_seat_get_focus_inactive(seat, output); | 128 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, output); |
125 | swayc_t *workspace = (focus->type == C_WORKSPACE ? | 129 | struct sway_container *workspace = (focus->type == C_WORKSPACE ? |
126 | focus : | 130 | focus : |
127 | swayc_parent_by_type(focus, C_WORKSPACE)); | 131 | container_parent(focus, C_WORKSPACE)); |
128 | 132 | ||
129 | int i; | 133 | int i; |
130 | for (i = 0; i < output->children->length; i++) { | 134 | for (i = 0; i < output->children->length; i++) { |
@@ -134,7 +138,8 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { | |||
134 | } | 138 | } |
135 | } | 139 | } |
136 | 140 | ||
137 | // Doesn't happen, at worst the for loop returns the previously active workspace | 141 | // Doesn't happen, at worst the for loop returns the previously active |
142 | // workspace | ||
138 | return NULL; | 143 | return NULL; |
139 | } | 144 | } |
140 | 145 | ||
@@ -144,13 +149,14 @@ swayc_t *workspace_output_prev_next_impl(swayc_t *output, bool next) { | |||
144 | * next is false, the previous workspace is returned, otherwise the next one is | 149 | * next is false, the previous workspace is returned, otherwise the next one is |
145 | * returned. | 150 | * returned. |
146 | */ | 151 | */ |
147 | swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { | 152 | struct sway_container *workspace_prev_next_impl( |
153 | struct sway_container *workspace, bool next) { | ||
148 | if (!sway_assert(workspace->type == C_WORKSPACE, | 154 | if (!sway_assert(workspace->type == C_WORKSPACE, |
149 | "Argument must be a workspace, is %d", workspace->type)) { | 155 | "Argument must be a workspace, is %d", workspace->type)) { |
150 | return NULL; | 156 | return NULL; |
151 | } | 157 | } |
152 | 158 | ||
153 | swayc_t *current_output = workspace->parent; | 159 | struct sway_container *current_output = workspace->parent; |
154 | int offset = next ? 1 : -1; | 160 | int offset = next ? 1 : -1; |
155 | int start = next ? 0 : 1; | 161 | int start = next ? 0 : 1; |
156 | int end; | 162 | int end; |
@@ -166,54 +172,57 @@ swayc_t *workspace_prev_next_impl(swayc_t *workspace, bool next) { | |||
166 | } | 172 | } |
167 | } | 173 | } |
168 | 174 | ||
169 | // Given workspace is the first/last on the output, jump to the previous/next output | 175 | // Given workspace is the first/last on the output, jump to the |
176 | // previous/next output | ||
170 | int num_outputs = root_container.children->length; | 177 | int num_outputs = root_container.children->length; |
171 | for (i = 0; i < num_outputs; i++) { | 178 | for (i = 0; i < num_outputs; i++) { |
172 | if (root_container.children->items[i] == current_output) { | 179 | if (root_container.children->items[i] == current_output) { |
173 | swayc_t *next_output = root_container.children->items[ | 180 | struct sway_container *next_output = root_container.children->items[ |
174 | wrap(i + offset, num_outputs)]; | 181 | wrap(i + offset, num_outputs)]; |
175 | return workspace_output_prev_next_impl(next_output, next); | 182 | return workspace_output_prev_next_impl(next_output, next); |
176 | } | 183 | } |
177 | } | 184 | } |
178 | 185 | ||
179 | // Doesn't happen, at worst the for loop returns the previously active workspace on the active output | 186 | // Doesn't happen, at worst the for loop returns the previously active |
187 | // workspace on the active output | ||
180 | return NULL; | 188 | return NULL; |
181 | } | 189 | } |
182 | 190 | ||
183 | swayc_t *workspace_output_next(swayc_t *current) { | 191 | struct sway_container *workspace_output_next(struct sway_container *current) { |
184 | return workspace_output_prev_next_impl(current, true); | 192 | return workspace_output_prev_next_impl(current, true); |
185 | } | 193 | } |
186 | 194 | ||
187 | swayc_t *workspace_next(swayc_t *current) { | 195 | struct sway_container *workspace_next(struct sway_container *current) { |
188 | return workspace_prev_next_impl(current, true); | 196 | return workspace_prev_next_impl(current, true); |
189 | } | 197 | } |
190 | 198 | ||
191 | swayc_t *workspace_output_prev(swayc_t *current) { | 199 | struct sway_container *workspace_output_prev(struct sway_container *current) { |
192 | return workspace_output_prev_next_impl(current, false); | 200 | return workspace_output_prev_next_impl(current, false); |
193 | } | 201 | } |
194 | 202 | ||
195 | swayc_t *workspace_prev(swayc_t *current) { | 203 | struct sway_container *workspace_prev(struct sway_container *current) { |
196 | return workspace_prev_next_impl(current, false); | 204 | return workspace_prev_next_impl(current, false); |
197 | } | 205 | } |
198 | 206 | ||
199 | bool workspace_switch(swayc_t *workspace) { | 207 | bool workspace_switch(struct sway_container *workspace) { |
200 | if (!workspace) { | 208 | if (!workspace) { |
201 | return false; | 209 | return false; |
202 | } | 210 | } |
203 | struct sway_seat *seat = input_manager_current_seat(input_manager); | 211 | struct sway_seat *seat = input_manager_current_seat(input_manager); |
204 | swayc_t *focus = sway_seat_get_focus_inactive(seat, &root_container); | 212 | struct sway_container *focus = |
213 | sway_seat_get_focus_inactive(seat, &root_container); | ||
205 | if (!seat || !focus) { | 214 | if (!seat || !focus) { |
206 | return false; | 215 | return false; |
207 | } | 216 | } |
208 | swayc_t *active_ws = focus; | 217 | struct sway_container *active_ws = focus; |
209 | if (active_ws->type != C_WORKSPACE) { | 218 | if (active_ws->type != C_WORKSPACE) { |
210 | swayc_parent_by_type(focus, C_WORKSPACE); | 219 | container_parent(focus, C_WORKSPACE); |
211 | } | 220 | } |
212 | 221 | ||
213 | if (config->auto_back_and_forth | 222 | if (config->auto_back_and_forth |
214 | && active_ws == workspace | 223 | && active_ws == workspace |
215 | && prev_workspace_name) { | 224 | && prev_workspace_name) { |
216 | swayc_t *new_ws = workspace_by_name(prev_workspace_name); | 225 | struct sway_container *new_ws = workspace_by_name(prev_workspace_name); |
217 | workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); | 226 | workspace = new_ws ? new_ws : workspace_create(prev_workspace_name); |
218 | } | 227 | } |
219 | 228 | ||
@@ -230,13 +239,14 @@ bool workspace_switch(swayc_t *workspace) { | |||
230 | 239 | ||
231 | // TODO: Deal with sticky containers | 240 | // TODO: Deal with sticky containers |
232 | 241 | ||
233 | wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); | 242 | wlr_log(L_DEBUG, "Switching to workspace %p:%s", |
234 | swayc_t *next = sway_seat_get_focus_inactive(seat, workspace); | 243 | workspace, workspace->name); |
244 | struct sway_container *next = sway_seat_get_focus_inactive(seat, workspace); | ||
235 | if (next == NULL) { | 245 | if (next == NULL) { |
236 | next = workspace; | 246 | next = workspace; |
237 | } | 247 | } |
238 | sway_seat_set_focus(seat, next); | 248 | sway_seat_set_focus(seat, next); |
239 | swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); | 249 | struct sway_container *output = container_parent(workspace, C_OUTPUT); |
240 | arrange_windows(output, -1, -1); | 250 | arrange_windows(output, -1, -1); |
241 | return true; | 251 | return true; |
242 | } | 252 | } |