Signed-off-by: Stephen Chandler Paul <thatsly...@gmail.com> --- src/compositor.h | 13 +++++++++ src/input.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++---- src/libinput-device.c | 57 ++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 5 deletions(-)
diff --git a/src/compositor.h b/src/compositor.h index 081be57..5d49c1d 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -50,6 +50,9 @@ extern "C" { const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) +#define WL_TABLET_AXIS_MAX 65535 +#define WL_TABLET_AXIS_MIN (-65535) + struct weston_transform { struct weston_matrix matrix; struct wl_list link; @@ -447,6 +450,7 @@ struct weston_tablet { enum wl_tablet_manager_tablet_type type; uint32_t vid; uint32_t pid; + enum wl_tablet_axis_flag supported_axes; struct weston_output *output; }; @@ -1134,6 +1138,15 @@ void notify_tablet_motion(struct weston_tablet *tablet, uint32_t time, wl_fixed_t x, wl_fixed_t y); void +notify_tablet_pressure(struct weston_tablet *tablet, uint32_t time, + wl_fixed_t pressure); +void +notify_tablet_distance(struct weston_tablet *tablet, uint32_t time, + wl_fixed_t distance); +void +notify_tablet_tilt(struct weston_tablet *tablet, uint32_t time, + wl_fixed_t tilt_x, wl_fixed_t tilt_y); +void notify_tablet_button(struct weston_tablet *tablet, uint32_t time, uint32_t button, enum wl_tablet_button_state state); void diff --git a/src/input.c b/src/input.c index baafd70..b7e7e0b 100644 --- a/src/input.c +++ b/src/input.c @@ -481,6 +481,48 @@ default_grab_tablet_motion(struct weston_tablet_grab *grab, } static void +default_grab_tablet_pressure(struct weston_tablet_grab *grab, + uint32_t time, wl_fixed_t pressure) +{ + struct weston_tablet *tablet = grab->tablet; + struct wl_resource *resource; + struct wl_list *resource_list = &tablet->focus_resource_list; + + if (!wl_list_empty(resource_list)) { + wl_resource_for_each(resource, resource_list) + wl_tablet_send_pressure(resource, time, pressure); + } +} + +static void +default_grab_tablet_distance(struct weston_tablet_grab *grab, + uint32_t time, wl_fixed_t distance) +{ + struct weston_tablet *tablet = grab->tablet; + struct wl_resource *resource; + struct wl_list *resource_list = &tablet->focus_resource_list; + + if (!wl_list_empty(resource_list)) { + wl_resource_for_each(resource, resource_list) + wl_tablet_send_distance(resource, time, distance); + } +} + +static void +default_grab_tablet_tilt(struct weston_tablet_grab *grab, + uint32_t time, wl_fixed_t tilt_x, wl_fixed_t tilt_y) +{ + struct weston_tablet *tablet = grab->tablet; + struct wl_resource *resource; + struct wl_list *resource_list = &tablet->focus_resource_list; + + if (!wl_list_empty(resource_list)) { + wl_resource_for_each(resource, resource_list) + wl_tablet_send_tilt(resource, time, tilt_x, tilt_y); + } +} + +static void default_grab_tablet_down(struct weston_tablet_grab *grab, uint32_t time) { struct weston_tablet *tablet = grab->tablet; @@ -547,9 +589,9 @@ static struct weston_tablet_grab_interface default_tablet_grab_interface = { default_grab_tablet_motion, default_grab_tablet_down, default_grab_tablet_up, - NULL, - NULL, - NULL, + default_grab_tablet_pressure, + default_grab_tablet_distance, + default_grab_tablet_tilt, default_grab_tablet_button, default_grab_tablet_frame, default_grab_tablet_cancel, @@ -1892,7 +1934,8 @@ notify_tablet_added(struct weston_tablet *tablet) wl_resource_set_user_data(tablet_resource, tablet); wl_tablet_manager_send_device_added(resource, tablet_resource, tablet->name, tablet->vid, - tablet->pid, 0, 0); + tablet->pid, 0, + tablet->supported_axes); } } @@ -1926,6 +1969,33 @@ notify_tablet_motion(struct weston_tablet *tablet, uint32_t time, } WL_EXPORT void +notify_tablet_pressure(struct weston_tablet *tablet, uint32_t time, + wl_fixed_t pressure) +{ + struct weston_tablet_grab *grab = tablet->grab; + + grab->interface->pressure(grab, time, pressure); +} + +WL_EXPORT void +notify_tablet_distance(struct weston_tablet *tablet, uint32_t time, + wl_fixed_t distance) +{ + struct weston_tablet_grab *grab = tablet->grab; + + grab->interface->distance(grab, time, distance); +} + +WL_EXPORT void +notify_tablet_tilt(struct weston_tablet *tablet, uint32_t time, + wl_fixed_t tilt_x, wl_fixed_t tilt_y) +{ + struct weston_tablet_grab *grab = tablet->grab; + + grab->interface->tilt(grab, time, tilt_x, tilt_y); +} + +WL_EXPORT void notify_tablet_frame(struct weston_tablet *tablet) { struct weston_tablet_grab *grab = tablet->grab; @@ -2437,7 +2507,8 @@ bind_tablet_manager(struct wl_client *client, void *data, uint32_t version, wl_tablet_manager_send_device_added(resource, tablet_resource, tablet->name, tablet->vid, - tablet->pid, 0, 0); + tablet->pid, 0, + tablet->supported_axes); } } diff --git a/src/libinput-device.c b/src/libinput-device.c index 6294466..040748d 100644 --- a/src/libinput-device.c +++ b/src/libinput-device.c @@ -313,6 +313,49 @@ handle_tablet_axis(struct libinput_device *libinput_device, wl_fixed_from_double(x), wl_fixed_from_double(y)); } + if (libinput_event_tablet_axis_has_changed(axis_event, + LIBINPUT_TABLET_AXIS_PRESSURE)) { + double pressure; + uint32_t time; + + time = libinput_event_tablet_get_time(axis_event); + pressure = libinput_event_tablet_get_axis_value( + axis_event, LIBINPUT_TABLET_AXIS_PRESSURE) + * WL_TABLET_AXIS_MAX; + + notify_tablet_pressure(tablet, time, + wl_fixed_from_double(pressure)); + } + if (libinput_event_tablet_axis_has_changed(axis_event, + LIBINPUT_TABLET_AXIS_DISTANCE)) { + double distance; + uint32_t time; + + time = libinput_event_tablet_get_time(axis_event); + distance = libinput_event_tablet_get_axis_value( + axis_event, LIBINPUT_TABLET_AXIS_DISTANCE) + * WL_TABLET_AXIS_MAX; + + notify_tablet_distance(tablet, time, + wl_fixed_from_double(distance)); + } + if (libinput_event_tablet_axis_has_changed(axis_event, + LIBINPUT_TABLET_AXIS_TILT_X) || + libinput_event_tablet_axis_has_changed(axis_event, + LIBINPUT_TABLET_AXIS_TILT_Y)) { + double tilt_x, tilt_y; + uint32_t time; + + time = libinput_event_tablet_get_time(axis_event); + tilt_x = libinput_event_tablet_get_axis_value( + axis_event, LIBINPUT_TABLET_AXIS_TILT_X) * WL_TABLET_AXIS_MAX; + tilt_y = libinput_event_tablet_get_axis_value( + axis_event, LIBINPUT_TABLET_AXIS_TILT_Y) * WL_TABLET_AXIS_MAX; + + notify_tablet_tilt(tablet, time, + wl_fixed_from_double(tilt_x), + wl_fixed_from_double(tilt_y)); + } notify_tablet_frame(tablet); } @@ -567,6 +610,20 @@ evdev_device_create(struct libinput_device *libinput_device, LIBINPUT_DEVICE_CAP_TABLET)) { struct weston_tablet *tablet = weston_seat_add_tablet(seat); + if (libinput_tablet_has_axis(libinput_device, + LIBINPUT_TABLET_AXIS_PRESSURE)) + tablet->supported_axes |= WL_TABLET_AXIS_FLAG_PRESSURE; + + if (libinput_tablet_has_axis(libinput_device, + LIBINPUT_TABLET_AXIS_DISTANCE)) + tablet->supported_axes |= WL_TABLET_AXIS_FLAG_DISTANCE; + + if (libinput_tablet_has_axis(libinput_device, + LIBINPUT_TABLET_AXIS_TILT_X) && + libinput_tablet_has_axis(libinput_device, + LIBINPUT_TABLET_AXIS_TILT_Y)) + tablet->supported_axes |= WL_TABLET_AXIS_FLAG_TILT; + tablet->name = strdup(libinput_device_get_name(libinput_device)); tablet->vid = libinput_device_get_id_vendor(libinput_device); tablet->pid = libinput_device_get_id_product(libinput_device); -- 1.8.5.5 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel