Merge pull request #765 from swaywm/transformed-events

Use libinput transformed events instead of width_mm/height_mm
This commit is contained in:
emersion 2018-03-28 14:11:39 -04:00 committed by GitHub
commit 5dd022da13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 105 additions and 100 deletions

View File

@ -47,7 +47,7 @@ bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm,
if (drmModeSetCursor(drm->fd, crtc->id, gbm_bo_get_handle(bo).u32, if (drmModeSetCursor(drm->fd, crtc->id, gbm_bo_get_handle(bo).u32,
plane->surf.width, plane->surf.height)) { plane->surf.width, plane->surf.height)) {
wlr_log_errno(L_ERROR, "Failed to set hardware cursor"); wlr_log_errno(L_DEBUG, "Failed to set hardware cursor");
return false; return false;
} }

View File

@ -46,6 +46,8 @@ static struct wlr_input_device *allocate_device(
return NULL; return NULL;
} }
struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device; struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device;
libinput_device_get_size(libinput_dev,
&wlr_dev->width_mm, &wlr_dev->height_mm);
wl_list_insert(wlr_devices, &wlr_dev->link); wl_list_insert(wlr_devices, &wlr_dev->link);
wlr_libinput_dev->handle = libinput_dev; wlr_libinput_dev->handle = libinput_dev;
libinput_device_ref(libinput_dev); libinput_device_ref(libinput_dev);

View File

@ -53,9 +53,8 @@ void handle_pointer_motion_abs(struct libinput_event *event,
wlr_event.device = wlr_dev; wlr_event.device = wlr_dev;
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); usec_to_msec(libinput_event_pointer_get_time_usec(pevent));
wlr_event.x_mm = libinput_event_pointer_get_absolute_x(pevent); wlr_event.x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1);
wlr_event.y_mm = libinput_event_pointer_get_absolute_y(pevent); wlr_event.y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1);
libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm);
wlr_signal_emit_safe(&wlr_dev->pointer->events.motion_absolute, &wlr_event); wlr_signal_emit_safe(&wlr_dev->pointer->events.motion_absolute, &wlr_event);
} }

View File

@ -34,14 +34,13 @@ void handle_tablet_tool_axis(struct libinput_event *event,
wlr_event.device = wlr_dev; wlr_event.device = wlr_dev;
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent)); usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent));
libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm);
if (libinput_event_tablet_tool_x_has_changed(tevent)) { if (libinput_event_tablet_tool_x_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_X; wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_X;
wlr_event.x_mm = libinput_event_tablet_tool_get_x(tevent); wlr_event.x = libinput_event_tablet_tool_get_x_transformed(tevent, 1);
} }
if (libinput_event_tablet_tool_y_has_changed(tevent)) { if (libinput_event_tablet_tool_y_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_Y; wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_Y;
wlr_event.y_mm = libinput_event_tablet_tool_get_y(tevent); wlr_event.y = libinput_event_tablet_tool_get_y_transformed(tevent, 1);
} }
if (libinput_event_tablet_tool_pressure_has_changed(tevent)) { if (libinput_event_tablet_tool_pressure_has_changed(tevent)) {
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE; wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE;

View File

@ -35,9 +35,8 @@ void handle_touch_down(struct libinput_event *event,
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_touch_get_time_usec(tevent)); usec_to_msec(libinput_event_touch_get_time_usec(tevent));
wlr_event.touch_id = libinput_event_touch_get_slot(tevent); wlr_event.touch_id = libinput_event_touch_get_slot(tevent);
wlr_event.x_mm = libinput_event_touch_get_x(tevent); wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1);
wlr_event.y_mm = libinput_event_touch_get_y(tevent); wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1);
libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm);
wlr_signal_emit_safe(&wlr_dev->touch->events.down, &wlr_event); wlr_signal_emit_safe(&wlr_dev->touch->events.down, &wlr_event);
} }
@ -74,9 +73,8 @@ void handle_touch_motion(struct libinput_event *event,
wlr_event.time_msec = wlr_event.time_msec =
usec_to_msec(libinput_event_touch_get_time_usec(tevent)); usec_to_msec(libinput_event_touch_get_time_usec(tevent));
wlr_event.touch_id = libinput_event_touch_get_slot(tevent); wlr_event.touch_id = libinput_event_touch_get_slot(tevent);
wlr_event.x_mm = libinput_event_touch_get_x(tevent); wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1);
wlr_event.y_mm = libinput_event_touch_get_y(tevent); wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1);
libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm);
wlr_signal_emit_safe(&wlr_dev->touch->events.motion, &wlr_event); wlr_signal_emit_safe(&wlr_dev->touch->events.motion, &wlr_event);
} }

