aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seat.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 16:09:27 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 16:09:27 -0400
commitd434da563239c43c5fe417ce83b23b417f2ab635 (patch)
treee154daaf43c42d11c5afb8b7739ae6b52dd01215 /sway/input/seat.c
parentfix workspace splits (diff)
parentMerge pull request #1699 from acrisci/seat-fixes (diff)
downloadsway-d434da563239c43c5fe417ce83b23b417f2ab635.tar.gz
sway-d434da563239c43c5fe417ce83b23b417f2ab635.tar.zst
sway-d434da563239c43c5fe417ce83b23b417f2ab635.zip
Merge branch 'wlroots' into split-containers
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r--sway/input/seat.c102
1 files changed, 54 insertions, 48 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 1fd204d4..c41f7b2e 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -26,8 +26,7 @@ static void seat_device_destroy(struct sway_seat_device *seat_device) {
26 free(seat_device); 26 free(seat_device);
27} 27}
28 28
29void sway_seat_destroy(struct sway_seat *seat) { 29void seat_destroy(struct sway_seat *seat) {
30 // TODO destroy seat containers
31 struct sway_seat_device *seat_device, *next; 30 struct sway_seat_device *seat_device, *next;
32 wl_list_for_each_safe(seat_device, next, &seat->devices, link) { 31 wl_list_for_each_safe(seat_device, next, &seat->devices, link) {
33 seat_device_destroy(seat_device); 32 seat_device_destroy(seat_device);
@@ -90,7 +89,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
90 struct sway_seat *seat = seat_con->seat; 89 struct sway_seat *seat = seat_con->seat;
91 struct sway_container *con = seat_con->container; 90 struct sway_container *con = seat_con->container;
92 struct sway_container *parent = con->parent; 91 struct sway_container *parent = con->parent;
93 struct sway_container *focus = sway_seat_get_focus(seat); 92 struct sway_container *focus = seat_get_focus(seat);
94 93
95 bool set_focus = 94 bool set_focus =
96 focus != NULL && 95 focus != NULL &&
@@ -102,7 +101,7 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
102 if (set_focus) { 101 if (set_focus) {
103 struct sway_container *next_focus = NULL; 102 struct sway_container *next_focus = NULL;
104 while (next_focus == NULL) { 103 while (next_focus == NULL) {
105 next_focus = sway_seat_get_focus_by_type(seat, parent, C_VIEW); 104 next_focus = seat_get_focus_by_type(seat, parent, C_VIEW);
106 105
107 if (next_focus == NULL && parent->type == C_WORKSPACE) { 106 if (next_focus == NULL && parent->type == C_WORKSPACE) {
108 next_focus = parent; 107 next_focus = parent;
@@ -114,10 +113,10 @@ static void handle_seat_container_destroy(struct wl_listener *listener,
114 113
115 // the structure change might have caused it to move up to the top of 114 // the structure change might have caused it to move up to the top of
116 // the focus stack without sending focus notifications to the view 115 // the focus stack without sending focus notifications to the view
117 if (sway_seat_get_focus(seat) == next_focus) { 116 if (seat_get_focus(seat) == next_focus) {
118 seat_send_focus(seat, next_focus); 117 seat_send_focus(seat, next_focus);
119 } else { 118 } else {
120 sway_seat_set_focus(seat, next_focus); 119 seat_set_focus(seat, next_focus);
121 } 120 }
122 } 121 }
123} 122}
@@ -171,7 +170,7 @@ static void collect_focus_iter(struct sway_container *con, void *data) {
171 wl_list_insert(&seat->focus_stack, &seat_con->link); 170 wl_list_insert(&seat->focus_stack, &seat_con->link);
172} 171}
173 172
174struct sway_seat *sway_seat_create(struct sway_input_manager *input, 173struct sway_seat *seat_create(struct sway_input_manager *input,
175 const char *seat_name) { 174 const char *seat_name) {
176 struct sway_seat *seat = calloc(1, sizeof(struct sway_seat)); 175 struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));
177 if (!seat) { 176 if (!seat) {
@@ -194,7 +193,8 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
194 // init the focus stack 193 // init the focus stack
195 wl_list_init(&seat->focus_stack); 194 wl_list_init(&seat->focus_stack);
196 195
197 container_for_each_descendant_dfs(&root_container, collect_focus_iter, seat); 196 container_for_each_descendant_dfs(&root_container,
197 collect_focus_iter, seat);
198 198
199 wl_signal_add(&root_container.sway_root->events.new_container, 199 wl_signal_add(&root_container.sway_root->events.new_container,
200 &seat->new_container); 200 &seat->new_container);
@@ -208,7 +208,7 @@ struct sway_seat *sway_seat_create(struct sway_input_manager *input,
208 WL_SEAT_CAPABILITY_POINTER | 208 WL_SEAT_CAPABILITY_POINTER |
209 WL_SEAT_CAPABILITY_TOUCH); 209 WL_SEAT_CAPABILITY_TOUCH);
210 210
211 sway_seat_configure_xcursor(seat); 211 seat_configure_xcursor(seat);
212 212
213 wl_list_insert(&input->seats, &seat->link); 213 wl_list_insert(&input->seats, &seat->link);
214 214
@@ -226,11 +226,12 @@ static void seat_configure_keyboard(struct sway_seat *seat,
226 if (!seat_device->keyboard) { 226 if (!seat_device->keyboard) {
227 sway_keyboard_create(seat, seat_device); 227 sway_keyboard_create(seat, seat_device);
228 } 228 }
229 struct wlr_keyboard *wlr_keyboard = seat_device->input_device->wlr_device->keyboard; 229 struct wlr_keyboard *wlr_keyboard =
230 seat_device->input_device->wlr_device->keyboard;
230 sway_keyboard_configure(seat_device->keyboard); 231 sway_keyboard_configure(seat_device->keyboard);
231 wlr_seat_set_keyboard(seat->wlr_seat, 232 wlr_seat_set_keyboard(seat->wlr_seat,
232 seat_device->input_device->wlr_device); 233 seat_device->input_device->wlr_device);
233 struct sway_container *focus = sway_seat_get_focus(seat); 234 struct sway_container *focus = seat_get_focus(seat);
234 if (focus && focus->type == C_VIEW) { 235 if (focus && focus->type == C_VIEW) {
235 // force notify reenter to pick up the new configuration 236 // force notify reenter to pick up the new configuration
236 wlr_seat_keyboard_clear_focus(seat->wlr_seat); 237 wlr_seat_keyboard_clear_focus(seat->wlr_seat);
@@ -240,7 +241,7 @@ static void seat_configure_keyboard(struct sway_seat *seat,
240 } 241 }
241} 242}
242 243
243static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat, 244static struct sway_seat_device *seat_get_device(struct sway_seat *seat,
244 struct sway_input_device *input_device) { 245 struct sway_input_device *input_device) {
245 struct sway_seat_device *seat_device = NULL; 246 struct sway_seat_device *seat_device = NULL;
246 wl_list_for_each(seat_device, &seat->devices, link) { 247 wl_list_for_each(seat_device, &seat->devices, link) {
@@ -252,19 +253,14 @@ static struct sway_seat_device *sway_seat_get_device(struct sway_seat *seat,
252 return NULL; 253 return NULL;
253} 254}
254 255
255void sway_seat_configure_device(struct sway_seat *seat, 256void seat_configure_device(struct sway_seat *seat,
256 struct sway_input_device *input_device) { 257 struct sway_input_device *input_device) {
257 struct sway_seat_device *seat_device = 258 struct sway_seat_device *seat_device =
258 sway_seat_get_device(seat, input_device); 259 seat_get_device(seat, input_device);
259 if (!seat_device) { 260 if (!seat_device) {
260 return; 261 return;
261 } 262 }
262 263
263 if (seat->config) {
264 seat_device->attachment_config =
265 seat_config_get_attachment(seat->config, input_device->identifier);
266 }
267
268 switch (input_device->wlr_device->type) { 264 switch (input_device->wlr_device->type) {
269 case WLR_INPUT_DEVICE_POINTER: 265 case WLR_INPUT_DEVICE_POINTER:
270 seat_configure_pointer(seat, seat_device); 266 seat_configure_pointer(seat, seat_device);
@@ -280,10 +276,10 @@ void sway_seat_configure_device(struct sway_seat *seat,
280 } 276 }
281} 277}
282 278
283void sway_seat_add_device(struct sway_seat *seat, 279void seat_add_device(struct sway_seat *seat,
284 struct sway_input_device *input_device) { 280 struct sway_input_device *input_device) {
285 if (sway_seat_get_device(seat, input_device)) { 281 if (seat_get_device(seat, input_device)) {
286 sway_seat_configure_device(seat, input_device); 282 seat_configure_device(seat, input_device);
287 return; 283 return;
288 } 284 }
289 285
@@ -301,13 +297,13 @@ void sway_seat_add_device(struct sway_seat *seat,
301 seat_device->input_device = input_device; 297 seat_device->input_device = input_device;
302 wl_list_insert(&seat->devices, &seat_device->link); 298 wl_list_insert(&seat->devices, &seat_device->link);
303 299
304 sway_seat_configure_device(seat, input_device); 300 seat_configure_device(seat, input_device);
305} 301}
306 302
307void sway_seat_remove_device(struct sway_seat *seat, 303void seat_remove_device(struct sway_seat *seat,
308 struct sway_input_device *input_device) { 304 struct sway_input_device *input_device) {
309 struct sway_seat_device *seat_device = 305 struct sway_seat_device *seat_device =
310 sway_seat_get_device(seat, input_device); 306 seat_get_device(seat, input_device);
311 307
312 if (!seat_device) { 308 if (!seat_device) {
313 return; 309 return;
@@ -319,7 +315,7 @@ void sway_seat_remove_device(struct sway_seat *seat,
319 seat_device_destroy(seat_device); 315 seat_device_destroy(seat_device);
320} 316}
321 317
322void sway_seat_configure_xcursor(struct sway_seat *seat) { 318void seat_configure_xcursor(struct sway_seat *seat) {
323 // TODO configure theme and size 319 // TODO configure theme and size
324 const char *cursor_theme = NULL; 320 const char *cursor_theme = NULL;
325 321
@@ -334,7 +330,8 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
334 } 330 }
335 331
336 for (int i = 0; i < root_container.children->length; ++i) { 332 for (int i = 0; i < root_container.children->length; ++i) {
337 struct sway_container *output_container = root_container.children->items[i]; 333 struct sway_container *output_container =
334 root_container.children->items[i];
338 struct wlr_output *output = 335 struct wlr_output *output =
339 output_container->sway_output->wlr_output; 336 output_container->sway_output->wlr_output;
340 bool result = 337 bool result =
@@ -353,9 +350,9 @@ void sway_seat_configure_xcursor(struct sway_seat *seat) {
353 seat->cursor->cursor->y); 350 seat->cursor->cursor->y);
354} 351}
355 352
356void sway_seat_set_focus_warp(struct sway_seat *seat, 353void seat_set_focus_warp(struct sway_seat *seat,
357 struct sway_container *container, bool warp) { 354 struct sway_container *container, bool warp) {
358 struct sway_container *last_focus = sway_seat_get_focus(seat); 355 struct sway_container *last_focus = seat_get_focus(seat);
359 356
360 if (container && last_focus == container) { 357 if (container && last_focus == container) {
361 return; 358 return;
@@ -409,7 +406,7 @@ void sway_seat_set_focus_warp(struct sway_seat *seat,
409 } 406 }
410 407
411 if (last_focus && last_focus->type == C_VIEW && 408 if (last_focus && last_focus->type == C_VIEW &&
412 !sway_input_manager_has_focus(seat->input, last_focus)) { 409 !input_manager_has_focus(seat->input, last_focus)) {
413 struct sway_view *view = last_focus->sway_view; 410 struct sway_view *view = last_focus->sway_view;
414 view_set_activated(view, false); 411 view_set_activated(view, false);
415 } 412 }
@@ -417,24 +414,24 @@ void sway_seat_set_focus_warp(struct sway_seat *seat,
417 seat->has_focus = (container != NULL); 414 seat->has_focus = (container != NULL);
418} 415}
419 416
420void sway_seat_set_focus(struct sway_seat *seat, 417void seat_set_focus(struct sway_seat *seat,
421 struct sway_container *container) { 418 struct sway_container *container) {
422 sway_seat_set_focus_warp(seat, container, true); 419 seat_set_focus_warp(seat, container, true);
423} 420}
424 421
425struct sway_container *sway_seat_get_focus_inactive(struct sway_seat *seat, 422struct sway_container *seat_get_focus_inactive(struct sway_seat *seat,
426 struct sway_container *container) { 423 struct sway_container *container) {
427 return sway_seat_get_focus_by_type(seat, container, C_TYPES); 424 return seat_get_focus_by_type(seat, container, C_TYPES);
428} 425}
429 426
430struct sway_container *sway_seat_get_focus(struct sway_seat *seat) { 427struct sway_container *sway_seat_get_focus(struct sway_seat *seat) {
431 if (!seat->has_focus) { 428 if (!seat->has_focus) {
432 return NULL; 429 return NULL;
433 } 430 }
434 return sway_seat_get_focus_inactive(seat, &root_container); 431 return seat_get_focus_inactive(seat, &root_container);
435} 432}
436 433
437struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat, 434struct sway_container *seat_get_focus_by_type(struct sway_seat *seat,
438 struct sway_container *container, enum sway_container_type type) { 435 struct sway_container *container, enum sway_container_type type) {
439 struct sway_seat_container *current = NULL; 436 struct sway_seat_container *current = NULL;
440 struct sway_container *parent = NULL; 437 struct sway_container *parent = NULL;
@@ -458,25 +455,34 @@ struct sway_container *sway_seat_get_focus_by_type(struct sway_seat *seat,
458 return NULL; 455 return NULL;
459} 456}
460 457
461void sway_seat_set_config(struct sway_seat *seat, 458struct sway_container *seat_get_focus(struct sway_seat *seat) {
462 struct seat_config *seat_config) { 459 if (!seat->has_focus) {
463 // clear configs 460 return NULL;
464 free_seat_config(seat->config); 461 }
465 seat->config = NULL; 462 return seat_get_focus_inactive(seat, &root_container);
463}
466 464
465void seat_apply_config(struct sway_seat *seat,
466 struct seat_config *seat_config) {
467 struct sway_seat_device *seat_device = NULL; 467 struct sway_seat_device *seat_device = NULL;
468 wl_list_for_each(seat_device, &seat->devices, link) {
469 seat_device->attachment_config = NULL;
470 }
471 468
472 if (!seat_config) { 469 if (!seat_config) {
473 return; 470 return;
474 } 471 }
475 472
476 // add configs
477 seat->config = copy_seat_config(seat_config);
478
479 wl_list_for_each(seat_device, &seat->devices, link) { 473 wl_list_for_each(seat_device, &seat->devices, link) {
480 sway_seat_configure_device(seat, seat_device->input_device); 474 seat_configure_device(seat, seat_device->input_device);
475 }
476}
477
478struct seat_config *seat_get_config(struct sway_seat *seat) {
479 struct seat_config *seat_config = NULL;
480 for (int i = 0; i < config->seat_configs->length; ++i ) {
481 seat_config = config->seat_configs->items[i];
482 if (strcmp(seat->wlr_seat->name, seat_config->name) == 0) {
483 return seat_config;
484 }
481 } 485 }
486
487 return NULL;
482} 488}