diff options
author | 2018-02-10 16:52:45 -0500 | |
---|---|---|
committer | 2018-02-10 16:52:45 -0500 | |
commit | 145b4fdf582d3817a19819250cf01836b193c76f (patch) | |
tree | f7c81a0094c10ca202ac8665223789ff4179e11c /sway/input/seat.c | |
parent | fix build for output damage (diff) | |
download | sway-145b4fdf582d3817a19819250cf01836b193c76f.tar.gz sway-145b4fdf582d3817a19819250cf01836b193c76f.tar.zst sway-145b4fdf582d3817a19819250cf01836b193c76f.zip |
use bfs iterator to collect focus stack
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r-- | sway/input/seat.c | 27 |
1 files changed, 16 insertions, 11 deletions
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); |