View File

@ -64,6 +64,9 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window, wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window,
&width, &height); &width, &height);
int owidth, oheight;
wlr_output_effective_resolution(wlr_output, &owidth, &oheight);
struct wlr_box box = { struct wlr_box box = {
.x = wl_fixed_to_int(surface_x), .x = wl_fixed_to_int(surface_x),
.y = wl_fixed_to_int(surface_y), .y = wl_fixed_to_int(surface_y),
@ -80,10 +83,15 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
struct wlr_event_pointer_motion_absolute wlr_event; struct wlr_event_pointer_motion_absolute wlr_event;
wlr_event.device = dev; wlr_event.device = dev;
wlr_event.time_msec = time; wlr_event.time_msec = time;
wlr_event.width_mm = layout_box.width;
wlr_event.height_mm = layout_box.height; double tx = transformed.x / (double)owidth;
wlr_event.x_mm = transformed.x + wlr_output->lx - layout_box.x; double ty = transformed.y / (double)oheight;
wlr_event.y_mm = transformed.y + wlr_output->ly - layout_box.y; double ox = wlr_output->lx / (double)layout_box.width;
double oy = wlr_output->ly / (double)layout_box.height;
wlr_event.x = tx * ((double)owidth / layout_box.width) + ox;
wlr_event.y = ty * ((double)oheight / layout_box.height) + oy;
wlr_signal_emit_safe(&dev->pointer->events.motion_absolute, &wlr_event); wlr_signal_emit_safe(&dev->pointer->events.motion_absolute, &wlr_event);
} }

View File

@ -112,10 +112,8 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
struct wlr_event_pointer_motion_absolute abs = { struct wlr_event_pointer_motion_absolute abs = {
.device = &x11->pointer_dev, .device = &x11->pointer_dev,
.time_msec = ev->time, .time_msec = ev->time,
.x_mm = ev->event_x, .x = (double)ev->event_x / output->wlr_output.width,
.y_mm = ev->event_y, .y = (double)ev->event_y / output->wlr_output.height,
.width_mm = output->wlr_output.width,
.height_mm = output->wlr_output.height,
}; };
wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs);
@ -140,10 +138,8 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
struct wlr_event_pointer_motion_absolute abs = { struct wlr_event_pointer_motion_absolute abs = {
.device = &x11->pointer_dev, .device = &x11->pointer_dev,
.time_msec = x11->time, .time_msec = x11->time,
.x_mm = pointer->root_x, .x = (double)pointer->root_x / output->wlr_output.width,
.y_mm = pointer->root_y, .y = (double)pointer->root_y / output->wlr_output.height,
.width_mm = output->wlr_output.width,
.height_mm = output->wlr_output.height,
}; };
wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs);

View File

@ -118,8 +118,7 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
struct sample_cursor *cursor = struct sample_cursor *cursor =
wl_container_of(listener, cursor, cursor_motion_absolute); wl_container_of(listener, cursor, cursor_motion_absolute);
struct wlr_event_pointer_motion_absolute *event = data; struct wlr_event_pointer_motion_absolute *event = data;
wlr_cursor_warp_absolute(cursor->cursor, event->device, wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
} }
static void handle_input_add(struct compositor_state *state, static void handle_input_add(struct compositor_state *state,

View File

@ -154,8 +154,8 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
wl_container_of(listener, sample, cursor_motion_absolute); wl_container_of(listener, sample, cursor_motion_absolute);
struct wlr_event_pointer_motion_absolute *event = data; struct wlr_event_pointer_motion_absolute *event = data;
sample->cur_x = event->x_mm; sample->cur_x = event->x;
sample->cur_y = event->y_mm; sample->cur_y = event->y;
wlr_cursor_warp_absolute(sample->cursor, event->device, sample->cur_x, wlr_cursor_warp_absolute(sample->cursor, event->device, sample->cur_x,
sample->cur_y); sample->cur_y);
@ -217,8 +217,8 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
struct wlr_event_touch_down *event = data; struct wlr_event_touch_down *event = data;
struct touch_point *point = calloc(1, sizeof(struct touch_point)); struct touch_point *point = calloc(1, sizeof(struct touch_point));
point->touch_id = event->touch_id; point->touch_id = event->touch_id;
point->x = event->x_mm / event->width_mm; point->x = event->x;
point->y = event->y_mm / event->height_mm; point->y = event->y;
wl_list_insert(&sample->touch_points, &point->link); wl_list_insert(&sample->touch_points, &point->link);
warp_to_touch(sample, event->device); warp_to_touch(sample, event->device);
@ -232,8 +232,8 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
struct touch_point *point; struct touch_point *point;
wl_list_for_each(point, &sample->touch_points, link) { wl_list_for_each(point, &sample->touch_points, link) {
if (point->touch_id == event->touch_id) { if (point->touch_id == event->touch_id) {
point->x = event->x_mm / event->width_mm; point->x = event->x;
point->y = event->y_mm / event->height_mm; point->y = event->y;
break; break;
} }
} }
@ -251,8 +251,8 @@ static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) {
struct wlr_event_tablet_tool_axis *event = data; struct wlr_event_tablet_tool_axis *event = data;
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
wlr_cursor_warp_absolute(sample->cursor, event->device, wlr_cursor_warp_absolute(sample->cursor,
event->x_mm / event->width_mm, event->y_mm / event->height_mm); event->device, event->x, event->y);
} }
} }

