diff options
-rw-r--r-- | include/sway/container.h | 6 | ||||
-rw-r--r-- | sway/input/seat.c | 27 | ||||
-rw-r--r-- | sway/tree/container.c | 15 |
3 files changed, 26 insertions, 22 deletions
diff --git a/include/sway/container.h b/include/sway/container.h index 997240bd..01e166ad 100644 --- a/include/sway/container.h +++ b/include/sway/container.h | |||
@@ -163,9 +163,9 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | |||
163 | struct wlr_surface **surface, double *sx, double *sy); | 163 | struct wlr_surface **surface, double *sx, double *sy); |
164 | 164 | ||
165 | /** | 165 | /** |
166 | * Get a list of containers that are descendents of the container in rendering | 166 | * Apply the function for each child of the container breadth first. |
167 | * order | ||
168 | */ | 167 | */ |
169 | list_t *container_list_children(swayc_t *con); | 168 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), |
169 | void *data); | ||
170 | 170 | ||
171 | #endif | 171 | #endif |
diff --git a/sway/input/seat.c b/sway/input/seat.c index d2ffca64..ab751b54 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -70,6 +70,20 @@ static void handle_new_container(struct wl_listener *listener, void *data) { | |||
70 | seat_container_from_container(seat, con); | 70 | seat_container_from_container(seat, con); |
71 | } | 71 | } |
72 | 72 | ||
73 | static void collect_focus_iter(swayc_t *con, void *data) { | ||
74 | struct sway_seat *seat = data; | ||
75 | if (con->type > C_WORKSPACE) { | ||
76 | return; | ||
77 | } | ||
78 | struct sway_seat_container *seat_con = | ||
79 | seat_container_from_container(seat, con); | ||
80 | if (!seat_con) { | ||
81 | return; | ||
82 | } | ||
83 | wl_list_remove(&seat_con->link); | ||
84 | wl_list_insert(&seat->focus_stack, &seat_con->link); | ||
85 | } | ||
86 | |||
73 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, | 87 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, |
74 | const char *seat_name) { | 88 | const char *seat_name) { |
75 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); | 89 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); |
@@ -92,17 +106,8 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input, | |||
92 | 106 | ||
93 | // init the focus stack | 107 | // init the focus stack |
94 | wl_list_init(&seat->focus_stack); | 108 | wl_list_init(&seat->focus_stack); |
95 | list_t *containers = container_list_children(&root_container); | 109 | |
96 | if (containers == NULL) { | 110 | container_for_each_bfs(&root_container, collect_focus_iter, seat); |
97 | wlr_seat_destroy(seat->wlr_seat); | ||
98 | free(seat); | ||
99 | return NULL; | ||
100 | } | ||
101 | for (int i = containers->length - 1; i >= 0; --i) { | ||
102 | swayc_t *con = containers->items[i]; | ||
103 | seat_container_from_container(seat, con); | ||
104 | } | ||
105 | free(containers); | ||
106 | 111 | ||
107 | wl_signal_add(&root_container.sway_root->events.new_container, | 112 | wl_signal_add(&root_container.sway_root->events.new_container, |
108 | &seat->new_container); | 113 | &seat->new_container); |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 67fac5ee..ebf9f98e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -381,13 +381,13 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi | |||
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | /** | 384 | void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data), |
385 | * Get a list of containers that are descendents of the container in rendering | 385 | void *data) { |
386 | * order | ||
387 | */ | ||
388 | list_t *container_list_children(swayc_t *con) { | ||
389 | list_t *list = create_list(); | ||
390 | list_t *queue = create_list(); | 386 | list_t *queue = create_list(); |
387 | if (queue == NULL) { | ||
388 | wlr_log(L_ERROR, "could not allocate list"); | ||
389 | return; | ||
390 | } | ||
391 | 391 | ||
392 | list_add(queue, con); | 392 | list_add(queue, con); |
393 | 393 | ||
@@ -395,11 +395,10 @@ list_t *container_list_children(swayc_t *con) { | |||
395 | while (queue->length) { | 395 | while (queue->length) { |
396 | current = queue->items[0]; | 396 | current = queue->items[0]; |
397 | list_del(queue, 0); | 397 | list_del(queue, 0); |
398 | list_add(list, current); | 398 | f(current, data); |
399 | // TODO floating containers | 399 | // TODO floating containers |
400 | list_cat(queue, current->children); | 400 | list_cat(queue, current->children); |
401 | } | 401 | } |
402 | 402 | ||
403 | list_free(queue); | 403 | list_free(queue); |
404 | return list; | ||
405 | } | 404 | } |