diff options
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/cursor.c | 60 | ||||
-rw-r--r-- | sway/input/input-manager.c | 1 | ||||
-rw-r--r-- | sway/input/seat.c | 4 |
3 files changed, 52 insertions, 13 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 831109dc..944ad8eb 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -261,22 +261,60 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { wlr_log(L_DEBUG, "TODO: handle touch motion event: %p", event); } +static double apply_mapping_from_coord(double low, double high, double value) { + if (value == -1) { + return value; + } + + value = (value - low) / (high - low); + if (value < 0) { + return 0; + } else if (value > 1) { + return 1; + } else { + return value; + } +} + +static void apply_mapping_from_region(struct wlr_input_device *device, + struct input_config_mapped_from_region *region, double *x, double *y) { + double x1 = region->x1, x2 = region->x2; + double y1 = region->y1, y2 = region->y2; + + if (region->mm) { + if (device->width_mm == 0 || device->height_mm == 0) { + return; + } + x1 /= device->width_mm; + x2 /= device->width_mm; + y1 /= device->height_mm; + y2 /= device->height_mm; + } + + *x = apply_mapping_from_coord(x1, x2, *x); + *y = apply_mapping_from_coord(y1, y2, *y); +} + static void handle_tool_axis(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); struct wlr_event_tablet_tool_axis *event = data; + struct sway_input_device *input_device = event->device->data; - if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && - (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { - wlr_cursor_warp_absolute(cursor->cursor, event->device, - event->x, event->y); - cursor_send_pointer_motion(cursor, event->time_msec); - } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { - wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1); - cursor_send_pointer_motion(cursor, event->time_msec); - } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { - wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y); - cursor_send_pointer_motion(cursor, event->time_msec); + double x = -1, y = -1; + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { + x = event->x; + } + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + y = event->y; } + + struct input_config *ic = input_device_get_config(input_device); + if (ic != NULL && ic->mapped_from_region != NULL) { + apply_mapping_from_region(event->device, ic->mapped_from_region, &x, &y); + } + + wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y); + cursor_send_pointer_motion(cursor, event->time_msec); } static void handle_tool_tip(struct wl_listener *listener, void *data) { diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index ae55d2a1..29b47a7b 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -211,6 +211,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) { if (!sway_assert(input_device, "could not allocate input device")) { return; } + device->data = input_device; input_device->wlr_device = device; input_device->identifier = get_device_identifier(device); diff --git a/sway/input/seat.c b/sway/input/seat.c index e88bcfd1..963d38b2 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -269,11 +269,11 @@ static void seat_apply_input_config(struct sway_seat *seat, } wlr_log(L_DEBUG, "Applying input config to %s", sway_device->input_device->identifier); - if (ic->mapped_output) { + if (ic->mapped_to_output) { struct sway_container *output = NULL; for (int i = 0; i < root_container.children->length; ++i) { struct sway_container *_output = root_container.children->items[i]; - if (strcasecmp(_output->name, ic->mapped_output) == 0) { + if (strcasecmp(_output->name, ic->mapped_to_output) == 0) { output = _output; break; } |