From a35a5786b0e40cb1ffa87344d3cb21dff9fd99f4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 10:46:50 -0400 Subject: Remove width_mm from wlr_pointer events --- backend/libinput/pointer.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'backend/libinput') diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 8a31d312..9ccda634 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -53,9 +53,8 @@ void handle_pointer_motion_abs(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); - wlr_event.x_mm = libinput_event_pointer_get_absolute_x(pevent); - wlr_event.y_mm = libinput_event_pointer_get_absolute_y(pevent); - libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); + wlr_event.x = libinput_event_pointer_get_absolute_x_transformed(pevent, 1); + wlr_event.y = libinput_event_pointer_get_absolute_y_transformed(pevent, 1); wlr_signal_emit_safe(&wlr_dev->pointer->events.motion_absolute, &wlr_event); } -- cgit v1.2.3 From 324b9d910dc237151fd71c01bef015d0080be191 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 11:04:40 -0400 Subject: Remove width_mm from wlr_touch events --- backend/drm/legacy.c | 2 +- backend/libinput/touch.c | 10 ++++------ examples/pointer.c | 8 ++++---- examples/support/shared.c | 8 ++++---- examples/support/shared.h | 8 ++++---- examples/touch.c | 16 ++++++++-------- include/wlr/types/wlr_cursor.h | 2 +- include/wlr/types/wlr_touch.h | 8 ++++---- rootston/cursor.c | 9 +++------ types/wlr_cursor.c | 12 ++++-------- 10 files changed, 37 insertions(+), 46 deletions(-) (limited to 'backend/libinput') diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c index 88a01b89..7c45ae21 100644 --- a/backend/drm/legacy.c +++ b/backend/drm/legacy.c @@ -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, 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; } diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 2b87f9cd..419c11ea 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -35,9 +35,8 @@ void handle_touch_down(struct libinput_event *event, wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); wlr_event.touch_id = libinput_event_touch_get_slot(tevent); - wlr_event.x_mm = libinput_event_touch_get_x(tevent); - wlr_event.y_mm = libinput_event_touch_get_y(tevent); - libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); + wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1); + wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1); 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 = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); wlr_event.touch_id = libinput_event_touch_get_slot(tevent); - wlr_event.x_mm = libinput_event_touch_get_x(tevent); - wlr_event.y_mm = libinput_event_touch_get_y(tevent); - libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); + wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1); + wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1); wlr_signal_emit_safe(&wlr_dev->touch->events.motion, &wlr_event); } diff --git a/examples/pointer.c b/examples/pointer.c index 12312092..2c598b9a 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -217,8 +217,8 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { struct wlr_event_touch_down *event = data; struct touch_point *point = calloc(1, sizeof(struct touch_point)); point->touch_id = event->touch_id; - point->x = event->x_mm / event->width_mm; - point->y = event->y_mm / event->height_mm; + point->x = event->x; + point->y = event->y; wl_list_insert(&sample->touch_points, &point->link); 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; wl_list_for_each(point, &sample->touch_points, link) { if (point->touch_id == event->touch_id) { - point->x = event->x_mm / event->width_mm; - point->y = event->y_mm / event->height_mm; + point->x = event->x; + point->y = event->y; break; } } diff --git a/examples/support/shared.c b/examples/support/shared.c index c6460374..02b324f5 100644 --- a/examples/support/shared.c +++ b/examples/support/shared.c @@ -167,8 +167,8 @@ static void touch_down_notify(struct wl_listener *listener, void *data) { struct wlr_event_touch_down *event = data; struct touch_state *tstate = wl_container_of(listener, tstate, down); if (tstate->compositor->touch_down_cb) { - tstate->compositor->touch_down_cb(tstate, event->touch_id, - event->x_mm, event->y_mm, event->width_mm, event->height_mm); + tstate->compositor->touch_down_cb(tstate, + 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 touch_state *tstate = wl_container_of(listener, tstate, motion); if (tstate->compositor->touch_motion_cb) { - tstate->compositor->touch_motion_cb(tstate, event->touch_id, - event->x_mm, event->y_mm, event->width_mm, event->height_mm); + tstate->compositor->touch_motion_cb(tstate, + event->touch_id, event->x, event->y); } } diff --git a/examples/support/shared.h b/examples/support/shared.h index d00e75b3..2079a9ef 100644 --- a/examples/support/shared.h +++ b/examples/support/shared.h @@ -102,10 +102,10 @@ struct compositor_state { enum wlr_axis_source source, enum wlr_axis_orientation orientation, double delta); - void (*touch_down_cb)(struct touch_state *s, int32_t touch_id, - double x, double y, double width, double height); - void (*touch_motion_cb)(struct touch_state *s, int32_t touch_id, - double x, double y, double width, double height); + void (*touch_down_cb)(struct touch_state *s, + int32_t touch_id, double x, double y); + void (*touch_motion_cb)(struct touch_state *s, + int32_t touch_id, double x, double y); 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 (*tool_axis_cb)(struct tablet_tool_state *s, diff --git a/examples/touch.c b/examples/touch.c index 7639165c..e9dcf29c 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -60,13 +60,13 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts wlr_output_swap_buffers(wlr_output, NULL, NULL); } -static void handle_touch_down(struct touch_state *tstate, int32_t touch_id, - double x, double y, double width, double height) { +static void handle_touch_down(struct touch_state *tstate, + int32_t touch_id, double x, double y) { struct sample_state *sample = tstate->compositor->data; struct touch_point *point = calloc(1, sizeof(struct touch_point)); point->touch_id = touch_id; - point->x = x / width; - point->y = y / height; + point->x = x; + point->y = y; 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, - double x, double y, double width, double height) { +static void handle_touch_motion(struct touch_state *tstate, + int32_t touch_id, double x, double y) { struct sample_state *sample = tstate->compositor->data; struct touch_point *point; wl_list_for_each(point, &sample->touch_points, link) { if (point->touch_id == touch_id) { - point->x = x / width; - point->y = y / height; + point->x = x; + point->y = y; break; } } diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index ffe149c9..fc541271 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -156,6 +156,6 @@ void wlr_cursor_map_input_to_region(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, - double width_mm, double height_mm, double *lx, double *ly); + double *lx, double *ly); #endif diff --git a/include/wlr/types/wlr_touch.h b/include/wlr/types/wlr_touch.h index 8ea293eb..70070f84 100644 --- a/include/wlr/types/wlr_touch.h +++ b/include/wlr/types/wlr_touch.h @@ -23,8 +23,8 @@ struct wlr_event_touch_down { struct wlr_input_device *device; uint32_t time_msec; int32_t touch_id; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; }; struct wlr_event_touch_up { @@ -37,8 +37,8 @@ struct wlr_event_touch_motion { struct wlr_input_device *device; uint32_t time_msec; int32_t touch_id; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; }; struct wlr_event_touch_cancel { diff --git a/rootston/cursor.c b/rootston/cursor.c index c1fd7d31..786dff0e 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -310,10 +310,8 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct wlr_surface *surface = NULL; double lx, ly; - bool result = - wlr_cursor_absolute_to_layout_coords(cursor->cursor, - event->device, event->x_mm, event->y_mm, event->width_mm, - event->height_mm, &lx, &ly); + bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor, + event->device, event->x, event->y, &lx, &ly); if (!result) { return; } @@ -365,8 +363,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, double lx, ly; bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor, - event->device, event->x_mm, event->y_mm, event->width_mm, - event->height_mm, &lx, &ly); + event->device, event->x, event->y, &lx, &ly); if (!result) { return; } diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index ed1a67da..5142513b 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -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, - struct wlr_input_device *device, double x_mm, double y_mm, - double width_mm, double height_mm, double *lx, double *ly) { - if (width_mm <= 0 || height_mm <= 0) { - return false; - } - + struct wlr_input_device *device, double x, double y, + double *lx, double *ly) { struct wlr_box *mapping = get_mapping(cur, device); if (!mapping) { mapping = wlr_output_layout_get_box(cur->state->layout, NULL); } - *lx = x_mm > 0 ? mapping->width * (x_mm / width_mm) + mapping->x : cur->x; - *ly = y_mm > 0 ? mapping->height * (y_mm / height_mm) + mapping->y : cur->y; + *lx = x > 0 ? mapping->width * x + mapping->x : cur->x; + *ly = y > 0 ? mapping->height * y + mapping->y : cur->y; return true; } -- cgit v1.2.3 From ac219cbda6dc3122fcc7f1bfa89b7e8fbb03b8ce Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 28 Mar 2018 11:40:35 -0400 Subject: Remove width_mm from tablet events --- backend/libinput/events.c | 2 ++ backend/libinput/tablet_tool.c | 5 ++--- examples/pointer.c | 4 ++-- examples/tablet.c | 27 +++++++++++++++++++-------- include/wlr/types/wlr_input_device.h | 2 ++ include/wlr/types/wlr_tablet_tool.h | 12 ++++++------ rootston/cursor.c | 8 +++----- 7 files changed, 36 insertions(+), 24 deletions(-) (limited to 'backend/libinput') diff --git a/backend/libinput/events.c b/backend/libinput/events.c index d92de830..da7b2be4 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -46,6 +46,8 @@ static struct wlr_input_device *allocate_device( return NULL; } 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); wlr_libinput_dev->handle = libinput_dev; libinput_device_ref(libinput_dev); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 27cf7c81..815c4daf 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -34,14 +34,13 @@ void handle_tablet_tool_axis(struct libinput_event *event, wlr_event.device = wlr_dev; wlr_event.time_msec = 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)) { 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)) { 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)) { wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE; diff --git a/examples/pointer.c b/examples/pointer.c index 2c598b9a..aaaad841 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -251,8 +251,8 @@ static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_axis *event = data; if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { - wlr_cursor_warp_absolute(sample->cursor, event->device, - event->x_mm / event->width_mm, event->y_mm / event->height_mm); + wlr_cursor_warp_absolute(sample->cursor, + event->device, event->x, event->y); } } diff --git a/examples/tablet.c b/examples/tablet.c index 9379fac3..be428f86 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -28,7 +28,7 @@ struct sample_state { bool proximity, tap, button; double distance; double pressure; - double x_mm, y_mm; + double x, y; double x_tilt, y_tilt; double width_mm, height_mm; double ring; @@ -69,8 +69,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts if (sample->proximity) { struct wlr_box box = { - .x = sample->x_mm * scale - 8 * (sample->pressure + 1) + left, - .y = sample->y_mm * scale - 8 * (sample->pressure + 1) + top, + .x = (sample->x * pad_width) - 8 * (sample->pressure + 1) + left, + .y = (sample->y * pad_height) - 8 * (sample->pressure + 1) + top, .width = 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, struct wlr_event_tablet_tool_axis *event) { 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)) { - sample->x_mm = event->x_mm; + sample->x = event->x; } 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)) { 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[]) { wlr_log_init(L_DEBUG, NULL); struct sample_state state = { .tool_color = { 1, 1, 1, 1 }, .pad_color = { 0.5, 0.5, 0.5, 1.0 } }; - struct compositor_state compositor = { 0, + struct compositor_state compositor = { .data = &state, .output_frame_cb = handle_output_frame, .tool_axis_cb = handle_tool_axis, @@ -178,6 +187,8 @@ int main(int argc, char *argv[]) { .tool_button_cb = handle_tool_button, .pad_button_cb = handle_pad_button, .pad_ring_cb = handle_pad_ring, + .input_add_cb = handle_input_add, + 0 }; compositor_init(&compositor); diff --git a/include/wlr/types/wlr_input_device.h b/include/wlr/types/wlr_input_device.h index 6d8e3631..d65172c1 100644 --- a/include/wlr/types/wlr_input_device.h +++ b/include/wlr/types/wlr_input_device.h @@ -29,6 +29,8 @@ struct wlr_input_device { enum wlr_input_device_type type; int vendor, product; 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 */ union { diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index 59e49ef8..22bf2649 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -36,8 +36,8 @@ struct wlr_event_tablet_tool_axis { struct wlr_input_device *device; uint32_t time_msec; uint32_t updated_axes; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; double pressure; double distance; double tilt_x, tilt_y; @@ -54,8 +54,8 @@ enum wlr_tablet_tool_proximity_state { struct wlr_event_tablet_tool_proximity { struct wlr_input_device *device; uint32_t time_msec; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; 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_input_device *device; uint32_t time_msec; - double x_mm, y_mm; - double width_mm, height_mm; + // From 0..1 + double x, y; enum wlr_tablet_tool_tip_state state; }; diff --git a/rootston/cursor.c b/rootston/cursor.c index 786dff0e..a5953e4a 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -392,15 +392,13 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor, 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_mm / event->width_mm, event->y_mm / event->height_mm); + event->x, event->y); roots_cursor_update_position(cursor, event->time_msec); } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { - wlr_cursor_warp_absolute(cursor->cursor, event->device, - event->x_mm / event->width_mm, -1); + wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1); roots_cursor_update_position(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_mm / event->height_mm); + wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y); roots_cursor_update_position(cursor, event->time_msec); } } -- cgit v1.2.3