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 | |
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')
-rw-r--r-- | sway/tree/container.c | 221 | ||||
-rw-r--r-- | sway/tree/layout.c | 133 | ||||
-rw-r--r-- | sway/tree/view.c | 7 | ||||
-rw-r--r-- | sway/tree/workspace.c | 92 |
4 files changed, 237 insertions, 216 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index bbafe9ec..40047dcf 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -7,14 +7,14 @@ | |||
7 | #include <wlr/types/wlr_output_layout.h> | 7 | #include <wlr/types/wlr_output_layout.h> |
8 | #include <wlr/types/wlr_wl_shell.h> | 8 | #include <wlr/types/wlr_wl_shell.h> |
9 | #include "sway/config.h" | 9 | #include "sway/config.h" |
10 | #include "sway/container.h" | 10 | #include "sway/tree/container.h" |
11 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
12 | #include "sway/input/seat.h" | 12 | #include "sway/input/seat.h" |
13 | #include "sway/layout.h" | 13 | #include "sway/tree/layout.h" |
14 | #include "sway/output.h" | 14 | #include "sway/output.h" |
15 | #include "sway/server.h" | 15 | #include "sway/server.h" |
16 | #include "sway/view.h" | 16 | #include "sway/tree/view.h" |
17 | #include "sway/workspace.h" | 17 | #include "sway/tree/workspace.h" |
18 | #include "sway/ipc-server.h" | 18 | #include "sway/ipc-server.h" |
19 | #include "log.h" | 19 | #include "log.h" |
20 | 20 | ||
@@ -33,48 +33,15 @@ static list_t *get_bfs_queue() { | |||
33 | return bfs_queue; | 33 | return bfs_queue; |
34 | } | 34 | } |
35 | 35 | ||
36 | static void notify_new_container(swayc_t *container) { | 36 | static void notify_new_container(struct sway_container *container) { |
37 | wl_signal_emit(&root_container.sway_root->events.new_container, container); | 37 | wl_signal_emit(&root_container.sway_root->events.new_container, container); |
38 | ipc_event_window(container, "new"); | 38 | ipc_event_window(container, "new"); |
39 | } | 39 | } |
40 | 40 | ||
41 | swayc_t *swayc_by_test(swayc_t *container, | 41 | static struct sway_container *container_create(enum sway_container_type type) { |
42 | bool (*test)(swayc_t *view, void *data), void *data) { | ||
43 | if (!container->children) { | ||
44 | return NULL; | ||
45 | } | ||
46 | // TODO: floating windows | ||
47 | for (int i = 0; i < container->children->length; ++i) { | ||
48 | swayc_t *child = container->children->items[i]; | ||
49 | if (test(child, data)) { | ||
50 | return child; | ||
51 | } else { | ||
52 | swayc_t *res = swayc_by_test(child, test, data); | ||
53 | if (res) { | ||
54 | return res; | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | return NULL; | ||
59 | } | ||
60 | |||
61 | void swayc_descendants_of_type(swayc_t *root, enum swayc_types type, | ||
62 | void (*func)(swayc_t *item, void *data), void *data) { | ||
63 | for (int i = 0; i < root->children->length; ++i) { | ||
64 | swayc_t *item = root->children->items[i]; | ||
65 | if (item->type == type) { | ||
66 | func(item, data); | ||
67 | } | ||
68 | if (item->children && item->children->length) { | ||
69 | swayc_descendants_of_type(item, type, func, data); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | |||
74 | static swayc_t *new_swayc(enum swayc_types type) { | ||
75 | // next id starts at 1 because 0 is assigned to root_container in layout.c | 42 | // next id starts at 1 because 0 is assigned to root_container in layout.c |
76 | static size_t next_id = 1; | 43 | static size_t next_id = 1; |
77 | swayc_t *c = calloc(1, sizeof(swayc_t)); | 44 | struct sway_container *c = calloc(1, sizeof(struct sway_container)); |
78 | if (!c) { | 45 | if (!c) { |
79 | return NULL; | 46 | return NULL; |
80 | } | 47 | } |
@@ -82,8 +49,6 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
82 | c->layout = L_NONE; | 49 | c->layout = L_NONE; |
83 | c->workspace_layout = L_NONE; | 50 | c->workspace_layout = L_NONE; |
84 | c->type = type; | 51 | c->type = type; |
85 | c->nb_master = 1; | ||
86 | c->nb_slave_groups = 1; | ||
87 | if (type != C_VIEW) { | 52 | if (type != C_VIEW) { |
88 | c->children = create_list(); | 53 | c->children = create_list(); |
89 | } | 54 | } |
@@ -93,18 +58,18 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
93 | return c; | 58 | return c; |
94 | } | 59 | } |
95 | 60 | ||
96 | static void free_swayc(swayc_t *cont) { | 61 | static void container_destroy(struct sway_container *cont) { |
97 | if (!sway_assert(cont, "free_swayc passed NULL")) { | 62 | if (cont == NULL) { |
98 | return; | 63 | return; |
99 | } | 64 | } |
100 | 65 | ||
101 | wl_signal_emit(&cont->events.destroy, cont); | 66 | wl_signal_emit(&cont->events.destroy, cont); |
102 | 67 | ||
103 | if (cont->children) { | 68 | if (cont->children) { |
104 | // remove children until there are no more, free_swayc calls | 69 | // remove children until there are no more, container_destroy calls |
105 | // remove_child, which removes child from this container | 70 | // container_remove_child, which removes child from this container |
106 | while (cont->children->length) { | 71 | while (cont->children->length) { |
107 | free_swayc(cont->children->items[0]); | 72 | container_destroy(cont->children->items[0]); |
108 | } | 73 | } |
109 | list_free(cont->children); | 74 | list_free(cont->children); |
110 | } | 75 | } |
@@ -113,7 +78,7 @@ static void free_swayc(swayc_t *cont) { | |||
113 | list_free(cont->marks); | 78 | list_free(cont->marks); |
114 | } | 79 | } |
115 | if (cont->parent) { | 80 | if (cont->parent) { |
116 | remove_child(cont); | 81 | container_remove_child(cont); |
117 | } | 82 | } |
118 | if (cont->name) { | 83 | if (cont->name) { |
119 | free(cont->name); | 84 | free(cont->name); |
@@ -121,7 +86,8 @@ static void free_swayc(swayc_t *cont) { | |||
121 | free(cont); | 86 | free(cont); |
122 | } | 87 | } |
123 | 88 | ||
124 | swayc_t *new_output(struct sway_output *sway_output) { | 89 | struct sway_container *container_output_create( |
90 | struct sway_output *sway_output) { | ||
125 | struct wlr_box size; | 91 | struct wlr_box size; |
126 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, | 92 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, |
127 | &size.height); | 93 | &size.height); |
@@ -156,22 +122,22 @@ swayc_t *new_output(struct sway_output *sway_output) { | |||
156 | return NULL; | 122 | return NULL; |
157 | } | 123 | } |
158 | 124 | ||
159 | swayc_t *output = new_swayc(C_OUTPUT); | 125 | struct sway_container *output = container_create(C_OUTPUT); |
160 | output->sway_output = sway_output; | 126 | output->sway_output = sway_output; |
161 | output->name = strdup(name); | 127 | output->name = strdup(name); |
162 | if (output->name == NULL) { | 128 | if (output->name == NULL) { |
163 | free_swayc(output); | 129 | container_destroy(output); |
164 | return NULL; | 130 | return NULL; |
165 | } | 131 | } |
166 | 132 | ||
167 | apply_output_config(oc, output); | 133 | apply_output_config(oc, output); |
168 | 134 | ||
169 | add_child(&root_container, output); | 135 | container_add_child(&root_container, output); |
170 | 136 | ||
171 | // Create workspace | 137 | // Create workspace |
172 | char *ws_name = workspace_next_name(output->name); | 138 | char *ws_name = workspace_next_name(output->name); |
173 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); | 139 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); |
174 | swayc_t *ws = new_workspace(output, ws_name); | 140 | struct sway_container *ws = container_workspace_create(output, ws_name); |
175 | // Set each seat's focus if not already set | 141 | // Set each seat's focus if not already set |
176 | struct sway_seat *seat = NULL; | 142 | struct sway_seat *seat = NULL; |
177 | wl_list_for_each(seat, &input_manager->seats, link) { | 143 | wl_list_for_each(seat, &input_manager->seats, link) { |
@@ -185,12 +151,14 @@ swayc_t *new_output(struct sway_output *sway_output) { | |||
185 | return output; | 151 | return output; |
186 | } | 152 | } |
187 | 153 | ||
188 | swayc_t *new_workspace(swayc_t *output, const char *name) { | 154 | struct sway_container *container_workspace_create( |
189 | if (!sway_assert(output, "new_workspace called with null output")) { | 155 | struct sway_container *output, const char *name) { |
156 | if (!sway_assert(output, | ||
157 | "container_workspace_create called with null output")) { | ||
190 | return NULL; | 158 | return NULL; |
191 | } | 159 | } |
192 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); | 160 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); |
193 | swayc_t *workspace = new_swayc(C_WORKSPACE); | 161 | struct sway_container *workspace = container_create(C_WORKSPACE); |
194 | 162 | ||
195 | workspace->x = output->x; | 163 | workspace->x = output->x; |
196 | workspace->y = output->y; | 164 | workspace->y = output->y; |
@@ -198,21 +166,23 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
198 | workspace->height = output->height; | 166 | workspace->height = output->height; |
199 | workspace->name = !name ? NULL : strdup(name); | 167 | workspace->name = !name ? NULL : strdup(name); |
200 | workspace->prev_layout = L_NONE; | 168 | workspace->prev_layout = L_NONE; |
201 | workspace->layout = default_layout(output); | 169 | workspace->layout = container_get_default_layout(output); |
202 | workspace->workspace_layout = default_layout(output); | 170 | workspace->workspace_layout = container_get_default_layout(output); |
203 | 171 | ||
204 | add_child(output, workspace); | 172 | container_add_child(output, workspace); |
205 | sort_workspaces(output); | 173 | container_sort_workspaces(output); |
206 | notify_new_container(workspace); | 174 | notify_new_container(workspace); |
207 | return workspace; | 175 | return workspace; |
208 | } | 176 | } |
209 | 177 | ||
210 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { | 178 | struct sway_container *container_view_create(struct sway_container *sibling, |
211 | if (!sway_assert(sibling, "new_view called with NULL sibling/parent")) { | 179 | struct sway_view *sway_view) { |
180 | if (!sway_assert(sibling, | ||
181 | "container_view_create called with NULL sibling/parent")) { | ||
212 | return NULL; | 182 | return NULL; |
213 | } | 183 | } |
214 | const char *title = view_get_title(sway_view); | 184 | const char *title = view_get_title(sway_view); |
215 | swayc_t *swayc = new_swayc(C_VIEW); | 185 | struct sway_container *swayc = container_create(C_VIEW); |
216 | wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", | 186 | wlr_log(L_DEBUG, "Adding new view %p:%s to container %p %d %s", |
217 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); | 187 | swayc, title, sibling, sibling ? sibling->type : 0, sibling->name); |
218 | // Setup values | 188 | // Setup values |
@@ -223,17 +193,18 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) { | |||
223 | 193 | ||
224 | if (sibling->type == C_WORKSPACE) { | 194 | if (sibling->type == C_WORKSPACE) { |
225 | // Case of focused workspace, just create as child of it | 195 | // Case of focused workspace, just create as child of it |
226 | add_child(sibling, swayc); | 196 | container_add_child(sibling, swayc); |
227 | } else { | 197 | } else { |
228 | // Regular case, create as sibling of current container | 198 | // Regular case, create as sibling of current container |
229 | add_sibling(sibling, swayc); | 199 | container_add_sibling(sibling, swayc); |
230 | } | 200 | } |
231 | notify_new_container(swayc); | 201 | notify_new_container(swayc); |
232 | return swayc; | 202 | return swayc; |
233 | } | 203 | } |
234 | 204 | ||
235 | swayc_t *destroy_output(swayc_t *output) { | 205 | struct sway_container *container_output_destroy(struct sway_container *output) { |
236 | if (!sway_assert(output, "null output passed to destroy_output")) { | 206 | if (!sway_assert(output, |
207 | "null output passed to container_output_destroy")) { | ||
237 | return NULL; | 208 | return NULL; |
238 | } | 209 | } |
239 | 210 | ||
@@ -245,12 +216,13 @@ swayc_t *destroy_output(swayc_t *output) { | |||
245 | int p = root_container.children->items[0] == output; | 216 | int p = root_container.children->items[0] == output; |
246 | // Move workspace from this output to another output | 217 | // Move workspace from this output to another output |
247 | while (output->children->length) { | 218 | while (output->children->length) { |
248 | swayc_t *child = output->children->items[0]; | 219 | struct sway_container *child = output->children->items[0]; |
249 | remove_child(child); | 220 | container_remove_child(child); |
250 | add_child(root_container.children->items[p], child); | 221 | container_add_child(root_container.children->items[p], child); |
251 | } | 222 | } |
252 | sort_workspaces(root_container.children->items[p]); | 223 | container_sort_workspaces(root_container.children->items[p]); |
253 | arrange_windows(root_container.children->items[p], -1, -1); | 224 | arrange_windows(root_container.children->items[p], |
225 | -1, -1); | ||
254 | } | 226 | } |
255 | } | 227 | } |
256 | 228 | ||
@@ -259,18 +231,18 @@ swayc_t *destroy_output(swayc_t *output) { | |||
259 | wl_list_remove(&output->sway_output->mode.link); | 231 | wl_list_remove(&output->sway_output->mode.link); |
260 | 232 | ||
261 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | 233 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); |
262 | free_swayc(output); | 234 | container_destroy(output); |
263 | 235 | ||
264 | return &root_container; | 236 | return &root_container; |
265 | } | 237 | } |
266 | 238 | ||
267 | swayc_t *destroy_view(swayc_t *view) { | 239 | struct sway_container *container_view_destroy(struct sway_container *view) { |
268 | if (!view) { | 240 | if (!view) { |
269 | return NULL; | 241 | return NULL; |
270 | } | 242 | } |
271 | wlr_log(L_DEBUG, "Destroying view '%s'", view->name); | 243 | wlr_log(L_DEBUG, "Destroying view '%s'", view->name); |
272 | swayc_t *parent = view->parent; | 244 | struct sway_container *parent = view->parent; |
273 | free_swayc(view); | 245 | container_destroy(view); |
274 | 246 | ||
275 | // TODO WLR: Destroy empty containers | 247 | // TODO WLR: Destroy empty containers |
276 | /* | 248 | /* |
@@ -281,7 +253,55 @@ swayc_t *destroy_view(swayc_t *view) { | |||
281 | return parent; | 253 | return parent; |
282 | } | 254 | } |
283 | 255 | ||
284 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | 256 | struct sway_container *container_set_layout(struct sway_container *container, |
257 | enum sway_container_layout layout) { | ||
258 | if (container->type == C_WORKSPACE) { | ||
259 | container->workspace_layout = layout; | ||
260 | if (layout == L_HORIZ || layout == L_VERT) { | ||
261 | container->layout = layout; | ||
262 | } | ||
263 | } else { | ||
264 | container->layout = layout; | ||
265 | } | ||
266 | return container; | ||
267 | } | ||
268 | |||
269 | void container_descendents(struct sway_container *root, | ||
270 | enum sway_container_type type, | ||
271 | void (*func)(struct sway_container *item, void *data), void *data) { | ||
272 | for (int i = 0; i < root->children->length; ++i) { | ||
273 | struct sway_container *item = root->children->items[i]; | ||
274 | if (item->type == type) { | ||
275 | func(item, data); | ||
276 | } | ||
277 | if (item->children && item->children->length) { | ||
278 | container_descendents(item, type, func, data); | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | |||
283 | struct sway_container *container_find(struct sway_container *container, | ||
284 | bool (*test)(struct sway_container *view, void *data), void *data) { | ||
285 | if (!container->children) { | ||
286 | return NULL; | ||
287 | } | ||
288 | // TODO: floating windows | ||
289 | for (int i = 0; i < container->children->length; ++i) { | ||
290 | struct sway_container *child = container->children->items[i]; | ||
291 | if (test(child, data)) { | ||
292 | return child; | ||
293 | } else { | ||
294 | struct sway_container *res = container_find(child, test, data); | ||
295 | if (res) { | ||
296 | return res; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | return NULL; | ||
301 | } | ||
302 | |||
303 | struct sway_container *container_parent(struct sway_container *container, | ||
304 | enum sway_container_type type) { | ||
285 | if (!sway_assert(container, "container is NULL")) { | 305 | if (!sway_assert(container, "container is NULL")) { |
286 | return NULL; | 306 | return NULL; |
287 | } | 307 | } |
@@ -294,7 +314,8 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | |||
294 | return container; | 314 | return container; |
295 | } | 315 | } |
296 | 316 | ||
297 | swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | 317 | struct sway_container *container_at(struct sway_container *parent, |
318 | double lx, double ly, | ||
298 | struct wlr_surface **surface, double *sx, double *sy) { | 319 | struct wlr_surface **surface, double *sx, double *sy) { |
299 | list_t *queue = get_bfs_queue(); | 320 | list_t *queue = get_bfs_queue(); |
300 | if (!queue) { | 321 | if (!queue) { |
@@ -303,13 +324,13 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | |||
303 | 324 | ||
304 | list_add(queue, parent); | 325 | list_add(queue, parent); |
305 | 326 | ||
306 | swayc_t *swayc = NULL; | 327 | struct sway_container *swayc = NULL; |
307 | while (queue->length) { | 328 | while (queue->length) { |
308 | swayc = queue->items[0]; | 329 | swayc = queue->items[0]; |
309 | list_del(queue, 0); | 330 | list_del(queue, 0); |
310 | if (swayc->type == C_VIEW) { | 331 | if (swayc->type == C_VIEW) { |
311 | struct sway_view *sview = swayc->sway_view; | 332 | struct sway_view *sview = swayc->sway_view; |
312 | swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); | 333 | struct sway_container *soutput = container_parent(swayc, C_OUTPUT); |
313 | struct wlr_box *output_box = | 334 | struct wlr_box *output_box = |
314 | wlr_output_layout_get_box( | 335 | wlr_output_layout_get_box( |
315 | root_container.sway_root->output_layout, | 336 | root_container.sway_root->output_layout, |
@@ -379,30 +400,8 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | |||
379 | return NULL; | 400 | return NULL; |
380 | } | 401 | } |
381 | 402 | ||
382 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { | 403 | void container_for_each_descendent(struct sway_container *con, |
383 | if (container) { | 404 | void (*f)(struct sway_container *con, void *data), void *data) { |
384 | int i; | ||
385 | if (container->children) { | ||
386 | for (i = 0; i < container->children->length; ++i) { | ||
387 | swayc_t *child = container->children->items[i]; | ||
388 | container_map(child, f, data); | ||
389 | } | ||
390 | } | ||
391 | // TODO | ||
392 | /* | ||
393 | if (container->floating) { | ||
394 | for (i = 0; i < container->floating->length; ++i) { | ||
395 | swayc_t *child = container->floating->items[i]; | ||
396 | container_map(child, f, data); | ||
397 | } | ||
398 | } | ||
399 | */ | ||
400 | f(container, data); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | ||
405 | void *data) { | ||
406 | list_t *queue = get_bfs_queue(); | 405 | list_t *queue = get_bfs_queue(); |
407 | if (!queue) { | 406 | if (!queue) { |
408 | return; | 407 | return; |
@@ -415,7 +414,7 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | |||
415 | 414 | ||
416 | list_add(queue, con); | 415 | list_add(queue, con); |
417 | 416 | ||
418 | swayc_t *current = NULL; | 417 | struct sway_container *current = NULL; |
419 | while (queue->length) { | 418 | while (queue->length) { |
420 | current = queue->items[0]; | 419 | current = queue->items[0]; |
421 | list_del(queue, 0); | 420 | list_del(queue, 0); |
@@ -424,15 +423,3 @@ void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), | |||
424 | list_cat(queue, current->children); | 423 | list_cat(queue, current->children); |
425 | } | 424 | } |
426 | } | 425 | } |
427 | |||
428 | swayc_t *swayc_change_layout(swayc_t *container, enum swayc_layouts layout) { | ||
429 | if (container->type == C_WORKSPACE) { | ||
430 | container->workspace_layout = layout; | ||
431 | if (layout == L_HORIZ || layout == L_VERT) { | ||
432 | container->layout = layout; | ||
433 | } | ||
434 | } else { | ||
435 | container->layout = layout; | ||
436 | } | ||
437 | return container; | ||
438 | } | ||
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index de9e7b58..dc0ee5b4 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -6,24 +6,26 @@ | |||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <wlr/types/wlr_output.h> | 7 | #include <wlr/types/wlr_output.h> |
8 | #include <wlr/types/wlr_output_layout.h> | 8 | #include <wlr/types/wlr_output_layout.h> |
9 | #include "sway/container.h" | 9 | #include "sway/tree/container.h" |
10 | #include "sway/layout.h" | 10 | #include "sway/tree/layout.h" |
11 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/view.h" | 12 | #include "sway/tree/view.h" |
13 | #include "sway/input/seat.h" | 13 | #include "sway/input/seat.h" |
14 | #include "list.h" | 14 | #include "list.h" |
15 | #include "log.h" | 15 | #include "log.h" |
16 | 16 | ||
17 | swayc_t root_container; | 17 | struct sway_container root_container; |
18 | 18 | ||
19 | static void output_layout_change_notify(struct wl_listener *listener, void *data) { | 19 | static void output_layout_change_notify(struct wl_listener *listener, |
20 | void *data) { | ||
20 | struct wlr_box *layout_box = wlr_output_layout_get_box( | 21 | struct wlr_box *layout_box = wlr_output_layout_get_box( |
21 | root_container.sway_root->output_layout, NULL); | 22 | root_container.sway_root->output_layout, NULL); |
22 | root_container.width = layout_box->width; | 23 | root_container.width = layout_box->width; |
23 | root_container.height = layout_box->height; | 24 | root_container.height = layout_box->height; |
24 | 25 | ||
25 | for (int i = 0 ; i < root_container.children->length; ++i) { | 26 | for (int i = 0 ; i < root_container.children->length; ++i) { |
26 | swayc_t *output_container = root_container.children->items[i]; | 27 | struct sway_container *output_container = |
28 | root_container.children->items[i]; | ||
27 | if (output_container->type != C_OUTPUT) { | 29 | if (output_container->type != C_OUTPUT) { |
28 | continue; | 30 | continue; |
29 | } | 31 | } |
@@ -43,7 +45,7 @@ static void output_layout_change_notify(struct wl_listener *listener, void *data | |||
43 | arrange_windows(&root_container, -1, -1); | 45 | arrange_windows(&root_container, -1, -1); |
44 | } | 46 | } |
45 | 47 | ||
46 | void init_layout(void) { | 48 | void layout_init(void) { |
47 | root_container.id = 0; // normally assigned in new_swayc() | 49 | root_container.id = 0; // normally assigned in new_swayc() |
48 | root_container.type = C_ROOT; | 50 | root_container.type = C_ROOT; |
49 | root_container.layout = L_NONE; | 51 | root_container.layout = L_NONE; |
@@ -62,9 +64,9 @@ void init_layout(void) { | |||
62 | &root_container.sway_root->output_layout_change); | 64 | &root_container.sway_root->output_layout_change); |
63 | } | 65 | } |
64 | 66 | ||
65 | static int index_child(const swayc_t *child) { | 67 | static int index_child(const struct sway_container *child) { |
66 | // TODO handle floating | 68 | // TODO handle floating |
67 | swayc_t *parent = child->parent; | 69 | struct sway_container *parent = child->parent; |
68 | int i, len; | 70 | int i, len; |
69 | len = parent->children->length; | 71 | len = parent->children->length; |
70 | for (i = 0; i < len; ++i) { | 72 | for (i = 0; i < len; ++i) { |
@@ -79,16 +81,18 @@ static int index_child(const swayc_t *child) { | |||
79 | return i; | 81 | return i; |
80 | } | 82 | } |
81 | 83 | ||
82 | swayc_t *add_sibling(swayc_t *fixed, swayc_t *active) { | 84 | struct sway_container *container_add_sibling(struct sway_container *fixed, |
85 | struct sway_container *active) { | ||
83 | // TODO handle floating | 86 | // TODO handle floating |
84 | swayc_t *parent = fixed->parent; | 87 | struct sway_container *parent = fixed->parent; |
85 | int i = index_child(fixed); | 88 | int i = index_child(fixed); |
86 | list_insert(parent->children, i + 1, active); | 89 | list_insert(parent->children, i + 1, active); |
87 | active->parent = parent; | 90 | active->parent = parent; |
88 | return active->parent; | 91 | return active->parent; |
89 | } | 92 | } |
90 | 93 | ||
91 | void add_child(swayc_t *parent, swayc_t *child) { | 94 | void container_add_child(struct sway_container *parent, |
95 | struct sway_container *child) { | ||
92 | wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", | 96 | wlr_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", |
93 | child, child->type, child->width, child->height, | 97 | child, child->type, child->width, child->height, |
94 | parent, parent->type, parent->width, parent->height); | 98 | parent, parent->type, parent->width, parent->height); |
@@ -96,15 +100,17 @@ void add_child(swayc_t *parent, swayc_t *child) { | |||
96 | child->parent = parent; | 100 | child->parent = parent; |
97 | // set focus for this container | 101 | // set focus for this container |
98 | /* TODO WLR | 102 | /* TODO WLR |
99 | if (parent->type == C_WORKSPACE && child->type == C_VIEW && (parent->workspace_layout == L_TABBED || parent->workspace_layout == L_STACKED)) { | 103 | if (parent->type == C_WORKSPACE && child->type == C_VIEW && |
104 | (parent->workspace_layout == L_TABBED || parent->workspace_layout == | ||
105 | L_STACKED)) { | ||
100 | child = new_container(child, parent->workspace_layout); | 106 | child = new_container(child, parent->workspace_layout); |
101 | } | 107 | } |
102 | */ | 108 | */ |
103 | } | 109 | } |
104 | 110 | ||
105 | swayc_t *remove_child(swayc_t *child) { | 111 | struct sway_container *container_remove_child(struct sway_container *child) { |
106 | int i; | 112 | int i; |
107 | swayc_t *parent = child->parent; | 113 | struct sway_container *parent = child->parent; |
108 | for (i = 0; i < parent->children->length; ++i) { | 114 | for (i = 0; i < parent->children->length; ++i) { |
109 | if (parent->children->items[i] == child) { | 115 | if (parent->children->items[i] == child) { |
110 | list_del(parent->children, i); | 116 | list_del(parent->children, i); |
@@ -115,7 +121,8 @@ swayc_t *remove_child(swayc_t *child) { | |||
115 | return parent; | 121 | return parent; |
116 | } | 122 | } |
117 | 123 | ||
118 | enum swayc_layouts default_layout(swayc_t *output) { | 124 | enum sway_container_layout container_get_default_layout( |
125 | struct sway_container *output) { | ||
119 | /* TODO WLR | 126 | /* TODO WLR |
120 | if (config->default_layout != L_NONE) { | 127 | if (config->default_layout != L_NONE) { |
121 | //return config->default_layout; | 128 | //return config->default_layout; |
@@ -129,8 +136,8 @@ enum swayc_layouts default_layout(swayc_t *output) { | |||
129 | } | 136 | } |
130 | 137 | ||
131 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | 138 | static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { |
132 | swayc_t *a = *(void **)_a; | 139 | struct sway_container *a = *(void **)_a; |
133 | swayc_t *b = *(void **)_b; | 140 | struct sway_container *b = *(void **)_b; |
134 | int retval = 0; | 141 | int retval = 0; |
135 | 142 | ||
136 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { | 143 | if (isdigit(a->name[0]) && isdigit(b->name[0])) { |
@@ -146,21 +153,22 @@ static int sort_workspace_cmp_qsort(const void *_a, const void *_b) { | |||
146 | return retval; | 153 | return retval; |
147 | } | 154 | } |
148 | 155 | ||
149 | void sort_workspaces(swayc_t *output) { | 156 | void container_sort_workspaces(struct sway_container *output) { |
150 | list_stable_sort(output->children, sort_workspace_cmp_qsort); | 157 | list_stable_sort(output->children, sort_workspace_cmp_qsort); |
151 | } | 158 | } |
152 | 159 | ||
153 | static void apply_horiz_layout(swayc_t *container, const double x, | 160 | static void apply_horiz_layout(struct sway_container *container, const double x, |
154 | const double y, const double width, | 161 | const double y, const double width, |
155 | const double height, const int start, | 162 | const double height, const int start, |
156 | const int end); | 163 | const int end); |
157 | 164 | ||
158 | static void apply_vert_layout(swayc_t *container, const double x, | 165 | static void apply_vert_layout(struct sway_container *container, const double x, |
159 | const double y, const double width, | 166 | const double y, const double width, |
160 | const double height, const int start, | 167 | const double height, const int start, |
161 | const int end); | 168 | const int end); |
162 | 169 | ||
163 | void arrange_windows(swayc_t *container, double width, double height) { | 170 | void arrange_windows(struct sway_container *container, |
171 | double width, double height) { | ||
164 | int i; | 172 | int i; |
165 | if (width == -1 || height == -1) { | 173 | if (width == -1 || height == -1) { |
166 | width = container->width; | 174 | width = container->width; |
@@ -181,7 +189,7 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
181 | case C_ROOT: | 189 | case C_ROOT: |
182 | // TODO: wlr_output_layout probably | 190 | // TODO: wlr_output_layout probably |
183 | for (i = 0; i < container->children->length; ++i) { | 191 | for (i = 0; i < container->children->length; ++i) { |
184 | swayc_t *output = container->children->items[i]; | 192 | struct sway_container *output = container->children->items[i]; |
185 | wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", | 193 | wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", |
186 | output->name, output->x, output->y); | 194 | output->name, output->x, output->y); |
187 | arrange_windows(output, -1, -1); | 195 | arrange_windows(output, -1, -1); |
@@ -197,13 +205,14 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
197 | } | 205 | } |
198 | // arrange all workspaces: | 206 | // arrange all workspaces: |
199 | for (i = 0; i < container->children->length; ++i) { | 207 | for (i = 0; i < container->children->length; ++i) { |
200 | swayc_t *child = container->children->items[i]; | 208 | struct sway_container *child = container->children->items[i]; |
201 | arrange_windows(child, -1, -1); | 209 | arrange_windows(child, -1, -1); |
202 | } | 210 | } |
203 | return; | 211 | return; |
204 | case C_WORKSPACE: | 212 | case C_WORKSPACE: |
205 | { | 213 | { |
206 | swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); | 214 | struct sway_container *output = |
215 | container_parent(container, C_OUTPUT); | ||
207 | struct wlr_box *area = &output->sway_output->usable_area; | 216 | struct wlr_box *area = &output->sway_output->usable_area; |
208 | wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", | 217 | wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", |
209 | area->width, area->height, area->x, area->y); | 218 | area->width, area->height, area->x, area->y); |
@@ -252,14 +261,15 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
252 | } | 261 | } |
253 | } | 262 | } |
254 | 263 | ||
255 | static void apply_horiz_layout(swayc_t *container, | 264 | static void apply_horiz_layout(struct sway_container *container, |
256 | const double x, const double y, | 265 | const double x, const double y, |
257 | const double width, const double height, | 266 | const double width, const double height, |
258 | const int start, const int end) { | 267 | const int start, const int end) { |
259 | double scale = 0; | 268 | double scale = 0; |
260 | // Calculate total width | 269 | // Calculate total width |
261 | for (int i = start; i < end; ++i) { | 270 | for (int i = start; i < end; ++i) { |
262 | double *old_width = &((swayc_t *)container->children->items[i])->width; | 271 | double *old_width = |
272 | &((struct sway_container *)container->children->items[i])->width; | ||
263 | if (*old_width <= 0) { | 273 | if (*old_width <= 0) { |
264 | if (end - start > 1) { | 274 | if (end - start > 1) { |
265 | *old_width = width / (end - start - 1); | 275 | *old_width = width / (end - start - 1); |
@@ -276,7 +286,7 @@ static void apply_horiz_layout(swayc_t *container, | |||
276 | if (scale > 0.1) { | 286 | if (scale > 0.1) { |
277 | wlr_log(L_DEBUG, "Arranging %p horizontally", container); | 287 | wlr_log(L_DEBUG, "Arranging %p horizontally", container); |
278 | for (int i = start; i < end; ++i) { | 288 | for (int i = start; i < end; ++i) { |
279 | swayc_t *child = container->children->items[i]; | 289 | struct sway_container *child = container->children->items[i]; |
280 | wlr_log(L_DEBUG, | 290 | wlr_log(L_DEBUG, |
281 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 291 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
282 | child, child->type, width, scale); | 292 | child, child->type, width, scale); |
@@ -301,7 +311,7 @@ static void apply_horiz_layout(swayc_t *container, | |||
301 | } | 311 | } |
302 | } | 312 | } |
303 | 313 | ||
304 | void apply_vert_layout(swayc_t *container, | 314 | void apply_vert_layout(struct sway_container *container, |
305 | const double x, const double y, | 315 | const double x, const double y, |
306 | const double width, const double height, const int start, | 316 | const double width, const double height, const int start, |
307 | const int end) { | 317 | const int end) { |
@@ -309,7 +319,8 @@ void apply_vert_layout(swayc_t *container, | |||
309 | double scale = 0; | 319 | double scale = 0; |
310 | // Calculate total height | 320 | // Calculate total height |
311 | for (i = start; i < end; ++i) { | 321 | for (i = start; i < end; ++i) { |
312 | double *old_height = &((swayc_t *)container->children->items[i])->height; | 322 | double *old_height = |
323 | &((struct sway_container *)container->children->items[i])->height; | ||
313 | if (*old_height <= 0) { | 324 | if (*old_height <= 0) { |
314 | if (end - start > 1) { | 325 | if (end - start > 1) { |
315 | *old_height = height / (end - start - 1); | 326 | *old_height = height / (end - start - 1); |
@@ -326,7 +337,7 @@ void apply_vert_layout(swayc_t *container, | |||
326 | if (scale > 0.1) { | 337 | if (scale > 0.1) { |
327 | wlr_log(L_DEBUG, "Arranging %p vertically", container); | 338 | wlr_log(L_DEBUG, "Arranging %p vertically", container); |
328 | for (i = start; i < end; ++i) { | 339 | for (i = start; i < end; ++i) { |
329 | swayc_t *child = container->children->items[i]; | 340 | struct sway_container *child = container->children->items[i]; |
330 | wlr_log(L_DEBUG, | 341 | wlr_log(L_DEBUG, |
331 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 342 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
332 | child, child->type, height, scale); | 343 | child, child->type, height, scale); |
@@ -354,15 +365,16 @@ void apply_vert_layout(swayc_t *container, | |||
354 | /** | 365 | /** |
355 | * Get swayc in the direction of newly entered output. | 366 | * Get swayc in the direction of newly entered output. |
356 | */ | 367 | */ |
357 | static swayc_t *get_swayc_in_output_direction(swayc_t *output, | 368 | static struct sway_container *get_swayc_in_output_direction( |
358 | enum movement_direction dir, struct sway_seat *seat) { | 369 | struct sway_container *output, enum movement_direction dir, |
370 | struct sway_seat *seat) { | ||
359 | if (!output) { | 371 | if (!output) { |
360 | return NULL; | 372 | return NULL; |
361 | } | 373 | } |
362 | 374 | ||
363 | swayc_t *ws = sway_seat_get_focus_inactive(seat, output); | 375 | struct sway_container *ws = sway_seat_get_focus_inactive(seat, output); |
364 | if (ws->type != C_WORKSPACE) { | 376 | if (ws->type != C_WORKSPACE) { |
365 | ws = swayc_parent_by_type(ws, C_WORKSPACE); | 377 | ws = container_parent(ws, C_WORKSPACE); |
366 | } | 378 | } |
367 | 379 | ||
368 | if (ws == NULL) { | 380 | if (ws == NULL) { |
@@ -380,13 +392,15 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, | |||
380 | return ws->children->items[0]; | 392 | return ws->children->items[0]; |
381 | case MOVE_UP: | 393 | case MOVE_UP: |
382 | case MOVE_DOWN: { | 394 | case MOVE_DOWN: { |
383 | swayc_t *focused = sway_seat_get_focus_inactive(seat, ws); | 395 | struct sway_container *focused = |
396 | sway_seat_get_focus_inactive(seat, ws); | ||
384 | if (focused && focused->parent) { | 397 | if (focused && focused->parent) { |
385 | swayc_t *parent = focused->parent; | 398 | struct sway_container *parent = focused->parent; |
386 | if (parent->layout == L_VERT) { | 399 | if (parent->layout == L_VERT) { |
387 | if (dir == MOVE_UP) { | 400 | if (dir == MOVE_UP) { |
388 | // get child furthest down on new output | 401 | // get child furthest down on new output |
389 | return parent->children->items[parent->children->length-1]; | 402 | int idx = parent->children->length - 1; |
403 | return parent->children->items[idx]; | ||
390 | } else if (dir == MOVE_DOWN) { | 404 | } else if (dir == MOVE_DOWN) { |
391 | // get child furthest up on new output | 405 | // get child furthest up on new output |
392 | return parent->children->items[0]; | 406 | return parent->children->items[0]; |
@@ -404,13 +418,14 @@ static swayc_t *get_swayc_in_output_direction(swayc_t *output, | |||
404 | return ws; | 418 | return ws; |
405 | } | 419 | } |
406 | 420 | ||
407 | static void get_layout_center_position(swayc_t *container, int *x, int *y) { | 421 | static void get_layout_center_position(struct sway_container *container, |
422 | int *x, int *y) { | ||
408 | // FIXME view coords are inconsistently referred to in layout/output systems | 423 | // FIXME view coords are inconsistently referred to in layout/output systems |
409 | if (container->type == C_OUTPUT) { | 424 | if (container->type == C_OUTPUT) { |
410 | *x = container->x + container->width/2; | 425 | *x = container->x + container->width/2; |
411 | *y = container->y + container->height/2; | 426 | *y = container->y + container->height/2; |
412 | } else { | 427 | } else { |
413 | swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); | 428 | struct sway_container *output = container_parent(container, C_OUTPUT); |
414 | if (container->type == C_WORKSPACE) { | 429 | if (container->type == C_WORKSPACE) { |
415 | // Workspace coordinates are actually wrong/arbitrary, but should | 430 | // Workspace coordinates are actually wrong/arbitrary, but should |
416 | // be same as output. | 431 | // be same as output. |
@@ -423,7 +438,8 @@ static void get_layout_center_position(swayc_t *container, int *x, int *y) { | |||
423 | } | 438 | } |
424 | } | 439 | } |
425 | 440 | ||
426 | static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) { | 441 | static bool sway_dir_to_wlr(enum movement_direction dir, |
442 | enum wlr_direction *out) { | ||
427 | switch (dir) { | 443 | switch (dir) { |
428 | case MOVE_UP: | 444 | case MOVE_UP: |
429 | *out = WLR_DIRECTION_UP; | 445 | *out = WLR_DIRECTION_UP; |
@@ -444,12 +460,12 @@ static bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out | |||
444 | return true; | 460 | return true; |
445 | } | 461 | } |
446 | 462 | ||
447 | static swayc_t *sway_output_from_wlr(struct wlr_output *output) { | 463 | static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { |
448 | if (output == NULL) { | 464 | if (output == NULL) { |
449 | return NULL; | 465 | return NULL; |
450 | } | 466 | } |
451 | for (int i = 0; i < root_container.children->length; ++i) { | 467 | for (int i = 0; i < root_container.children->length; ++i) { |
452 | swayc_t *o = root_container.children->items[i]; | 468 | struct sway_container *o = root_container.children->items[i]; |
453 | if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { | 469 | if (o->type == C_OUTPUT && o->sway_output->wlr_output == output) { |
454 | return o; | 470 | return o; |
455 | } | 471 | } |
@@ -457,13 +473,14 @@ static swayc_t *sway_output_from_wlr(struct wlr_output *output) { | |||
457 | return NULL; | 473 | return NULL; |
458 | } | 474 | } |
459 | 475 | ||
460 | static swayc_t *get_swayc_in_direction_under(swayc_t *container, | 476 | static struct sway_container *get_swayc_in_direction_under( |
461 | enum movement_direction dir, struct sway_seat *seat, swayc_t *limit) { | 477 | struct sway_container *container, enum movement_direction dir, |
478 | struct sway_seat *seat, struct sway_container *limit) { | ||
462 | if (dir == MOVE_CHILD) { | 479 | if (dir == MOVE_CHILD) { |
463 | return sway_seat_get_focus_inactive(seat, container); | 480 | return sway_seat_get_focus_inactive(seat, container); |
464 | } | 481 | } |
465 | 482 | ||
466 | swayc_t *parent = container->parent; | 483 | struct sway_container *parent = container->parent; |
467 | if (dir == MOVE_PARENT) { | 484 | if (dir == MOVE_PARENT) { |
468 | if (parent->type == C_OUTPUT) { | 485 | if (parent->type == C_OUTPUT) { |
469 | return NULL; | 486 | return NULL; |
@@ -496,9 +513,10 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
496 | /* | 513 | /* |
497 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { | 514 | if (container->type == C_VIEW && swayc_is_fullscreen(container)) { |
498 | wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); | 515 | wlr_log(L_DEBUG, "Moving from fullscreen view, skipping to output"); |
499 | container = swayc_parent_by_type(container, C_OUTPUT); | 516 | container = container_parent(container, C_OUTPUT); |
500 | get_layout_center_position(container, &abs_pos); | 517 | get_layout_center_position(container, &abs_pos); |
501 | swayc_t *output = swayc_adjacent_output(container, dir, &abs_pos, true); | 518 | struct sway_container *output = |
519 | swayc_adjacent_output(container, dir, &abs_pos, true); | ||
502 | return get_swayc_in_output_direction(output, dir); | 520 | return get_swayc_in_output_direction(output, dir); |
503 | } | 521 | } |
504 | if (container->type == C_WORKSPACE && container->fullscreen) { | 522 | if (container->type == C_WORKSPACE && container->fullscreen) { |
@@ -507,7 +525,7 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
507 | } | 525 | } |
508 | */ | 526 | */ |
509 | 527 | ||
510 | swayc_t *wrap_candidate = NULL; | 528 | struct sway_container *wrap_candidate = NULL; |
511 | while (true) { | 529 | while (true) { |
512 | // Test if we can even make a difference here | 530 | // Test if we can even make a difference here |
513 | bool can_move = false; | 531 | bool can_move = false; |
@@ -521,16 +539,19 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
521 | } | 539 | } |
522 | int lx, ly; | 540 | int lx, ly; |
523 | get_layout_center_position(container, &lx, &ly); | 541 | get_layout_center_position(container, &lx, &ly); |
524 | struct wlr_output_layout *layout = root_container.sway_root->output_layout; | 542 | struct wlr_output_layout *layout = |
543 | root_container.sway_root->output_layout; | ||
525 | struct wlr_output *wlr_adjacent = | 544 | struct wlr_output *wlr_adjacent = |
526 | wlr_output_layout_adjacent_output(layout, wlr_dir, | 545 | wlr_output_layout_adjacent_output(layout, wlr_dir, |
527 | container->sway_output->wlr_output, lx, ly); | 546 | container->sway_output->wlr_output, lx, ly); |
528 | swayc_t *adjacent = sway_output_from_wlr(wlr_adjacent); | 547 | struct sway_container *adjacent = |
548 | sway_output_from_wlr(wlr_adjacent); | ||
529 | 549 | ||
530 | if (!adjacent || adjacent == container) { | 550 | if (!adjacent || adjacent == container) { |
531 | return wrap_candidate; | 551 | return wrap_candidate; |
532 | } | 552 | } |
533 | swayc_t *next = get_swayc_in_output_direction(adjacent, dir, seat); | 553 | struct sway_container *next = |
554 | get_swayc_in_output_direction(adjacent, dir, seat); | ||
534 | if (next == NULL) { | 555 | if (next == NULL) { |
535 | return NULL; | 556 | return NULL; |
536 | } | 557 | } |
@@ -570,8 +591,9 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
570 | } | 591 | } |
571 | } | 592 | } |
572 | } else { | 593 | } else { |
573 | wlr_log(L_DEBUG, "%s cont %d-%p dir %i sibling %d: %p", __func__, | 594 | wlr_log(L_DEBUG, |
574 | idx, container, dir, desired, parent->children->items[desired]); | 595 | "cont %d-%p dir %i sibling %d: %p", idx, |
596 | container, dir, desired, parent->children->items[desired]); | ||
575 | return parent->children->items[desired]; | 597 | return parent->children->items[desired]; |
576 | } | 598 | } |
577 | } | 599 | } |
@@ -587,7 +609,8 @@ static swayc_t *get_swayc_in_direction_under(swayc_t *container, | |||
587 | } | 609 | } |
588 | } | 610 | } |
589 | 611 | ||
590 | swayc_t *get_swayc_in_direction(swayc_t *container, struct sway_seat *seat, | 612 | struct sway_container *container_get_in_direction( |
613 | struct sway_container *container, struct sway_seat *seat, | ||
591 | enum movement_direction dir) { | 614 | enum movement_direction dir) { |
592 | return get_swayc_in_direction_under(container, dir, seat, NULL); | 615 | return get_swayc_in_direction_under(container, dir, seat, NULL); |
593 | } | 616 | } |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 9499adca..d5325c31 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -1,8 +1,8 @@ | |||
1 | #include <wayland-server.h> | 1 | #include <wayland-server.h> |
2 | #include <wlr/types/wlr_output_layout.h> | 2 | #include <wlr/types/wlr_output_layout.h> |
3 | #include "sway/container.h" | 3 | #include "sway/tree/container.h" |
4 | #include "sway/layout.h" | 4 | #include "sway/tree/layout.h" |
5 | #include "sway/view.h" | 5 | #include "sway/tree/view.h" |
6 | 6 | ||
7 | const char *view_get_title(struct sway_view *view) { | 7 | const char *view_get_title(struct sway_view *view) { |
8 | if (view->iface.get_prop) { | 8 | if (view->iface.get_prop) { |
@@ -45,6 +45,7 @@ void view_set_size(struct sway_view *view, int width, int height) { | |||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | // TODO make view coordinates in layout coordinates | ||
48 | void view_set_position(struct sway_view *view, double ox, double oy) { | 49 | void view_set_position(struct sway_view *view, double ox, double oy) { |
49 | if (view->iface.set_position) { | 50 | if (view->iface.set_position) { |
50 | struct wlr_box box = { | 51 | struct wlr_box box = { |
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 | } |