aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seat.c
diff options
context:
space:
mode:
authorLibravatar Tadeo Kondrak <me@tadeo.ca>2019-11-01 11:37:29 -0600
committerLibravatar Simon Ser <contact@emersion.fr>2019-11-17 13:34:24 +0100
commit7f54495b5e62a65627cdb61f099e241f0594a6d9 (patch)
treea0480453d0721ab7df31a43c1e45c7fd7dbeb3d5 /sway/input/seat.c
parentImplement input map_to_region command (diff)
downloadsway-7f54495b5e62a65627cdb61f099e241f0594a6d9.tar.gz
sway-7f54495b5e62a65627cdb61f099e241f0594a6d9.tar.zst
sway-7f54495b5e62a65627cdb61f099e241f0594a6d9.zip
Use an enum instead of a marker string for map_to_
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r--sway/input/seat.c67
1 files changed, 31 insertions, 36 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 5fc23a19..f486d5e7 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -575,62 +575,57 @@ static void seat_reset_input_config(struct sway_seat *seat,
575 575
576static void seat_apply_input_config(struct sway_seat *seat, 576static void seat_apply_input_config(struct sway_seat *seat,
577 struct sway_seat_device *sway_device) { 577 struct sway_seat_device *sway_device) {
578 const char *mapped_to_output = NULL; 578 struct input_config *ic =
579 struct wlr_box *mapped_to_region = NULL; 579 input_device_get_config(sway_device->input_device);
580 580 if (ic == NULL) {
581 struct input_config *ic = input_device_get_config( 581 return;
582 sway_device->input_device); 582 }
583 if (ic != NULL) {
584 sway_log(SWAY_DEBUG, "Applying input config to %s",
585 sway_device->input_device->identifier);
586
587 // We use an empty string as a marker to clear the mapped_to_output
588 // property, because a NULL set in a handler_context isn't preserved.
589 if (ic->mapped_to_output != NULL && ic->mapped_to_output[0] == '\0') {
590 free(ic->mapped_to_output);
591 ic->mapped_to_output = NULL;
592 wlr_cursor_map_input_to_output(seat->cursor->cursor,
593 sway_device->input_device->wlr_device, NULL);
594 }
595 583
596 mapped_to_output = ic->mapped_to_output; 584 sway_log(SWAY_DEBUG, "Applying input config to %s",
597 if (mapped_to_output != NULL) { 585 sway_device->input_device->identifier);
598 // Output has just been set, clear region setting.
599 free(ic->mapped_to_region);
600 ic->mapped_to_region = NULL;
601 wlr_cursor_map_input_to_region(seat->cursor->cursor,
602 sway_device->input_device->wlr_device, NULL);
603 }
604 586
605 mapped_to_region = ic->mapped_to_region; 587 const char *mapped_to_output = ic->mapped_to_output;
606 } 588 struct wlr_box *mapped_to_region = ic->mapped_to_region;
607 589
608 if (mapped_to_output == NULL && mapped_to_region == NULL) { 590 switch (ic->mapped_to) {
591 case MAPPED_TO_DEFAULT:
609 mapped_to_output = sway_device->input_device->wlr_device->output_name; 592 mapped_to_output = sway_device->input_device->wlr_device->output_name;
610 } 593 if (mapped_to_output == NULL) {
611 594 return;
612 if (mapped_to_output != NULL) { 595 }
596 /* fallthrough */
597 case MAPPED_TO_OUTPUT:
613 sway_log(SWAY_DEBUG, "Mapping input device %s to output %s", 598 sway_log(SWAY_DEBUG, "Mapping input device %s to output %s",
614 sway_device->input_device->identifier, mapped_to_output); 599 sway_device->input_device->identifier, mapped_to_output);
615 if (strcmp("*", mapped_to_output) == 0) { 600 if (strcmp("*", mapped_to_output) == 0) {
616 wlr_cursor_map_input_to_output(seat->cursor->cursor, 601 wlr_cursor_map_input_to_output(seat->cursor->cursor,
617 sway_device->input_device->wlr_device, NULL); 602 sway_device->input_device->wlr_device, NULL);
603 wlr_cursor_map_input_to_region(seat->cursor->cursor,
604 sway_device->input_device->wlr_device, NULL);
618 sway_log(SWAY_DEBUG, "Reset output mapping"); 605 sway_log(SWAY_DEBUG, "Reset output mapping");
619 return; 606 return;
620 } 607 }
621 struct sway_output *output = output_by_name_or_id(mapped_to_output); 608 struct sway_output *output = output_by_name_or_id(mapped_to_output);
622 if (output) { 609 if (!output) {
623 wlr_cursor_map_input_to_output(seat->cursor->cursor, 610 return;
624 sway_device->input_device->wlr_device, output->wlr_output);
625 sway_log(SWAY_DEBUG, "Mapped to output %s", output->wlr_output->name);
626 } 611 }
627 } else if (mapped_to_region != NULL) { 612 wlr_cursor_map_input_to_output(seat->cursor->cursor,
613 sway_device->input_device->wlr_device, output->wlr_output);
614 wlr_cursor_map_input_to_region(seat->cursor->cursor,
615 sway_device->input_device->wlr_device, NULL);
616 sway_log(SWAY_DEBUG,
617 "Mapped to output %s", output->wlr_output->name);
618 return;
619 case MAPPED_TO_REGION:
628 sway_log(SWAY_DEBUG, "Mapping input device %s to %d,%d %dx%d", 620 sway_log(SWAY_DEBUG, "Mapping input device %s to %d,%d %dx%d",
629 sway_device->input_device->identifier, 621 sway_device->input_device->identifier,
630 mapped_to_region->x, mapped_to_region->y, 622 mapped_to_region->x, mapped_to_region->y,
631 mapped_to_region->width, mapped_to_region->height); 623 mapped_to_region->width, mapped_to_region->height);
624 wlr_cursor_map_input_to_output(seat->cursor->cursor,
625 sway_device->input_device->wlr_device, NULL);
632 wlr_cursor_map_input_to_region(seat->cursor->cursor, 626 wlr_cursor_map_input_to_region(seat->cursor->cursor,
633 sway_device->input_device->wlr_device, mapped_to_region); 627 sway_device->input_device->wlr_device, mapped_to_region);
628 return;
634 } 629 }
635} 630}
636 631