aboutsummaryrefslogtreecommitdiffstats
path: root/sway
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
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')
-rw-r--r--sway/commands/input/map_to_output.c1
-rw-r--r--sway/commands/input/map_to_region.c4
-rw-r--r--sway/config/input.c3
-rw-r--r--sway/input/seat.c67
4 files changed, 36 insertions, 39 deletions
diff --git a/sway/commands/input/map_to_output.c b/sway/commands/input/map_to_output.c
index 6d623186..f60fb7d5 100644
--- a/sway/commands/input/map_to_output.c
+++ b/sway/commands/input/map_to_output.c
@@ -16,6 +16,7 @@ struct cmd_results *input_cmd_map_to_output(int argc, char **argv) {
16 return cmd_results_new(CMD_FAILURE, "No input device defined."); 16 return cmd_results_new(CMD_FAILURE, "No input device defined.");
17 } 17 }
18 18
19 ic->mapped_to = MAPPED_TO_OUTPUT;
19 ic->mapped_to_output = strdup(argv[0]); 20 ic->mapped_to_output = strdup(argv[0]);
20 21
21 return cmd_results_new(CMD_SUCCESS, NULL); 22 return cmd_results_new(CMD_SUCCESS, NULL);
diff --git a/sway/commands/input/map_to_region.c b/sway/commands/input/map_to_region.c
index e0b69ed5..e85495e5 100644
--- a/sway/commands/input/map_to_region.c
+++ b/sway/commands/input/map_to_region.c
@@ -15,9 +15,7 @@ struct cmd_results *input_cmd_map_to_region(int argc, char **argv) {
15 return cmd_results_new(CMD_FAILURE, "No input device defined"); 15 return cmd_results_new(CMD_FAILURE, "No input device defined");
16 } 16 }
17 17
18 // This is used to clear the current output mapping. 18 ic->mapped_to = MAPPED_TO_REGION;
19 ic->mapped_to_output = strdup("");
20
21 ic->mapped_to_region = calloc(1, sizeof(struct wlr_box)); 19 ic->mapped_to_region = calloc(1, sizeof(struct wlr_box));
22 20
23 const char *errstr; 21 const char *errstr;
diff --git a/sway/config/input.c b/sway/config/input.c
index 294ed08f..0993e9ab 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -134,6 +134,9 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
134 memcpy(dst->mapped_from_region, src->mapped_from_region, 134 memcpy(dst->mapped_from_region, src->mapped_from_region,
135 sizeof(struct input_config_mapped_from_region)); 135 sizeof(struct input_config_mapped_from_region));
136 } 136 }
137 if (src->mapped_to) {
138 dst->mapped_to = src->mapped_to;
139 }
137 if (src->mapped_to_output) { 140 if (src->mapped_to_output) {
138 free(dst->mapped_to_output); 141 free(dst->mapped_to_output);
139 dst->mapped_to_output = strdup(src->mapped_to_output); 142 dst->mapped_to_output = strdup(src->mapped_to_output);
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