aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-09-21 18:30:04 -0400
committerDrew DeVault <sir@cmpwn.com>2017-09-21 18:51:33 -0400
commitd558745633e83b47e08f362f44164f3965dac2f7 (patch)
treed42c678034e82d78c2f5f92fda73ee208a4c1b8e
parent446adda1a3ad55b21522b9e81fd192c4a63510e7 (diff)
Handle tablet motion in example compositor
-rw-r--r--examples/compositor.c37
-rw-r--r--include/wlr/types/wlr_seat.h2
-rw-r--r--types/wlr_seat.c2
3 files changed, 39 insertions, 2 deletions
diff --git a/examples/compositor.c b/examples/compositor.c
index fa5f3286..085cbb0e 100644
--- a/examples/compositor.c
+++ b/examples/compositor.c
@@ -7,6 +7,8 @@
#include <unistd.h>
#include <sys/mman.h>
#include <wayland-server.h>
+// TODO: BSD et al
+#include <linux/input-event-codes.h>
#include <wlr/backend.h>
#include <wlr/backend/session.h>
#include <wlr/render.h>
@@ -59,6 +61,10 @@ struct sample_state {
struct wl_listener cursor_button;
struct wl_listener cursor_axis;
+ struct wl_listener tool_axis;
+ struct wl_listener tool_tip;
+ struct wl_listener tool_button;
+
struct wl_listener new_xdg_surface_v6;
struct wlr_xdg_surface_v6 *focused_surface;
@@ -431,6 +437,31 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
event->button, event->state);
}
+static void handle_tool_axis(struct wl_listener *listener, void *data) {
+ struct sample_state *sample =
+ wl_container_of(listener, sample, tool_axis);
+ 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);
+ update_pointer_position(sample, event->time_sec);
+ }
+}
+
+static void handle_tool_tip(struct wl_listener *listener, void *data) {
+ struct sample_state *sample =
+ wl_container_of(listener, sample, tool_tip);
+ struct wlr_event_tablet_tool_tip *event = data;
+
+ struct wlr_xdg_surface_v6 *surface =
+ example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y);
+ example_set_focused_surface(sample, surface);
+
+ wlr_seat_pointer_send_button(sample->wl_seat, event->time_sec,
+ BTN_MOUSE, event->state);
+}
+
static void handle_input_add(struct compositor_state *state,
struct wlr_input_device *device) {
struct sample_state *sample = state->data;
@@ -528,6 +559,12 @@ int main(int argc, char *argv[]) {
wl_signal_add(&state.cursor->events.axis, &state.cursor_axis);
state.cursor_axis.notify = handle_cursor_axis;
+ wl_signal_add(&state.cursor->events.tablet_tool_axis, &state.tool_axis);
+ state.tool_axis.notify = handle_tool_axis;
+
+ wl_signal_add(&state.cursor->events.tablet_tool_tip, &state.tool_tip);
+ state.tool_tip.notify = handle_tool_tip;
+
compositor_init(&compositor);
state.renderer = wlr_gles2_renderer_create(compositor.backend);
diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h
index 221e4489..4b433ccb 100644
--- a/include/wlr/types/wlr_seat.h
+++ b/include/wlr/types/wlr_seat.h
@@ -107,6 +107,6 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
* button event are surface-local.
*/
void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
- uint32_t button, enum wlr_button_state state);
+ uint32_t button, uint32_t state);
#endif
diff --git a/types/wlr_seat.c b/types/wlr_seat.c
index 411c1182..9a254b35 100644
--- a/types/wlr_seat.c
+++ b/types/wlr_seat.c
@@ -338,7 +338,7 @@ void wlr_seat_pointer_send_motion(struct wlr_seat *wlr_seat, uint32_t time,
}
void wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time,
- uint32_t button, enum wlr_button_state state) {
+ uint32_t button, uint32_t state) {
if (!wlr_seat->pointer_state.focused_handle) {
// nobody to send the event to
return;