diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-21 17:00:00 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-21 17:00:00 -0400 |
commit | 39041d07b5fc3420cd964142a948f429b36a7a5c (patch) | |
tree | 1849aab63cd338bbb14567d9534d5266ca64dd6e | |
parent | Minor fix to resizing with mouse (diff) | |
parent | style (diff) | |
download | sway-39041d07b5fc3420cd964142a948f429b36a7a5c.tar.gz sway-39041d07b5fc3420cd964142a948f429b36a7a5c.tar.zst sway-39041d07b5fc3420cd964142a948f429b36a7a5c.zip |
Merge remote-tracking branch 'taiyu-len/master'
-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 | 58 | ||||
-rw-r--r-- | sway/container.c | 140 | ||||
-rw-r--r-- | sway/focus.c | 46 | ||||
-rw-r--r-- | sway/handlers.c | 34 | ||||
-rw-r--r-- | sway/layout.c | 43 | ||||
-rw-r--r-- | sway/log.c | 5 | ||||
-rw-r--r-- | sway/workspace.c | 27 |
10 files changed, 213 insertions, 164 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..efaa7472 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 | ||
@@ -680,7 +684,7 @@ static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
680 | } | 684 | } |
681 | 685 | ||
682 | swayc_t *container = get_focused_view(&root_container); | 686 | swayc_t *container = get_focused_view(&root_container); |
683 | bool current = (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) > 0; | 687 | bool current = swayc_is_fullscreen(container); |
684 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); | 688 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); |
685 | // Resize workspace if going from fullscreen -> notfullscreen | 689 | // Resize workspace if going from fullscreen -> notfullscreen |
686 | // otherwise just resize container | 690 | // otherwise just resize container |
@@ -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..62ff1c4a 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -26,14 +26,11 @@ static void free_swayc(swayc_t *cont) { | |||
26 | if (!ASSERT_NONNULL(cont)) { | 26 | if (!ASSERT_NONNULL(cont)) { |
27 | return; | 27 | return; |
28 | } | 28 | } |
29 | // TODO does not properly handle containers with children, | ||
30 | // TODO but functions that call this usually check for that | ||
31 | if (cont->children) { | 29 | if (cont->children) { |
32 | if (cont->children->length) { | 30 | // remove children until there are no more, free_swayc calls |
33 | int i; | 31 | // remove_child, which removes child from this container |
34 | for (i = 0; i < cont->children->length; ++i) { | 32 | while (cont->children->length) { |
35 | free_swayc(cont->children->items[i]); | 33 | free_swayc(cont->children->items[0]); |
36 | } | ||
37 | } | 34 | } |
38 | list_free(cont->children); | 35 | list_free(cont->children); |
39 | } | 36 | } |
@@ -57,10 +54,6 @@ static void free_swayc(swayc_t *cont) { | |||
57 | 54 | ||
58 | // New containers | 55 | // New containers |
59 | 56 | ||
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) { | 57 | swayc_t *new_output(wlc_handle handle) { |
65 | const struct wlc_size* size = wlc_output_get_resolution(handle); | 58 | const struct wlc_size* size = wlc_output_get_resolution(handle); |
66 | const char *name = wlc_output_get_name(handle); | 59 | const char *name = wlc_output_get_name(handle); |
@@ -84,7 +77,7 @@ swayc_t *new_output(wlc_handle handle) { | |||
84 | if (strcasecmp(wso->output, name) == 0) { | 77 | if (strcasecmp(wso->output, name) == 0) { |
85 | sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); | 78 | 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 | 79 | // Check if any other workspaces are using this name |
87 | if (find_container(&root_container, workspace_test, wso->workspace)) { | 80 | if (workspace_by_name(wso->workspace)) { |
88 | sway_log(L_DEBUG, "But it's already taken"); | 81 | sway_log(L_DEBUG, "But it's already taken"); |
89 | break; | 82 | break; |
90 | } | 83 | } |
@@ -128,7 +121,8 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { | |||
128 | } | 121 | } |
129 | 122 | ||
130 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { | 123 | swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { |
131 | if (!ASSERT_NONNULL(child)) { | 124 | if (!ASSERT_NONNULL(child) |
125 | && !sway_assert(!child->is_floating, "cannot create container around floating window")) { | ||
132 | return NULL; | 126 | return NULL; |
133 | } | 127 | } |
134 | swayc_t *cont = new_swayc(C_CONTAINER); | 128 | swayc_t *cont = new_swayc(C_CONTAINER); |
@@ -207,6 +201,9 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { | |||
207 | } | 201 | } |
208 | 202 | ||
209 | swayc_t *new_floating_view(wlc_handle handle) { | 203 | swayc_t *new_floating_view(wlc_handle handle) { |
204 | if (swayc_active_workspace() == NULL) { | ||
205 | return NULL; | ||
206 | } | ||
210 | const char *title = wlc_view_get_title(handle); | 207 | const char *title = wlc_view_get_title(handle); |
211 | swayc_t *view = new_swayc(C_VIEW); | 208 | swayc_t *view = new_swayc(C_VIEW); |
212 | sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", | 209 | sway_log(L_DEBUG, "Adding new view %lu:%x:%s as a floating view", |
@@ -220,8 +217,8 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
220 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); | 217 | const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); |
221 | 218 | ||
222 | // give it requested geometry, but place in center | 219 | // give it requested geometry, but place in center |
223 | view->x = (active_workspace->width - geometry->size.w) / 2; | 220 | view->x = (swayc_active_workspace()->width - geometry->size.w) / 2; |
224 | view->y = (active_workspace->height- geometry->size.h) / 2; | 221 | view->y = (swayc_active_workspace()->height- geometry->size.h) / 2; |
225 | view->width = geometry->size.w; | 222 | view->width = geometry->size.w; |
226 | view->height = geometry->size.h; | 223 | view->height = geometry->size.h; |
227 | 224 | ||
@@ -231,10 +228,10 @@ swayc_t *new_floating_view(wlc_handle handle) { | |||
231 | view->is_floating = true; | 228 | view->is_floating = true; |
232 | 229 | ||
233 | // Case of focused workspace, just create as child of it | 230 | // Case of focused workspace, just create as child of it |
234 | list_add(active_workspace->floating, view); | 231 | list_add(swayc_active_workspace()->floating, view); |
235 | view->parent = active_workspace; | 232 | view->parent = swayc_active_workspace(); |
236 | if (active_workspace->focused == NULL) { | 233 | if (swayc_active_workspace()->focused == NULL) { |
237 | set_focused_container_for(active_workspace, view); | 234 | set_focused_container_for(swayc_active_workspace(), view); |
238 | } | 235 | } |
239 | return view; | 236 | return view; |
240 | } | 237 | } |
@@ -306,6 +303,35 @@ swayc_t *destroy_view(swayc_t *view) { | |||
306 | 303 | ||
307 | // Container lookup | 304 | // Container lookup |
308 | 305 | ||
306 | |||
307 | swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) { | ||
308 | if (!container->children) { | ||
309 | return NULL; | ||
310 | } | ||
311 | // Special case for checking floating stuff | ||
312 | int i; | ||
313 | if (container->type == C_WORKSPACE) { | ||
314 | for (i = 0; i < container->floating->length; ++i) { | ||
315 | swayc_t *child = container->floating->items[i]; | ||
316 | if (test(child, data)) { | ||
317 | return child; | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | for (i = 0; i < container->children->length; ++i) { | ||
322 | swayc_t *child = container->children->items[i]; | ||
323 | if (test(child, data)) { | ||
324 | return child; | ||
325 | } else { | ||
326 | swayc_t *res = swayc_by_test(child, test, data); | ||
327 | if (res) { | ||
328 | return res; | ||
329 | } | ||
330 | } | ||
331 | } | ||
332 | return NULL; | ||
333 | } | ||
334 | |||
309 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | 335 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { |
310 | if (!ASSERT_NONNULL(container)) { | 336 | if (!ASSERT_NONNULL(container)) { |
311 | return NULL; | 337 | return NULL; |
@@ -315,7 +341,7 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { | |||
315 | } | 341 | } |
316 | do { | 342 | do { |
317 | container = container->parent; | 343 | container = container->parent; |
318 | } while(container && container->type != type); | 344 | } while (container && container->type != type); |
319 | return container; | 345 | return container; |
320 | } | 346 | } |
321 | 347 | ||
@@ -332,27 +358,30 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) { | |||
332 | return container; | 358 | return container; |
333 | } | 359 | } |
334 | 360 | ||
335 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) { | 361 | static swayc_t *_swayc_by_handle_helper(wlc_handle handle, swayc_t *parent) { |
336 | if (!container->children) { | 362 | if (!parent || !parent->children) { |
337 | return NULL; | 363 | return NULL; |
338 | } | 364 | } |
339 | // Special case for checking floating stuff | 365 | int i, len; |
340 | int i; | 366 | swayc_t **child; |
341 | if (container->type == C_WORKSPACE) { | 367 | if (parent->type == C_WORKSPACE) { |
342 | for (i = 0; i < container->floating->length; ++i) { | 368 | len = parent->floating->length; |
343 | swayc_t *child = container->floating->items[i]; | 369 | child = (swayc_t **)parent->floating->items; |
344 | if (test(child, data)) { | 370 | for (i = 0; i < len; ++i, ++child) { |
345 | return child; | 371 | if ((*child)->handle == handle) { |
372 | return *child; | ||
346 | } | 373 | } |
347 | } | 374 | } |
348 | } | 375 | } |
349 | for (i = 0; i < container->children->length; ++i) { | 376 | |
350 | swayc_t *child = container->children->items[i]; | 377 | len = parent->children->length; |
351 | if (test(child, data)) { | 378 | child = (swayc_t**)parent->children->items; |
352 | return child; | 379 | for (i = 0; i < len; ++i, ++child) { |
380 | if ((*child)->handle == handle) { | ||
381 | return *child; | ||
353 | } else { | 382 | } else { |
354 | swayc_t *res = find_container(child, test, data); | 383 | swayc_t *res; |
355 | if (res) { | 384 | if ((res = _swayc_by_handle_helper(handle, *child))) { |
356 | return res; | 385 | return res; |
357 | } | 386 | } |
358 | } | 387 | } |
@@ -360,6 +389,47 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da | |||
360 | return NULL; | 389 | return NULL; |
361 | } | 390 | } |
362 | 391 | ||
392 | swayc_t *swayc_by_handle(wlc_handle handle) { | ||
393 | return _swayc_by_handle_helper(handle, &root_container); | ||
394 | } | ||
395 | |||
396 | swayc_t *swayc_active_output(void) { | ||
397 | return root_container.focused; | ||
398 | } | ||
399 | |||
400 | swayc_t *swayc_active_workspace(void) { | ||
401 | return root_container.focused ? root_container.focused->focused : NULL; | ||
402 | } | ||
403 | |||
404 | swayc_t *swayc_active_workspace_for(swayc_t *cont) { | ||
405 | if (!cont) { | ||
406 | return NULL; | ||
407 | } | ||
408 | switch (cont->type) { | ||
409 | case C_ROOT: | ||
410 | cont = cont->focused; | ||
411 | /* Fallthrough */ | ||
412 | |||
413 | case C_OUTPUT: | ||
414 | cont = cont->focused; | ||
415 | /* Fallthrough */ | ||
416 | |||
417 | case C_WORKSPACE: | ||
418 | return cont; | ||
419 | |||
420 | default: | ||
421 | return swayc_parent_by_type(cont, C_WORKSPACE); | ||
422 | } | ||
423 | } | ||
424 | |||
425 | // Container information | ||
426 | |||
427 | bool swayc_is_fullscreen(swayc_t *view) { | ||
428 | return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN); | ||
429 | } | ||
430 | |||
431 | // Mapping | ||
432 | |||
363 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { | 433 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { |
364 | if (container && container->children && container->children->length) { | 434 | if (container && container->children && container->children->length) { |
365 | int i; | 435 | 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 4f28dea9..57251307 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 |
@@ -568,13 +566,13 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
568 | } | 566 | } |
569 | } | 567 | } |
570 | } | 568 | } |
571 | arrange_windows(active_workspace, -1, -1); | 569 | arrange_windows(swayc_active_workspace(), -1, -1); |
572 | } | 570 | } |
573 | } | 571 | } |
574 | if (config->focus_follows_mouse && prev_handle != handle) { | 572 | if (config->focus_follows_mouse && prev_handle != handle) { |
575 | // Dont change focus if fullscreen | 573 | // Dont change focus if fullscreen |
576 | swayc_t *focused = get_focused_view(view); | 574 | swayc_t *focused = get_focused_view(view); |
577 | if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) | 575 | if (!swayc_is_fullscreen(focused) |
578 | && !(pointer_state.l_held || pointer_state.r_held)) { | 576 | && !(pointer_state.l_held || pointer_state.r_held)) { |
579 | set_focused_container(container_under_pointer()); | 577 | set_focused_container(container_under_pointer()); |
580 | } | 578 | } |
@@ -606,7 +604,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
606 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { | 604 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { |
607 | swayc_t *focused = get_focused_container(&root_container); | 605 | swayc_t *focused = get_focused_container(&root_container); |
608 | // dont change focus if fullscreen | 606 | // dont change focus if fullscreen |
609 | if (focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) { | 607 | if (swayc_is_fullscreen(focused)) { |
610 | return false; | 608 | return false; |
611 | } | 609 | } |
612 | if (state == WLC_BUTTON_STATE_PRESSED) { | 610 | if (state == WLC_BUTTON_STATE_PRESSED) { |
@@ -646,8 +644,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
646 | // Dont want pointer sent to window while dragging or resizing | 644 | // Dont want pointer sent to window while dragging or resizing |
647 | return (pointer_state.floating.drag || pointer_state.floating.resize); | 645 | return (pointer_state.floating.drag || pointer_state.floating.resize); |
648 | } else { | 646 | } else { |
649 | pointer_state.tiling.resize = pointer_state.r_held; | 647 | if (modifiers->mods & config->floating_mod) { |
650 | pointer_state.tiling.init_view = pointer; | 648 | pointer_state.tiling.resize = pointer_state.r_held; |
649 | pointer_state.tiling.init_view = pointer; | ||
650 | // Dont want pointer sent when resizing | ||
651 | return (pointer_state.tiling.resize); | ||
652 | } | ||
651 | } | 653 | } |
652 | return (pointer && pointer != focused); | 654 | return (pointer && pointer != focused); |
653 | } else { | 655 | } else { |
diff --git a/sway/layout.c b/sway/layout.c index 573c6f70..70d9eb21 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 | } |
@@ -204,7 +204,7 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
204 | .h = height - container->gaps | 204 | .h = height - container->gaps |
205 | } | 205 | } |
206 | }; | 206 | }; |
207 | if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { | 207 | if (swayc_is_fullscreen(container)) { |
208 | swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT); | 208 | swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT); |
209 | geometry.origin.x = 0; | 209 | geometry.origin.x = 0; |
210 | geometry.origin.y = 0; | 210 | geometry.origin.y = 0; |
@@ -303,7 +303,7 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
303 | .h = view->height | 303 | .h = view->height |
304 | } | 304 | } |
305 | }; | 305 | }; |
306 | if (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN) { | 306 | if (swayc_is_fullscreen(view)) { |
307 | swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); | 307 | swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); |
308 | geometry.origin.x = 0; | 308 | geometry.origin.x = 0; |
309 | geometry.origin.y = 0; | 309 | geometry.origin.y = 0; |
@@ -318,7 +318,7 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
318 | // have higher indexes | 318 | // have higher indexes |
319 | // This is conditional on there not being a fullscreen view in the workspace | 319 | // This is conditional on there not being a fullscreen view in the workspace |
320 | if (!container->focused | 320 | if (!container->focused |
321 | || !(wlc_view_get_state(container->focused->handle) & WLC_BIT_FULLSCREEN)) { | 321 | || !swayc_is_fullscreen(container->focused)) { |
322 | wlc_view_bring_to_front(view->handle); | 322 | wlc_view_bring_to_front(view->handle); |
323 | } | 323 | } |
324 | } | 324 | } |
@@ -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 | } |