Remove width_mm from tablet events
This commit is contained in:
parent
324b9d910d
commit
ac219cbda6
|
@ -46,6 +46,8 @@ static struct wlr_input_device *allocate_device(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
struct wlr_input_device *wlr_dev = &wlr_libinput_dev->wlr_input_device;
|
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);
|
wl_list_insert(wlr_devices, &wlr_dev->link);
|
||||||
wlr_libinput_dev->handle = libinput_dev;
|
wlr_libinput_dev->handle = libinput_dev;
|
||||||
libinput_device_ref(libinput_dev);
|
libinput_device_ref(libinput_dev);
|
||||||
|
|
|
@ -34,14 +34,13 @@ void handle_tablet_tool_axis(struct libinput_event *event,
|
||||||
wlr_event.device = wlr_dev;
|
wlr_event.device = wlr_dev;
|
||||||
wlr_event.time_msec =
|
wlr_event.time_msec =
|
||||||
usec_to_msec(libinput_event_tablet_tool_get_time_usec(tevent));
|
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)) {
|
if (libinput_event_tablet_tool_x_has_changed(tevent)) {
|
||||||
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_X;
|
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)) {
|
if (libinput_event_tablet_tool_y_has_changed(tevent)) {
|
||||||
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_Y;
|
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)) {
|
if (libinput_event_tablet_tool_pressure_has_changed(tevent)) {
|
||||||
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE;
|
wlr_event.updated_axes |= WLR_TABLET_TOOL_AXIS_PRESSURE;
|
||||||
|
|
|
@ -251,8 +251,8 @@ static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_event_tablet_tool_axis *event = data;
|
struct wlr_event_tablet_tool_axis *event = data;
|
||||||
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
|
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
|
||||||
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
||||||
wlr_cursor_warp_absolute(sample->cursor, event->device,
|
wlr_cursor_warp_absolute(sample->cursor,
|
||||||
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
|
event->device, event->x, event->y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct sample_state {
|
||||||
bool proximity, tap, button;
|
bool proximity, tap, button;
|
||||||
double distance;
|
double distance;
|
||||||
double pressure;
|
double pressure;
|
||||||
double x_mm, y_mm;
|
double x, y;
|
||||||
double x_tilt, y_tilt;
|
double x_tilt, y_tilt;
|
||||||
double width_mm, height_mm;
|
double width_mm, height_mm;
|
||||||
double ring;
|
double ring;
|
||||||
|
@ -69,8 +69,8 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
||||||
|
|
||||||
if (sample->proximity) {
|
if (sample->proximity) {
|
||||||
struct wlr_box box = {
|
struct wlr_box box = {
|
||||||
.x = sample->x_mm * scale - 8 * (sample->pressure + 1) + left,
|
.x = (sample->x * pad_width) - 8 * (sample->pressure + 1) + left,
|
||||||
.y = sample->y_mm * scale - 8 * (sample->pressure + 1) + top,
|
.y = (sample->y * pad_height) - 8 * (sample->pressure + 1) + top,
|
||||||
.width = 16 * (sample->pressure + 1),
|
.width = 16 * (sample->pressure + 1),
|
||||||
.height = 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,
|
static void handle_tool_axis(struct tablet_tool_state *tstate,
|
||||||
struct wlr_event_tablet_tool_axis *event) {
|
struct wlr_event_tablet_tool_axis *event) {
|
||||||
struct sample_state *sample = tstate->compositor->data;
|
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)) {
|
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)) {
|
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)) {
|
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE)) {
|
||||||
sample->distance = event->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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
wlr_log_init(L_DEBUG, NULL);
|
wlr_log_init(L_DEBUG, NULL);
|
||||||
struct sample_state state = {
|
struct sample_state state = {
|
||||||
.tool_color = { 1, 1, 1, 1 },
|
.tool_color = { 1, 1, 1, 1 },
|
||||||
.pad_color = { 0.5, 0.5, 0.5, 1.0 }
|
.pad_color = { 0.5, 0.5, 0.5, 1.0 }
|
||||||
};
|
};
|
||||||
struct compositor_state compositor = { 0,
|
struct compositor_state compositor = {
|
||||||
.data = &state,
|
.data = &state,
|
||||||
.output_frame_cb = handle_output_frame,
|
.output_frame_cb = handle_output_frame,
|
||||||
.tool_axis_cb = handle_tool_axis,
|
.tool_axis_cb = handle_tool_axis,
|
||||||
|
@ -178,6 +187,8 @@ int main(int argc, char *argv[]) {
|
||||||
.tool_button_cb = handle_tool_button,
|
.tool_button_cb = handle_tool_button,
|
||||||
.pad_button_cb = handle_pad_button,
|
.pad_button_cb = handle_pad_button,
|
||||||
.pad_ring_cb = handle_pad_ring,
|
.pad_ring_cb = handle_pad_ring,
|
||||||
|
.input_add_cb = handle_input_add,
|
||||||
|
0
|
||||||
};
|
};
|
||||||
compositor_init(&compositor);
|
compositor_init(&compositor);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@ struct wlr_input_device {
|
||||||
enum wlr_input_device_type type;
|
enum wlr_input_device_type type;
|
||||||
int vendor, product;
|
int vendor, product;
|
||||||
char *name;
|
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 */
|
/* wlr_input_device.type determines which of these is valid */
|
||||||
union {
|
union {
|
||||||
|
|
|
@ -36,8 +36,8 @@ struct wlr_event_tablet_tool_axis {
|
||||||
struct wlr_input_device *device;
|
struct wlr_input_device *device;
|
||||||
uint32_t time_msec;
|
uint32_t time_msec;
|
||||||
uint32_t updated_axes;
|
uint32_t updated_axes;
|
||||||
double x_mm, y_mm;
|
// From 0..1
|
||||||
double width_mm, height_mm;
|
double x, y;
|
||||||
double pressure;
|
double pressure;
|
||||||
double distance;
|
double distance;
|
||||||
double tilt_x, tilt_y;
|
double tilt_x, tilt_y;
|
||||||
|
@ -54,8 +54,8 @@ enum wlr_tablet_tool_proximity_state {
|
||||||
struct wlr_event_tablet_tool_proximity {
|
struct wlr_event_tablet_tool_proximity {
|
||||||
struct wlr_input_device *device;
|
struct wlr_input_device *device;
|
||||||
uint32_t time_msec;
|
uint32_t time_msec;
|
||||||
double x_mm, y_mm;
|
// From 0..1
|
||||||
double width_mm, height_mm;
|
double x, y;
|
||||||
enum wlr_tablet_tool_proximity_state state;
|
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_event_tablet_tool_tip {
|
||||||
struct wlr_input_device *device;
|
struct wlr_input_device *device;
|
||||||
uint32_t time_msec;
|
uint32_t time_msec;
|
||||||
double x_mm, y_mm;
|
// From 0..1
|
||||||
double width_mm, height_mm;
|
double x, y;
|
||||||
enum wlr_tablet_tool_tip_state state;
|
enum wlr_tablet_tool_tip_state state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -392,15 +392,13 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
|
||||||
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
|
if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) &&
|
||||||
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
||||||
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
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);
|
roots_cursor_update_position(cursor, event->time_msec);
|
||||||
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
|
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
|
||||||
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1);
|
||||||
event->x_mm / event->width_mm, -1);
|
|
||||||
roots_cursor_update_position(cursor, event->time_msec);
|
roots_cursor_update_position(cursor, event->time_msec);
|
||||||
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
|
||||||
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y);
|
||||||
-1, event->y_mm / event->height_mm);
|
|
||||||
roots_cursor_update_position(cursor, event->time_msec);
|
roots_cursor_update_position(cursor, event->time_msec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue