From e3d47376dc9a7ffef3823cb2b4db78296e3cf717 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 20 Aug 2017 16:02:39 -0400 Subject: add wlr_cursor basic implementation --- backend/drm/drm.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'backend') diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 332926b9..5b24e05f 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -598,6 +598,8 @@ static bool wlr_drm_output_set_cursor(struct wlr_output *_output, wlr_matrix_texture(plane->matrix, plane->width, plane->height, output->output.transform ^ WL_OUTPUT_TRANSFORM_FLIPPED_180); + // TODO the image needs to be rotated depending on the output rotation + plane->wlr_rend = wlr_gles2_renderer_create(&backend->backend); if (!plane->wlr_rend) { return false; @@ -651,6 +653,31 @@ static bool wlr_drm_output_move_cursor(struct wlr_output *_output, struct wlr_drm_output *output = (struct wlr_drm_output *)_output; struct wlr_drm_backend *backend = wl_container_of(output->renderer, backend, renderer); + + int width, height, tmp; + wlr_output_effective_resolution(_output, &width, &height); + + switch (_output->transform) { + case WL_OUTPUT_TRANSFORM_NORMAL: + // nothing to do + break; + case WL_OUTPUT_TRANSFORM_270: + tmp = x; + x = y; + y = -(tmp - width); + break; + case WL_OUTPUT_TRANSFORM_90: + tmp = x; + x = -(y - height); + y = tmp; + break; + default: + // TODO other transformations + wlr_log(L_ERROR, "TODO: handle surface to crtc for transformation = %d", + _output->transform); + break; + } + return backend->iface->crtc_move_cursor(backend, output->crtc, x, y); } -- cgit v1.2.3 From 98f4cdfccb7d2ace2929bca45f0479b3472b96ac Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Thu, 24 Aug 2017 14:35:55 -0400 Subject: implement wlr_cursor_map_input_to_output --- backend/libinput/pointer.c | 4 +++ backend/wayland/wl_seat.c | 3 ++ examples/pointer.c | 33 ++++++++++++++++++++- include/wlr/types/wlr_cursor.h | 12 ++++++-- include/wlr/types/wlr_pointer.h | 4 +++ types/wlr_cursor.c | 63 +++++++++++++++++++++++++++++++++-------- 6 files changed, 104 insertions(+), 15 deletions(-) (limited to 'backend') diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 8bda205d..005c9516 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -30,6 +30,7 @@ void handle_pointer_motion(struct libinput_event *event, struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); struct wlr_event_pointer_motion wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_pointer_get_time(pevent); wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent); wlr_event.delta_x = libinput_event_pointer_get_dx(pevent); @@ -48,6 +49,7 @@ void handle_pointer_motion_abs(struct libinput_event *event, struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); struct wlr_event_pointer_motion_absolute wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_pointer_get_time(pevent); wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent); wlr_event.x_mm = libinput_event_pointer_get_absolute_x(pevent); @@ -67,6 +69,7 @@ void handle_pointer_button(struct libinput_event *event, struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); struct wlr_event_pointer_button wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_pointer_get_time(pevent); wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent); wlr_event.button = libinput_event_pointer_get_button(pevent); @@ -92,6 +95,7 @@ void handle_pointer_axis(struct libinput_event *event, struct libinput_event_pointer *pevent = libinput_event_get_pointer_event(event); struct wlr_event_pointer_axis wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_pointer_get_time(pevent); wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent); switch (libinput_event_pointer_get_axis_source(pevent)) { diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index a4cc0ba5..3e6982a0 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -51,6 +51,7 @@ 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, &width, &height); struct wlr_event_pointer_motion_absolute wlr_event; + wlr_event.device = dev; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; wlr_event.width_mm = width; @@ -66,6 +67,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, assert(dev && dev->pointer); struct wlr_event_pointer_button wlr_event; + wlr_event.device = dev; wlr_event.button = button; wlr_event.state = state; wlr_event.time_sec = time / 1000; @@ -80,6 +82,7 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, struct wlr_wl_pointer *wlr_wl_pointer = (struct wlr_wl_pointer *)dev->pointer; struct wlr_event_pointer_axis wlr_event; + wlr_event.device = dev; wlr_event.delta = value; wlr_event.orientation = axis; wlr_event.time_sec = time / 1000; diff --git a/examples/pointer.c b/examples/pointer.c index 0092c633..95e28bb2 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -24,6 +24,11 @@ #include "shared.h" #include "cat.h" +struct sample_input_device { + struct wlr_input_device *device; + struct wl_list link; +}; + struct sample_state { struct compositor_state *compositor; struct example_config *config; @@ -33,6 +38,7 @@ struct sample_state { float default_color[4]; float clear_color[4]; struct wlr_output_layout *layout; + struct wl_list devices; struct wl_listener cursor_motion; struct wl_listener cursor_motion_absolute; @@ -63,6 +69,16 @@ static void handle_output_add(struct output_state *ostate) { sample->layout = configure_layout(sample->config, &ostate->compositor->outputs); wlr_cursor_attach_output_layout(sample->cursor, sample->layout); + /* + // TODO configuration + if (strcmp("DP-1", ostate->output->name) == 0) { + struct sample_input_device *dev; + wl_list_for_each(dev, &sample->devices, link) { + wlr_cursor_map_input_to_output(sample->cursor, dev->device, ostate->output); + } + } + */ + if (!wlr_output_set_cursor(wlr_output, image->buffer, image->width, image->width, image->height)) { wlr_log(L_DEBUG, "Failed to set hardware cursor"); @@ -94,6 +110,20 @@ static void handle_input_add(struct compositor_state *state, struct // TODO handle other input devices if (device->type == WLR_INPUT_DEVICE_POINTER) { + struct sample_input_device *s_device = calloc(1, sizeof(struct sample_input_device)); + s_device->device = device; + wl_list_insert(&sample->devices, &s_device->link); + + /* + // TODO configuration + struct output_state *ostate; + wl_list_for_each(ostate, &sample->compositor->outputs, link) { + if (strcmp(ostate->output->name, "DP-1") == 0) { + wlr_cursor_map_input_to_output(sample->cursor, device, ostate->output); + } + } + */ + wlr_cursor_attach_input_device(sample->cursor, device); } } @@ -101,7 +131,7 @@ static void handle_input_add(struct compositor_state *state, struct static void handle_cursor_motion(struct wl_listener *listener, void *data) { struct sample_state *sample = wl_container_of(listener, sample, cursor_motion); struct wlr_event_pointer_motion *event = data; - wlr_cursor_move(sample->cursor, event->delta_x, event->delta_y); + wlr_cursor_move(sample->cursor, event->device, event->delta_x, event->delta_y); } static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) { @@ -163,6 +193,7 @@ int main(int argc, char *argv[]) { state.config = parse_args(argc, argv); state.cursor = wlr_cursor_init(); + wl_list_init(&state.devices); wl_signal_add(&state.cursor->events.motion, &state.cursor_motion); state.cursor_motion.notify = handle_cursor_motion; diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index 380d8a6f..64a75e4f 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -32,14 +32,22 @@ void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur); * Warp the cursor to the given x and y in layout coordinates. If x and y are * out of the layout boundaries or constraints, no warp will happen. * + * `dev` may be passed to respect device mapping constraints. If `dev` is NULL, + * device mapping constraints will be ignored. + * * Returns true when the mouse warp was successful. */ -bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y); +bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev, + double x, double y); /** * Move the cursor in the direction of the given x and y coordinates. + * + * `dev` may be passed to respect device mapping constraints. If `dev` is NULL, + * device mapping constraints will be ignored. */ -void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y); +void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev, + double delta_x, double delta_y); /** * Attaches this input device to this cursor. The input device must be one of: diff --git a/include/wlr/types/wlr_pointer.h b/include/wlr/types/wlr_pointer.h index 13a2d045..9153963a 100644 --- a/include/wlr/types/wlr_pointer.h +++ b/include/wlr/types/wlr_pointer.h @@ -20,12 +20,14 @@ struct wlr_pointer { }; struct wlr_event_pointer_motion { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; double delta_x, delta_y; }; struct wlr_event_pointer_motion_absolute { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; double x_mm, y_mm; @@ -33,6 +35,7 @@ struct wlr_event_pointer_motion_absolute { }; struct wlr_event_pointer_button { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; uint32_t button; @@ -52,6 +55,7 @@ enum wlr_axis_orientation { }; struct wlr_event_pointer_axis { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; enum wlr_axis_source source; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index affdcdeb..6917526e 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -11,6 +11,7 @@ struct wlr_cursor_device { struct wlr_cursor *cursor; struct wlr_input_device *device; struct wl_list link; + struct wlr_output *mapped_output; struct wl_listener motion; struct wl_listener motion_absolute; @@ -54,8 +55,8 @@ struct wlr_cursor *wlr_cursor_init() { } void wlr_cursor_destroy(struct wlr_cursor *cur) { - struct wlr_cursor_device *device, *tmp = NULL; - wl_list_for_each_safe(device, tmp, &cur->state->devices, link) { + struct wlr_cursor_device *device, *device_tmp = NULL; + wl_list_for_each_safe(device, device_tmp, &cur->state->devices, link) { wl_list_remove(&device->link); free(device); } @@ -67,18 +68,41 @@ void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur) { cur->state->xcursor = xcur; } -bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y) { +static struct wlr_cursor_device *get_cursor_device(struct wlr_cursor *cur, + struct wlr_input_device *device) { + struct wlr_cursor_device *c_device, *ret = NULL; + wl_list_for_each(c_device, &cur->state->devices, link) { + if (c_device->device == device) { + ret = c_device; + break; + } + } + + return ret; +} + +bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev, + double x, double y) { assert(cur->state->layout); struct wlr_output *output; output = wlr_output_layout_output_at(cur->state->layout, x, y); + struct wlr_output *mapped_output = NULL; + struct wlr_cursor_device *c_device = get_cursor_device(cur, dev); + + if (c_device && c_device->mapped_output) { + mapped_output = c_device->mapped_output; + } else { + mapped_output = cur->state->mapped_output; + } + if (!output) { return false; } - if (cur->state->mapped_output && - !wlr_output_layout_contains_point(cur->state->layout, - cur->state->mapped_output, x, y)) { + if (mapped_output && + !wlr_output_layout_contains_point(cur->state->layout, mapped_output, + x, y)) { return false; } @@ -106,8 +130,17 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y) { return true; } -void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) { +void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev, + double delta_x, double delta_y) { assert(cur->state->layout); + struct wlr_output *mapped_output = NULL; + struct wlr_cursor_device *c_device = get_cursor_device(cur, dev); + + if (c_device && c_device->mapped_output) { + mapped_output = c_device->mapped_output; + } else { + mapped_output = cur->state->mapped_output; + } double x = cur->x + delta_x; double y = cur->y + delta_y; @@ -115,15 +148,15 @@ void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) { struct wlr_output *output; output = wlr_output_layout_output_at(cur->state->layout, x, y); - if (!output || (cur->state->mapped_output && cur->state->mapped_output != output)) { + if (!output || (mapped_output && mapped_output != output)) { double closest_x, closest_y; - wlr_output_layout_closest_boundary(cur->state->layout, - cur->state->mapped_output, x, y, &closest_x, &closest_y); + wlr_output_layout_closest_boundary(cur->state->layout, mapped_output, x, + y, &closest_x, &closest_y); x = closest_x; y = closest_y; } - if (wlr_cursor_warp(cur, x, y)) { + if (wlr_cursor_warp(cur, dev, x, y)) { cur->x = x; cur->y = y; } @@ -230,5 +263,11 @@ void wlr_cursor_map_to_output(struct wlr_cursor *cur, void wlr_cursor_map_input_to_output(struct wlr_cursor *cur, struct wlr_input_device *dev, struct wlr_output *output) { - wlr_log(L_DEBUG, "TODO map input to output"); + struct wlr_cursor_device *c_device = get_cursor_device(cur, dev); + if (!c_device) { + wlr_log(L_ERROR, "Cannot map device \"%s\" to output (not found in this cursor)", dev->name); + return; + } + + c_device->mapped_output = output; } -- cgit v1.2.3 From c91469767631c84375678f3428a43c355d2c9742 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sun, 27 Aug 2017 11:44:55 -0400 Subject: add device to touch events --- backend/libinput/touch.c | 4 ++++ include/wlr/types/wlr_touch.h | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'backend') diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 9e08d028..2f300482 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -30,6 +30,7 @@ void handle_touch_down(struct libinput_event *event, struct libinput_event_touch *tevent = libinput_event_get_touch_event(event); struct wlr_event_touch_down wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_touch_get_time(tevent); wlr_event.time_usec = libinput_event_touch_get_time_usec(tevent); wlr_event.slot = libinput_event_touch_get_slot(tevent); @@ -50,6 +51,7 @@ void handle_touch_up(struct libinput_event *event, struct libinput_event_touch *tevent = libinput_event_get_touch_event(event); struct wlr_event_touch_up wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_touch_get_time(tevent); wlr_event.time_usec = libinput_event_touch_get_time_usec(tevent); wlr_event.slot = libinput_event_touch_get_slot(tevent); @@ -67,6 +69,7 @@ void handle_touch_motion(struct libinput_event *event, struct libinput_event_touch *tevent = libinput_event_get_touch_event(event); struct wlr_event_touch_motion wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_touch_get_time(tevent); wlr_event.time_usec = libinput_event_touch_get_time_usec(tevent); wlr_event.slot = libinput_event_touch_get_slot(tevent); @@ -87,6 +90,7 @@ void handle_touch_cancel(struct libinput_event *event, struct libinput_event_touch *tevent = libinput_event_get_touch_event(event); struct wlr_event_touch_cancel wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_touch_get_time(tevent); wlr_event.time_usec = libinput_event_touch_get_time_usec(tevent); wlr_event.slot = libinput_event_touch_get_slot(tevent); diff --git a/include/wlr/types/wlr_touch.h b/include/wlr/types/wlr_touch.h index 93069fcb..1a27cad3 100644 --- a/include/wlr/types/wlr_touch.h +++ b/include/wlr/types/wlr_touch.h @@ -19,6 +19,7 @@ struct wlr_touch { }; struct wlr_event_touch_down { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; int32_t slot; @@ -27,12 +28,14 @@ struct wlr_event_touch_down { }; struct wlr_event_touch_up { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; int32_t slot; }; struct wlr_event_touch_motion { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; int32_t slot; @@ -41,6 +44,7 @@ struct wlr_event_touch_motion { }; struct wlr_event_touch_cancel { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; int32_t slot; -- cgit v1.2.3 From df0ee7f25ff628360f38d87b8a74daaa2cc742a8 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 28 Aug 2017 08:42:39 -0400 Subject: implement tablet tool devices --- backend/libinput/tablet_tool.c | 4 +++ examples/pointer.c | 4 +-- include/wlr/types/wlr_cursor.h | 5 +++ include/wlr/types/wlr_tablet_tool.h | 4 +++ types/wlr_cursor.c | 61 ++++++++++++++++++++++++++++++++----- 5 files changed, 69 insertions(+), 9 deletions(-) (limited to 'backend') diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 8b3d34ed..472e8506 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -30,6 +30,7 @@ void handle_tablet_tool_axis(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_axis wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_tablet_tool_get_time(tevent); wlr_event.time_usec = libinput_event_tablet_tool_get_time_usec(tevent); libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); @@ -83,6 +84,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_proximity wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_tablet_tool_get_time(tevent); wlr_event.time_usec = libinput_event_tablet_tool_get_time_usec(tevent); switch (libinput_event_tablet_tool_get_proximity_state(tevent)) { @@ -109,6 +111,7 @@ void handle_tablet_tool_tip(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_tip wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_tablet_tool_get_time(tevent); wlr_event.time_usec = libinput_event_tablet_tool_get_time_usec(tevent); switch (libinput_event_tablet_tool_get_tip_state(tevent)) { @@ -134,6 +137,7 @@ void handle_tablet_tool_button(struct libinput_event *event, struct libinput_event_tablet_tool *tevent = libinput_event_get_tablet_tool_event(event); struct wlr_event_tablet_tool_button wlr_event = { 0 }; + wlr_event.device = wlr_dev; wlr_event.time_sec = libinput_event_tablet_tool_get_time(tevent); wlr_event.time_usec = libinput_event_tablet_tool_get_time_usec(tevent); wlr_event.button = libinput_event_tablet_tool_get_button(tevent); diff --git a/examples/pointer.c b/examples/pointer.c index 98b4735a..3863c0e8 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -175,9 +175,9 @@ static void handle_input_add(struct compositor_state *state, struct wlr_input_device *device) { struct sample_state *sample = state->data; - // TODO handle other input devices if (device->type == WLR_INPUT_DEVICE_POINTER || - device->type == WLR_INPUT_DEVICE_TOUCH) { + device->type == WLR_INPUT_DEVICE_TOUCH || + device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { struct sample_input_device *s_device; s_device = calloc(1, sizeof(struct sample_input_device)); s_device->device = device; diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index 4ba7b25f..35c2ff8e 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -25,6 +25,11 @@ struct wlr_cursor { struct wl_signal touch_down; struct wl_signal touch_motion; struct wl_signal touch_cancel; + + struct wl_signal tablet_tool_axis; + struct wl_signal tablet_tool_proximity; + struct wl_signal tablet_tool_tip; + struct wl_signal tablet_tool_button; } events; }; diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index dcb9c191..98fd82c0 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -32,6 +32,7 @@ enum wlr_tablet_tool_axes { }; struct wlr_event_tablet_tool_axis { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; uint32_t updated_axes; @@ -51,6 +52,7 @@ enum wlr_tablet_tool_proximity_state { }; struct wlr_event_tablet_tool_proximity { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; double x, y; @@ -64,6 +66,7 @@ enum wlr_tablet_tool_tip_state { }; struct wlr_event_tablet_tool_tip { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; double x, y; @@ -72,6 +75,7 @@ struct wlr_event_tablet_tool_tip { }; struct wlr_event_tablet_tool_button { + struct wlr_input_device *device; uint32_t time_sec; uint64_t time_usec; uint32_t button; diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index f183e64a..c62fba9b 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -24,6 +24,11 @@ struct wlr_cursor_device { struct wl_listener touch_up; struct wl_listener touch_motion; struct wl_listener touch_cancel; + + struct wl_listener tablet_tool_axis; + struct wl_listener tablet_tool_proximity; + struct wl_listener tablet_tool_tip; + struct wl_listener tablet_tool_button; }; struct wlr_cursor_state { @@ -63,6 +68,12 @@ struct wlr_cursor *wlr_cursor_init() { wl_signal_init(&cur->events.touch_motion); wl_signal_init(&cur->events.touch_cancel); + // tablet tool signals + wl_signal_init(&cur->events.tablet_tool_tip); + wl_signal_init(&cur->events.tablet_tool_axis); + wl_signal_init(&cur->events.tablet_tool_button); + wl_signal_init(&cur->events.tablet_tool_proximity); + cur->x = 100; cur->y = 100; @@ -279,6 +290,34 @@ static void handle_touch_cancel(struct wl_listener *listener, void *data) { wl_signal_emit(&device->cursor->events.touch_cancel, event); } +static void handle_tablet_tool_tip(struct wl_listener *listener, void *data) { + struct wlr_event_tablet_tool_tip *event = data; + struct wlr_cursor_device *device; + device = wl_container_of(listener, device, tablet_tool_tip); + wl_signal_emit(&device->cursor->events.tablet_tool_tip, event); +} + +static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) { + struct wlr_event_tablet_tool_axis *event = data; + struct wlr_cursor_device *device; + device = wl_container_of(listener, device, tablet_tool_axis); + wl_signal_emit(&device->cursor->events.tablet_tool_axis, event); +} + +static void handle_tablet_tool_button(struct wl_listener *listener, void *data) { + struct wlr_event_tablet_tool_button *event = data; + struct wlr_cursor_device *device; + device = wl_container_of(listener, device, tablet_tool_button); + wl_signal_emit(&device->cursor->events.tablet_tool_button, event); +} + +static void handle_tablet_tool_proximity(struct wl_listener *listener, void *data) { + struct wlr_event_tablet_tool_proximity *event = data; + struct wlr_cursor_device *device; + device = wl_container_of(listener, device, tablet_tool_proximity); + wl_signal_emit(&device->cursor->events.tablet_tool_proximity, event); +} + void wlr_cursor_attach_input_device(struct wlr_cursor *cur, struct wlr_input_device *dev) { if (dev->type != WLR_INPUT_DEVICE_POINTER && @@ -289,13 +328,6 @@ void wlr_cursor_attach_input_device(struct wlr_cursor *cur, return; } - // TODO support other device types - if (dev->type != WLR_INPUT_DEVICE_POINTER && - dev->type != WLR_INPUT_DEVICE_TOUCH) { - wlr_log(L_ERROR, "TODO: support tablet tool devices"); - return; - } - // make sure it is not already attached struct wlr_cursor_device *_dev; wl_list_for_each(_dev, &cur->state->devices, link) { @@ -340,6 +372,21 @@ void wlr_cursor_attach_input_device(struct wlr_cursor *cur, wl_signal_add(&dev->touch->events.cancel, &device->touch_cancel); device->touch_cancel.notify = handle_touch_cancel; + } else if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) { + wl_signal_add(&dev->tablet_tool->events.tip, &device->tablet_tool_tip); + device->tablet_tool_tip.notify = handle_tablet_tool_tip; + + wl_signal_add(&dev->tablet_tool->events.proximity, + &device->tablet_tool_proximity); + device->tablet_tool_proximity.notify = handle_tablet_tool_proximity; + + wl_signal_add(&dev->tablet_tool->events.axis, + &device->tablet_tool_axis); + device->tablet_tool_axis.notify = handle_tablet_tool_axis; + + wl_signal_add(&dev->tablet_tool->events.button, + &device->tablet_tool_button); + device->tablet_tool_button.notify = handle_tablet_tool_button; } wl_list_insert(&cur->state->devices, &device->link); -- cgit v1.2.3