View File

@ -108,8 +108,8 @@ static void pointer_motion_absolute_notify(struct wl_listener *listener, void *d
struct wlr_event_pointer_motion_absolute *event = data; struct wlr_event_pointer_motion_absolute *event = data;
struct pointer_state *pstate = wl_container_of(listener, pstate, motion_absolute); struct pointer_state *pstate = wl_container_of(listener, pstate, motion_absolute);
if (pstate->compositor->pointer_motion_absolute_cb) { if (pstate->compositor->pointer_motion_absolute_cb) {
pstate->compositor->pointer_motion_absolute_cb(pstate, pstate->compositor->pointer_motion_absolute_cb(
event->x_mm, event->y_mm); pstate, event->x, event->y);
} }
} }
@ -167,8 +167,8 @@ static void touch_down_notify(struct wl_listener *listener, void *data) {
struct wlr_event_touch_down *event = data; struct wlr_event_touch_down *event = data;
struct touch_state *tstate = wl_container_of(listener, tstate, down); struct touch_state *tstate = wl_container_of(listener, tstate, down);
if (tstate->compositor->touch_down_cb) { if (tstate->compositor->touch_down_cb) {
tstate->compositor->touch_down_cb(tstate, event->touch_id, tstate->compositor->touch_down_cb(tstate,
event->x_mm, event->y_mm, event->width_mm, event->height_mm); event->touch_id, event->x, event->y);
} }
} }
@ -176,8 +176,8 @@ static void touch_motion_notify(struct wl_listener *listener, void *data) {
struct wlr_event_touch_motion *event = data; struct wlr_event_touch_motion *event = data;
struct touch_state *tstate = wl_container_of(listener, tstate, motion); struct touch_state *tstate = wl_container_of(listener, tstate, motion);
if (tstate->compositor->touch_motion_cb) { if (tstate->compositor->touch_motion_cb) {
tstate->compositor->touch_motion_cb(tstate, event->touch_id, tstate->compositor->touch_motion_cb(tstate,
event->x_mm, event->y_mm, event->width_mm, event->height_mm); event->touch_id, event->x, event->y);
} }
} }

View File

