diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-21 10:28:37 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-21 10:28:37 -0700 |
commit | 1a1ac64662a603fdeb7025bed3822e24f9158076 (patch) | |
tree | 4ac14ed2cb3942072824a3376337ea5492bf4e75 | |
parent | Merge pull request #110 from minus7/sign-comparsion-fix (diff) | |
download | sway-1a1ac64662a603fdeb7025bed3822e24f9158076.tar.gz sway-1a1ac64662a603fdeb7025bed3822e24f9158076.tar.zst sway-1a1ac64662a603fdeb7025bed3822e24f9158076.zip |
bugfixes, renames
-rw-r--r-- | include/container.h | 13 | ||||
-rw-r--r-- | include/layout.h | 7 | ||||
-rw-r--r-- | include/workspace.h | 4 | ||||
-rw-r--r-- | sway/commands.c | 56 | ||||
-rw-r--r-- | sway/container.c | 118 | ||||
-rw-r--r-- | sway/focus.c | 46 | ||||
-rw-r--r-- | sway/handlers.c | 22 | ||||
-rw-r--r-- | sway/layout.c | 37 | ||||
-rw-r--r-- | sway/log.c | 5 | ||||
-rw-r--r-- | sway/workspace.c | 27 |
10 files changed, 187 insertions, 148 deletions
diff --git a/include/container.h b/include/container.h index 4e21461c..2ced248b 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -81,12 +81,21 @@ swayc_t *destroy_view(swayc_t *view); | |||
81 | 81 | ||
82 | // Container Lookup | 82 | // Container Lookup |
83 | 83 | ||
84 | swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); | ||
84 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); | 85 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); |
85 | swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); | 86 | swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); |
87 | swayc_t *swayc_by_handle(wlc_handle handle); | ||
88 | swayc_t *swayc_active_output(void); | ||
89 | swayc_t *swayc_active_workspace(void); | ||
90 | swayc_t *swayc_active_workspace_for(swayc_t *view); | ||
86 | 91 | ||
87 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); | 92 | // Container information |
88 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | 93 | |
94 | bool swayc_is_fullscreen(swayc_t *view); | ||
89 | 95 | ||
96 | // Mapping functions | ||
97 | |||
98 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | ||
90 | 99 | ||
91 | // Mappings | 100 | // Mappings |
92 | void set_view_visibility(swayc_t *view, void *data); | 101 | void set_view_visibility(swayc_t *view, void *data); |
diff --git a/include/layout.h b/include/layout.h index 55bb6709..7b8829ed 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -19,17 +19,10 @@ swayc_t *remove_child(swayc_t *child); | |||
19 | 19 | ||
20 | void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); | 20 | void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); |
21 | 21 | ||
22 | |||
23 | // Layout | 22 | // Layout |
24 | void arrange_windows(swayc_t *container, double width, double height); | 23 | void arrange_windows(swayc_t *container, double width, double height); |
25 | 24 | ||
26 | // Focus | ||
27 | void unfocus_all(swayc_t *container); | ||
28 | void focus_view(swayc_t *view); | ||
29 | void focus_view_for(swayc_t *ancestor, swayc_t *container); | ||
30 | |||
31 | swayc_t *get_focused_container(swayc_t *parent); | 25 | swayc_t *get_focused_container(swayc_t *parent); |
32 | swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); | ||
33 | swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); | 26 | swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); |
34 | 27 | ||
35 | void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge); | 28 | void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge); |
diff --git a/include/workspace.h b/include/workspace.h index 042a15d9..d447ac2d 100644 --- a/include/workspace.h +++ b/include/workspace.h | |||
@@ -5,11 +5,9 @@ | |||
5 | #include "list.h" | 5 | #include "list.h" |
6 | #include "layout.h" | 6 | #include "layout.h" |
7 | 7 | ||
8 | extern swayc_t *active_workspace; | ||
9 | |||
10 | char *workspace_next_name(void); | 8 | char *workspace_next_name(void); |
11 | swayc_t *workspace_create(const char*); | 9 | swayc_t *workspace_create(const char*); |
12 | swayc_t *workspace_find_by_name(const char*); | 10 | swayc_t *workspace_by_name(const char*); |
13 | void workspace_switch(swayc_t*); | 11 | void workspace_switch(swayc_t*); |
14 | void workspace_output_next(); | 12 | void workspace_output_next(); |
15 | void workspace_next(); | 13 | void workspace_next(); |
diff --git a/sway/commands.c b/sway/commands.c index e90a40a3..e485cdb5 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -208,16 +208,16 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
208 | destroy_container(remove_child(view)); | 208 | destroy_container(remove_child(view)); |
209 | 209 | ||
210 | // and move it into workspace floating | 210 | // and move it into workspace floating |
211 | add_floating(active_workspace,view); | 211 | add_floating(swayc_active_workspace(),view); |
212 | view->x = (active_workspace->width - view->width)/2; | 212 | view->x = (swayc_active_workspace()->width - view->width)/2; |
213 | view->y = (active_workspace->height - view->height)/2; | 213 | view->y = (swayc_active_workspace()->height - view->height)/2; |
214 | if (view->desired_width != -1) { | 214 | if (view->desired_width != -1) { |
215 | view->width = view->desired_width; | 215 | view->width = view->desired_width; |
216 | } | 216 | } |
217 | if (view->desired_height != -1) { | 217 | if (view->desired_height != -1) { |
218 | view->height = view->desired_height; | 218 | view->height = view->desired_height; |
219 | } | 219 | } |
220 | arrange_windows(active_workspace, -1, -1); | 220 | arrange_windows(swayc_active_workspace(), -1, -1); |
221 | } else { | 221 | } else { |
222 | // Delete the view from the floating list and unset its is_floating flag | 222 | // Delete the view from the floating list and unset its is_floating flag |
223 | // Using length-1 as the index is safe because the view must be the currently | 223 | // Using length-1 as the index is safe because the view must be the currently |
@@ -228,7 +228,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
228 | swayc_t *focused = container_under_pointer(); | 228 | swayc_t *focused = container_under_pointer(); |
229 | // If focused is null, it's because the currently focused container is a workspace | 229 | // If focused is null, it's because the currently focused container is a workspace |
230 | if (focused == NULL) { | 230 | if (focused == NULL) { |
231 | focused = active_workspace; | 231 | focused = swayc_active_workspace(); |
232 | } | 232 | } |
233 | set_focused_container(focused); | 233 | set_focused_container(focused); |
234 | 234 | ||
@@ -244,7 +244,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
244 | } | 244 | } |
245 | // Refocus on the view once its been put back into the layout | 245 | // Refocus on the view once its been put back into the layout |
246 | view->width = view->height = 0; | 246 | view->width = view->height = 0; |
247 | arrange_windows(active_workspace, -1, -1); | 247 | arrange_windows(swayc_active_workspace(), -1, -1); |
248 | } | 248 | } |
249 | set_focused_container(view); | 249 | set_focused_container(view); |
250 | } | 250 | } |
@@ -293,37 +293,38 @@ static bool cmd_focus(struct sway_config *config, int argc, char **argv) { | |||
293 | return move_focus(MOVE_PARENT); | 293 | return move_focus(MOVE_PARENT); |
294 | } else if (strcasecmp(argv[0], "mode_toggle") == 0) { | 294 | } else if (strcasecmp(argv[0], "mode_toggle") == 0) { |
295 | int i; | 295 | int i; |
296 | swayc_t *focused = get_focused_view(active_workspace); | 296 | swayc_t *workspace = swayc_active_workspace(); |
297 | swayc_t *focused = get_focused_view(workspace); | ||
297 | if (focused->is_floating) { | 298 | if (focused->is_floating) { |
298 | if (active_workspace->children->length > 0) { | 299 | if (workspace->children->length > 0) { |
299 | for (i = 0;i < active_workspace->floating->length; i++) { | 300 | for (i = 0;i < workspace->floating->length; i++) { |
300 | if (active_workspace->floating->items[i] == focused) { | 301 | if (workspace->floating->items[i] == focused) { |
301 | floating_toggled_index = i; | 302 | floating_toggled_index = i; |
302 | break; | 303 | break; |
303 | } | 304 | } |
304 | } | 305 | } |
305 | if (active_workspace->children->length > tiled_toggled_index) { | 306 | if (workspace->children->length > tiled_toggled_index) { |
306 | set_focused_container(get_focused_view(active_workspace->children->items[tiled_toggled_index])); | 307 | set_focused_container(get_focused_view(workspace->children->items[tiled_toggled_index])); |
307 | } else { | 308 | } else { |
308 | set_focused_container(get_focused_view(active_workspace->children->items[0])); | 309 | set_focused_container(get_focused_view(workspace->children->items[0])); |
309 | tiled_toggled_index = 0; | 310 | tiled_toggled_index = 0; |
310 | } | 311 | } |
311 | } | 312 | } |
312 | } else { | 313 | } else { |
313 | if (active_workspace->floating->length > 0) { | 314 | if (workspace->floating->length > 0) { |
314 | for (i = 0;i < active_workspace->children->length; i++) { | 315 | for (i = 0;i < workspace->children->length; i++) { |
315 | if (active_workspace->children->items[i] == focused) { | 316 | if (workspace->children->items[i] == focused) { |
316 | tiled_toggled_index = i; | 317 | tiled_toggled_index = i; |
317 | break; | 318 | break; |
318 | } | 319 | } |
319 | } | 320 | } |
320 | if (active_workspace->floating->length > floating_toggled_index) { | 321 | if (workspace->floating->length > floating_toggled_index) { |
321 | swayc_t *floating = active_workspace->floating->items[floating_toggled_index]; | 322 | swayc_t *floating = workspace->floating->items[floating_toggled_index]; |
322 | set_focused_container(get_focused_view(floating)); | 323 | set_focused_container(get_focused_view(floating)); |
323 | } else { | 324 | } else { |
324 | swayc_t *floating = active_workspace->floating->items[active_workspace->floating->length - 1]; | 325 | swayc_t *floating = workspace->floating->items[workspace->floating->length - 1]; |
325 | set_focused_container(get_focused_view(floating)); | 326 | set_focused_container(get_focused_view(floating)); |
326 | tiled_toggled_index = active_workspace->floating->length - 1; | 327 | tiled_toggled_index = workspace->floating->length - 1; |
327 | } | 328 | } |
328 | } | 329 | } |
329 | } | 330 | } |
@@ -459,7 +460,7 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) { | |||
459 | amount *= -1; | 460 | amount *= -1; |
460 | } | 461 | } |
461 | 462 | ||
462 | swayc_t *parent = get_focused_view(active_workspace); | 463 | swayc_t *parent = get_focused_view(swayc_active_workspace()); |
463 | swayc_t *focused = parent; | 464 | swayc_t *focused = parent; |
464 | swayc_t *sibling; | 465 | swayc_t *sibling; |
465 | if (!parent) { | 466 | if (!parent) { |
@@ -529,7 +530,7 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) { | |||
529 | } | 530 | } |
530 | // Recursive resize does not handle positions, let arrange_windows | 531 | // Recursive resize does not handle positions, let arrange_windows |
531 | // take care of that. | 532 | // take care of that. |
532 | arrange_windows(active_workspace, -1, -1); | 533 | arrange_windows(swayc_active_workspace(), -1, -1); |
533 | return true; | 534 | return true; |
534 | } else if (strcmp(argv[1], "height") == 0) { | 535 | } else if (strcmp(argv[1], "height") == 0) { |
535 | int tnumber = 0; | 536 | int tnumber = 0; |
@@ -589,7 +590,7 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) { | |||
589 | } | 590 | } |
590 | } | 591 | } |
591 | } | 592 | } |
592 | arrange_windows(active_workspace, -1, -1); | 593 | arrange_windows(swayc_active_workspace(), -1, -1); |
593 | return true; | 594 | return true; |
594 | } | 595 | } |
595 | return true; | 596 | return true; |
@@ -616,8 +617,12 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay | |||
616 | } | 617 | } |
617 | swayc_t *focused = get_focused_container(&root_container); | 618 | swayc_t *focused = get_focused_container(&root_container); |
618 | 619 | ||
620 | // Case of floating window, dont split | ||
621 | if (focused->is_floating) { | ||
622 | return true; | ||
623 | } | ||
624 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
619 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { | 625 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { |
620 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
621 | sway_log(L_DEBUG, "changing workspace layout"); | 626 | sway_log(L_DEBUG, "changing workspace layout"); |
622 | focused->layout = layout; | 627 | focused->layout = layout; |
623 | } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { | 628 | } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { |
@@ -632,7 +637,6 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay | |||
632 | set_focused_container(focused); | 637 | set_focused_container(focused); |
633 | arrange_windows(parent, -1, -1); | 638 | arrange_windows(parent, -1, -1); |
634 | } | 639 | } |
635 | |||
636 | return true; | 640 | return true; |
637 | } | 641 | } |
638 | 642 | ||
@@ -721,7 +725,7 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { | |||
721 | return true; | 725 | return true; |
722 | } | 726 | } |
723 | 727 | ||
724 | swayc_t *workspace = workspace_find_by_name(argv[0]); | 728 | swayc_t *workspace = workspace_by_name(argv[0]); |
725 | if (!workspace) { | 729 | if (!workspace) { |
726 | workspace = workspace_create(argv[0]); | 730 | workspace = workspace_create(argv[0]); |
727 | } | 731 | } |
diff --git a/sway/container.c b/sway/container.c index 7ccc2e09..5f1510a9 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -57,10 +57,6 @@ static void free_swayc(swayc_t *cont) { | |||
57 | 57 | ||
58 | // New containers | 58 | // New containers |
59 | 59 | ||
60 | static bool workspace_test(swayc_t *view, void *name) { | ||
61 | return strcasecmp(view->name, (char *)name) == 0; | ||
62 | } | ||
63 | |||
64 | swayc_t *new_output(wlc_handle handle) { | 60 | swayc_t *new_output(wlc_handle handle) { |
65 | const struct wlc_size* size = wlc_output_get_resolution(handle); | 61 | const struct wlc_size* size = wlc_output_get_resolution(handle); |
66 | const char *name = wlc_output_get_name(handle); | 62 | const char *name = wlc_output_get_name(handle); |
@@ -84,7 +80,7 @@ swayc_t *new_output(wlc_handle handle) { | |||
84 | if (strcasecmp(wso->output, name) == 0) { | 80 | if (strcasecmp(wso->output, name) == 0) { |
85 | sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); | 81 | sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); |
86 | // Check if any other workspaces are using this name | 82 | // Check if any other workspaces are using this name |
87 | if (find_container(&root_container, workspace_test, wso->workspace)) { | 83 | if (workspace_by_name(wso->workspace)) { |
88 | sway_log(L_DEBUG, "But it's already taken"); | 84 | sway_log(L_DEBUG, "But it's already taken"); |
89 | break; | 85 | break; |
90 | } | 86 | } |
@@ -128,7 +124,8 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
128 | } | 124 | } |
129 | 125 | ||
130 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { | 126 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { |
131 | if (!ASSERT_NONNULL(child)) { | 127 | if (!ASSERT_NONNULL(child) |
128 | && !sway_assert(!child->is_floating, "cannot create container around floating window")) { | ||
132 | return NULL; | 129 | return NULL; |
133 | } | 130 | } |
134 | swayc_t *cont = new_swayc(C_CONTAINER); | 131 | swayc_t *cont = new_swayc(C_CONTAINER); |
@@ -207,6 +204,9 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
207 | } | 204 | } |
208 | 205 | ||
209 | swayc_t *new_floating_view(wlc_handle handle) { | 206 | swayc_t *new_floating_view(wlc_handle handle) { |
207 | if (swayc_active_workspace() == NULL) { | ||
208 | return NULL; | ||
209 | } | ||
210 | const char *title = wlc_view_get_title(handle); | 210 | const char *title = wlc_view_get_title(handle); |
211 | swayc_t *view = new_swayc(C_VIEW); | 211 | swayc_t *view = new_swayc(C_VIEW); |
212 | sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", | 212 | sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", |
@@ -220,8 +220,8 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
220 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); | 220 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); |
221 | 221 | ||
222 | // give it requested geometry, but place in center | 222 | // give it requested geometry, but place in center |
223 | view->x = (active_workspace->width - geometry->size.w) / 2; | 223 | view->x = (swayc_active_workspace()->width - geometry->size.w) / 2; |
224 | view->y = (active_workspace->height- geometry->size.h) / 2; | 224 | view->y = (swayc_active_workspace()->height- geometry->size.h) / 2; |
225 | view->width = geometry->size.w; | 225 | view->width = geometry->size.w; |
226 | view->height = geometry->size.h; | 226 | view->height = geometry->size.h; |
227 | 227 | ||
@@ -231,10 +231,10 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
231 | view->is_floating = true; | 231 | view->is_floating = true; |
232 | 232 | ||
233 | // Case of focused workspace, just create as child of it | 233 | // Case of focused workspace, just create as child of it |
234 | list_add(active_workspace->floating, view); | 234 | list_add(swayc_active_workspace()->floating, view); |
235 | view->parent = active_workspace; | 235 | view->parent = swayc_active_workspace(); |
236 | if (active_workspace->focused == NULL) { | 236 | if (swayc_active_workspace()->focused == NULL) { |
237 | set_focused_container_for(active_workspace, view); | 237 | set_focused_container_for(swayc_active_workspace(), view); |
238 | } | 238 | } |
239 | return view; | 239 | return view; |
240 | } | 240 | } |
@@ -306,6 +306,35 @@ swayc_t *destroy_view(swayc_t *view) { | |||
306 | 306 | ||
307 | // Container lookup | 307 | // Container lookup |
308 | 308 | ||
309 | |||
310 | swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) { | ||
311 | if (!container->children) { | ||
312 | return NULL; | ||
313 | } | ||
314 | // Special case for checking floating stuff | ||
315 | int i; | ||
316 | if (container->type == C_WORKSPACE) { | ||
317 | for (i = 0; i < container->floating->length; ++i) { | ||
318 | swayc_t *child = container->floating->items[i]; | ||
319 | if (test(child, data)) { | ||
320 | return child; | ||
321 | } | ||
322 | } | ||
323 | } | ||
324 | for (i = 0; i < container->children->length; ++i) { | ||
325 | swayc_t *child = container->children->items[i]; | ||
326 | if (test(child, data)) { | ||
327 | return child; | ||
328 | } else { | ||
329 | swayc_t *res = swayc_by_test(child, test, data); | ||
330 | if (res) { | ||
331 | return res; | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | return NULL; | ||
336 | } | ||
337 | |||
309 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | 338 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { |
310 | if (!ASSERT_NONNULL(container)) { | 339 | if (!ASSERT_NONNULL(container)) { |
311 | return NULL; | 340 | return NULL; |
@@ -332,27 +361,30 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) { | |||
332 | return container; | 361 | return container; |
333 | } | 362 | } |
334 | 363 | ||
335 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) { | 364 | static swayc_t *_swayc_by_handle_helper(wlc_handle handle, swayc_t *parent) { |
336 | if (!container->children) { | 365 | if (!parent || !parent->children) { |
337 | return NULL; | 366 | return NULL; |
338 | } | 367 | } |
339 | // Special case for checking floating stuff | 368 | int i, len; |
340 | int i; | 369 | swayc_t **child; |
341 | if (container->type == C_WORKSPACE) { | 370 | if (parent->type == C_WORKSPACE) { |
342 | for (i = 0; i < container->floating->length; ++i) { | 371 | len = parent->floating->length; |
343 | swayc_t *child = container->floating->items[i]; | 372 | child = (swayc_t **)parent->floating->items; |
344 | if (test(child, data)) { | 373 | for (i = 0; i < len; ++i, ++child) { |
345 | return child; | 374 | if ((*child)->handle == handle) { |
375 | return *child; | ||
346 | } | 376 | } |
347 | } | 377 | } |
348 | } | 378 | } |
349 | for (i = 0; i < container->children->length; ++i) { | 379 | |
350 | swayc_t *child = container->children->items[i]; | 380 | len = parent->children->length; |
351 | if (test(child, data)) { | 381 | child = (swayc_t**)parent->children->items; |
352 | return child; | 382 | for (i = 0; i < len; ++i, ++child) { |
383 | if ((*child)->handle == handle) { | ||
384 | return *child; | ||
353 | } else { | 385 | } else { |
354 | swayc_t *res = find_container(child, test, data); | 386 | swayc_t *res; |
355 | if (res) { | 387 | if ((res = _swayc_by_handle_helper(handle, *child))) { |
356 | return res; | 388 | return res; |
357 | } | 389 | } |
358 | } | 390 | } |
@@ -360,6 +392,38 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da | |||
360 | return NULL; | 392 | return NULL; |
361 | } | 393 | } |
362 | 394 | ||
395 | swayc_t *swayc_by_handle(wlc_handle handle) { | ||
396 | return _swayc_by_handle_helper(handle, &root_container); | ||
397 | } | ||
398 | |||
399 | swayc_t *swayc_active_output(void) { | ||
400 | return root_container.focused; | ||
401 | } | ||
402 | |||
403 | swayc_t *swayc_active_workspace(void) { | ||
404 | return root_container.focused ? root_container.focused->focused : NULL; | ||
405 | } | ||
406 | |||
407 | swayc_t *swayc_active_workspace_for(swayc_t *cont) { | ||
408 | if (! cont) { | ||
409 | return NULL; | ||
410 | } | ||
411 | switch (cont->type) { | ||
412 | case C_ROOT: cont = cont->focused; | ||
413 | case C_OUTPUT: cont = cont->focused; | ||
414 | case C_WORKSPACE: return cont; | ||
415 | default: return swayc_parent_by_type(cont, C_WORKSPACE); | ||
416 | } | ||
417 | } | ||
418 | |||
419 | // Container information | ||
420 | |||
421 | bool swayc_is_fullscreen(swayc_t *view) { | ||
422 | return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN); | ||
423 | } | ||
424 | |||
425 | // Mapping | ||
426 | |||
363 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { | 427 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { |
364 | if (container && container->children && container->children->length) { | 428 | if (container && container->children && container->children->length) { |
365 | int i; | 429 | int i; |
diff --git a/sway/focus.c b/sway/focus.c index 5008dbbf..a3e5e77a 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -21,8 +21,6 @@ static void update_focus(swayc_t *c) { | |||
21 | // Case where output changes | 21 | // Case where output changes |
22 | case C_OUTPUT: | 22 | case C_OUTPUT: |
23 | wlc_output_focus(c->handle); | 23 | wlc_output_focus(c->handle); |
24 | // Set new workspace to the outputs focused workspace | ||
25 | active_workspace = c->focused; | ||
26 | break; | 24 | break; |
27 | 25 | ||
28 | // Case where workspace changes | 26 | // Case where workspace changes |
@@ -39,7 +37,6 @@ static void update_focus(swayc_t *c) { | |||
39 | c->parent->focused = c; | 37 | c->parent->focused = c; |
40 | destroy_workspace(ws); | 38 | destroy_workspace(ws); |
41 | } | 39 | } |
42 | active_workspace = c; | ||
43 | break; | 40 | break; |
44 | 41 | ||
45 | default: | 42 | default: |
@@ -54,8 +51,8 @@ static void update_focus(swayc_t *c) { | |||
54 | } | 51 | } |
55 | 52 | ||
56 | bool move_focus(enum movement_direction direction) { | 53 | bool move_focus(enum movement_direction direction) { |
57 | swayc_t *view = get_swayc_in_direction( | 54 | swayc_t *view = get_focused_container(&root_container); |
58 | get_focused_container(&root_container), direction); | 55 | view = get_swayc_in_direction(view, direction); |
59 | if (view) { | 56 | if (view) { |
60 | if (direction == MOVE_PARENT) { | 57 | if (direction == MOVE_PARENT) { |
61 | set_focused_container(view); | 58 | set_focused_container(view); |
@@ -68,13 +65,12 @@ bool move_focus(enum movement_direction direction) { | |||
68 | } | 65 | } |
69 | 66 | ||
70 | swayc_t *get_focused_container(swayc_t *parent) { | 67 | swayc_t *get_focused_container(swayc_t *parent) { |
71 | while (parent && !parent->is_focused) { | 68 | if (!parent) { |
72 | parent = parent->focused; | 69 | return swayc_active_workspace(); |
73 | } | 70 | } |
74 | // just incase | 71 | // get focusde container |
75 | if (parent == NULL) { | 72 | while (!parent->is_focused && parent->focused) { |
76 | sway_log(L_DEBUG, "get_focused_container unable to find container"); | 73 | parent = parent->focused; |
77 | return active_workspace; | ||
78 | } | 74 | } |
79 | return parent; | 75 | return parent; |
80 | } | 76 | } |
@@ -85,9 +81,13 @@ void set_focused_container(swayc_t *c) { | |||
85 | } | 81 | } |
86 | sway_log(L_DEBUG, "Setting focus to %p:%ld", c, c->handle); | 82 | sway_log(L_DEBUG, "Setting focus to %p:%ld", c, c->handle); |
87 | 83 | ||
88 | // Find previous focused view, and the new focused view, if they are the same return | 84 | // Get workspace for c, get that workspaces current focused container. |
89 | swayc_t *focused = get_focused_view(&root_container); | 85 | swayc_t *workspace = swayc_active_workspace_for(c); |
90 | swayc_t *workspace = active_workspace; | 86 | swayc_t *focused = get_focused_view(workspace); |
87 | // if the workspace we are changing focus to has a fullscreen view return | ||
88 | if (swayc_is_fullscreen(focused) && focused != c) { | ||
89 | return; | ||
90 | } | ||
91 | 91 | ||
92 | // update container focus from here to root, making necessary changes along | 92 | // update container focus from here to root, making necessary changes along |
93 | // the way | 93 | // the way |
@@ -101,13 +101,6 @@ void set_focused_container(swayc_t *c) { | |||
101 | p->is_focused = false; | 101 | p->is_focused = false; |
102 | } | 102 | } |
103 | 103 | ||
104 | // if the workspace is the same, and previous focus is fullscreen, dont | ||
105 | // change focus | ||
106 | if (workspace == active_workspace | ||
107 | && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | // get new focused view and set focus to it. | 104 | // get new focused view and set focus to it. |
112 | p = get_focused_view(c); | 105 | p = get_focused_view(c); |
113 | if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { | 106 | if (p->type == C_VIEW && !(wlc_view_get_type(p->handle) & WLC_BIT_POPUP)) { |
@@ -137,6 +130,15 @@ void set_focused_container_for(swayc_t *a, swayc_t *c) { | |||
137 | return; | 130 | return; |
138 | } | 131 | } |
139 | } | 132 | } |
133 | |||
134 | // Get workspace for c, get that workspaces current focused container. | ||
135 | swayc_t *workspace = swayc_active_workspace_for(c); | ||
136 | swayc_t *focused = get_focused_view(workspace); | ||
137 | // if the workspace we are changing focus to has a fullscreen view return | ||
138 | if (swayc_is_fullscreen(focused) && c != focused) { | ||
139 | return; | ||
140 | } | ||
141 | |||
140 | // Check if we changing a parent container that will see chnage | 142 | // Check if we changing a parent container that will see chnage |
141 | bool effective = true; | 143 | bool effective = true; |
142 | while (find != &root_container) { | 144 | while (find != &root_container) { |
@@ -171,7 +173,7 @@ swayc_t *get_focused_view(swayc_t *parent) { | |||
171 | parent = parent->focused; | 173 | parent = parent->focused; |
172 | } | 174 | } |
173 | if (parent == NULL) { | 175 | if (parent == NULL) { |
174 | return active_workspace; | 176 | return swayc_active_workspace_for(parent); |
175 | } | 177 | } |
176 | return parent; | 178 | return parent; |
177 | } | 179 | } |
diff --git a/sway/handlers.c b/sway/handlers.c index 78f8927d..8dc409e1 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -86,7 +86,7 @@ static bool handle_output_created(wlc_handle output) { | |||
86 | swayc_t *op = new_output(output); | 86 | swayc_t *op = new_output(output); |
87 | 87 | ||
88 | // Switch to workspace if we need to | 88 | // Switch to workspace if we need to |
89 | if (active_workspace == NULL) { | 89 | if (swayc_active_workspace() == NULL) { |
90 | swayc_t *ws = op->children->items[0]; | 90 | swayc_t *ws = op->children->items[0]; |
91 | workspace_switch(ws); | 91 | workspace_switch(ws); |
92 | } | 92 | } |
@@ -104,9 +104,7 @@ static void handle_output_destroyed(wlc_handle output) { | |||
104 | if (i < list->length) { | 104 | if (i < list->length) { |
105 | destroy_output(list->items[i]); | 105 | destroy_output(list->items[i]); |
106 | } | 106 | } |
107 | if (list->length == 0) { | 107 | if (list->length > 0) { |
108 | active_workspace = NULL; | ||
109 | } else { | ||
110 | // switch to other outputs active workspace | 108 | // switch to other outputs active workspace |
111 | workspace_switch(((swayc_t *)root_container.children->items[0])->focused); | 109 | workspace_switch(((swayc_t *)root_container.children->items[0])->focused); |
112 | } | 110 | } |
@@ -114,7 +112,7 @@ static void handle_output_destroyed(wlc_handle output) { | |||
114 | 112 | ||
115 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { | 113 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { |
116 | sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h); | 114 | sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h); |
117 | swayc_t *c = get_swayc_for_handle(output, &root_container); | 115 | swayc_t *c = swayc_by_handle(output); |
118 | if (!c) return; | 116 | if (!c) return; |
119 | c->width = to->w; | 117 | c->width = to->w; |
120 | c->height = to->h; | 118 | c->height = to->h; |
@@ -122,7 +120,7 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_ | |||
122 | } | 120 | } |
123 | 121 | ||
124 | static void handle_output_focused(wlc_handle output, bool focus) { | 122 | static void handle_output_focused(wlc_handle output, bool focus) { |
125 | swayc_t *c = get_swayc_for_handle(output, &root_container); | 123 | swayc_t *c = swayc_by_handle(output); |
126 | // if for some reason this output doesnt exist, create it. | 124 | // if for some reason this output doesnt exist, create it. |
127 | if (!c) { | 125 | if (!c) { |
128 | handle_output_created(output); | 126 | handle_output_created(output); |
@@ -140,7 +138,7 @@ static bool handle_view_created(wlc_handle handle) { | |||
140 | 138 | ||
141 | // Get parent container, to add view in | 139 | // Get parent container, to add view in |
142 | if (parent) { | 140 | if (parent) { |
143 | focused = get_swayc_for_handle(parent, &root_container); | 141 | focused = swayc_by_handle(parent); |
144 | } | 142 | } |
145 | if (!focused || focused->type == C_OUTPUT) { | 143 | if (!focused || focused->type == C_OUTPUT) { |
146 | focused = get_focused_container(&root_container); | 144 | focused = get_focused_container(&root_container); |
@@ -197,7 +195,7 @@ static bool handle_view_created(wlc_handle handle) { | |||
197 | 195 | ||
198 | static void handle_view_destroyed(wlc_handle handle) { | 196 | static void handle_view_destroyed(wlc_handle handle) { |
199 | sway_log(L_DEBUG, "Destroying window %lu", handle); | 197 | sway_log(L_DEBUG, "Destroying window %lu", handle); |
200 | swayc_t *view = get_swayc_for_handle(handle, &root_container); | 198 | swayc_t *view = swayc_by_handle(handle); |
201 | 199 | ||
202 | switch (wlc_view_get_type(handle)) { | 200 | switch (wlc_view_get_type(handle)) { |
203 | // regular view created regularly | 201 | // regular view created regularly |
@@ -231,7 +229,7 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo | |||
231 | // If the view is floating, then apply the geometry. | 229 | // If the view is floating, then apply the geometry. |
232 | // Otherwise save the desired width/height for the view. | 230 | // Otherwise save the desired width/height for the view. |
233 | // This will not do anything for the time being as WLC improperly sends geometry requests | 231 | // This will not do anything for the time being as WLC improperly sends geometry requests |
234 | swayc_t *view = get_swayc_for_handle(handle, &root_container); | 232 | swayc_t *view = swayc_by_handle(handle); |
235 | if (view) { | 233 | if (view) { |
236 | view->desired_width = geometry->size.w; | 234 | view->desired_width = geometry->size.w; |
237 | view->desired_height = geometry->size.h; | 235 | view->desired_height = geometry->size.h; |
@@ -247,7 +245,7 @@ static void handle_view_geometry_request(wlc_handle handle, const struct wlc_geo | |||
247 | } | 245 | } |
248 | 246 | ||
249 | static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { | 247 | static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit state, bool toggle) { |
250 | swayc_t *c = get_swayc_for_handle(view, &root_container); | 248 | swayc_t *c = swayc_by_handle(view); |
251 | switch (state) { | 249 | switch (state) { |
252 | case WLC_BIT_FULLSCREEN: | 250 | case WLC_BIT_FULLSCREEN: |
253 | // i3 just lets it become fullscreen | 251 | // i3 just lets it become fullscreen |
@@ -342,7 +340,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
342 | bool changed_tiling = false; | 340 | bool changed_tiling = false; |
343 | int min_sane_w = 100; | 341 | int min_sane_w = 100; |
344 | int min_sane_h = 60; | 342 | int min_sane_h = 60; |
345 | if (!active_workspace) { | 343 | if (!swayc_active_workspace()) { |
346 | return false; | 344 | return false; |
347 | } | 345 | } |
348 | // Do checks to determine if proper keys are being held | 346 | // Do checks to determine if proper keys are being held |
@@ -518,7 +516,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
518 | } | 516 | } |
519 | } | 517 | } |
520 | } | 518 | } |
521 | arrange_windows(active_workspace, -1, -1); | 519 | arrange_windows(swayc_active_workspace(), -1, -1); |
522 | } | 520 | } |
523 | } | 521 | } |
524 | if (config->focus_follows_mouse && prev_handle != handle) { | 522 | if (config->focus_follows_mouse && prev_handle != handle) { |
diff --git a/sway/layout.c b/sway/layout.c index 573c6f70..446ad066 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -35,7 +35,7 @@ void add_child(swayc_t *parent, swayc_t *child) { | |||
35 | child->parent = parent; | 35 | child->parent = parent; |
36 | // set focus for this container | 36 | // set focus for this container |
37 | if (parent->children->length == 1) { | 37 | if (parent->children->length == 1) { |
38 | set_focused_container_for(parent, child); | 38 | parent->focused = child; |
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
@@ -46,7 +46,7 @@ void add_floating(swayc_t *ws, swayc_t *child) { | |||
46 | child->parent = ws; | 46 | child->parent = ws; |
47 | child->is_floating = true; | 47 | child->is_floating = true; |
48 | if (!ws->focused) { | 48 | if (!ws->focused) { |
49 | set_focused_container_for(ws, child); | 49 | ws->focused = child; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
@@ -71,7 +71,7 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child) { | |||
71 | new_child->parent = child->parent; | 71 | new_child->parent = child->parent; |
72 | 72 | ||
73 | if (child->parent->focused == child) { | 73 | if (child->parent->focused == child) { |
74 | set_focused_container_for(child->parent, new_child); | 74 | child->parent->focused = new_child; |
75 | } | 75 | } |
76 | child->parent = NULL; | 76 | child->parent = NULL; |
77 | return parent; | 77 | return parent; |
@@ -100,7 +100,7 @@ swayc_t *remove_child(swayc_t *child) { | |||
100 | // Set focused to new container | 100 | // Set focused to new container |
101 | if (parent->focused == child) { | 101 | if (parent->focused == child) { |
102 | if (parent->children->length > 0) { | 102 | if (parent->children->length > 0) { |
103 | set_focused_container_for(parent, parent->children->items[i?i-1:0]); | 103 | parent->focused = parent->children->items[i?i-1:0]; |
104 | } else { | 104 | } else { |
105 | parent->focused = NULL; | 105 | parent->focused = NULL; |
106 | } | 106 | } |
@@ -328,35 +328,6 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
328 | layout_log(&root_container, 0); | 328 | layout_log(&root_container, 0); |
329 | } | 329 | } |
330 | 330 | ||
331 | swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) { | ||
332 | if (parent->children == NULL) { | ||
333 | return NULL; | ||
334 | } | ||
335 | |||
336 | // Search for floating workspaces | ||
337 | int i; | ||
338 | if (parent->type == C_WORKSPACE) { | ||
339 | for (i = 0; i < parent->floating->length; ++i) { | ||
340 | swayc_t *child = parent->floating->items[i]; | ||
341 | if (child->handle == handle) { | ||
342 | return child; | ||
343 | } | ||
344 | } | ||
345 | } | ||
346 | |||
347 | for (i = 0; i < parent->children->length; ++i) { | ||
348 | swayc_t *child = parent->children->items[i]; | ||
349 | if (child->handle == handle) { | ||
350 | return child; | ||
351 | } else { | ||
352 | swayc_t *res; | ||
353 | if ((res = get_swayc_for_handle(handle, child))) { | ||
354 | return res; | ||
355 | } | ||
356 | } | ||
357 | } | ||
358 | return NULL; | ||
359 | } | ||
360 | 331 | ||
361 | swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) { | 332 | swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) { |
362 | swayc_t *parent = container->parent; | 333 | swayc_t *parent = container->parent; |
@@ -119,8 +119,9 @@ bool sway_assert(bool condition, const char* format, ...) { | |||
119 | /* XXX:DEBUG:XXX */ | 119 | /* XXX:DEBUG:XXX */ |
120 | static void container_log(const swayc_t *c) { | 120 | static void container_log(const swayc_t *c) { |
121 | fprintf(stderr, "focus:%c|", | 121 | fprintf(stderr, "focus:%c|", |
122 | c->is_focused ? 'F' : // Focused | 122 | c == get_focused_view(&root_container) ? 'K': |
123 | c == active_workspace ? 'W' : // active workspace | 123 | c == get_focused_container(&root_container) ? 'F' : // Focused |
124 | c == swayc_active_workspace() ? 'W' : // active workspace | ||
124 | c == &root_container ? 'R' : // root | 125 | c == &root_container ? 'R' : // root |
125 | 'X');// not any others | 126 | 'X');// not any others |
126 | fprintf(stderr,"(%p)",c); | 127 | fprintf(stderr,"(%p)",c); |
diff --git a/sway/workspace.c b/sway/workspace.c index d436da8e..80b67128 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | #include <string.h> | ||
4 | #include "workspace.h" | 5 | #include "workspace.h" |
5 | #include "layout.h" | 6 | #include "layout.h" |
6 | #include "list.h" | 7 | #include "list.h" |
@@ -11,8 +12,6 @@ | |||
11 | #include "stringop.h" | 12 | #include "stringop.h" |
12 | #include "focus.h" | 13 | #include "focus.h" |
13 | 14 | ||
14 | swayc_t *active_workspace = NULL; | ||
15 | |||
16 | char *workspace_next_name(void) { | 15 | char *workspace_next_name(void) { |
17 | sway_log(L_DEBUG, "Workspace: Generating new name"); | 16 | sway_log(L_DEBUG, "Workspace: Generating new name"); |
18 | int i; | 17 | int i; |
@@ -48,7 +47,7 @@ char *workspace_next_name(void) { | |||
48 | } | 47 | } |
49 | 48 | ||
50 | // Make sure that the workspace doesn't already exist | 49 | // Make sure that the workspace doesn't already exist |
51 | if (workspace_find_by_name(target)) { | 50 | if (workspace_by_name(target)) { |
52 | list_free(args); | 51 | list_free(args); |
53 | continue; | 52 | continue; |
54 | } | 53 | } |
@@ -79,22 +78,22 @@ swayc_t *workspace_create(const char* name) { | |||
79 | return new_workspace(parent, name); | 78 | return new_workspace(parent, name); |
80 | } | 79 | } |
81 | 80 | ||
82 | bool workspace_by_name(swayc_t *view, void *data) { | 81 | static bool _workspace_by_name(swayc_t *view, void *data) { |
83 | return (view->type == C_WORKSPACE) && | 82 | return (view->type == C_WORKSPACE) && |
84 | (strcasecmp(view->name, (char *) data) == 0); | 83 | (strcasecmp(view->name, (char *) data) == 0); |
85 | } | 84 | } |
86 | 85 | ||
87 | swayc_t *workspace_find_by_name(const char* name) { | 86 | swayc_t *workspace_by_name(const char* name) { |
88 | return find_container(&root_container, workspace_by_name, (void *) name); | 87 | return swayc_by_test(&root_container, _workspace_by_name, (void *) name); |
89 | } | 88 | } |
90 | 89 | ||
91 | void workspace_output_next() { | 90 | void workspace_output_next() { |
92 | // Get the index of the workspace in the current output, and change the view to index+1 workspace. | 91 | // Get the index of the workspace in the current output, and change the view to index+1 workspace. |
93 | // if we're currently focused on the last workspace in the output, switch to the first | 92 | // if we're currently focused on the last workspace in the output, switch to the first |
94 | swayc_t *current_output = active_workspace->parent; | 93 | swayc_t *current_output = swayc_active_workspace()->parent; |
95 | int i; | 94 | int i; |
96 | for (i = 0; i < current_output->children->length - 1; i++) { | 95 | for (i = 0; i < current_output->children->length - 1; i++) { |
97 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | 96 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) { |
98 | workspace_switch(current_output->children->items[i + 1]); | 97 | workspace_switch(current_output->children->items[i + 1]); |
99 | return; | 98 | return; |
100 | } | 99 | } |
@@ -106,10 +105,10 @@ void workspace_next() { | |||
106 | // Get the index of the workspace in the current output, and change the view to index+1 workspace. | 105 | // Get the index of the workspace in the current output, and change the view to index+1 workspace. |
107 | // if we're currently focused on the last workspace in the output, change focus to there | 106 | // if we're currently focused on the last workspace in the output, change focus to there |
108 | // and call workspace_output_next(), as long as another output actually exists | 107 | // and call workspace_output_next(), as long as another output actually exists |
109 | swayc_t *current_output = active_workspace->parent; | 108 | swayc_t *current_output = swayc_active_workspace()->parent; |
110 | int i; | 109 | int i; |
111 | for (i = 0; i < current_output->children->length - 1; i++) { | 110 | for (i = 0; i < current_output->children->length - 1; i++) { |
112 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | 111 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) { |
113 | workspace_switch(current_output->children->items[i + 1]); | 112 | workspace_switch(current_output->children->items[i + 1]); |
114 | return; | 113 | return; |
115 | } | 114 | } |
@@ -134,10 +133,10 @@ void workspace_next() { | |||
134 | void workspace_output_prev() { | 133 | void workspace_output_prev() { |
135 | // Get the index of the workspace in the current output, and change the view to index+1 workspace | 134 | // Get the index of the workspace in the current output, and change the view to index+1 workspace |
136 | // if we're currently focused on the first workspace in the output, do nothing and return false | 135 | // if we're currently focused on the first workspace in the output, do nothing and return false |
137 | swayc_t *current_output = active_workspace->parent; | 136 | swayc_t *current_output = swayc_active_workspace()->parent; |
138 | int i; | 137 | int i; |
139 | for (i = 1; i < current_output->children->length; i++) { | 138 | for (i = 1; i < current_output->children->length; i++) { |
140 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | 139 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) { |
141 | workspace_switch(current_output->children->items[i - 1]); | 140 | workspace_switch(current_output->children->items[i - 1]); |
142 | return; | 141 | return; |
143 | } | 142 | } |
@@ -150,10 +149,10 @@ void workspace_prev() { | |||
150 | // if we're currently focused on the last workspace in the output, change focus to there | 149 | // if we're currently focused on the last workspace in the output, change focus to there |
151 | // and call workspace_output_next(), as long as another output actually exists | 150 | // and call workspace_output_next(), as long as another output actually exists |
152 | 151 | ||
153 | swayc_t *current_output = active_workspace->parent; | 152 | swayc_t *current_output = swayc_active_workspace()->parent; |
154 | int i; | 153 | int i; |
155 | for (i = 1; i < current_output->children->length; i++) { | 154 | for (i = 1; i < current_output->children->length; i++) { |
156 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), active_workspace->name) == 0) { | 155 | if (strcmp((((swayc_t *)current_output->children->items[i])->name), swayc_active_workspace()->name) == 0) { |
157 | workspace_switch(current_output->children->items[i - 1]); | 156 | workspace_switch(current_output->children->items[i - 1]); |
158 | return; | 157 | return; |
159 | } | 158 | } |