diff options
-rw-r--r-- | include/sway/config.h | 8 | ||||
-rw-r--r-- | sway/commands/input/map_to_output.c | 1 | ||||
-rw-r--r-- | sway/commands/input/map_to_region.c | 4 | ||||
-rw-r--r-- | sway/config/input.c | 3 | ||||
-rw-r--r-- | sway/input/seat.c | 67 |
5 files changed, 44 insertions, 39 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 0a010c6d..6892c946 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -108,6 +108,12 @@ struct calibration_matrix { | |||
108 | float matrix[6]; | 108 | float matrix[6]; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | enum input_config_mapped_to { | ||
112 | MAPPED_TO_DEFAULT, | ||
113 | MAPPED_TO_OUTPUT, | ||
114 | MAPPED_TO_REGION | ||
115 | }; | ||
116 | |||
111 | /** | 117 | /** |
112 | * options for input devices | 118 | * options for input devices |
113 | */ | 119 | */ |
@@ -147,6 +153,8 @@ struct input_config { | |||
147 | int xkb_capslock; | 153 | int xkb_capslock; |
148 | 154 | ||
149 | struct input_config_mapped_from_region *mapped_from_region; | 155 | struct input_config_mapped_from_region *mapped_from_region; |
156 | |||
157 | enum input_config_mapped_to mapped_to; | ||
150 | char *mapped_to_output; | 158 | char *mapped_to_output; |
151 | struct wlr_box *mapped_to_region; | 159 | struct wlr_box *mapped_to_region; |
152 | 160 | ||
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 | ||
576 | static void seat_apply_input_config(struct sway_seat *seat, | 576 | static 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 | ||