diff options
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r-- | sway/input/seat.c | 99 |
1 files changed, 51 insertions, 48 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c index 9aa34aca..27636c1e 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -25,7 +25,7 @@ static void seat_device_destroy(struct sway_seat_device *seat_device) { | |||
25 | free(seat_device); | 25 | free(seat_device); |
26 | } | 26 | } |
27 | 27 | ||
28 | void sway_seat_destroy(struct sway_seat *seat) { | 28 | void seat_destroy(struct sway_seat *seat) { |
29 | struct sway_seat_device *seat_device, *next; | 29 | struct sway_seat_device *seat_device, *next; |
30 | wl_list_for_each_safe(seat_device, next, &seat->devices, link) { | 30 | wl_list_for_each_safe(seat_device, next, &seat->devices, link) { |
31 | seat_device_destroy(seat_device); | 31 | seat_device_destroy(seat_device); |
@@ -42,18 +42,19 @@ static void handle_seat_container_destroy(struct wl_listener *listener, | |||
42 | struct sway_seat *seat = seat_con->seat; | 42 | struct sway_seat *seat = seat_con->seat; |
43 | struct sway_container *con = seat_con->container; | 43 | struct sway_container *con = seat_con->container; |
44 | 44 | ||
45 | bool is_focus = (sway_seat_get_focus(seat) == con); | 45 | bool is_focus = (seat_get_focus(seat) == con); |
46 | 46 | ||
47 | wl_list_remove(&seat_con->link); | 47 | wl_list_remove(&seat_con->link); |
48 | 48 | ||
49 | if (is_focus) { | 49 | if (is_focus) { |
50 | // pick next focus | 50 | // pick next focus |
51 | sway_seat_set_focus(seat, NULL); | 51 | seat_set_focus(seat, NULL); |
52 | struct sway_container *next = sway_seat_get_focus_inactive(seat, con->parent); | 52 | struct sway_container *next = |
53 | seat_get_focus_inactive(seat, con->parent); | ||
53 | if (next == NULL) { | 54 | if (next == NULL) { |
54 | next = con->parent; | 55 | next = con->parent; |
55 | } | 56 | } |
56 | sway_seat_set_focus(seat, next); | 57 | seat_set_focus(seat, next); |
57 | } | 58 | } |
58 | 59 | ||
59 | wl_list_remove(&seat_con->destroy.link); | 60 | wl_list_remove(&seat_con->destroy.link); |
@@ -110,7 +111,7 @@ static void collect_focus_iter(struct sway_container *con, void *data) { | |||
110 | wl_list_insert(&seat->focus_stack, &seat_con->link); | 111 | wl_list_insert(&seat->focus_stack, &seat_con->link); |
111 | } | 112 | } |
112 | 113 | ||
113 | struct sway_seat *sway_seat_create(struct sway_input_manager *input, | 114 | struct sway_seat *seat_create(struct sway_input_manager *input, |
114 | const char *seat_name) { | 115 | const char *seat_name) { |
115 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); | 116 | struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); |
116 | if (!seat) { | 117 | if (!seat) { |
@@ -133,7 +134,8 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input, | |||
133 | // init the focus stack | 134 | // init the focus stack |
134 | wl_list_init(&seat->focus_stack); | 135 | wl_list_init(&seat->focus_stack); |
135 | 136 | ||
136 | container_for_each_descendant_dfs(&root_container, collect_focus_iter, seat); | 137 | container_for_each_descendant_dfs(&root_container, |
138 | collect_focus_iter, seat); | ||
137 | 139 | ||
138 | wl_signal_add(&root_container.sway_root->events.new_container, | 140 | wl_signal_add(&root_container.sway_root->events.new_container, |
139 | &seat->new_container); | 141 | &seat->new_container); |
@@ -147,7 +149,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input, | |||
147 | WL_SEAT_CAPABILITY_POINTER | | 149 | WL_SEAT_CAPABILITY_POINTER | |
148 | WL_SEAT_CAPABILITY_TOUCH); | 150 | WL_SEAT_CAPABILITY_TOUCH); |
149 | 151 | ||
150 | sway_seat_configure_xcursor(seat); | 152 | seat_configure_xcursor(seat); |
151 | 153 | ||
152 | wl_list_insert(&input->seats, &seat->link); | 154 | wl_list_insert(&input->seats, &seat->link); |
153 | 155 | ||
@@ -165,11 +167,12 @@ static void seat_configure_keyboard(struct sway_seat *seat, | |||
165 | if (!seat_device->keyboard) { | 167 | if (!seat_device->keyboard) { |
166 | sway_keyboard_create(seat, seat_device); | 168 | sway_keyboard_create(seat, seat_device); |
167 | } | 169 | } |
168 | struct wlr_keyboard *wlr_keyboard = seat_device->input_device->wlr_device->keyboard; | 170 | struct wlr_keyboard *wlr_keyboard = |
171 | seat_device->input_device->wlr_device->keyboard; | ||
169 | sway_keyboard_configure(seat_device->keyboard); | 172 | sway_keyboard_configure(seat_device->keyboard); |
170 | wlr_seat_set_keyboard(seat->wlr_seat, | 173 | wlr_seat_set_keyboard(seat->wlr_seat, |
171 | seat_device->input_device->wlr_device); | 174 | seat_device->input_device->wlr_device); |
172 | struct sway_container *focus = sway_seat_get_focus(seat); | 175 | struct sway_container *focus = seat_get_focus(seat); |
173 | if (focus && focus->type == C_VIEW) { | 176 | if (focus && focus->type == C_VIEW) { |
174 | // force notify reenter to pick up the new configuration | 177 | // force notify reenter to pick up the new configuration |
175 | wlr_seat_keyboard_clear_focus(seat->wlr_seat); | 178 | wlr_seat_keyboard_clear_focus(seat->wlr_seat); |
@@ -179,7 +182,7 @@ static void seat_configure_keyboard(struct sway_seat *seat, | |||
179 | } | 182 | } |
180 | } | 183 | } |
181 | 184 | ||
182 | static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat, | 185 | static struct sway_seat_device *seat_get_device(struct sway_seat *seat, |
183 | struct sway_input_device *input_device) { | 186 | struct sway_input_device *input_device) { |
184 | struct sway_seat_device *seat_device = NULL; | 187 | struct sway_seat_device *seat_device = NULL; |
185 | wl_list_for_each(seat_device, &seat->devices, link) { | 188 | wl_list_for_each(seat_device, &seat->devices, link) { |
@@ -191,19 +194,14 @@ static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat, | |||
191 | return NULL; | 194 | return NULL; |
192 | } | 195 | } |
193 | 196 | ||
194 | void sway_seat_configure_device(struct sway_seat *seat, | 197 | void seat_configure_device(struct sway_seat *seat, |
195 | struct sway_input_device *input_device) { | 198 | struct sway_input_device *input_device) { |
196 | struct sway_seat_device *seat_device = | 199 | struct sway_seat_device *seat_device = |
197 | sway_seat_get_device(seat, input_device); | 200 | seat_get_device(seat, input_device); |
198 | if (!seat_device) { | 201 | if (!seat_device) { |
199 | return; | 202 | return; |
200 | } | 203 | } |
201 | 204 | ||
202 | if (seat->config) { | ||
203 | seat_device->attachment_config = | ||
204 | seat_config_get_attachment(seat->config, input_device->identifier); | ||
205 | } | ||
206 | |||
207 | switch (input_device->wlr_device->type) { | 205 | switch (input_device->wlr_device->type) { |
208 | case WLR_INPUT_DEVICE_POINTER: | 206 | case WLR_INPUT_DEVICE_POINTER: |
209 | seat_configure_pointer(seat, seat_device); | 207 | seat_configure_pointer(seat, seat_device); |
@@ -219,10 +217,10 @@ void sway_seat_configure_device(struct sway_seat *seat, | |||
219 | } | 217 | } |
220 | } | 218 | } |
221 | 219 | ||
222 | void sway_seat_add_device(struct sway_seat *seat, | 220 | void seat_add_device(struct sway_seat *seat, |
223 | struct sway_input_device *input_device) { | 221 | struct sway_input_device *input_device) { |
224 | if (sway_seat_get_device(seat, input_device)) { | 222 | if (seat_get_device(seat, input_device)) { |
225 | sway_seat_configure_device(seat, input_device); | 223 | seat_configure_device(seat, input_device); |
226 | return; | 224 | return; |
227 | } | 225 | } |
228 | 226 | ||
@@ -240,13 +238,13 @@ void sway_seat_add_device(struct sway_seat *seat, | |||
240 | seat_device->input_device = input_device; | 238 | seat_device->input_device = input_device; |
241 | wl_list_insert(&seat->devices, &seat_device->link); | 239 | wl_list_insert(&seat->devices, &seat_device->link); |
242 | 240 | ||
243 | sway_seat_configure_device(seat, input_device); | 241 | seat_configure_device(seat, input_device); |
244 | } | 242 | } |
245 | 243 | ||
246 | void sway_seat_remove_device(struct sway_seat *seat, | 244 | void seat_remove_device(struct sway_seat *seat, |
247 | struct sway_input_device *input_device) { | 245 | struct sway_input_device *input_device) { |
248 | struct sway_seat_device *seat_device = | 246 | struct sway_seat_device *seat_device = |
249 | sway_seat_get_device(seat, input_device); | 247 | seat_get_device(seat, input_device); |
250 | 248 | ||
251 | if (!seat_device) { | 249 | if (!seat_device) { |
252 | return; | 250 | return; |
@@ -258,7 +256,7 @@ void sway_seat_remove_device(struct sway_seat *seat, | |||
258 | seat_device_destroy(seat_device); | 256 | seat_device_destroy(seat_device); |
259 | } | 257 | } |
260 | 258 | ||
261 | void sway_seat_configure_xcursor(struct sway_seat *seat) { | 259 | void seat_configure_xcursor(struct sway_seat *seat) { |
262 | // TODO configure theme and size | 260 | // TODO configure theme and size |
263 | const char *cursor_theme = NULL; | 261 | const char *cursor_theme = NULL; |
264 | 262 | ||
@@ -273,7 +271,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { | |||
273 | } | 271 | } |
274 | 272 | ||
275 | for (int i = 0; i < root_container.children->length; ++i) { | 273 | for (int i = 0; i < root_container.children->length; ++i) { |
276 | struct sway_container *output_container = root_container.children->items[i]; | 274 | struct sway_container *output_container = |
275 | root_container.children->items[i]; | ||
277 | struct wlr_output *output = | 276 | struct wlr_output *output = |
278 | output_container->sway_output->wlr_output; | 277 | output_container->sway_output->wlr_output; |
279 | bool result = | 278 | bool result = |
@@ -292,9 +291,9 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) { | |||
292 | seat->cursor->cursor->y); | 291 | seat->cursor->cursor->y); |
293 | } | 292 | } |
294 | 293 | ||
295 | void sway_seat_set_focus_warp(struct sway_seat *seat, | 294 | void seat_set_focus_warp(struct sway_seat *seat, |
296 | struct sway_container *container, bool warp) { | 295 | struct sway_container *container, bool warp) { |
297 | struct sway_container *last_focus = sway_seat_get_focus(seat); | 296 | struct sway_container *last_focus = seat_get_focus(seat); |
298 | 297 | ||
299 | if (container && last_focus == container) { | 298 | if (container && last_focus == container) { |
300 | return; | 299 | return; |
@@ -364,7 +363,7 @@ void sway_seat_set_focus_warp(struct sway_seat *seat, | |||
364 | } | 363 | } |
365 | 364 | ||
366 | if (last_focus && last_focus->type == C_VIEW && | 365 | if (last_focus && last_focus->type == C_VIEW && |
367 | !sway_input_manager_has_focus(seat->input, last_focus)) { | 366 | !input_manager_has_focus(seat->input, last_focus)) { |
368 | struct sway_view *view = last_focus->sway_view; | 367 | struct sway_view *view = last_focus->sway_view; |
369 | view_set_activated(view, false); | 368 | view_set_activated(view, false); |
370 | } | 369 | } |
@@ -372,12 +371,13 @@ void sway_seat_set_focus_warp(struct sway_seat *seat, | |||
372 | seat->has_focus = (container != NULL); | 371 | seat->has_focus = (container != NULL); |
373 | } | 372 | } |
374 | 373 | ||
375 | void sway_seat_set_focus(struct sway_seat *seat, | 374 | void seat_set_focus(struct sway_seat *seat, |
376 | struct sway_container *container) { | 375 | struct sway_container *container) { |
377 | sway_seat_set_focus_warp(seat, container, true); | 376 | seat_set_focus_warp(seat, container, true); |
378 | } | 377 | } |
379 | 378 | ||
380 | struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) { | 379 | struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, |
380 | struct sway_container *container) { | ||
381 | struct sway_seat_container *current = NULL; | 381 | struct sway_seat_container *current = NULL; |
382 | struct sway_container *parent = NULL; | 382 | struct sway_container *parent = NULL; |
383 | wl_list_for_each(current, &seat->focus_stack, link) { | 383 | wl_list_for_each(current, &seat->focus_stack, link) { |
@@ -398,16 +398,17 @@ struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, stru | |||
398 | return NULL; | 398 | return NULL; |
399 | } | 399 | } |
400 | 400 | ||
401 | struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { | 401 | struct sway_container *seat_get_focus(struct sway_seat *seat) { |
402 | if (!seat->has_focus) { | 402 | if (!seat->has_focus) { |
403 | return NULL; | 403 | return NULL; |
404 | } | 404 | } |
405 | return sway_seat_get_focus_inactive(seat, &root_container); | 405 | return seat_get_focus_inactive(seat, &root_container); |
406 | } | 406 | } |
407 | 407 | ||
408 | struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, | 408 | struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, |
409 | enum sway_container_type type) { | 409 | enum sway_container_type type) { |
410 | struct sway_container *focus = sway_seat_get_focus_inactive(seat, &root_container); | 410 | struct sway_container *focus = |
411 | seat_get_focus_inactive(seat, &root_container); | ||
411 | if (focus->type == type) { | 412 | if (focus->type == type) { |
412 | return focus; | 413 | return focus; |
413 | } | 414 | } |
@@ -415,25 +416,27 @@ struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, | |||
415 | return container_parent(focus, type); | 416 | return container_parent(focus, type); |
416 | } | 417 | } |
417 | 418 | ||
418 | void sway_seat_set_config(struct sway_seat *seat, | 419 | void seat_apply_config(struct sway_seat *seat, |
419 | struct seat_config *seat_config) { | 420 | struct seat_config *seat_config) { |
420 | // clear configs | ||
421 | free_seat_config(seat->config); | ||
422 | seat->config = NULL; | ||
423 | |||
424 | struct sway_seat_device *seat_device = NULL; | 421 | struct sway_seat_device *seat_device = NULL; |
425 | wl_list_for_each(seat_device, &seat->devices, link) { | ||
426 | seat_device->attachment_config = NULL; | ||
427 | } | ||
428 | 422 | ||
429 | if (!seat_config) { | 423 | if (!seat_config) { |
430 | return; | 424 | return; |
431 | } | 425 | } |
432 | 426 | ||
433 | // add configs | ||
434 | seat->config = copy_seat_config(seat_config); | ||
435 | |||
436 | wl_list_for_each(seat_device, &seat->devices, link) { | 427 | wl_list_for_each(seat_device, &seat->devices, link) { |
437 | sway_seat_configure_device(seat, seat_device->input_device); | 428 | seat_configure_device(seat, seat_device->input_device); |
438 | } | 429 | } |
439 | } | 430 | } |
431 | |||
432 | struct seat_config *seat_get_config(struct sway_seat *seat) { | ||
433 | struct seat_config *seat_config = NULL; | ||
434 | for (int i = 0; i < config->seat_configs->length; ++i ) { | ||
435 | seat_config = config->seat_configs->items[i]; | ||
436 | if (strcmp(seat->wlr_seat->name, seat_config->name) == 0) { | ||
437 | return seat_config; | ||
438 | } | ||
439 | } | ||
440 | |||
441 | return NULL; | ||
442 | } | ||