@ -102,10 +102,10 @@ struct compositor_state {
enum wlr_axis_source source, enum wlr_axis_source source,
enum wlr_axis_orientation orientation, enum wlr_axis_orientation orientation,
double delta); double delta);
void (*touch_down_cb)(struct touch_state *s, int32_t touch_id, void (*touch_down_cb)(struct touch_state *s,
double x, double y, double width, double height); int32_t touch_id, double x, double y);
void (*touch_motion_cb)(struct touch_state *s, int32_t touch_id, void (*touch_motion_cb)(struct touch_state *s,
double x, double y, double width, double height); int32_t touch_id, double x, double y);
void (*touch_up_cb)(struct touch_state *s, int32_t touch_id); void (*touch_up_cb)(struct touch_state *s, int32_t touch_id);
void (*touch_cancel_cb)(struct touch_state *s, int32_t touch_id); void (*touch_cancel_cb)(struct touch_state *s, int32_t touch_id);
void (*tool_axis_cb)(struct tablet_tool_state *s, void (*tool_axis_cb)(struct tablet_tool_state *s,

View File

@ -28,7 +28,7 @@ struct sample_state {
bool proximity, tap, button; bool proximity, tap, button;
double distance; double distance;
double pressure; double pressure;
double x_mm, y_mm; double x, y;
double x_tilt, y_tilt; double x_tilt, y_tilt;
double width_mm, height_mm; double width_mm, height_mm;
double ring; double ring;
@ -69,8 +69,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
if (sample->proximity) { if (sample->proximity) {
struct wlr_box box = { struct wlr_box box = {
.x = sample->x_mm * scale - 8 * (sample->pressure + 1) + left, .x = (sample->x * pad_width) - 8 * (sample->pressure + 1) + left,
.y = sample->y_mm * scale - 8 * (sample->pressure + 1) + top, .y = (sample->y * pad_height) - 8 * (sample->pressure + 1) + top,
.width = 16 * (sample->pressure + 1), .width = 16 * (sample->pressure + 1),
.height = 16 * (sample->pressure + 1), .height = 16 * (sample->pressure + 1),
}; };
@ -94,13 +94,11 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
static void handle_tool_axis(struct tablet_tool_state *tstate, static void handle_tool_axis(struct tablet_tool_state *tstate,
struct wlr_event_tablet_tool_axis *event) { struct wlr_event_tablet_tool_axis *event) {
struct sample_state *sample = tstate->compositor->data; struct sample_state *sample = tstate->compositor->data;
sample->width_mm = event->width_mm;
sample->height_mm = event->height_mm;
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
sample->x_mm = event->x_mm; sample->x = event->x;
} }
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
sample->y_mm = event->y_mm; sample->y = event->y;
} }
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE)) { if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE)) {
sample->distance = event->distance; sample->distance = event->distance;
@ -164,13 +162,24 @@ static void handle_pad_ring(struct tablet_pad_state *pstate,
} }
} }
static void handle_input_add(struct compositor_state *cstate,
struct wlr_input_device *inputdev) {
struct sample_state *sample = cstate->data;
if (inputdev->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
sample->width_mm = inputdev->width_mm == 0 ?
20 : inputdev->width_mm;
sample->height_mm = inputdev->height_mm == 0 ?
10 : inputdev->height_mm;
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
wlr_log_init(L_DEBUG, NULL); wlr_log_init(L_DEBUG, NULL);
struct sample_state state = { struct sample_state state = {
.tool_color = { 1, 1, 1, 1 }, .tool_color = { 1, 1, 1, 1 },
.pad_color = { 0.5, 0.5, 0.5, 1.0 } .pad_color = { 0.5, 0.5, 0.5, 1.0 }
}; };
struct compositor_state compositor = { 0, struct compositor_state compositor = {
.data = &state, .data = &state,
.output_frame_cb = handle_output_frame, .output_frame_cb = handle_output_frame,
.tool_axis_cb = handle_tool_axis, .tool_axis_cb = handle_tool_axis,
@ -178,6 +187,8 @@ int main(int argc, char *argv[]) {
.tool_button_cb = handle_tool_button, .tool_button_cb = handle_tool_button,
.pad_button_cb = handle_pad_button, .pad_button_cb = handle_pad_button,
.pad_ring_cb = handle_pad_ring, .pad_ring_cb = handle_pad_ring,
.input_add_cb = handle_input_add,
0
}; };
compositor_init(&compositor); compositor_init(&compositor);

View File

@ -60,13 +60,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
wlr_output_swap_buffers(wlr_output, NULL, NULL); wlr_output_swap_buffers(wlr_output, NULL, NULL);
} }
static void handle_touch_down(struct touch_state *tstate, int32_t touch_id, static void handle_touch_down(struct touch_state *tstate,
double x, double y, double width, double height) { int32_t touch_id, double x, double y) {
struct sample_state *sample = tstate->compositor->data; struct sample_state *sample = tstate->compositor->data;
struct touch_point *point = calloc(1, sizeof(struct touch_point)); struct touch_point *point = calloc(1, sizeof(struct touch_point));
point->touch_id = touch_id; point->touch_id = touch_id;
point->x = x / width; point->x = x;
point->y = y / height; point->y = y;
wl_list_insert(&sample->touch_points, &point->link); wl_list_insert(&sample->touch_points, &point->link);
} }
@ -81,14 +81,14 @@ static void handle_touch_up(struct touch_state *tstate, int32_t touch_id) {
} }
} }
static void handle_touch_motion(struct touch_state *tstate, int32_t touch_id, static void handle_touch_motion(struct touch_state *tstate,
double x, double y, double width, double height) { int32_t touch_id, double x, double y) {
struct sample_state *sample = tstate->compositor->data; struct sample_state *sample = tstate->compositor->data;
struct touch_point *point; struct touch_point *point;
wl_list_for_each(point, &sample->touch_points, link) { wl_list_for_each(point, &sample->touch_points, link) {
if (point->touch_id == touch_id) { if (point->touch_id == touch_id) {
point->x = x / width; point->x = x;
point->y = y / height; point->y = y;
break; break;
} }
} }

View File

@ -73,7 +73,7 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
double x, double y); double x, double y);
void wlr_cursor_warp_absolute(struct wlr_cursor *cur, void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
struct wlr_input_device *dev, double x_mm, double y_mm); struct wlr_input_device *dev, double x, double y);
/** /**
* Move the cursor in the direction of the given x and y coordinates. * Move the cursor in the direction of the given x and y coordinates.
@ -155,7 +155,7 @@ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur,
* Convert absolute coordinates to layout coordinates for the device. * Convert absolute coordinates to layout coordinates for the device.
*/ */
bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur, bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur,
struct wlr_input_device *device, double x_mm, double y_mm, struct wlr_input_device *device, double x, double y,
double width_mm, double height_mm, double *lx, double *ly); double *lx, double *ly);
#endif #endif

