mirror of
https://github.com/NickHu/sway
synced 2024-12-28 22:23:30 +01:00
use bfs iterator to collect focus stack
This commit is contained in:
parent
095ddb1561
commit
145b4fdf58
3 changed files with 26 additions and 22 deletions
|
@ -163,9 +163,9 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
|
||||||
struct wlr_surface **surface, double *sx, double *sy);
|
struct wlr_surface **surface, double *sx, double *sy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of containers that are descendents of the container in rendering
|
* Apply the function for each child of the container breadth first.
|
||||||
* order
|
|
||||||
*/
|
*/
|
||||||
list_t *container_list_children(swayc_t *con);
|
void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
|
||||||
|
void *data);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -70,6 +70,20 @@ static void handle_new_container(struct wl_listener *listener, void *data) {
|
||||||
seat_container_from_container(seat, con);
|
seat_container_from_container(seat, con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void collect_focus_iter(swayc_t *con, void *data) {
|
||||||
|
struct sway_seat *seat = data;
|
||||||
|
if (con->type > C_WORKSPACE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct sway_seat_container *seat_con =
|
||||||
|
seat_container_from_container(seat, con);
|
||||||
|
if (!seat_con) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wl_list_remove(&seat_con->link);
|
||||||
|
wl_list_insert(&seat->focus_stack, &seat_con->link);
|
||||||
|
}
|
||||||
|
|
||||||
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
|
struct sway_seat *sway_seat_create(struct sway_input_manager *input,
|
||||||
const char *seat_name) {
|
const char *seat_name) {
|
||||||
struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));
|
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,
|
||||||
|
|
||||||
// init the focus stack
|
// init the focus stack
|
||||||
wl_list_init(&seat->focus_stack);
|
wl_list_init(&seat->focus_stack);
|
||||||
list_t *containers = container_list_children(&root_container);
|
|
||||||
if (containers == NULL) {
|
container_for_each_bfs(&root_container, collect_focus_iter, seat);
|
||||||
wlr_seat_destroy(seat->wlr_seat);
|
|
||||||
free(seat);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
for (int i = containers->length - 1; i >= 0; --i) {
|
|
||||||
swayc_t *con = containers->items[i];
|
|
||||||
seat_container_from_container(seat, con);
|
|
||||||
}
|
|
||||||
free(containers);
|
|
||||||
|
|
||||||
wl_signal_add(&root_container.sway_root->events.new_container,
|
wl_signal_add(&root_container.sway_root->events.new_container,
|
||||||
&seat->new_container);
|
&seat->new_container);
|
||||||
|
|
|
@ -381,13 +381,13 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void container_for_each_bfs(swayc_t *con, void (*f)(swayc_t *con, void *data),
|
||||||
* Get a list of containers that are descendents of the container in rendering
|
void *data) {
|
||||||
* order
|
|
||||||
*/
|
|
||||||
list_t *container_list_children(swayc_t *con) {
|
|
||||||
list_t *list = create_list();
|
|
||||||
list_t *queue = create_list();
|
list_t *queue = create_list();
|
||||||
|
if (queue == NULL) {
|
||||||
|
wlr_log(L_ERROR, "could not allocate list");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
list_add(queue, con);
|
list_add(queue, con);
|
||||||
|
|
||||||
|
@ -395,11 +395,10 @@ list_t *container_list_children(swayc_t *con) {
|
||||||
while (queue->length) {
|
while (queue->length) {
|
||||||
current = queue->items[0];
|
current = queue->items[0];
|
||||||
list_del(queue, 0);
|
list_del(queue, 0);
|
||||||
list_add(list, current);
|
f(current, data);
|
||||||
// TODO floating containers
|
// TODO floating containers
|
||||||
list_cat(queue, current->children);
|
list_cat(queue, current->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
list_free(queue);
|
list_free(queue);
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue