Implement tablet_tool support in pointer example

This commit is contained in:
Drew DeVault 2017-08-28 22:12:35 -04:00
parent 4fbe322fa6
commit 30611894f2
2 changed files with 22 additions and 2 deletions

View file

@ -51,6 +51,11 @@ struct sample_state {
struct wl_listener touch_down; struct wl_listener touch_down;
struct wl_listener touch_cancel; struct wl_listener touch_cancel;
list_t *touch_points; list_t *touch_points;
struct wl_listener tablet_tool_axis;
struct wl_listener tablet_tool_proxmity;
struct wl_listener tablet_tool_tip;
struct wl_listener tablet_tool_button;
}; };
struct touch_point { struct touch_point {
@ -306,6 +311,17 @@ static void handle_touch_cancel(struct wl_listener *listener, void *data) {
wlr_log(L_DEBUG, "TODO: touch cancel"); wlr_log(L_DEBUG, "TODO: touch cancel");
} }
static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) {
struct sample_state *sample = wl_container_of(listener, sample, tablet_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);
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct sample_state state = { struct sample_state state = {
.default_color = { 0.25f, 0.25f, 0.25f, 1 }, .default_color = { 0.25f, 0.25f, 0.25f, 1 },
@ -344,6 +360,10 @@ int main(int argc, char *argv[]) {
wl_signal_add(&state.cursor->events.touch_cancel, &state.touch_cancel); wl_signal_add(&state.cursor->events.touch_cancel, &state.touch_cancel);
state.touch_cancel.notify = handle_touch_cancel; state.touch_cancel.notify = handle_touch_cancel;
// tool events
wl_signal_add(&state.cursor->events.tablet_tool_axis, &state.tablet_tool_axis);
state.tablet_tool_axis.notify = handle_tablet_tool_axis;
struct compositor_state compositor = { 0 }; struct compositor_state compositor = { 0 };
compositor.data = &state; compositor.data = &state;
compositor.output_add_cb = handle_output_add; compositor.output_add_cb = handle_output_add;

View file

@ -55,7 +55,7 @@ struct wlr_event_tablet_tool_proximity {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_sec; uint32_t time_sec;
uint64_t time_usec; uint64_t time_usec;
double x, y; double x_mm, y_mm;
double width_mm, height_mm; double width_mm, height_mm;
enum wlr_tablet_tool_proximity_state state; enum wlr_tablet_tool_proximity_state state;
}; };
@ -69,7 +69,7 @@ struct wlr_event_tablet_tool_tip {
struct wlr_input_device *device; struct wlr_input_device *device;
uint32_t time_sec; uint32_t time_sec;
uint64_t time_usec; uint64_t time_usec;
double x, y; double x_mm, y_mm;
double width_mm, height_mm; double width_mm, height_mm;
enum wlr_tablet_tool_tip_state state; enum wlr_tablet_tool_tip_state state;
}; };