View File

@ -29,6 +29,8 @@ struct wlr_input_device {
enum wlr_input_device_type type; enum wlr_input_device_type type;
int vendor, product; int vendor, product;
char *name; char *name;
// Or 0 if not applicable to this device
double width_mm, height_mm;
/* wlr_input_device.type determines which of these is valid */ /* wlr_input_device.type determines which of these is valid */
union { union {

View File

@ -29,8 +29,8 @@ struct wlr_event_pointer_motion {
struct wlr_event_pointer_motion_absolute { struct wlr_event_pointer_motion_absolute {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_msec; uint32_t time_msec;
double x_mm, y_mm; // From 0..1
double width_mm, height_mm; double x, y;
}; };
struct wlr_event_pointer_button { struct wlr_event_pointer_button {

View File

@ -36,8 +36,8 @@ struct wlr_event_tablet_tool_axis {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_msec; uint32_t time_msec;
uint32_t updated_axes; uint32_t updated_axes;
double x_mm, y_mm; // From 0..1
double width_mm, height_mm; double x, y;
double pressure; double pressure;
double distance; double distance;
double tilt_x, tilt_y; double tilt_x, tilt_y;
@ -54,8 +54,8 @@ enum wlr_tablet_tool_proximity_state {
struct wlr_event_tablet_tool_proximity { struct wlr_event_tablet_tool_proximity {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_msec; uint32_t time_msec;
double x_mm, y_mm; // From 0..1
double width_mm, height_mm; double x, y;
enum wlr_tablet_tool_proximity_state state; enum wlr_tablet_tool_proximity_state state;
}; };
@ -67,8 +67,8 @@ enum wlr_tablet_tool_tip_state {
struct wlr_event_tablet_tool_tip { struct wlr_event_tablet_tool_tip {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_msec; uint32_t time_msec;
double x_mm, y_mm; // From 0..1
double width_mm, height_mm; double x, y;
enum wlr_tablet_tool_tip_state state; enum wlr_tablet_tool_tip_state state;
}; };

View File

@ -23,8 +23,8 @@ struct wlr_event_touch_down {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_msec; uint32_t time_msec;
int32_t touch_id; int32_t touch_id;
double x_mm, y_mm; // From 0..1
double width_mm, height_mm; double x, y;
}; };
struct wlr_event_touch_up { struct wlr_event_touch_up {
@ -37,8 +37,8 @@ struct wlr_event_touch_motion {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_msec; uint32_t time_msec;
int32_t touch_id; int32_t touch_id;
double x_mm, y_mm; // From 0..1
double width_mm, height_mm; double x, y;
}; };
struct wlr_event_touch_cancel { struct wlr_event_touch_cancel {

View File

@ -288,8 +288,8 @@ void roots_cursor_handle_motion(struct roots_cursor *cursor,
void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
struct wlr_event_pointer_motion_absolute *event) { struct wlr_event_pointer_motion_absolute *event) {
wlr_cursor_warp_absolute(cursor->cursor, event->device, wlr_cursor_warp_absolute(cursor->cursor,
event->x_mm / event->width_mm, event->y_mm / event->height_mm); event->device, event->x, event->y);
roots_cursor_update_position(cursor, event->time_msec); roots_cursor_update_position(cursor, event->time_msec);
} }
@ -310,10 +310,8 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct roots_desktop *desktop = cursor->seat->input->server->desktop;
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
double lx, ly; double lx, ly;
bool result = bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor,
wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, event->x, event->y, &lx, &ly);
event->device, event->x_mm, event->y_mm, event->width_mm,
event->height_mm, &lx, &ly);
if (!result) { if (!result) {
return; return;
} }
@ -365,8 +363,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
double lx, ly; double lx, ly;
bool result = bool result =
wlr_cursor_absolute_to_layout_coords(cursor->cursor, wlr_cursor_absolute_to_layout_coords(cursor->cursor,
event->device, event->x_mm, event->y_mm, event->width_mm, event->device, event->x, event->y, &lx, &ly);
event->height_mm, &lx, &ly);
if (!result) { if (!result) {
return; return;
} }
@ -395,15 +392,13 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
wlr_cursor_warp_absolute(cursor->cursor, event->device, wlr_cursor_warp_absolute(cursor->cursor, event->device,
event->x_mm / event->width_mm, event->y_mm / event->height_mm); event->x, event->y);
roots_cursor_update_position(cursor, event->time_msec); roots_cursor_update_position(cursor, event->time_msec);
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
wlr_cursor_warp_absolute(cursor->cursor, event->device, wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1);
event->x_mm / event->width_mm, -1);
roots_cursor_update_position(cursor, event->time_msec); roots_cursor_update_position(cursor, event->time_msec);
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
wlr_cursor_warp_absolute(cursor->cursor, event->device, wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y);
-1, event->y_mm / event->height_mm);
roots_cursor_update_position(cursor, event->time_msec); roots_cursor_update_position(cursor, event->time_msec);
} }
} }

View File

@ -254,7 +254,7 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
} }
void wlr_cursor_warp_absolute(struct wlr_cursor *cur, void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
struct wlr_input_device *dev, double x_mm, double y_mm) { struct wlr_input_device *dev, double x, double y) {
assert(cur->state->layout); assert(cur->state->layout);
struct wlr_box *mapping = get_mapping(cur, dev); struct wlr_box *mapping = get_mapping(cur, dev);
@ -262,8 +262,8 @@ void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
mapping = wlr_output_layout_get_box(cur->state->layout, NULL); mapping = wlr_output_layout_get_box(cur->state->layout, NULL);
} }
double x = x_mm > 0 ? mapping->width * x_mm + mapping->x : cur->x; x = x > 0 ? mapping->width * x + mapping->x : cur->x;
double y = y_mm > 0 ? mapping->height * y_mm + mapping->y : cur->y; y = y > 0 ? mapping->height * y + mapping->y : cur->y;
wlr_cursor_warp_unchecked(cur, x, y); wlr_cursor_warp_unchecked(cur, x, y);
} }
@ -640,19 +640,15 @@ void wlr_cursor_map_input_to_region(struct wlr_cursor *cur,
} }
bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur, bool wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur,
struct wlr_input_device *device, double x_mm, double y_mm, struct wlr_input_device *device, double x, double y,
double width_mm, double height_mm, double *lx, double *ly) { double *lx, double *ly) {
if (width_mm <= 0 || height_mm <= 0) {
return false;
}
struct wlr_box *mapping = get_mapping(cur, device); struct wlr_box *mapping = get_mapping(cur, device);
if (!mapping) { if (!mapping) {
mapping = wlr_output_layout_get_box(cur->state->layout, NULL); mapping = wlr_output_layout_get_box(cur->state->layout, NULL);
} }
*lx = x_mm > 0 ? mapping->width * (x_mm / width_mm) + mapping->x : cur->x; *lx = x > 0 ? mapping->width * x + mapping->x : cur->x;
*ly = y_mm > 0 ? mapping->height * (y_mm / height_mm) + mapping->y : cur->y; *ly = y > 0 ? mapping->height * y + mapping->y : cur->y;
return true; return true;
} }