2014-06-05 23:20:36 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Red Hat, Inc.
|
2017-11-17 08:40:07 +10:00
|
|
|
* Copyright © 2014 Lyude Paul
|
2014-06-05 23:20:36 -04:00
|
|
|
*
|
2018-08-07 08:26:53 +10:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2014-06-05 23:20:36 -04:00
|
|
|
*
|
2018-08-07 08:26:53 +10:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2014-06-05 23:20:36 -04:00
|
|
|
*/
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "evdev-tablet.h"
|
2023-08-28 09:06:49 +10:00
|
|
|
#include "util-input-event.h"
|
2014-06-05 23:20:36 -04:00
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2015-02-19 12:56:43 +10:00
|
|
|
#if HAVE_LIBWACOM
|
|
|
|
|
#include <libwacom/libwacom.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-03 15:56:54 +10:00
|
|
|
enum notify {
|
|
|
|
|
DONT_NOTIFY,
|
|
|
|
|
DO_NOTIFY,
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-22 12:11:43 +10:00
|
|
|
/* The tablet sends events every ~2ms , 50ms should be plenty enough to
|
2018-05-28 10:38:12 +10:00
|
|
|
detect out-of-range.
|
|
|
|
|
This value is higher during test suite runs */
|
|
|
|
|
static int FORCED_PROXOUT_TIMEOUT = 50 * 1000; /* µs */
|
2016-12-22 12:11:43 +10:00
|
|
|
|
2014-06-17 18:03:26 -04:00
|
|
|
#define tablet_set_status(tablet_,s_) (tablet_)->status |= (s_)
|
|
|
|
|
#define tablet_unset_status(tablet_,s_) (tablet_)->status &= ~(s_)
|
2014-06-05 23:20:36 -04:00
|
|
|
#define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_)))
|
|
|
|
|
|
2015-02-19 15:46:29 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_get_pressed_buttons(struct tablet_dispatch *tablet,
|
2016-02-10 09:24:51 +10:00
|
|
|
struct button_state *buttons)
|
2015-02-19 15:46:29 +10:00
|
|
|
{
|
|
|
|
|
size_t i;
|
|
|
|
|
const struct button_state *state = &tablet->button_state,
|
|
|
|
|
*prev_state = &tablet->prev_button_state;
|
|
|
|
|
|
2016-02-10 09:24:51 +10:00
|
|
|
for (i = 0; i < sizeof(buttons->bits); i++)
|
|
|
|
|
buttons->bits[i] = state->bits[i] & ~(prev_state->bits[i]);
|
2015-02-19 15:46:29 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_get_released_buttons(struct tablet_dispatch *tablet,
|
2016-02-10 09:24:51 +10:00
|
|
|
struct button_state *buttons)
|
2015-02-19 15:46:29 +10:00
|
|
|
{
|
|
|
|
|
size_t i;
|
|
|
|
|
const struct button_state *state = &tablet->button_state,
|
|
|
|
|
*prev_state = &tablet->prev_button_state;
|
|
|
|
|
|
2016-02-10 09:24:51 +10:00
|
|
|
for (i = 0; i < sizeof(buttons->bits); i++)
|
|
|
|
|
buttons->bits[i] = prev_state->bits[i] &
|
|
|
|
|
~(state->bits[i]);
|
2015-02-19 15:46:29 +10:00
|
|
|
}
|
2014-06-10 23:14:41 -04:00
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
static struct libinput_tablet_tool_pressure_threshold*
|
|
|
|
|
tablet_tool_get_threshold(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
ARRAY_FOR_EACH(tool->pressure.thresholds, threshold) {
|
|
|
|
|
if (threshold->tablet_id == tablet->tablet_id) {
|
|
|
|
|
return threshold;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we ever get here, we failed detecting the proximity for this tablet
|
|
|
|
|
* (or we have too many tablets). Return the first one which will
|
|
|
|
|
* make things work incorrectly but we don't need to NULL-check
|
|
|
|
|
* everything for an extremely unlikely situtation */
|
|
|
|
|
evdev_log_bug_libinput(tablet->device,
|
|
|
|
|
"Failed to find tablet_id %d for pressure offsets\n",
|
|
|
|
|
tablet->tablet_id);
|
|
|
|
|
|
|
|
|
|
return &tool->pressure.thresholds[0];
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 17:16:18 +10:00
|
|
|
/* Merge the previous state with the current one so all buttons look like
|
|
|
|
|
* they just got pressed in this frame */
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_force_button_presses(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
|
|
|
|
struct button_state *state = &tablet->button_state,
|
|
|
|
|
*prev_state = &tablet->prev_button_state;
|
|
|
|
|
size_t i;
|
|
|
|
|
|
2016-02-10 09:24:51 +10:00
|
|
|
for (i = 0; i < sizeof(state->bits); i++) {
|
|
|
|
|
state->bits[i] = state->bits[i] | prev_state->bits[i];
|
|
|
|
|
prev_state->bits[i] = 0;
|
2015-12-02 17:16:18 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:11:51 +10:00
|
|
|
static inline size_t
|
|
|
|
|
tablet_history_size(const struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
2020-10-08 09:47:36 +10:00
|
|
|
return tablet->history.size;
|
2017-03-07 13:11:51 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_history_reset(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
|
|
|
|
tablet->history.count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_history_push(struct tablet_dispatch *tablet,
|
|
|
|
|
const struct tablet_axes *axes)
|
|
|
|
|
{
|
|
|
|
|
unsigned int index = (tablet->history.index + 1) %
|
|
|
|
|
tablet_history_size(tablet);
|
|
|
|
|
|
|
|
|
|
tablet->history.samples[index] = *axes;
|
|
|
|
|
tablet->history.index = index;
|
|
|
|
|
tablet->history.count = min(tablet->history.count + 1,
|
|
|
|
|
tablet_history_size(tablet));
|
|
|
|
|
|
|
|
|
|
if (tablet->history.count < tablet_history_size(tablet))
|
|
|
|
|
tablet_history_push(tablet, axes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a previous axis state, where index of 0 means "most recent", 1 is
|
|
|
|
|
* "one before most recent", etc.
|
|
|
|
|
*/
|
|
|
|
|
static inline const struct tablet_axes*
|
|
|
|
|
tablet_history_get(const struct tablet_dispatch *tablet, unsigned int index)
|
|
|
|
|
{
|
|
|
|
|
size_t sz = tablet_history_size(tablet);
|
|
|
|
|
|
|
|
|
|
assert(index < sz);
|
|
|
|
|
assert(index < tablet->history.count);
|
|
|
|
|
|
|
|
|
|
index = (tablet->history.index + sz - index) % sz;
|
|
|
|
|
return &tablet->history.samples[index];
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 17:08:07 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_reset_changed_axes(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
|
|
|
|
memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-12 11:03:03 +10:00
|
|
|
static bool
|
2015-02-16 16:25:39 +10:00
|
|
|
tablet_device_has_axis(struct tablet_dispatch *tablet,
|
2015-11-16 15:35:40 +10:00
|
|
|
enum libinput_tablet_tool_axis axis)
|
2015-02-16 16:25:39 +10:00
|
|
|
{
|
2015-02-16 15:19:44 +10:00
|
|
|
struct libevdev *evdev = tablet->device->evdev;
|
|
|
|
|
bool has_axis = false;
|
2015-02-16 16:25:39 +10:00
|
|
|
unsigned int code;
|
|
|
|
|
|
2015-11-16 15:36:30 +10:00
|
|
|
if (axis == LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z) {
|
2015-02-16 15:19:44 +10:00
|
|
|
has_axis = (libevdev_has_event_code(evdev,
|
2015-06-29 14:20:20 +10:00
|
|
|
EV_KEY,
|
|
|
|
|
BTN_TOOL_MOUSE) &&
|
|
|
|
|
libevdev_has_event_code(evdev,
|
2015-02-16 15:19:44 +10:00
|
|
|
EV_ABS,
|
|
|
|
|
ABS_TILT_X) &&
|
|
|
|
|
libevdev_has_event_code(evdev,
|
|
|
|
|
EV_ABS,
|
|
|
|
|
ABS_TILT_Y));
|
2015-06-29 14:20:20 +10:00
|
|
|
code = axis_to_evcode(axis);
|
|
|
|
|
has_axis |= libevdev_has_event_code(evdev,
|
|
|
|
|
EV_ABS,
|
|
|
|
|
code);
|
2015-11-16 15:36:30 +10:00
|
|
|
} else if (axis == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) {
|
2015-02-20 11:41:06 +10:00
|
|
|
has_axis = libevdev_has_event_code(evdev,
|
|
|
|
|
EV_REL,
|
|
|
|
|
REL_WHEEL);
|
2015-02-16 15:19:44 +10:00
|
|
|
} else {
|
|
|
|
|
code = axis_to_evcode(axis);
|
|
|
|
|
has_axis = libevdev_has_event_code(evdev,
|
|
|
|
|
EV_ABS,
|
|
|
|
|
code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return has_axis;
|
2015-02-16 16:25:39 +10:00
|
|
|
}
|
|
|
|
|
|
2016-04-12 08:36:48 +10:00
|
|
|
static inline bool
|
|
|
|
|
tablet_filter_axis_fuzz(const struct tablet_dispatch *tablet,
|
|
|
|
|
const struct evdev_device *device,
|
|
|
|
|
const struct input_event *e,
|
|
|
|
|
enum libinput_tablet_tool_axis axis)
|
|
|
|
|
{
|
|
|
|
|
int delta, fuzz;
|
|
|
|
|
int current, previous;
|
|
|
|
|
|
|
|
|
|
previous = tablet->prev_value[axis];
|
|
|
|
|
current = e->value;
|
|
|
|
|
delta = previous - current;
|
|
|
|
|
|
|
|
|
|
fuzz = libevdev_get_abs_fuzz(device->evdev, e->code);
|
|
|
|
|
|
|
|
|
|
/* ABS_DISTANCE doesn't have have fuzz set and causes continuous
|
|
|
|
|
* updates for the cursor/lens tools. Add a minimum fuzz of 2, same
|
|
|
|
|
* as the xf86-input-wacom driver
|
|
|
|
|
*/
|
|
|
|
|
switch (e->code) {
|
|
|
|
|
case ABS_DISTANCE:
|
|
|
|
|
fuzz = max(2, fuzz);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return abs(delta) <= fuzz;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
static void
|
|
|
|
|
tablet_process_absolute(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct input_event *e,
|
2015-08-04 12:37:40 +10:00
|
|
|
uint64_t time)
|
2014-06-05 23:20:36 -04:00
|
|
|
{
|
2015-11-16 15:35:40 +10:00
|
|
|
enum libinput_tablet_tool_axis axis;
|
2014-06-05 23:20:36 -04:00
|
|
|
|
|
|
|
|
switch (e->code) {
|
|
|
|
|
case ABS_X:
|
|
|
|
|
case ABS_Y:
|
2015-02-18 11:40:55 +10:00
|
|
|
case ABS_Z:
|
2014-06-06 20:31:38 -04:00
|
|
|
case ABS_PRESSURE:
|
|
|
|
|
case ABS_TILT_X:
|
|
|
|
|
case ABS_TILT_Y:
|
|
|
|
|
case ABS_DISTANCE:
|
2015-02-17 13:04:06 +10:00
|
|
|
case ABS_WHEEL:
|
2014-06-05 23:20:36 -04:00
|
|
|
axis = evcode_to_axis(e->code);
|
2015-11-16 15:36:30 +10:00
|
|
|
if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) {
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_bug_libinput(device,
|
|
|
|
|
"Invalid ABS event code %#x\n",
|
|
|
|
|
e->code);
|
2014-06-05 23:20:36 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 08:36:48 +10:00
|
|
|
tablet->prev_value[axis] = tablet->current_value[axis];
|
|
|
|
|
if (tablet_filter_axis_fuzz(tablet, device, e, axis))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
tablet->current_value[axis] = e->value;
|
2014-06-05 23:20:36 -04:00
|
|
|
set_bit(tablet->changed_axes, axis);
|
|
|
|
|
tablet_set_status(tablet, TABLET_AXES_UPDATED);
|
|
|
|
|
break;
|
2015-02-19 14:56:34 +10:00
|
|
|
/* tool_id is the identifier for the tool we can use in libwacom
|
|
|
|
|
* to identify it (if we have one anyway) */
|
|
|
|
|
case ABS_MISC:
|
2019-04-01 15:10:55 +10:00
|
|
|
tablet->current_tool.id = e->value;
|
2015-02-19 14:56:34 +10:00
|
|
|
break;
|
2015-02-16 15:05:00 +10:00
|
|
|
/* Intuos 3 strip data. Should only happen on the Pad device, not on
|
|
|
|
|
the Pen device. */
|
|
|
|
|
case ABS_RX:
|
|
|
|
|
case ABS_RY:
|
|
|
|
|
/* Only on the 4D mouse (Intuos2), obsolete */
|
|
|
|
|
case ABS_RZ:
|
|
|
|
|
/* Only on the 4D mouse (Intuos2), obsolete.
|
|
|
|
|
The 24HD sends ABS_THROTTLE on the Pad device for the second
|
|
|
|
|
wheel but we shouldn't get here on kernel >= 3.17.
|
|
|
|
|
*/
|
|
|
|
|
case ABS_THROTTLE:
|
2014-06-05 23:20:36 -04:00
|
|
|
default:
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_info(device,
|
|
|
|
|
"Unhandled ABS event code %#x\n",
|
|
|
|
|
e->code);
|
2014-06-05 23:20:36 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 10:31:37 +10:00
|
|
|
static inline int
|
|
|
|
|
axis_range_percentage(const struct input_absinfo *a, double percent)
|
|
|
|
|
{
|
|
|
|
|
return (a->maximum - a->minimum) * percent/100.0 + a->minimum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_change_area(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
|
|
|
|
|
|
|
|
|
|
if (memcmp(&tablet->area.rect, &tablet->area.want_rect, sizeof(tablet->area.rect)) == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
tablet->area.rect = tablet->area.want_rect;
|
|
|
|
|
|
|
|
|
|
evdev_log_debug(device,
|
|
|
|
|
"tablet-area: area is %.2f/%.2f - %.2f/%.2f\n",
|
|
|
|
|
tablet->area.rect.x1,
|
|
|
|
|
tablet->area.rect.y1,
|
|
|
|
|
tablet->area.rect.x2,
|
|
|
|
|
tablet->area.rect.y2);
|
|
|
|
|
|
|
|
|
|
const struct input_absinfo *absx = device->abs.absinfo_x;
|
|
|
|
|
const struct input_absinfo *absy = device->abs.absinfo_y;
|
|
|
|
|
tablet->area.x.minimum = axis_range_percentage(absx, tablet->area.rect.x1 * 100);
|
|
|
|
|
tablet->area.x.maximum = axis_range_percentage(absx, tablet->area.rect.x2 * 100);
|
|
|
|
|
tablet->area.y.minimum = axis_range_percentage(absy, tablet->area.rect.y1 * 100);
|
|
|
|
|
tablet->area.y.maximum = axis_range_percentage(absy, tablet->area.rect.y2 * 100);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-16 22:48:40 -05:00
|
|
|
static void
|
2019-05-03 15:56:54 +10:00
|
|
|
tablet_apply_rotation(struct evdev_device *device)
|
2015-02-16 22:48:40 -05:00
|
|
|
{
|
2017-01-30 18:01:09 +10:00
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
|
2015-02-16 22:48:40 -05:00
|
|
|
|
2019-05-03 15:56:54 +10:00
|
|
|
if (tablet->rotation.rotate == tablet->rotation.want_rotate)
|
2015-02-16 22:48:40 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
|
|
|
|
|
return;
|
|
|
|
|
|
2019-05-03 15:56:54 +10:00
|
|
|
tablet->rotation.rotate = tablet->rotation.want_rotate;
|
|
|
|
|
|
|
|
|
|
evdev_log_debug(device,
|
|
|
|
|
"tablet-rotation: rotation is %s\n",
|
|
|
|
|
tablet->rotation.rotate ? "on" : "off");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_change_rotation(struct evdev_device *device, enum notify notify)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
|
|
|
|
|
struct evdev_device *touch_device = tablet->touch_device;
|
|
|
|
|
struct evdev_dispatch *dispatch;
|
|
|
|
|
bool tablet_is_left, touchpad_is_left;
|
|
|
|
|
|
|
|
|
|
tablet_is_left = tablet->device->left_handed.enabled;
|
|
|
|
|
touchpad_is_left = tablet->rotation.touch_device_left_handed_state;
|
|
|
|
|
|
|
|
|
|
tablet->rotation.want_rotate = tablet_is_left || touchpad_is_left;
|
|
|
|
|
tablet_apply_rotation(device);
|
|
|
|
|
|
|
|
|
|
if (notify == DO_NOTIFY && touch_device) {
|
|
|
|
|
bool enable = device->left_handed.want_enabled;
|
|
|
|
|
|
|
|
|
|
dispatch = touch_device->dispatch;
|
|
|
|
|
if (dispatch->interface->left_handed_toggle)
|
|
|
|
|
dispatch->interface->left_handed_toggle(dispatch,
|
|
|
|
|
touch_device,
|
|
|
|
|
enable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_change_to_left_handed(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
if (device->left_handed.enabled == device->left_handed.want_enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-02-16 22:48:40 -05:00
|
|
|
device->left_handed.enabled = device->left_handed.want_enabled;
|
2019-05-03 15:56:54 +10:00
|
|
|
|
|
|
|
|
tablet_change_rotation(device, DO_NOTIFY);
|
2015-02-16 22:48:40 -05:00
|
|
|
}
|
|
|
|
|
|
2014-06-10 16:48:19 -04:00
|
|
|
static void
|
|
|
|
|
tablet_update_tool(struct tablet_dispatch *tablet,
|
2014-06-19 01:18:08 -04:00
|
|
|
struct evdev_device *device,
|
2015-11-16 15:39:07 +10:00
|
|
|
enum libinput_tablet_tool_type tool,
|
2014-06-10 16:48:19 -04:00
|
|
|
bool enabled)
|
|
|
|
|
{
|
|
|
|
|
assert(tool != LIBINPUT_TOOL_NONE);
|
|
|
|
|
|
2014-06-19 01:18:06 -04:00
|
|
|
if (enabled) {
|
2019-04-01 15:10:55 +10:00
|
|
|
tablet->current_tool.type = tool;
|
2014-06-26 21:31:51 -04:00
|
|
|
tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
|
2014-06-19 01:18:06 -04:00
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
|
2014-06-10 16:48:19 -04:00
|
|
|
}
|
2016-08-23 10:19:56 +10:00
|
|
|
else if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
|
2014-06-26 18:02:48 -04:00
|
|
|
tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
|
2016-08-23 10:19:56 +10:00
|
|
|
}
|
2014-06-10 16:48:19 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 20:31:38 -04:00
|
|
|
static inline double
|
2016-04-26 10:55:37 +10:00
|
|
|
normalize_slider(const struct input_absinfo *absinfo)
|
2015-02-17 12:24:04 +10:00
|
|
|
{
|
2024-01-16 14:44:12 +10:00
|
|
|
return absinfo_normalize(absinfo) * 2 - 1;
|
2014-06-06 20:31:38 -04:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 10:55:37 +10:00
|
|
|
static inline double
|
|
|
|
|
normalize_distance(const struct input_absinfo *absinfo)
|
|
|
|
|
{
|
2024-01-16 14:44:12 +10:00
|
|
|
return absinfo_normalize(absinfo);
|
2016-04-26 10:55:37 +10:00
|
|
|
}
|
|
|
|
|
|
2015-12-01 11:07:57 +10:00
|
|
|
static inline double
|
2025-02-17 15:29:26 +10:00
|
|
|
normalize_pressure(struct libinput_tablet_tool_pressure_threshold *threshold,
|
|
|
|
|
int abs_value)
|
2015-12-01 11:07:57 +10:00
|
|
|
{
|
2019-08-06 14:04:16 +10:00
|
|
|
/**
|
tablet: require a minimum pressure before we process pressure events
Tools default to 1% lower threshold (tip up) and 5% upper threshold (tip
down). But our distance vs pressure exclusion would reset the distance
for *any* pressure value, regardless how low that value was and how high
distance was in comparison.
A very low pressure value of less than 1% would then result in a
normalized pressure of 0, so we'd effectively just reset the distance to
zero and do nothing with the pressure. This can cause distance jumps
when the tool arbitrarily sends low pressure values while hovering as
seen in https://github.com/libsdl-org/SDL/pull/5481#issuecomment-1118969064
Commit 61bdc05fb0f84303f97daaba6ae6b49c976dbfbf from Dec 2017
"tablet: set the tip-up pressure threshold to 1%"
was presumably to address this but no longer (?) works.
Fix this by addressing multiple issues at the same time:
- anything under that 1% threshold is now considered as zero pressure
and any distance value is kept as-is. Once pressure reaches 1%,
distance is always zero.
- axis normalization is now from 1% to 100% (previously: upper threshold
to 100%). So a tip down event should always have ~4% pressure and we
may get tablet motion events with nonzero pressure before the tip down
event.
From memory, this was always intended anyway since a tip event should
require some significant pressure, maybe too high compared to e.g.
pressure-sensitive painting
- where a tablet has an offset, add the same 1%/5% thresholds, on top of
that offset. And keep adjusting those thresholds as we change the
offset. Assuming that the offset is the absolute minimum a worn-out
pen can reach, this gives us the same behaviour as a new pen. The
calculation here uses a simple approach so the actual range is
slightly larger than 5% but it'll do.
Previously, the lower threshold for an offset pen was the axis minimum
but that can never be reached. So there was probably an undiscovered
bug in there.
And fix a bunch of comments that were either wrong, confusing or
incomplete, e.g. the pressure thresholds were already in device
coordinates.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-06 15:21:08 +10:00
|
|
|
* Note: the upper threshold takes the offset into account so that
|
|
|
|
|
* |- 4% -|
|
|
|
|
|
* min |------X------X-------------------------| max
|
|
|
|
|
* | |
|
|
|
|
|
* | + upper threshold / tip trigger
|
|
|
|
|
* +- offset and lower threshold
|
2019-08-06 14:04:16 +10:00
|
|
|
*
|
tablet: require a minimum pressure before we process pressure events
Tools default to 1% lower threshold (tip up) and 5% upper threshold (tip
down). But our distance vs pressure exclusion would reset the distance
for *any* pressure value, regardless how low that value was and how high
distance was in comparison.
A very low pressure value of less than 1% would then result in a
normalized pressure of 0, so we'd effectively just reset the distance to
zero and do nothing with the pressure. This can cause distance jumps
when the tool arbitrarily sends low pressure values while hovering as
seen in https://github.com/libsdl-org/SDL/pull/5481#issuecomment-1118969064
Commit 61bdc05fb0f84303f97daaba6ae6b49c976dbfbf from Dec 2017
"tablet: set the tip-up pressure threshold to 1%"
was presumably to address this but no longer (?) works.
Fix this by addressing multiple issues at the same time:
- anything under that 1% threshold is now considered as zero pressure
and any distance value is kept as-is. Once pressure reaches 1%,
distance is always zero.
- axis normalization is now from 1% to 100% (previously: upper threshold
to 100%). So a tip down event should always have ~4% pressure and we
may get tablet motion events with nonzero pressure before the tip down
event.
From memory, this was always intended anyway since a tip event should
require some significant pressure, maybe too high compared to e.g.
pressure-sensitive painting
- where a tablet has an offset, add the same 1%/5% thresholds, on top of
that offset. And keep adjusting those thresholds as we change the
offset. Assuming that the offset is the absolute minimum a worn-out
pen can reach, this gives us the same behaviour as a new pen. The
calculation here uses a simple approach so the actual range is
slightly larger than 5% but it'll do.
Previously, the lower threshold for an offset pen was the axis minimum
but that can never be reached. So there was probably an undiscovered
bug in there.
And fix a bunch of comments that were either wrong, confusing or
incomplete, e.g. the pressure thresholds were already in device
coordinates.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-06 15:21:08 +10:00
|
|
|
* The axis is scaled into the range [lower, max] so that the lower
|
|
|
|
|
* threshold is 0 pressure.
|
2019-08-06 14:04:16 +10:00
|
|
|
*/
|
2025-02-17 15:29:26 +10:00
|
|
|
struct input_absinfo abs = threshold->abs_pressure;
|
2024-01-15 17:07:17 +10:00
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
abs.minimum = threshold->threshold.lower;
|
2019-08-06 14:04:16 +10:00
|
|
|
|
2024-01-15 17:07:17 +10:00
|
|
|
return absinfo_normalize_value(&abs, abs_value);
|
2015-12-01 11:07:57 +10:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 20:31:38 -04:00
|
|
|
static inline double
|
2016-02-02 16:15:40 +10:00
|
|
|
adjust_tilt(const struct input_absinfo *absinfo)
|
2015-02-17 12:24:04 +10:00
|
|
|
{
|
2024-01-16 16:10:59 +10:00
|
|
|
double value = absinfo_normalize(absinfo);
|
2016-02-02 16:15:40 +10:00
|
|
|
const int WACOM_MAX_DEGREES = 64;
|
2014-06-06 20:31:38 -04:00
|
|
|
|
2016-02-18 09:42:27 +10:00
|
|
|
/* If resolution is nonzero, it's in units/radian. But require
|
|
|
|
|
* a min/max less/greater than zero so we can assume 0 is the
|
|
|
|
|
* center */
|
|
|
|
|
if (absinfo->resolution != 0 &&
|
|
|
|
|
absinfo->maximum > 0 &&
|
|
|
|
|
absinfo->minimum < 0) {
|
2024-01-16 15:37:10 +10:00
|
|
|
value = rad2deg((double)absinfo->value/absinfo->resolution);
|
2016-02-18 09:42:27 +10:00
|
|
|
} else {
|
|
|
|
|
/* Wacom supports physical [-64, 64] degrees, so map to that by
|
|
|
|
|
* default. If other tablets have a different physical range or
|
|
|
|
|
* nonzero physical offsets, they need extra treatment
|
|
|
|
|
* here.
|
|
|
|
|
*/
|
|
|
|
|
/* Map to the (-1, 1) range */
|
|
|
|
|
value = (value * 2) - 1;
|
|
|
|
|
value *= WACOM_MAX_DEGREES;
|
|
|
|
|
}
|
2016-02-02 16:15:40 +10:00
|
|
|
|
2016-02-18 09:42:27 +10:00
|
|
|
return value;
|
2014-06-06 20:31:38 -04:00
|
|
|
}
|
|
|
|
|
|
2015-02-16 22:48:40 -05:00
|
|
|
static inline int32_t
|
|
|
|
|
invert_axis(const struct input_absinfo *absinfo)
|
|
|
|
|
{
|
|
|
|
|
return absinfo->maximum - (absinfo->value - absinfo->minimum);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-16 15:19:44 +10:00
|
|
|
static void
|
|
|
|
|
convert_tilt_to_rotation(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
|
|
|
|
const int offset = 5;
|
|
|
|
|
double x, y;
|
|
|
|
|
double angle = 0.0;
|
|
|
|
|
|
|
|
|
|
/* Wacom Intuos 4, 5, Pro mouse calculates rotation from the x/y tilt
|
|
|
|
|
values. The device has a 175 degree CCW hardware offset but since we use
|
|
|
|
|
atan2 the effective offset is just 5 degrees.
|
|
|
|
|
*/
|
2016-01-06 16:16:46 +10:00
|
|
|
x = tablet->axes.tilt.x;
|
|
|
|
|
y = tablet->axes.tilt.y;
|
2015-02-16 15:19:44 +10:00
|
|
|
|
|
|
|
|
/* atan2 is CCW, we want CW -> negate x */
|
|
|
|
|
if (x || y)
|
2024-01-16 15:37:10 +10:00
|
|
|
angle = rad2deg(atan2(-x, y));
|
2015-02-16 15:19:44 +10:00
|
|
|
|
|
|
|
|
angle = fmod(360 + angle - offset, 360);
|
|
|
|
|
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.rotation = angle;
|
2015-11-16 15:36:30 +10:00
|
|
|
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
2015-02-16 15:19:44 +10:00
|
|
|
}
|
|
|
|
|
|
2015-02-18 11:40:55 +10:00
|
|
|
static double
|
|
|
|
|
convert_to_degrees(const struct input_absinfo *absinfo, double offset)
|
|
|
|
|
{
|
|
|
|
|
/* range is [0, 360[, i.e. range + 1 */
|
2023-08-28 09:06:49 +10:00
|
|
|
double value = (absinfo->value - absinfo->minimum) / absinfo_range(absinfo);
|
2015-02-18 11:40:55 +10:00
|
|
|
|
|
|
|
|
return fmod(value * 360.0 + offset, 360.0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-20 11:41:06 +10:00
|
|
|
static inline double
|
|
|
|
|
normalize_wheel(struct tablet_dispatch *tablet,
|
|
|
|
|
int value)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *device = tablet->device;
|
|
|
|
|
|
2016-08-16 14:48:47 +10:00
|
|
|
return value * device->scroll.wheel_click_angle.x;
|
2015-02-20 11:41:06 +10:00
|
|
|
}
|
|
|
|
|
|
2024-11-01 14:30:51 +10:00
|
|
|
static bool
|
|
|
|
|
is_inside_area(struct tablet_dispatch *tablet,
|
|
|
|
|
const struct device_coords *point,
|
|
|
|
|
double normalized_margin)
|
|
|
|
|
{
|
|
|
|
|
if (tablet->area.rect.x1 == 0.0 && tablet->area.rect.x2 == 1.0 &&
|
|
|
|
|
tablet->area.rect.y1 == 0.0 && tablet->area.rect.y2 == 1.0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
assert(normalized_margin > 0.0);
|
|
|
|
|
assert(normalized_margin <= 1.0);
|
|
|
|
|
|
|
|
|
|
int xmargin = (tablet->area.x.maximum - tablet->area.x.minimum) * normalized_margin;
|
|
|
|
|
int ymargin = (tablet->area.y.maximum - tablet->area.y.minimum) * normalized_margin;
|
|
|
|
|
|
|
|
|
|
return (point->x >= tablet->area.x.minimum - xmargin &&
|
|
|
|
|
point->x <= tablet->area.x.maximum + xmargin &&
|
|
|
|
|
point->y >= tablet->area.y.minimum - ymargin &&
|
|
|
|
|
point->y <= tablet->area.y.maximum + ymargin);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 10:31:37 +10:00
|
|
|
static void
|
|
|
|
|
apply_tablet_area(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct device_coords *point)
|
|
|
|
|
{
|
|
|
|
|
if (tablet->area.rect.x1 == 0.0 && tablet->area.rect.x2 == 1.0 &&
|
|
|
|
|
tablet->area.rect.y1 == 0.0 && tablet->area.rect.y2 == 1.0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* The point is somewhere on the tablet in device coordinates,
|
|
|
|
|
* but we need it relative to the x/y offset.
|
|
|
|
|
* So clip it first, then offset it to our area min/max.
|
|
|
|
|
*
|
|
|
|
|
* Right now we're just clipping, we don't completely
|
|
|
|
|
* ignore events. What we should do is ignore events outside
|
|
|
|
|
* altogether and generate prox in/out events when we actually
|
|
|
|
|
* enter the area.
|
|
|
|
|
*/
|
|
|
|
|
point->x = min(point->x, tablet->area.x.maximum);
|
|
|
|
|
point->y = min(point->y, tablet->area.y.maximum);
|
|
|
|
|
|
|
|
|
|
point->x = max(point->x, tablet->area.x.minimum);
|
|
|
|
|
point->y = max(point->y, tablet->area.y.minimum);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 15:26:49 +10:00
|
|
|
static inline void
|
2017-03-07 15:32:59 +10:00
|
|
|
tablet_update_xy(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device)
|
2014-06-05 23:20:36 -04:00
|
|
|
{
|
2015-12-01 14:05:16 +10:00
|
|
|
const struct input_absinfo *absinfo;
|
2016-01-06 15:26:49 +10:00
|
|
|
int value;
|
2014-06-05 23:20:36 -04:00
|
|
|
|
2022-10-03 12:53:22 +02:00
|
|
|
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_X) ||
|
|
|
|
|
!libevdev_has_event_code(device->evdev, EV_ABS, ABS_Y))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-03-07 15:32:59 +10:00
|
|
|
if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
|
|
|
|
|
bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) {
|
2024-06-14 10:36:59 +10:00
|
|
|
absinfo = device->abs.absinfo_x;
|
2015-12-01 14:05:16 +10:00
|
|
|
|
2019-05-03 15:56:54 +10:00
|
|
|
if (tablet->rotation.rotate)
|
2016-01-06 15:26:49 +10:00
|
|
|
value = invert_axis(absinfo);
|
2015-12-01 14:05:16 +10:00
|
|
|
else
|
2016-01-06 15:26:49 +10:00
|
|
|
value = absinfo->value;
|
|
|
|
|
|
|
|
|
|
tablet->axes.point.x = value;
|
2015-12-01 14:05:16 +10:00
|
|
|
|
2024-06-14 10:36:59 +10:00
|
|
|
absinfo = device->abs.absinfo_y;
|
2015-12-14 15:36:22 +10:00
|
|
|
|
2019-05-03 15:56:54 +10:00
|
|
|
if (tablet->rotation.rotate)
|
2016-01-06 15:26:49 +10:00
|
|
|
value = invert_axis(absinfo);
|
2015-12-01 14:05:16 +10:00
|
|
|
else
|
2016-01-06 15:26:49 +10:00
|
|
|
value = absinfo->value;
|
|
|
|
|
|
|
|
|
|
tablet->axes.point.y = value;
|
2015-12-01 14:05:16 +10:00
|
|
|
|
2024-06-13 10:31:37 +10:00
|
|
|
/* calibration and area are currently mutually exclusive so
|
|
|
|
|
* one of those is a noop */
|
2017-03-07 15:32:59 +10:00
|
|
|
evdev_transform_absolute(device, &tablet->axes.point);
|
2024-06-13 10:31:37 +10:00
|
|
|
apply_tablet_area(tablet, device, &tablet->axes.point);
|
2017-03-07 15:32:59 +10:00
|
|
|
}
|
2016-01-06 15:26:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline struct normalized_coords
|
2017-03-07 15:32:59 +10:00
|
|
|
tablet_tool_process_delta(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
const struct evdev_device *device,
|
2017-03-07 16:00:45 +10:00
|
|
|
struct tablet_axes *axes,
|
2017-03-07 15:32:59 +10:00
|
|
|
uint64_t time)
|
2016-01-06 15:26:49 +10:00
|
|
|
{
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
const struct normalized_coords zero = { 0.0, 0.0 };
|
2017-03-07 15:32:59 +10:00
|
|
|
struct device_coords delta = { 0, 0 };
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
struct device_float_coords accel;
|
2016-01-06 15:26:49 +10:00
|
|
|
|
2018-09-06 14:11:23 +10:00
|
|
|
/* When tool contact changes, we probably got a cursor jump. Don't
|
|
|
|
|
try to calculate a delta for that event */
|
2017-03-07 15:32:59 +10:00
|
|
|
if (!tablet_has_status(tablet,
|
|
|
|
|
TABLET_TOOL_ENTERING_PROXIMITY) &&
|
2018-09-06 14:11:23 +10:00
|
|
|
!tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) &&
|
|
|
|
|
!tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) &&
|
2017-03-07 15:32:59 +10:00
|
|
|
(bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
|
|
|
|
|
bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y))) {
|
2017-03-07 16:00:45 +10:00
|
|
|
delta.x = axes->point.x - tablet->last_smooth_point.x;
|
|
|
|
|
delta.y = axes->point.y - tablet->last_smooth_point.y;
|
2017-03-07 15:32:59 +10:00
|
|
|
}
|
|
|
|
|
|
2018-09-05 15:57:02 +10:00
|
|
|
if (axes->point.x != tablet->last_smooth_point.x)
|
|
|
|
|
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X);
|
|
|
|
|
if (axes->point.y != tablet->last_smooth_point.y)
|
|
|
|
|
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y);
|
|
|
|
|
|
2017-03-07 16:00:45 +10:00
|
|
|
tablet->last_smooth_point = axes->point;
|
|
|
|
|
|
2017-03-07 15:32:59 +10:00
|
|
|
accel.x = 1.0 * delta.x;
|
|
|
|
|
accel.y = 1.0 * delta.y;
|
2015-12-01 14:05:16 +10:00
|
|
|
|
filter: change the filter functions to take raw device coordinates
We used to normalize all deltas to equivalents of a 1000dpi mouse before
passing it into the acceleration functions. This has a bunch of drawbacks, not
least that we already have to un-normalize back into device units for a few
devices already (trackpoints, tablet, low-dpi mice).
Switch the filter code over to use device units, relying on the dpi set
earlier during filter creation to convert to normalized. To make things easy,
the output of the filter code is still normalized data, i.e. data ready to be
handed to the libinput caller.
No effective functional changes. For touchpads, we still send normalized
coordinates (for now, anyway). For the various filter methods, we either drop
the places where we unnormalized before or we normalize where needed.
Two possible changes: for trackpoints and low-dpi mice we had a max dpi factor
of 1.0 before - now we don't anymore. This was only the case if a low-dpi
mouse had more than 1000dpi (never true) or a trackpoint had a const accel
lower than 1.0 (yeah, whatever).
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-15 08:36:22 +10:00
|
|
|
if (device_float_is_zero(accel))
|
|
|
|
|
return zero;
|
2016-01-06 15:26:49 +10:00
|
|
|
|
|
|
|
|
return filter_dispatch(device->pointer.filter,
|
2016-06-21 15:20:08 +10:00
|
|
|
&accel,
|
|
|
|
|
tool,
|
|
|
|
|
time);
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:29:23 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_pressure(struct tablet_dispatch *tablet,
|
2015-12-14 16:28:07 +10:00
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
2024-01-15 17:07:17 +10:00
|
|
|
const struct input_absinfo *abs = libevdev_get_abs_info(device->evdev,
|
|
|
|
|
ABS_PRESSURE);
|
|
|
|
|
if (!abs)
|
2022-10-03 12:53:22 +02:00
|
|
|
return;
|
|
|
|
|
|
2024-01-15 17:07:17 +10:00
|
|
|
if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) {
|
2025-02-17 15:29:26 +10:00
|
|
|
struct libinput_tablet_tool_pressure_threshold *threshold =
|
|
|
|
|
tablet_tool_get_threshold(tablet, tool);
|
|
|
|
|
tablet->axes.pressure = normalize_pressure(threshold, abs->value);
|
2015-12-14 15:36:22 +10:00
|
|
|
}
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:29:23 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_distance(struct tablet_dispatch *tablet,
|
2015-12-14 16:28:07 +10:00
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *absinfo;
|
2015-12-14 15:36:22 +10:00
|
|
|
|
2022-10-03 12:53:22 +02:00
|
|
|
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_DISTANCE))
|
|
|
|
|
return;
|
|
|
|
|
|
2016-01-06 16:16:46 +10:00
|
|
|
if (bit_is_set(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) {
|
2015-12-14 15:36:22 +10:00
|
|
|
absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
|
2016-04-26 10:55:37 +10:00
|
|
|
tablet->axes.distance = normalize_distance(absinfo);
|
2015-12-14 15:36:22 +10:00
|
|
|
}
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:29:23 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_slider(struct tablet_dispatch *tablet,
|
2015-12-14 16:28:07 +10:00
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *absinfo;
|
2015-12-14 15:36:22 +10:00
|
|
|
|
2022-10-03 12:53:22 +02:00
|
|
|
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_WHEEL))
|
|
|
|
|
return;
|
|
|
|
|
|
2016-01-06 16:16:46 +10:00
|
|
|
if (bit_is_set(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) {
|
2015-12-14 15:36:22 +10:00
|
|
|
absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL);
|
2016-04-26 10:55:37 +10:00
|
|
|
tablet->axes.slider = normalize_slider(absinfo);
|
2015-12-14 15:36:22 +10:00
|
|
|
}
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:29:23 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_tilt(struct tablet_dispatch *tablet,
|
2015-12-14 16:28:07 +10:00
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *absinfo;
|
2015-12-14 15:36:22 +10:00
|
|
|
|
2022-09-12 18:28:38 +02:00
|
|
|
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_TILT_X) ||
|
|
|
|
|
!libevdev_has_event_code(device->evdev, EV_ABS, ABS_TILT_Y))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-03-07 14:02:53 +10:00
|
|
|
/* mouse rotation resets tilt to 0 so always fetch both axes if
|
|
|
|
|
* either has changed */
|
2016-01-06 16:16:46 +10:00
|
|
|
if (bit_is_set(tablet->changed_axes,
|
2017-03-07 14:02:53 +10:00
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
|
|
|
|
|
bit_is_set(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
|
|
|
|
|
|
2015-12-14 15:36:22 +10:00
|
|
|
absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X);
|
2016-02-02 16:15:40 +10:00
|
|
|
tablet->axes.tilt.x = adjust_tilt(absinfo);
|
2015-02-16 15:19:44 +10:00
|
|
|
|
2015-12-14 15:36:22 +10:00
|
|
|
absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y);
|
2016-02-02 16:15:40 +10:00
|
|
|
tablet->axes.tilt.y = adjust_tilt(absinfo);
|
2017-03-07 14:02:53 +10:00
|
|
|
|
|
|
|
|
if (device->left_handed.enabled) {
|
|
|
|
|
tablet->axes.tilt.x *= -1;
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.tilt.y *= -1;
|
2017-03-07 14:02:53 +10:00
|
|
|
}
|
2015-12-14 15:36:22 +10:00
|
|
|
}
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:29:23 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_artpen_rotation(struct tablet_dispatch *tablet,
|
2015-12-14 16:28:07 +10:00
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *absinfo;
|
2015-02-16 15:19:44 +10:00
|
|
|
|
2022-10-03 12:53:22 +02:00
|
|
|
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_Z))
|
|
|
|
|
return;
|
|
|
|
|
|
2016-01-06 16:16:46 +10:00
|
|
|
if (bit_is_set(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) {
|
2015-12-14 16:28:07 +10:00
|
|
|
absinfo = libevdev_get_abs_info(device->evdev,
|
|
|
|
|
ABS_Z);
|
|
|
|
|
/* artpen has 0 with buttons pointing east */
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.rotation = convert_to_degrees(absinfo, 90);
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:29:23 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_mouse_rotation(struct tablet_dispatch *tablet,
|
2015-12-14 16:28:07 +10:00
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
if (bit_is_set(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
|
|
|
|
|
bit_is_set(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
|
|
|
|
|
convert_tilt_to_rotation(tablet);
|
2015-12-14 15:36:22 +10:00
|
|
|
}
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 14:02:53 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_rotation(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
/* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are
|
|
|
|
|
* already normalized and set if we have the mouse/lens tool */
|
2019-04-01 15:10:55 +10:00
|
|
|
if (tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
|
|
|
|
|
tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) {
|
2017-03-07 14:02:53 +10:00
|
|
|
tablet_update_mouse_rotation(tablet, device);
|
|
|
|
|
clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
|
|
|
|
|
clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
|
|
|
|
|
tablet->axes.tilt.x = 0;
|
|
|
|
|
tablet->axes.tilt.y = 0;
|
|
|
|
|
|
|
|
|
|
/* tilt is already converted to left-handed, so mouse
|
|
|
|
|
* rotation is converted to left-handed automatically */
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
tablet_update_artpen_rotation(tablet, device);
|
|
|
|
|
|
|
|
|
|
if (device->left_handed.enabled) {
|
|
|
|
|
double r = tablet->axes.rotation;
|
|
|
|
|
tablet->axes.rotation = fmod(180 + r, 360);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:29:23 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_update_wheel(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device)
|
2015-12-14 16:28:07 +10:00
|
|
|
{
|
|
|
|
|
int a;
|
2014-06-05 23:20:36 -04:00
|
|
|
|
2015-12-14 15:36:22 +10:00
|
|
|
a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL;
|
|
|
|
|
if (bit_is_set(tablet->changed_axes, a)) {
|
2017-03-07 13:29:23 +10:00
|
|
|
/* tablet->axes.wheel_discrete is already set */
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.wheel = normalize_wheel(tablet,
|
2016-01-06 16:20:38 +10:00
|
|
|
tablet->axes.wheel_discrete);
|
2015-12-14 16:25:22 +10:00
|
|
|
} else {
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.wheel = 0;
|
2017-03-07 13:29:23 +10:00
|
|
|
tablet->axes.wheel_discrete = 0;
|
2015-12-14 16:28:07 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 16:00:45 +10:00
|
|
|
static void
|
|
|
|
|
tablet_smoothen_axes(const struct tablet_dispatch *tablet,
|
|
|
|
|
struct tablet_axes *axes)
|
|
|
|
|
{
|
|
|
|
|
size_t i;
|
|
|
|
|
size_t count = tablet_history_size(tablet);
|
|
|
|
|
struct tablet_axes smooth = { 0 };
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
|
const struct tablet_axes *a = tablet_history_get(tablet, i);
|
|
|
|
|
|
|
|
|
|
smooth.point.x += a->point.x;
|
|
|
|
|
smooth.point.y += a->point.y;
|
|
|
|
|
|
|
|
|
|
smooth.tilt.x += a->tilt.x;
|
|
|
|
|
smooth.tilt.y += a->tilt.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
axes->point.x = smooth.point.x/count;
|
|
|
|
|
axes->point.y = smooth.point.y/count;
|
|
|
|
|
|
|
|
|
|
axes->tilt.x = smooth.tilt.x/count;
|
|
|
|
|
axes->tilt.y = smooth.tilt.y/count;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 08:39:56 +10:00
|
|
|
static bool
|
2015-12-14 16:28:07 +10:00
|
|
|
tablet_check_notify_axes(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
2015-12-15 08:39:56 +10:00
|
|
|
struct libinput_tablet_tool *tool,
|
2016-01-06 15:26:49 +10:00
|
|
|
struct tablet_axes *axes_out,
|
|
|
|
|
uint64_t time)
|
2015-12-14 16:28:07 +10:00
|
|
|
{
|
2016-01-06 16:16:46 +10:00
|
|
|
struct tablet_axes axes = {0};
|
2015-12-14 16:28:07 +10:00
|
|
|
const char tmp[sizeof(tablet->changed_axes)] = {0};
|
2017-03-07 13:11:51 +10:00
|
|
|
bool rc = false;
|
2015-12-14 16:28:07 +10:00
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) {
|
2017-03-07 13:11:51 +10:00
|
|
|
axes = tablet->axes;
|
|
|
|
|
goto out;
|
2017-03-01 15:22:49 +10:00
|
|
|
}
|
2015-12-14 16:28:07 +10:00
|
|
|
|
2017-03-07 15:32:59 +10:00
|
|
|
tablet_update_xy(tablet, device);
|
2017-03-07 13:29:23 +10:00
|
|
|
tablet_update_pressure(tablet, device, tool);
|
|
|
|
|
tablet_update_distance(tablet, device);
|
|
|
|
|
tablet_update_slider(tablet, device);
|
|
|
|
|
tablet_update_tilt(tablet, device);
|
|
|
|
|
tablet_update_wheel(tablet, device);
|
2017-03-07 14:02:53 +10:00
|
|
|
/* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are
|
|
|
|
|
* already normalized and set if we have the mouse/lens tool */
|
|
|
|
|
tablet_update_rotation(tablet, device);
|
2017-03-07 13:29:23 +10:00
|
|
|
|
2017-03-07 15:32:59 +10:00
|
|
|
axes.point = tablet->axes.point;
|
2017-03-07 13:29:23 +10:00
|
|
|
axes.pressure = tablet->axes.pressure;
|
|
|
|
|
axes.distance = tablet->axes.distance;
|
|
|
|
|
axes.slider = tablet->axes.slider;
|
|
|
|
|
axes.tilt = tablet->axes.tilt;
|
|
|
|
|
axes.wheel = tablet->axes.wheel;
|
|
|
|
|
axes.wheel_discrete = tablet->axes.wheel_discrete;
|
2017-03-07 14:02:53 +10:00
|
|
|
axes.rotation = tablet->axes.rotation;
|
2015-12-14 16:28:07 +10:00
|
|
|
|
2017-03-07 13:11:51 +10:00
|
|
|
rc = true;
|
|
|
|
|
|
|
|
|
|
out:
|
2018-07-30 13:03:03 -04:00
|
|
|
/* The tool position often jumps to a different spot when contact changes.
|
|
|
|
|
* If tool contact changes, clear the history to prevent axis smoothing
|
|
|
|
|
* from trying to average over the spatial discontinuity. */
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) ||
|
|
|
|
|
tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) {
|
|
|
|
|
tablet_history_reset(tablet);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 13:11:51 +10:00
|
|
|
tablet_history_push(tablet, &tablet->axes);
|
2017-03-07 16:00:45 +10:00
|
|
|
tablet_smoothen_axes(tablet, &axes);
|
|
|
|
|
|
|
|
|
|
/* The delta relies on the last *smooth* point, so we do it last */
|
|
|
|
|
axes.delta = tablet_tool_process_delta(tablet, tool, device, &axes, time);
|
|
|
|
|
|
|
|
|
|
*axes_out = axes;
|
2014-06-05 23:20:36 -04:00
|
|
|
|
2017-03-07 13:11:51 +10:00
|
|
|
return rc;
|
|
|
|
|
}
|
2017-03-07 16:00:45 +10:00
|
|
|
|
2014-06-10 23:14:41 -04:00
|
|
|
static void
|
|
|
|
|
tablet_update_button(struct tablet_dispatch *tablet,
|
|
|
|
|
uint32_t evcode,
|
|
|
|
|
uint32_t enable)
|
|
|
|
|
{
|
2015-02-19 17:18:58 +10:00
|
|
|
switch (evcode) {
|
|
|
|
|
case BTN_LEFT:
|
|
|
|
|
case BTN_RIGHT:
|
|
|
|
|
case BTN_MIDDLE:
|
|
|
|
|
case BTN_SIDE:
|
|
|
|
|
case BTN_EXTRA:
|
|
|
|
|
case BTN_FORWARD:
|
|
|
|
|
case BTN_BACK:
|
|
|
|
|
case BTN_TASK:
|
|
|
|
|
case BTN_STYLUS:
|
|
|
|
|
case BTN_STYLUS2:
|
2024-01-23 20:09:04 +10:00
|
|
|
case BTN_STYLUS3:
|
2015-02-19 17:18:58 +10:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_info(tablet->device,
|
|
|
|
|
"Unhandled button %s (%#x)\n",
|
|
|
|
|
libevdev_event_code_get_name(EV_KEY, evcode),
|
|
|
|
|
evcode);
|
2014-06-10 23:14:41 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (enable) {
|
2016-02-10 09:24:51 +10:00
|
|
|
set_bit(tablet->button_state.bits, evcode);
|
2014-06-10 23:14:41 -04:00
|
|
|
tablet_set_status(tablet, TABLET_BUTTONS_PRESSED);
|
|
|
|
|
} else {
|
2016-02-10 09:24:51 +10:00
|
|
|
clear_bit(tablet->button_state.bits, evcode);
|
2014-06-10 23:14:41 -04:00
|
|
|
tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 15:39:07 +10:00
|
|
|
static inline enum libinput_tablet_tool_type
|
2015-02-19 11:00:27 +10:00
|
|
|
tablet_evcode_to_tool(int code)
|
|
|
|
|
{
|
2015-11-16 15:39:07 +10:00
|
|
|
enum libinput_tablet_tool_type type;
|
2015-02-19 11:00:27 +10:00
|
|
|
|
|
|
|
|
switch (code) {
|
2015-11-16 15:40:43 +10:00
|
|
|
case BTN_TOOL_PEN: type = LIBINPUT_TABLET_TOOL_TYPE_PEN; break;
|
|
|
|
|
case BTN_TOOL_RUBBER: type = LIBINPUT_TABLET_TOOL_TYPE_ERASER; break;
|
2019-04-05 14:51:42 +10:00
|
|
|
case BTN_TOOL_BRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_BRUSH; break;
|
2015-11-16 15:40:43 +10:00
|
|
|
case BTN_TOOL_PENCIL: type = LIBINPUT_TABLET_TOOL_TYPE_PENCIL; break;
|
|
|
|
|
case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH; break;
|
2019-04-05 14:51:42 +10:00
|
|
|
case BTN_TOOL_MOUSE: type = LIBINPUT_TABLET_TOOL_TYPE_MOUSE; break;
|
2015-11-16 15:40:43 +10:00
|
|
|
case BTN_TOOL_LENS: type = LIBINPUT_TABLET_TOOL_TYPE_LENS; break;
|
2015-02-19 11:00:27 +10:00
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-10 16:48:19 -04:00
|
|
|
static void
|
|
|
|
|
tablet_process_key(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct input_event *e,
|
2015-08-04 12:37:40 +10:00
|
|
|
uint64_t time)
|
2014-06-10 16:48:19 -04:00
|
|
|
{
|
2019-04-05 14:58:56 +10:00
|
|
|
enum libinput_tablet_tool_type type;
|
|
|
|
|
|
2020-06-02 10:52:11 +10:00
|
|
|
/* ignore kernel key repeat */
|
|
|
|
|
if (e->value == 2)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-06-10 16:48:19 -04:00
|
|
|
switch (e->code) {
|
2015-11-26 06:33:17 +10:00
|
|
|
case BTN_TOOL_FINGER:
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_bug_libinput(device,
|
|
|
|
|
"Invalid tool 'finger' on tablet interface\n");
|
2015-11-26 06:33:17 +10:00
|
|
|
break;
|
2014-06-10 16:48:19 -04:00
|
|
|
case BTN_TOOL_PEN:
|
|
|
|
|
case BTN_TOOL_RUBBER:
|
|
|
|
|
case BTN_TOOL_BRUSH:
|
|
|
|
|
case BTN_TOOL_PENCIL:
|
|
|
|
|
case BTN_TOOL_AIRBRUSH:
|
|
|
|
|
case BTN_TOOL_MOUSE:
|
|
|
|
|
case BTN_TOOL_LENS:
|
2019-04-05 14:58:56 +10:00
|
|
|
type = tablet_evcode_to_tool(e->code);
|
2019-06-17 11:18:57 +10:00
|
|
|
tablet_set_status(tablet, TABLET_TOOL_UPDATED);
|
2019-04-05 14:58:56 +10:00
|
|
|
if (e->value)
|
|
|
|
|
tablet->tool_state |= bit(type);
|
|
|
|
|
else
|
|
|
|
|
tablet->tool_state &= ~bit(type);
|
2014-06-10 16:48:19 -04:00
|
|
|
break;
|
2014-06-10 23:14:41 -04:00
|
|
|
case BTN_TOUCH:
|
2015-12-11 17:40:36 +10:00
|
|
|
if (!bit_is_set(tablet->axis_caps,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) {
|
|
|
|
|
if (e->value)
|
|
|
|
|
tablet_set_status(tablet,
|
|
|
|
|
TABLET_TOOL_ENTERING_CONTACT);
|
|
|
|
|
else
|
|
|
|
|
tablet_set_status(tablet,
|
|
|
|
|
TABLET_TOOL_LEAVING_CONTACT);
|
|
|
|
|
}
|
2015-11-11 14:03:05 +10:00
|
|
|
break;
|
2014-06-10 16:48:19 -04:00
|
|
|
default:
|
2014-06-10 23:14:41 -04:00
|
|
|
tablet_update_button(tablet, e->code, e->value);
|
2014-06-10 16:48:19 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-20 11:41:06 +10:00
|
|
|
static void
|
|
|
|
|
tablet_process_relative(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct input_event *e,
|
2015-08-04 12:37:40 +10:00
|
|
|
uint64_t time)
|
2015-02-20 11:41:06 +10:00
|
|
|
{
|
2015-11-16 15:35:40 +10:00
|
|
|
enum libinput_tablet_tool_axis axis;
|
2015-03-02 16:43:32 +10:00
|
|
|
|
2015-02-20 11:41:06 +10:00
|
|
|
switch (e->code) {
|
|
|
|
|
case REL_WHEEL:
|
|
|
|
|
axis = rel_evcode_to_axis(e->code);
|
2015-11-16 15:36:30 +10:00
|
|
|
if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) {
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_bug_libinput(device,
|
|
|
|
|
"Invalid ABS event code %#x\n",
|
|
|
|
|
e->code);
|
2015-02-20 11:41:06 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
set_bit(tablet->changed_axes, axis);
|
2016-01-06 16:20:38 +10:00
|
|
|
tablet->axes.wheel_discrete = -1 * e->value;
|
2015-02-20 11:41:06 +10:00
|
|
|
tablet_set_status(tablet, TABLET_AXES_UPDATED);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_info(device,
|
|
|
|
|
"Unhandled relative axis %s (%#x)\n",
|
|
|
|
|
libevdev_event_code_get_name(EV_REL, e->code),
|
|
|
|
|
e->code);
|
2015-02-20 11:41:06 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-10 16:48:19 -04:00
|
|
|
static void
|
|
|
|
|
tablet_process_misc(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct input_event *e,
|
2015-08-04 12:37:40 +10:00
|
|
|
uint64_t time)
|
2014-06-10 16:48:19 -04:00
|
|
|
{
|
|
|
|
|
switch (e->code) {
|
|
|
|
|
case MSC_SERIAL:
|
2014-06-26 21:31:52 -04:00
|
|
|
if (e->value != -1)
|
2019-04-01 15:10:55 +10:00
|
|
|
tablet->current_tool.serial = e->value;
|
2014-06-26 21:31:52 -04:00
|
|
|
|
2016-09-14 09:43:39 +10:00
|
|
|
break;
|
|
|
|
|
case MSC_SCAN:
|
2014-06-10 16:48:19 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_info(device,
|
|
|
|
|
"Unhandled MSC event code %s (%#x)\n",
|
|
|
|
|
libevdev_event_code_get_name(EV_MSC, e->code),
|
|
|
|
|
e->code);
|
2014-06-10 16:48:19 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 12:03:34 +10:00
|
|
|
static inline void
|
|
|
|
|
copy_axis_cap(const struct tablet_dispatch *tablet,
|
2015-11-16 15:34:19 +10:00
|
|
|
struct libinput_tablet_tool *tool,
|
2015-11-16 15:35:40 +10:00
|
|
|
enum libinput_tablet_tool_axis axis)
|
2015-02-18 12:03:34 +10:00
|
|
|
{
|
|
|
|
|
if (bit_is_set(tablet->axis_caps, axis))
|
|
|
|
|
set_bit(tool->axis_caps, axis);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 13:53:31 +10:00
|
|
|
static inline void
|
|
|
|
|
copy_button_cap(const struct tablet_dispatch *tablet,
|
2015-11-16 15:34:19 +10:00
|
|
|
struct libinput_tablet_tool *tool,
|
2015-02-18 13:53:31 +10:00
|
|
|
uint32_t button)
|
|
|
|
|
{
|
|
|
|
|
struct libevdev *evdev = tablet->device->evdev;
|
|
|
|
|
if (libevdev_has_event_code(evdev, EV_KEY, button))
|
|
|
|
|
set_bit(tool->buttons, button);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 09:23:09 +10:00
|
|
|
static inline bool
|
2015-02-18 13:53:31 +10:00
|
|
|
tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet,
|
2015-11-16 15:34:19 +10:00
|
|
|
struct libinput_tablet_tool *tool)
|
2015-02-18 13:53:31 +10:00
|
|
|
{
|
2024-10-29 09:23:09 +10:00
|
|
|
bool rc = false;
|
|
|
|
|
#if HAVE_LIBWACOM
|
2015-02-18 13:53:31 +10:00
|
|
|
WacomDeviceDatabase *db;
|
|
|
|
|
const WacomStylus *s = NULL;
|
|
|
|
|
int code;
|
2015-02-19 18:04:27 +10:00
|
|
|
WacomStylusType type;
|
2015-03-10 12:40:14 +10:00
|
|
|
WacomAxisTypeFlags axes;
|
2015-02-18 13:53:31 +10:00
|
|
|
|
2019-05-27 18:21:09 +10:00
|
|
|
db = tablet_libinput_context(tablet)->libwacom.db;
|
|
|
|
|
if (!db)
|
|
|
|
|
return rc;
|
|
|
|
|
|
2015-02-18 13:53:31 +10:00
|
|
|
s = libwacom_stylus_get_for_id(db, tool->tool_id);
|
|
|
|
|
if (!s)
|
2019-05-27 18:21:09 +10:00
|
|
|
return rc;
|
2015-02-18 13:53:31 +10:00
|
|
|
|
2015-02-19 18:04:27 +10:00
|
|
|
type = libwacom_stylus_get_type(s);
|
|
|
|
|
if (type == WSTYLUS_PUCK) {
|
2015-02-18 13:53:31 +10:00
|
|
|
for (code = BTN_LEFT;
|
|
|
|
|
code < BTN_LEFT + libwacom_stylus_get_num_buttons(s);
|
|
|
|
|
code++)
|
|
|
|
|
copy_button_cap(tablet, tool, code);
|
|
|
|
|
} else {
|
2024-01-23 20:09:04 +10:00
|
|
|
if (libwacom_stylus_get_num_buttons(s) >= 3)
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_STYLUS3);
|
2015-02-18 13:53:31 +10:00
|
|
|
if (libwacom_stylus_get_num_buttons(s) >= 2)
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_STYLUS2);
|
|
|
|
|
if (libwacom_stylus_get_num_buttons(s) >= 1)
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_STYLUS);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 12:40:14 +10:00
|
|
|
if (libwacom_stylus_has_wheel(s))
|
2015-11-16 15:36:30 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
|
2015-03-10 12:40:14 +10:00
|
|
|
|
|
|
|
|
axes = libwacom_stylus_get_axes(s);
|
|
|
|
|
|
|
|
|
|
if (axes & WACOM_AXIS_TYPE_TILT) {
|
|
|
|
|
/* tilt on the puck is converted to rotation */
|
|
|
|
|
if (type == WSTYLUS_PUCK) {
|
|
|
|
|
set_bit(tool->axis_caps,
|
2015-11-16 15:36:30 +10:00
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
2015-03-10 12:40:14 +10:00
|
|
|
} else {
|
2015-02-20 11:41:06 +10:00
|
|
|
copy_axis_cap(tablet,
|
|
|
|
|
tool,
|
2015-11-16 15:36:30 +10:00
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
|
2015-03-10 12:40:14 +10:00
|
|
|
copy_axis_cap(tablet,
|
|
|
|
|
tool,
|
2015-11-16 15:36:30 +10:00
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
|
2015-03-10 12:40:14 +10:00
|
|
|
}
|
2015-02-19 18:04:27 +10:00
|
|
|
}
|
2015-03-10 12:40:14 +10:00
|
|
|
if (axes & WACOM_AXIS_TYPE_ROTATION_Z)
|
2015-11-16 15:36:30 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
2015-03-10 12:40:14 +10:00
|
|
|
if (axes & WACOM_AXIS_TYPE_DISTANCE)
|
2015-11-16 15:36:30 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
|
2015-03-10 12:40:14 +10:00
|
|
|
if (axes & WACOM_AXIS_TYPE_SLIDER)
|
2015-11-16 15:36:30 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
|
2015-03-10 12:40:14 +10:00
|
|
|
if (axes & WACOM_AXIS_TYPE_PRESSURE)
|
2015-11-16 15:36:30 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
2015-02-19 18:04:27 +10:00
|
|
|
|
2024-10-29 09:23:09 +10:00
|
|
|
rc = true;
|
|
|
|
|
#endif
|
2015-02-19 18:04:27 +10:00
|
|
|
return rc;
|
2015-02-18 13:53:31 +10:00
|
|
|
}
|
|
|
|
|
|
2015-02-18 12:03:34 +10:00
|
|
|
static void
|
|
|
|
|
tool_set_bits(const struct tablet_dispatch *tablet,
|
2015-11-16 15:34:19 +10:00
|
|
|
struct libinput_tablet_tool *tool)
|
2015-02-18 12:03:34 +10:00
|
|
|
{
|
2015-11-16 15:39:07 +10:00
|
|
|
enum libinput_tablet_tool_type type = tool->type;
|
2015-02-18 12:03:34 +10:00
|
|
|
|
2015-12-15 11:18:14 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_X);
|
|
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_Y);
|
|
|
|
|
|
2024-10-29 09:23:09 +10:00
|
|
|
if (tool_set_bits_from_libwacom(tablet, tool))
|
2015-02-19 18:04:27 +10:00
|
|
|
return;
|
2024-10-29 09:23:09 +10:00
|
|
|
|
2015-02-19 18:04:27 +10:00
|
|
|
/* If we don't have libwacom, we simply copy any axis we have on the
|
|
|
|
|
tablet onto the tool. Except we know that mice only have rotation
|
|
|
|
|
anyway.
|
2015-02-18 12:03:34 +10:00
|
|
|
*/
|
|
|
|
|
switch (type) {
|
2015-11-16 15:40:43 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PEN:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_ERASER:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH:
|
2015-11-16 15:36:30 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
|
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
|
|
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
|
|
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
|
|
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
|
2018-02-05 09:11:42 +10:00
|
|
|
|
|
|
|
|
/* Rotation is special, it can be either ABS_Z or
|
|
|
|
|
* BTN_TOOL_MOUSE+ABS_TILT_X/Y. Aiptek tablets have
|
|
|
|
|
* mouse+tilt (and thus rotation), but they do not have
|
|
|
|
|
* ABS_Z. So let's not copy the axis bit if we don't have
|
|
|
|
|
* ABS_Z, otherwise we try to get the value from it later on
|
|
|
|
|
* proximity in and go boom because the absinfo isn't there.
|
|
|
|
|
*/
|
|
|
|
|
if (libevdev_has_event_code(tablet->device->evdev, EV_ABS,
|
|
|
|
|
ABS_Z))
|
|
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
2015-02-18 12:03:34 +10:00
|
|
|
break;
|
2015-11-16 15:40:43 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_LENS:
|
2015-11-16 15:36:30 +10:00
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
|
|
|
|
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
|
2015-02-16 15:19:44 +10:00
|
|
|
break;
|
2015-02-18 12:03:34 +10:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-02-18 13:53:31 +10:00
|
|
|
|
2015-12-15 11:26:29 +10:00
|
|
|
/* If we don't have libwacom, copy all pen-related buttons from the
|
|
|
|
|
tablet vs all mouse-related buttons */
|
2015-02-18 13:53:31 +10:00
|
|
|
switch (type) {
|
2015-11-16 15:40:43 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PEN:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_ERASER:
|
2015-02-18 13:53:31 +10:00
|
|
|
copy_button_cap(tablet, tool, BTN_STYLUS);
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_STYLUS2);
|
2024-01-23 20:09:04 +10:00
|
|
|
copy_button_cap(tablet, tool, BTN_STYLUS3);
|
2015-02-18 13:53:31 +10:00
|
|
|
break;
|
2015-11-16 15:40:43 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE:
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_LENS:
|
2015-02-18 13:53:31 +10:00
|
|
|
copy_button_cap(tablet, tool, BTN_LEFT);
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_MIDDLE);
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_RIGHT);
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_SIDE);
|
|
|
|
|
copy_button_cap(tablet, tool, BTN_EXTRA);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-02-18 12:03:34 +10:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 17:07:17 +10:00
|
|
|
static bool
|
|
|
|
|
tablet_get_quirked_pressure_thresholds(struct tablet_dispatch *tablet,
|
|
|
|
|
int *hi,
|
|
|
|
|
int *lo)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *device = tablet->device;
|
|
|
|
|
struct quirks_context *quirks = evdev_libinput_context(device)->quirks;
|
|
|
|
|
struct quirks *q = quirks_fetch_for_device(quirks, device->udev_device);
|
|
|
|
|
struct quirk_range r;
|
|
|
|
|
bool status = false;
|
|
|
|
|
|
|
|
|
|
/* Note: the quirk term "range" refers to the hi/lo settings, not the
|
|
|
|
|
* full available range for the pressure axis */
|
|
|
|
|
if (q && quirks_get_range(q, QUIRK_ATTR_PRESSURE_RANGE, &r)) {
|
|
|
|
|
if (r.lower < r.upper) {
|
|
|
|
|
*hi = r.lower;
|
|
|
|
|
*lo = r.upper;
|
|
|
|
|
status = true;
|
|
|
|
|
} else {
|
|
|
|
|
evdev_log_info(device, "Invalid pressure range, using defaults\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quirks_unref(q);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
apply_pressure_range_configuration(struct tablet_dispatch *tablet,
|
2025-03-31 12:16:52 +10:00
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
bool force_update)
|
2024-01-15 17:07:17 +10:00
|
|
|
{
|
|
|
|
|
struct evdev_device *device = tablet->device;
|
|
|
|
|
|
|
|
|
|
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_PRESSURE) ||
|
2025-03-31 12:16:52 +10:00
|
|
|
(!force_update &&
|
|
|
|
|
tool->pressure.range.min == tool->pressure.wanted_range.min &&
|
2024-01-15 17:07:17 +10:00
|
|
|
tool->pressure.range.max == tool->pressure.wanted_range.max))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
double min = tool->pressure.wanted_range.min;
|
|
|
|
|
double max = tool->pressure.wanted_range.max;
|
|
|
|
|
|
|
|
|
|
struct input_absinfo abs = *libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
|
|
|
|
|
|
|
|
|
|
int minimum = axis_range_percentage(&abs, min * 100.0);
|
|
|
|
|
int maximum = axis_range_percentage(&abs, max * 100.0);
|
|
|
|
|
|
|
|
|
|
abs.minimum = minimum;
|
|
|
|
|
abs.maximum = maximum;
|
|
|
|
|
|
|
|
|
|
/* Only use the quirk pressure range if we don't have a custom range */
|
|
|
|
|
int hi, lo;
|
|
|
|
|
if (tool->pressure.wanted_range.min != 0.0 ||
|
|
|
|
|
tool->pressure.wanted_range.max != 1.0 ||
|
|
|
|
|
!tablet_get_quirked_pressure_thresholds(tablet, &hi, &lo)) {
|
|
|
|
|
/* 5 and 1% of the pressure range */
|
|
|
|
|
hi = axis_range_percentage(&abs, 5);
|
|
|
|
|
lo = axis_range_percentage(&abs, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
struct libinput_tablet_tool_pressure_threshold *threshold =
|
|
|
|
|
tablet_tool_get_threshold(tablet, tool);
|
|
|
|
|
threshold->abs_pressure = abs;
|
|
|
|
|
threshold->threshold.upper = hi;
|
|
|
|
|
threshold->threshold.lower = lo;
|
2024-01-15 17:07:17 +10:00
|
|
|
tool->pressure.range.min = tool->pressure.wanted_range.min;
|
|
|
|
|
tool->pressure.range.max = tool->pressure.wanted_range.max;
|
|
|
|
|
|
|
|
|
|
/* Disable any heuristics */
|
|
|
|
|
if (tool->pressure.has_configured_range) {
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->has_offset = true;
|
|
|
|
|
threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_DONE;
|
2024-01-15 17:07:17 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-29 09:19:27 +10:00
|
|
|
static inline void
|
2024-01-15 17:07:17 +10:00
|
|
|
tool_init_pressure_thresholds(struct tablet_dispatch *tablet,
|
2025-02-17 15:29:26 +10:00
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
struct libinput_tablet_tool_pressure_threshold *threshold)
|
2020-03-29 09:19:27 +10:00
|
|
|
{
|
|
|
|
|
struct evdev_device *device = tablet->device;
|
2023-06-13 13:12:53 +10:00
|
|
|
const struct input_absinfo *pressure, *distance;
|
2020-03-29 09:19:27 +10:00
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->tablet_id = tablet->tablet_id;
|
|
|
|
|
threshold->offset = 0;
|
|
|
|
|
threshold->has_offset = false;
|
2025-03-31 12:16:52 +10:00
|
|
|
threshold->threshold.upper = 1;
|
|
|
|
|
threshold->threshold.lower = 0;
|
2020-03-29 09:19:27 +10:00
|
|
|
|
|
|
|
|
pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
|
2025-03-31 12:16:52 +10:00
|
|
|
if (!pressure)
|
2024-01-15 17:07:17 +10:00
|
|
|
return;
|
2025-03-31 12:16:52 +10:00
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->abs_pressure = *pressure;
|
2020-03-29 09:19:27 +10:00
|
|
|
|
2023-06-13 13:12:53 +10:00
|
|
|
distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
|
|
|
|
|
if (distance) {
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->offset = pressure->minimum;
|
|
|
|
|
threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_DONE;
|
2023-06-13 13:12:53 +10:00
|
|
|
} else {
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->offset = pressure->maximum;
|
|
|
|
|
threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_PROXIN1;
|
2023-06-13 13:12:53 +10:00
|
|
|
}
|
2020-03-29 09:19:27 +10:00
|
|
|
|
2025-03-31 12:16:52 +10:00
|
|
|
apply_pressure_range_configuration(tablet, tool, true);
|
2024-01-15 17:07:17 +10:00
|
|
|
}
|
2020-03-29 09:19:27 +10:00
|
|
|
|
2024-01-15 17:07:17 +10:00
|
|
|
static int
|
|
|
|
|
pressure_range_is_available(struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
|
|
|
|
}
|
2020-03-29 09:19:27 +10:00
|
|
|
|
2024-01-15 17:07:17 +10:00
|
|
|
static enum libinput_config_status
|
|
|
|
|
pressure_range_set(struct libinput_tablet_tool *tool, double min, double max)
|
|
|
|
|
{
|
|
|
|
|
if (min < 0.0 || min >= 1.0 || max <= 0.0 || max > 1.0 || max <= min)
|
|
|
|
|
return LIBINPUT_CONFIG_STATUS_INVALID;
|
|
|
|
|
|
|
|
|
|
tool->pressure.wanted_range.min = min;
|
|
|
|
|
tool->pressure.wanted_range.max = max;
|
|
|
|
|
tool->pressure.has_configured_range = true;
|
|
|
|
|
|
|
|
|
|
return LIBINPUT_CONFIG_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pressure_range_get(struct libinput_tablet_tool *tool, double *min, double *max)
|
|
|
|
|
{
|
|
|
|
|
*min = tool->pressure.wanted_range.min;
|
|
|
|
|
*max = tool->pressure.wanted_range.max;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pressure_range_get_default(struct libinput_tablet_tool *tool, double *min, double *max)
|
|
|
|
|
{
|
|
|
|
|
*min = 0.0;
|
|
|
|
|
*max = 1.0;
|
2020-03-29 09:19:27 +10:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 17:33:43 +10:00
|
|
|
static struct libinput_tablet_tool *
|
|
|
|
|
tablet_new_tool(struct tablet_dispatch *tablet,
|
|
|
|
|
enum libinput_tablet_tool_type type,
|
|
|
|
|
uint32_t tool_id,
|
|
|
|
|
uint32_t serial)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_tablet_tool *tool = zalloc(sizeof *tool);
|
|
|
|
|
|
|
|
|
|
*tool = (struct libinput_tablet_tool) {
|
|
|
|
|
.type = type,
|
|
|
|
|
.serial = serial,
|
|
|
|
|
.tool_id = tool_id,
|
|
|
|
|
.refcount = 1,
|
2024-01-15 17:07:17 +10:00
|
|
|
|
|
|
|
|
.pressure.range.min = 0.0,
|
|
|
|
|
.pressure.range.max = 0.0, /* to trigger configuration */
|
|
|
|
|
.pressure.wanted_range.min = 0.0,
|
|
|
|
|
.pressure.wanted_range.max = 1.0,
|
|
|
|
|
|
|
|
|
|
.config.pressure_range.is_available = pressure_range_is_available,
|
|
|
|
|
.config.pressure_range.set = pressure_range_set,
|
|
|
|
|
.config.pressure_range.get = pressure_range_get,
|
|
|
|
|
.config.pressure_range.get_default = pressure_range_get_default,
|
2024-01-15 17:33:43 +10:00
|
|
|
};
|
|
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
tool_init_pressure_thresholds(tablet, tool, &tool->pressure.thresholds[0]);
|
2024-01-15 17:33:43 +10:00
|
|
|
tool_set_bits(tablet, tool);
|
|
|
|
|
|
|
|
|
|
return tool;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 15:34:19 +10:00
|
|
|
static struct libinput_tablet_tool *
|
2014-08-07 19:00:52 -04:00
|
|
|
tablet_get_tool(struct tablet_dispatch *tablet,
|
2015-11-16 15:39:07 +10:00
|
|
|
enum libinput_tablet_tool_type type,
|
2015-02-19 14:56:34 +10:00
|
|
|
uint32_t tool_id,
|
2014-06-26 21:31:50 -04:00
|
|
|
uint32_t serial)
|
2014-06-10 16:48:19 -04:00
|
|
|
{
|
2016-08-29 15:14:55 +10:00
|
|
|
struct libinput *libinput = tablet_libinput_context(tablet);
|
2015-11-16 15:34:19 +10:00
|
|
|
struct libinput_tablet_tool *tool = NULL, *t;
|
2014-08-07 19:00:52 -04:00
|
|
|
struct list *tool_list;
|
2014-06-10 16:48:19 -04:00
|
|
|
|
2014-08-07 19:00:52 -04:00
|
|
|
if (serial) {
|
2016-06-09 11:15:51 +10:00
|
|
|
tool_list = &libinput->tool_list;
|
2014-08-07 19:00:52 -04:00
|
|
|
/* Check if we already have the tool in our list of tools */
|
|
|
|
|
list_for_each(t, tool_list, link) {
|
|
|
|
|
if (type == t->type && serial == t->serial) {
|
|
|
|
|
tool = t;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-29 15:14:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we get a tool with a delayed serial number, we already created
|
|
|
|
|
* a 0-serial number tool for it earlier. Re-use that, even though
|
|
|
|
|
* it means we can't distinguish this tool from others.
|
|
|
|
|
* https://bugs.freedesktop.org/show_bug.cgi?id=97526
|
|
|
|
|
*/
|
|
|
|
|
if (!tool) {
|
|
|
|
|
tool_list = &tablet->tool_list;
|
2014-08-07 19:00:52 -04:00
|
|
|
/* We can't guarantee that tools without serial numbers are
|
|
|
|
|
* unique, so we keep them local to the tablet that they come
|
|
|
|
|
* into proximity of instead of storing them in the global tool
|
2016-08-29 15:14:55 +10:00
|
|
|
* list
|
|
|
|
|
* Same as above, but don't bother checking the serial number
|
|
|
|
|
*/
|
2014-08-07 19:00:52 -04:00
|
|
|
list_for_each(t, tool_list, link) {
|
|
|
|
|
if (type == t->type) {
|
|
|
|
|
tool = t;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-06-10 16:48:19 -04:00
|
|
|
}
|
2016-08-29 15:14:55 +10:00
|
|
|
|
|
|
|
|
/* Didn't find the tool but we have a serial. Switch
|
|
|
|
|
* tool_list back so we create in the correct list */
|
|
|
|
|
if (!tool && serial)
|
|
|
|
|
tool_list = &libinput->tool_list;
|
2014-06-10 16:48:19 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-26 21:31:50 -04:00
|
|
|
/* If we didn't already have the new_tool in our list of tools,
|
|
|
|
|
* add it */
|
|
|
|
|
if (!tool) {
|
2024-01-15 17:33:43 +10:00
|
|
|
tool = tablet_new_tool(tablet, type, tool_id, serial);
|
2014-08-07 19:00:52 -04:00
|
|
|
list_insert(tool_list, &tool->link);
|
2025-02-17 15:29:26 +10:00
|
|
|
} else {
|
|
|
|
|
ARRAY_FOR_EACH(tool->pressure.thresholds, t) {
|
|
|
|
|
if (t->tablet_id == tablet->tablet_id)
|
|
|
|
|
break;
|
|
|
|
|
if (t->tablet_id == 0) {
|
|
|
|
|
tool_init_pressure_thresholds(tablet, tool, t);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-14 12:04:31 +10:00
|
|
|
}
|
2014-06-10 16:48:19 -04:00
|
|
|
|
2014-06-26 21:31:50 -04:00
|
|
|
return tool;
|
2014-06-10 16:48:19 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-10 23:14:41 -04:00
|
|
|
static void
|
|
|
|
|
tablet_notify_button_mask(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
2015-08-04 12:37:40 +10:00
|
|
|
uint64_t time,
|
2015-11-16 15:34:19 +10:00
|
|
|
struct libinput_tablet_tool *tool,
|
2016-02-10 09:24:51 +10:00
|
|
|
const struct button_state *buttons,
|
2014-06-10 23:14:41 -04:00
|
|
|
enum libinput_button_state state)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_device *base = &device->base;
|
2015-02-19 15:46:29 +10:00
|
|
|
size_t i;
|
2016-02-10 09:24:51 +10:00
|
|
|
size_t nbits = 8 * sizeof(buttons->bits);
|
2015-11-16 15:43:41 +10:00
|
|
|
enum libinput_tablet_tool_tip_state tip_state;
|
2015-11-12 08:01:43 +10:00
|
|
|
|
2020-09-11 08:42:15 +10:00
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT))
|
|
|
|
|
tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN;
|
|
|
|
|
else
|
|
|
|
|
tip_state = LIBINPUT_TABLET_TOOL_TIP_UP;
|
2014-06-10 23:14:41 -04:00
|
|
|
|
2015-02-19 15:46:29 +10:00
|
|
|
for (i = 0; i < nbits; i++) {
|
2016-02-10 09:24:51 +10:00
|
|
|
if (!bit_is_set(buttons->bits, i))
|
2014-06-10 23:14:41 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
tablet_notify_button(base,
|
|
|
|
|
time,
|
2014-06-26 21:31:52 -04:00
|
|
|
tool,
|
2015-11-12 08:01:43 +10:00
|
|
|
tip_state,
|
2016-01-06 16:16:46 +10:00
|
|
|
&tablet->axes,
|
2015-02-19 15:46:29 +10:00
|
|
|
i,
|
2024-06-13 10:31:37 +10:00
|
|
|
state,
|
|
|
|
|
&tablet->area.x,
|
|
|
|
|
&tablet->area.y);
|
2014-06-10 23:14:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_notify_buttons(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
2015-08-04 12:37:40 +10:00
|
|
|
uint64_t time,
|
2015-11-16 15:34:19 +10:00
|
|
|
struct libinput_tablet_tool *tool,
|
2014-06-10 23:14:41 -04:00
|
|
|
enum libinput_button_state state)
|
|
|
|
|
{
|
2016-02-10 09:24:51 +10:00
|
|
|
struct button_state buttons;
|
2014-06-10 23:14:41 -04:00
|
|
|
|
2014-06-20 14:51:28 +10:00
|
|
|
if (state == LIBINPUT_BUTTON_STATE_PRESSED)
|
2016-02-10 09:24:51 +10:00
|
|
|
tablet_get_pressed_buttons(tablet, &buttons);
|
2014-06-20 14:51:28 +10:00
|
|
|
else
|
2016-02-10 09:24:51 +10:00
|
|
|
tablet_get_released_buttons(tablet, &buttons);
|
2014-06-10 23:14:41 -04:00
|
|
|
|
2014-06-26 21:31:52 -04:00
|
|
|
tablet_notify_button_mask(tablet,
|
|
|
|
|
device,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
2016-02-10 09:24:51 +10:00
|
|
|
&buttons,
|
2014-06-26 21:31:52 -04:00
|
|
|
state);
|
2014-06-10 23:14:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-06-12 18:46:26 -04:00
|
|
|
static void
|
2015-12-11 17:40:36 +10:00
|
|
|
sanitize_pressure_distance(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
2014-06-12 18:46:26 -04:00
|
|
|
{
|
2015-11-30 15:04:49 +10:00
|
|
|
bool tool_in_contact;
|
2014-06-12 18:46:26 -04:00
|
|
|
const struct input_absinfo *distance,
|
|
|
|
|
*pressure;
|
|
|
|
|
|
|
|
|
|
distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE);
|
2024-01-15 17:07:17 +10:00
|
|
|
/* Note: for pressure/distance sanitization we use the real pressure
|
|
|
|
|
axis, not our configured one */
|
2014-06-12 18:46:26 -04:00
|
|
|
pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE);
|
|
|
|
|
|
2015-12-11 17:40:36 +10:00
|
|
|
if (!pressure || !distance)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-05-06 14:59:05 +10:00
|
|
|
bool pressure_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
|
|
|
|
bool distance_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
|
|
|
|
|
|
|
|
|
|
if (!pressure_changed && !distance_changed)
|
2015-12-11 17:40:36 +10:00
|
|
|
return;
|
|
|
|
|
|
tablet: require a minimum pressure before we process pressure events
Tools default to 1% lower threshold (tip up) and 5% upper threshold (tip
down). But our distance vs pressure exclusion would reset the distance
for *any* pressure value, regardless how low that value was and how high
distance was in comparison.
A very low pressure value of less than 1% would then result in a
normalized pressure of 0, so we'd effectively just reset the distance to
zero and do nothing with the pressure. This can cause distance jumps
when the tool arbitrarily sends low pressure values while hovering as
seen in https://github.com/libsdl-org/SDL/pull/5481#issuecomment-1118969064
Commit 61bdc05fb0f84303f97daaba6ae6b49c976dbfbf from Dec 2017
"tablet: set the tip-up pressure threshold to 1%"
was presumably to address this but no longer (?) works.
Fix this by addressing multiple issues at the same time:
- anything under that 1% threshold is now considered as zero pressure
and any distance value is kept as-is. Once pressure reaches 1%,
distance is always zero.
- axis normalization is now from 1% to 100% (previously: upper threshold
to 100%). So a tip down event should always have ~4% pressure and we
may get tablet motion events with nonzero pressure before the tip down
event.
From memory, this was always intended anyway since a tip event should
require some significant pressure, maybe too high compared to e.g.
pressure-sensitive painting
- where a tablet has an offset, add the same 1%/5% thresholds, on top of
that offset. And keep adjusting those thresholds as we change the
offset. Assuming that the offset is the absolute minimum a worn-out
pen can reach, this gives us the same behaviour as a new pen. The
calculation here uses a simple approach so the actual range is
slightly larger than 5% but it'll do.
Previously, the lower threshold for an offset pen was the axis minimum
but that can never be reached. So there was probably an undiscovered
bug in there.
And fix a bunch of comments that were either wrong, confusing or
incomplete, e.g. the pressure thresholds were already in device
coordinates.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-06 15:21:08 +10:00
|
|
|
/* Note: this is an arbitrary "in contact" decision rather than "tip
|
|
|
|
|
* down". We use the lower threshold as minimum pressure value,
|
|
|
|
|
* anything less than that gets filtered away */
|
2025-02-17 15:29:26 +10:00
|
|
|
struct libinput_tablet_tool_pressure_threshold* threshold =
|
|
|
|
|
tablet_tool_get_threshold(tablet, tool);
|
|
|
|
|
tool_in_contact = (pressure->value > threshold->threshold.lower);
|
2015-11-30 15:04:49 +10:00
|
|
|
|
2015-02-15 19:06:34 -05:00
|
|
|
/* Keep distance and pressure mutually exclusive */
|
2015-11-30 15:00:43 +10:00
|
|
|
if (distance &&
|
2014-06-19 01:18:06 -04:00
|
|
|
distance->value > distance->minimum &&
|
|
|
|
|
pressure->value > pressure->minimum) {
|
2015-11-30 15:04:49 +10:00
|
|
|
if (tool_in_contact) {
|
|
|
|
|
clear_bit(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.distance = 0;
|
2015-11-30 15:04:49 +10:00
|
|
|
} else {
|
|
|
|
|
clear_bit(tablet->changed_axes,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.pressure = 0;
|
2015-11-30 15:04:49 +10:00
|
|
|
}
|
2022-05-06 14:59:05 +10:00
|
|
|
} else if (pressure_changed && !tool_in_contact) {
|
2014-06-17 21:17:58 -04:00
|
|
|
/* Make sure that the last axis value sent to the caller is a 0 */
|
2016-01-06 16:16:46 +10:00
|
|
|
if (tablet->axes.pressure == 0)
|
2014-06-17 21:17:58 -04:00
|
|
|
clear_bit(tablet->changed_axes,
|
2015-11-16 15:36:30 +10:00
|
|
|
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
|
2014-06-17 21:17:58 -04:00
|
|
|
else
|
2016-01-06 16:16:46 +10:00
|
|
|
tablet->axes.pressure = 0;
|
2014-06-12 18:46:26 -04:00
|
|
|
}
|
2015-12-15 08:39:56 +10:00
|
|
|
}
|
2015-02-16 15:19:44 +10:00
|
|
|
|
2015-12-15 08:39:56 +10:00
|
|
|
static inline void
|
|
|
|
|
sanitize_mouse_lens_rotation(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
2015-02-16 15:19:44 +10:00
|
|
|
/* If we have a mouse/lens cursor and the tilt changed, the rotation
|
|
|
|
|
changed. Mark this, calculate the angle later */
|
2019-04-01 15:10:55 +10:00
|
|
|
if ((tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
|
|
|
|
|
tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) &&
|
2015-11-16 15:36:30 +10:00
|
|
|
(bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
|
|
|
|
|
bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)))
|
|
|
|
|
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
|
2014-06-12 18:46:26 -04:00
|
|
|
}
|
|
|
|
|
|
2015-12-15 08:39:56 +10:00
|
|
|
static void
|
2015-12-11 17:40:36 +10:00
|
|
|
sanitize_tablet_axes(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
2015-12-15 08:39:56 +10:00
|
|
|
{
|
2015-12-11 17:40:36 +10:00
|
|
|
sanitize_pressure_distance(tablet, tool);
|
2015-12-15 08:39:56 +10:00
|
|
|
sanitize_mouse_lens_rotation(tablet);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-13 10:56:10 +10:00
|
|
|
static void
|
2025-02-17 15:29:26 +10:00
|
|
|
set_pressure_offset(struct libinput_tablet_tool_pressure_threshold *threshold, int offset)
|
2023-06-13 10:56:10 +10:00
|
|
|
{
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->offset = offset;
|
|
|
|
|
threshold->has_offset = true;
|
2023-06-13 10:56:10 +10:00
|
|
|
|
|
|
|
|
/* Adjust the tresholds accordingly - we use the same gap (4% in
|
|
|
|
|
* device coordinates) between upper and lower as before which isn't
|
|
|
|
|
* technically correct (our range shrunk) but it's easy to calculate.
|
|
|
|
|
*/
|
2025-02-17 15:29:26 +10:00
|
|
|
int gap = threshold->threshold.upper - threshold->threshold.lower;
|
|
|
|
|
threshold->threshold.lower = offset;
|
|
|
|
|
threshold->threshold.upper = offset + gap;
|
2023-06-13 10:56:10 +10:00
|
|
|
}
|
|
|
|
|
|
2023-06-13 12:49:05 +10:00
|
|
|
static void
|
|
|
|
|
update_pressure_offset(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *pressure =
|
|
|
|
|
libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
|
|
|
|
|
|
2024-01-15 17:07:17 +10:00
|
|
|
if (!pressure || tool->pressure.has_configured_range ||
|
2023-06-13 13:12:53 +10:00
|
|
|
!bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
|
2023-06-13 12:49:05 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* If we have an event that falls below the current offset, adjust
|
|
|
|
|
* the offset downwards. A fast contact can start with a
|
|
|
|
|
* higher-than-needed pressure offset and then we'd be tied into a
|
|
|
|
|
* high pressure offset for the rest of the session.
|
2023-06-13 13:12:53 +10:00
|
|
|
*
|
|
|
|
|
* If we are still pending the offset decision, only update the observed
|
|
|
|
|
* offset value, don't actually set it to have an offset.
|
2023-06-13 12:49:05 +10:00
|
|
|
*/
|
|
|
|
|
int offset = pressure->value;
|
2025-02-17 15:29:26 +10:00
|
|
|
struct libinput_tablet_tool_pressure_threshold *threshold =
|
|
|
|
|
tablet_tool_get_threshold(tablet, tool);
|
|
|
|
|
if (threshold->has_offset) {
|
|
|
|
|
if (offset < threshold->offset)
|
|
|
|
|
set_pressure_offset(threshold, offset);
|
|
|
|
|
} else if (threshold->heuristic_state != PRESSURE_HEURISTIC_STATE_DONE) {
|
|
|
|
|
threshold->offset = min(offset, threshold->offset);
|
2023-06-13 13:12:53 +10:00
|
|
|
}
|
2023-06-13 12:49:05 +10:00
|
|
|
}
|
|
|
|
|
|
2015-12-01 11:07:57 +10:00
|
|
|
static void
|
|
|
|
|
detect_pressure_offset(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *pressure, *distance;
|
|
|
|
|
int offset;
|
|
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
if (tool->pressure.has_configured_range ||
|
2023-06-13 12:49:05 +10:00
|
|
|
!bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
|
2015-12-01 11:07:57 +10:00
|
|
|
return;
|
|
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
struct libinput_tablet_tool_pressure_threshold *threshold =
|
|
|
|
|
tablet_tool_get_threshold(tablet, tool);
|
|
|
|
|
if (threshold->has_offset)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-12-01 11:07:57 +10:00
|
|
|
pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
|
|
|
|
|
distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
|
|
|
|
|
|
2023-06-13 13:12:53 +10:00
|
|
|
if (!pressure)
|
2015-12-01 11:07:57 +10:00
|
|
|
return;
|
|
|
|
|
|
2019-08-06 12:57:51 +10:00
|
|
|
offset = pressure->value;
|
|
|
|
|
if (offset <= pressure->minimum)
|
2016-01-05 11:09:35 +10:00
|
|
|
return;
|
|
|
|
|
|
2023-06-13 13:12:53 +10:00
|
|
|
if (distance) {
|
|
|
|
|
/* If we're closer than 50% of the distance axis, skip pressure
|
|
|
|
|
* offset detection, too likely to be wrong */
|
|
|
|
|
if (distance->value < axis_range_percentage(distance, 50))
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
/* A device without distance will always have some pressure on
|
|
|
|
|
* contact. Offset detection is delayed for a few proximity ins
|
|
|
|
|
* in the hope we'll find the minimum value until then. That
|
|
|
|
|
* offset is updated during motion events so by the time the
|
|
|
|
|
* deciding prox-in arrives we should know the minimum offset.
|
|
|
|
|
*/
|
|
|
|
|
if (offset > pressure->minimum)
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->offset = min(offset, threshold->offset);
|
2023-06-13 13:12:53 +10:00
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
switch (threshold->heuristic_state) {
|
2023-06-13 13:12:53 +10:00
|
|
|
case PRESSURE_HEURISTIC_STATE_PROXIN1:
|
|
|
|
|
case PRESSURE_HEURISTIC_STATE_PROXIN2:
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->heuristic_state++;
|
2023-06-13 13:12:53 +10:00
|
|
|
return;
|
|
|
|
|
case PRESSURE_HEURISTIC_STATE_DECIDE:
|
2025-02-17 15:29:26 +10:00
|
|
|
threshold->heuristic_state++;
|
|
|
|
|
offset = threshold->offset;
|
2023-06-13 13:12:53 +10:00
|
|
|
break;
|
|
|
|
|
case PRESSURE_HEURISTIC_STATE_DONE:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (offset <= pressure->minimum)
|
2015-12-01 11:07:57 +10:00
|
|
|
return;
|
|
|
|
|
|
2022-12-17 17:52:39 +01:00
|
|
|
if (offset > axis_range_percentage(pressure, 50)) {
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_error(device,
|
2022-12-17 17:52:39 +01:00
|
|
|
"Ignoring pressure offset greater than 50%% detected on tool %s (serial %#x). "
|
2020-09-09 11:17:12 +10:00
|
|
|
"See %s/tablet-support.html\n",
|
2015-12-01 11:07:57 +10:00
|
|
|
tablet_tool_type_to_string(tool->type),
|
|
|
|
|
tool->serial,
|
2019-08-06 13:24:11 +10:00
|
|
|
HTTP_DOC_LINK);
|
2015-12-01 11:07:57 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_info(device,
|
2015-12-01 11:07:57 +10:00
|
|
|
"Pressure offset detected on tool %s (serial %#x). "
|
2020-09-09 11:17:12 +10:00
|
|
|
"See %s/tablet-support.html\n",
|
2015-12-01 11:07:57 +10:00
|
|
|
tablet_tool_type_to_string(tool->type),
|
|
|
|
|
tool->serial,
|
2019-08-06 13:24:11 +10:00
|
|
|
HTTP_DOC_LINK);
|
tablet: require a minimum pressure before we process pressure events
Tools default to 1% lower threshold (tip up) and 5% upper threshold (tip
down). But our distance vs pressure exclusion would reset the distance
for *any* pressure value, regardless how low that value was and how high
distance was in comparison.
A very low pressure value of less than 1% would then result in a
normalized pressure of 0, so we'd effectively just reset the distance to
zero and do nothing with the pressure. This can cause distance jumps
when the tool arbitrarily sends low pressure values while hovering as
seen in https://github.com/libsdl-org/SDL/pull/5481#issuecomment-1118969064
Commit 61bdc05fb0f84303f97daaba6ae6b49c976dbfbf from Dec 2017
"tablet: set the tip-up pressure threshold to 1%"
was presumably to address this but no longer (?) works.
Fix this by addressing multiple issues at the same time:
- anything under that 1% threshold is now considered as zero pressure
and any distance value is kept as-is. Once pressure reaches 1%,
distance is always zero.
- axis normalization is now from 1% to 100% (previously: upper threshold
to 100%). So a tip down event should always have ~4% pressure and we
may get tablet motion events with nonzero pressure before the tip down
event.
From memory, this was always intended anyway since a tip event should
require some significant pressure, maybe too high compared to e.g.
pressure-sensitive painting
- where a tablet has an offset, add the same 1%/5% thresholds, on top of
that offset. And keep adjusting those thresholds as we change the
offset. Assuming that the offset is the absolute minimum a worn-out
pen can reach, this gives us the same behaviour as a new pen. The
calculation here uses a simple approach so the actual range is
slightly larger than 5% but it'll do.
Previously, the lower threshold for an offset pen was the axis minimum
but that can never be reached. So there was probably an undiscovered
bug in there.
And fix a bunch of comments that were either wrong, confusing or
incomplete, e.g. the pressure thresholds were already in device
coordinates.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-05-06 15:21:08 +10:00
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
set_pressure_offset(threshold, offset);
|
2015-12-01 11:07:57 +10:00
|
|
|
}
|
|
|
|
|
|
2015-12-11 17:40:36 +10:00
|
|
|
static void
|
|
|
|
|
detect_tool_contact(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *p;
|
|
|
|
|
int pressure;
|
|
|
|
|
|
|
|
|
|
if (!bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* if we have pressure, always use that for contact, not BTN_TOUCH */
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT))
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_bug_libinput(device,
|
|
|
|
|
"Invalid status: entering contact\n");
|
2015-12-11 17:40:36 +10:00
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) &&
|
|
|
|
|
!tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_bug_libinput(device,
|
|
|
|
|
"Invalid status: leaving contact\n");
|
2015-12-11 17:40:36 +10:00
|
|
|
|
|
|
|
|
p = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE);
|
|
|
|
|
if (!p) {
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_bug_libinput(device,
|
|
|
|
|
"Missing pressure axis\n");
|
2015-12-11 17:40:36 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pressure = p->value;
|
|
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
struct libinput_tablet_tool_pressure_threshold *threshold =
|
|
|
|
|
tablet_tool_get_threshold(tablet, tool);
|
|
|
|
|
if (pressure <= threshold->threshold.lower &&
|
2015-12-11 17:40:36 +10:00
|
|
|
tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) {
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
|
2025-02-17 15:29:26 +10:00
|
|
|
} else if (pressure >= threshold->threshold.upper &&
|
2015-12-11 17:40:36 +10:00
|
|
|
!tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) {
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-15 11:18:14 +10:00
|
|
|
static void
|
|
|
|
|
tablet_mark_all_axes_changed(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
static_assert(sizeof(tablet->changed_axes) ==
|
|
|
|
|
sizeof(tool->axis_caps),
|
|
|
|
|
"Mismatching array sizes");
|
|
|
|
|
|
|
|
|
|
memcpy(tablet->changed_axes,
|
|
|
|
|
tool->axis_caps,
|
|
|
|
|
sizeof(tablet->changed_axes));
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 17:16:18 +10:00
|
|
|
static void
|
|
|
|
|
tablet_update_proximity_state(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct libinput_tablet_tool *tool)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *distance;
|
|
|
|
|
int dist_max = tablet->cursor_proximity_threshold;
|
|
|
|
|
int dist;
|
|
|
|
|
|
|
|
|
|
distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE);
|
|
|
|
|
if (!distance)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
dist = distance->value;
|
|
|
|
|
if (dist == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Tool got into permitted range */
|
|
|
|
|
if (dist < dist_max &&
|
|
|
|
|
(tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) ||
|
|
|
|
|
tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))) {
|
|
|
|
|
tablet_unset_status(tablet,
|
|
|
|
|
TABLET_TOOL_OUT_OF_RANGE);
|
|
|
|
|
tablet_unset_status(tablet,
|
|
|
|
|
TABLET_TOOL_OUT_OF_PROXIMITY);
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
|
|
|
|
|
tablet_mark_all_axes_changed(tablet, tool);
|
|
|
|
|
|
|
|
|
|
tablet_set_status(tablet, TABLET_BUTTONS_PRESSED);
|
|
|
|
|
tablet_force_button_presses(tablet);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dist < dist_max)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Still out of range/proximity */
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) ||
|
|
|
|
|
tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Tool entered prox but is outside of permitted range */
|
|
|
|
|
if (tablet_has_status(tablet,
|
|
|
|
|
TABLET_TOOL_ENTERING_PROXIMITY)) {
|
|
|
|
|
tablet_set_status(tablet,
|
|
|
|
|
TABLET_TOOL_OUT_OF_RANGE);
|
|
|
|
|
tablet_unset_status(tablet,
|
|
|
|
|
TABLET_TOOL_ENTERING_PROXIMITY);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Tool was in prox and is now outside of range. Set leaving
|
|
|
|
|
* proximity, on the next event it will be OUT_OF_PROXIMITY and thus
|
|
|
|
|
* caught by the above conditions */
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 11:47:32 +10:00
|
|
|
static struct phys_rect
|
|
|
|
|
tablet_calculate_arbitration_rect(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *device = tablet->device;
|
|
|
|
|
struct phys_rect r = {0};
|
|
|
|
|
struct phys_coords mm;
|
|
|
|
|
|
|
|
|
|
mm = evdev_device_units_to_mm(device, &tablet->axes.point);
|
|
|
|
|
|
2022-11-23 08:48:55 +01:00
|
|
|
/* The rect we disable is 20mm left of the tip, 100mm north of the
|
|
|
|
|
* tip, and 200x250mm large.
|
2018-09-28 11:47:32 +10:00
|
|
|
* If the stylus is tilted left (tip further right than the eraser
|
|
|
|
|
* end) assume left-handed mode.
|
|
|
|
|
*
|
2023-02-07 11:19:35 +01:00
|
|
|
* Obviously if we'd run out of the boundaries, we clip the rect
|
2018-09-28 11:47:32 +10:00
|
|
|
* accordingly.
|
|
|
|
|
*/
|
|
|
|
|
if (tablet->axes.tilt.x > 0) {
|
|
|
|
|
r.x = mm.x - 20;
|
|
|
|
|
r.w = 200;
|
|
|
|
|
} else {
|
|
|
|
|
r.x = mm.x + 20;
|
|
|
|
|
r.w = 200;
|
|
|
|
|
r.x -= r.w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (r.x < 0) {
|
2023-02-07 11:19:35 +01:00
|
|
|
r.w += r.x;
|
2018-09-28 11:47:32 +10:00
|
|
|
r.x = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 08:48:55 +01:00
|
|
|
r.y = mm.y - 100;
|
|
|
|
|
r.h = 250;
|
2018-09-28 11:47:32 +10:00
|
|
|
if (r.y < 0) {
|
2023-02-07 11:19:35 +01:00
|
|
|
r.h += r.y;
|
2018-09-28 11:47:32 +10:00
|
|
|
r.y = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_update_touch_device_rect(struct tablet_dispatch *tablet,
|
|
|
|
|
const struct tablet_axes *axes,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_dispatch *dispatch;
|
|
|
|
|
struct phys_rect rect = {0};
|
|
|
|
|
|
|
|
|
|
if (tablet->touch_device == NULL ||
|
|
|
|
|
tablet->arbitration != ARBITRATION_IGNORE_RECT)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
rect = tablet_calculate_arbitration_rect(tablet);
|
|
|
|
|
|
|
|
|
|
dispatch = tablet->touch_device->dispatch;
|
|
|
|
|
if (dispatch->interface->touch_arbitration_update_rect)
|
|
|
|
|
dispatch->interface->touch_arbitration_update_rect(dispatch,
|
|
|
|
|
tablet->touch_device,
|
|
|
|
|
&rect,
|
|
|
|
|
time);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
static inline bool
|
|
|
|
|
tablet_send_proximity_in(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
struct evdev_device *device,
|
2017-03-07 17:08:07 +10:00
|
|
|
struct tablet_axes *axes,
|
2017-03-01 15:22:49 +10:00
|
|
|
uint64_t time)
|
2015-12-15 08:39:56 +10:00
|
|
|
{
|
2017-03-01 15:22:49 +10:00
|
|
|
if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY))
|
|
|
|
|
return false;
|
2015-12-15 08:39:56 +10:00
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
tablet_notify_proximity(&device->base,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
|
|
|
|
|
tablet->changed_axes,
|
2024-06-13 10:31:37 +10:00
|
|
|
axes,
|
|
|
|
|
&tablet->area.x,
|
|
|
|
|
&tablet->area.y);
|
2017-03-01 15:22:49 +10:00
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
2015-12-15 08:39:56 +10:00
|
|
|
|
2017-03-07 17:08:07 +10:00
|
|
|
tablet_reset_changed_axes(tablet);
|
|
|
|
|
axes->delta.x = 0;
|
|
|
|
|
axes->delta.y = 0;
|
|
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2015-12-15 08:39:56 +10:00
|
|
|
|
2025-01-07 11:29:46 +10:00
|
|
|
static inline void
|
2017-03-01 15:22:49 +10:00
|
|
|
tablet_send_proximity_out(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
struct evdev_device *device,
|
2017-03-07 17:08:07 +10:00
|
|
|
struct tablet_axes *axes,
|
2017-03-01 15:22:49 +10:00
|
|
|
uint64_t time)
|
|
|
|
|
{
|
2025-01-07 11:29:46 +10:00
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY) &&
|
|
|
|
|
!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA)) {
|
2024-11-01 14:30:51 +10:00
|
|
|
tablet_notify_proximity(&device->base,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT,
|
|
|
|
|
tablet->changed_axes,
|
|
|
|
|
axes,
|
|
|
|
|
&tablet->area.x,
|
|
|
|
|
&tablet->area.y);
|
|
|
|
|
}
|
2017-03-01 15:22:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
|
tablet_send_tip(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
struct evdev_device *device,
|
2017-03-07 17:08:07 +10:00
|
|
|
struct tablet_axes *axes,
|
2017-03-01 15:22:49 +10:00
|
|
|
uint64_t time)
|
|
|
|
|
{
|
2015-12-15 08:39:56 +10:00
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) {
|
|
|
|
|
tablet_notify_tip(&device->base,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_TIP_DOWN,
|
|
|
|
|
tablet->changed_axes,
|
2024-06-13 10:31:37 +10:00
|
|
|
axes,
|
|
|
|
|
&tablet->area.x,
|
|
|
|
|
&tablet->area.y);
|
2015-12-15 08:39:56 +10:00
|
|
|
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT);
|
2017-03-07 17:08:07 +10:00
|
|
|
|
|
|
|
|
tablet_reset_changed_axes(tablet);
|
|
|
|
|
axes->delta.x = 0;
|
|
|
|
|
axes->delta.y = 0;
|
|
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) {
|
2015-12-15 08:39:56 +10:00
|
|
|
tablet_notify_tip(&device->base,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
|
|
|
|
LIBINPUT_TABLET_TOOL_TIP_UP,
|
|
|
|
|
tablet->changed_axes,
|
2024-06-13 10:31:37 +10:00
|
|
|
axes,
|
|
|
|
|
&tablet->area.x,
|
|
|
|
|
&tablet->area.y);
|
2015-12-15 08:39:56 +10:00
|
|
|
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT);
|
2017-03-07 17:08:07 +10:00
|
|
|
|
|
|
|
|
tablet_reset_changed_axes(tablet);
|
|
|
|
|
axes->delta.x = 0;
|
|
|
|
|
axes->delta.y = 0;
|
|
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
2015-12-15 08:39:56 +10:00
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_send_axes(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
struct evdev_device *device,
|
2017-03-07 17:08:07 +10:00
|
|
|
struct tablet_axes *axes,
|
2017-03-01 15:22:49 +10:00
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
enum libinput_tablet_tool_tip_state tip_state;
|
|
|
|
|
|
|
|
|
|
if (!tablet_has_status(tablet, TABLET_AXES_UPDATED))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (tablet_has_status(tablet,
|
|
|
|
|
TABLET_TOOL_IN_CONTACT))
|
|
|
|
|
tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN;
|
|
|
|
|
else
|
|
|
|
|
tip_state = LIBINPUT_TABLET_TOOL_TIP_UP;
|
|
|
|
|
|
|
|
|
|
tablet_notify_axis(&device->base,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
|
|
|
|
tip_state,
|
|
|
|
|
tablet->changed_axes,
|
2024-06-13 10:31:37 +10:00
|
|
|
axes,
|
|
|
|
|
&tablet->area.x,
|
|
|
|
|
&tablet->area.y);
|
2017-03-01 15:22:49 +10:00
|
|
|
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
2017-03-07 17:08:07 +10:00
|
|
|
tablet_reset_changed_axes(tablet);
|
|
|
|
|
axes->delta.x = 0;
|
|
|
|
|
axes->delta.y = 0;
|
2017-03-01 15:22:49 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_send_buttons(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) {
|
|
|
|
|
tablet_notify_buttons(tablet,
|
|
|
|
|
device,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_RELEASED);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) {
|
|
|
|
|
tablet_notify_buttons(tablet,
|
|
|
|
|
device,
|
|
|
|
|
time,
|
|
|
|
|
tool,
|
|
|
|
|
LIBINPUT_BUTTON_STATE_PRESSED);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_send_events(struct tablet_dispatch *tablet,
|
|
|
|
|
struct libinput_tablet_tool *tool,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_axes axes = {0};
|
|
|
|
|
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
|
|
|
|
|
/* Tool is leaving proximity, we can't rely on the last axis
|
|
|
|
|
* information (it'll be mostly 0), so we just get the
|
|
|
|
|
* current state and skip over updating the axes.
|
|
|
|
|
*/
|
|
|
|
|
axes = tablet->axes;
|
|
|
|
|
|
2020-08-27 19:52:34 +02:00
|
|
|
/* Don't send an axis event, but we may have a tip event
|
2017-03-01 15:22:49 +10:00
|
|
|
* update */
|
2015-12-15 08:39:56 +10:00
|
|
|
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
|
2017-03-01 15:22:49 +10:00
|
|
|
} else {
|
2018-09-28 11:47:32 +10:00
|
|
|
if (tablet_check_notify_axes(tablet, device, tool, &axes, time))
|
|
|
|
|
tablet_update_touch_device_rect(tablet, &axes, time);
|
2015-12-15 08:39:56 +10:00
|
|
|
}
|
|
|
|
|
|
2017-03-07 16:37:55 +10:00
|
|
|
assert(tablet->axes.delta.x == 0);
|
|
|
|
|
assert(tablet->axes.delta.y == 0);
|
|
|
|
|
|
2017-03-01 15:22:49 +10:00
|
|
|
tablet_send_proximity_in(tablet, tool, device, &axes, time);
|
|
|
|
|
if (!tablet_send_tip(tablet, tool, device, &axes, time))
|
|
|
|
|
tablet_send_axes(tablet, tool, device, &axes, time);
|
|
|
|
|
|
2015-12-15 08:39:56 +10:00
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
|
2017-03-07 17:08:07 +10:00
|
|
|
tablet_reset_changed_axes(tablet);
|
2017-03-01 15:22:49 +10:00
|
|
|
|
|
|
|
|
tablet_send_buttons(tablet, tool, device, time);
|
|
|
|
|
|
2025-01-07 11:29:46 +10:00
|
|
|
tablet_send_proximity_out(tablet, tool, device, &axes, time);
|
2015-12-15 08:39:56 +10:00
|
|
|
}
|
|
|
|
|
|
2019-04-05 14:58:56 +10:00
|
|
|
/**
|
|
|
|
|
* Handling for the proximity out workaround. Some tablets only send
|
|
|
|
|
* BTN_TOOL_PEN on the very first event, then leave it set even when the pen
|
|
|
|
|
* leaves the detectable range. To libinput this looks like we always have
|
|
|
|
|
* the pen in proximity.
|
|
|
|
|
*
|
|
|
|
|
* To avoid this, we set a timer on BTN_TOOL_PEN in. We expect the tablet to
|
|
|
|
|
* continuously send events, and while it's doing so we keep updating the
|
|
|
|
|
* timer. Once we go Xms without an event we assume proximity out and inject
|
|
|
|
|
* a BTN_TOOL_PEN event into the sequence through the timer func.
|
|
|
|
|
*
|
|
|
|
|
* We need to remember that we did that, on the first event after the
|
|
|
|
|
* timeout we need to emulate a BTN_TOOL_PEN event again to force proximity
|
|
|
|
|
* in.
|
|
|
|
|
*
|
|
|
|
|
* Other tools never send the BTN_TOOL_PEN event. For those tools, we
|
|
|
|
|
* piggyback along with the proximity out quirks by injecting
|
|
|
|
|
* the event during the first event frame.
|
|
|
|
|
*/
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_proximity_out_quirk_set_timer(struct tablet_dispatch *tablet,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
2019-06-17 13:25:59 +10:00
|
|
|
if (tablet->quirks.need_to_force_prox_out)
|
|
|
|
|
libinput_timer_set(&tablet->quirks.prox_out_timer,
|
|
|
|
|
time + FORCED_PROXOUT_TIMEOUT);
|
2019-04-05 14:58:56 +10:00
|
|
|
}
|
|
|
|
|
|
2019-10-30 15:23:24 +10:00
|
|
|
static bool
|
2019-04-05 14:58:56 +10:00
|
|
|
tablet_update_tool_state(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
|
|
|
|
enum libinput_tablet_tool_type type;
|
|
|
|
|
uint32_t changed;
|
|
|
|
|
int state;
|
2019-10-30 15:23:24 +10:00
|
|
|
uint32_t doubled_up_new_tool_bit = 0;
|
2019-04-05 14:58:56 +10:00
|
|
|
|
2020-03-27 21:15:50 +10:00
|
|
|
/* we were already out of proximity but now got a tool update but
|
|
|
|
|
* our tool state is zero - i.e. we got a valid prox out from the
|
|
|
|
|
* device.
|
|
|
|
|
*/
|
|
|
|
|
if (tablet->quirks.proximity_out_forced &&
|
|
|
|
|
tablet_has_status(tablet, TABLET_TOOL_UPDATED) &&
|
|
|
|
|
!tablet->tool_state) {
|
|
|
|
|
tablet->quirks.need_to_force_prox_out = false;
|
|
|
|
|
tablet->quirks.proximity_out_forced = false;
|
|
|
|
|
}
|
2019-04-05 14:58:56 +10:00
|
|
|
/* We need to emulate a BTN_TOOL_PEN if we get an axis event (i.e.
|
|
|
|
|
* stylus is def. in proximity) and:
|
|
|
|
|
* - we forced a proximity out before, or
|
|
|
|
|
* - on the very first event after init, because if we didn't get a
|
|
|
|
|
* BTN_TOOL_PEN and the state for the tool was 0, this device will
|
|
|
|
|
* never send the event.
|
|
|
|
|
* We don't do this for pure button events because we discard those.
|
2019-06-17 11:18:57 +10:00
|
|
|
*
|
|
|
|
|
* But: on some devices the proximity out is delayed by the kernel,
|
|
|
|
|
* so we get it after our forced prox-out has triggered. In that
|
|
|
|
|
* case we need to just ignore the change.
|
2019-04-05 14:58:56 +10:00
|
|
|
*/
|
2019-06-17 11:18:57 +10:00
|
|
|
if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
|
|
|
|
|
if (tablet->quirks.proximity_out_forced) {
|
2020-01-31 12:12:59 +10:00
|
|
|
if (!tablet_has_status(tablet, TABLET_TOOL_UPDATED) &&
|
|
|
|
|
!tablet->tool_state)
|
2019-06-17 11:18:57 +10:00
|
|
|
tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
|
|
|
|
|
tablet->quirks.proximity_out_forced = false;
|
|
|
|
|
} else if (tablet->tool_state == 0 &&
|
|
|
|
|
tablet->current_tool.type == LIBINPUT_TOOL_NONE) {
|
|
|
|
|
tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
|
|
|
|
|
tablet->quirks.proximity_out_forced = false;
|
|
|
|
|
}
|
2019-04-05 14:58:56 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tablet->tool_state == tablet->prev_tool_state)
|
2019-10-30 15:23:24 +10:00
|
|
|
return false;
|
2019-04-05 14:58:56 +10:00
|
|
|
|
2021-11-17 16:24:00 +10:00
|
|
|
/* Kernel tools are supposed to be mutually exclusive, but we may have
|
|
|
|
|
* two bits set due to firmware/kernel bugs.
|
|
|
|
|
* Two cases that have been seen in the wild:
|
|
|
|
|
* - BTN_TOOL_PEN on proximity in, followed by
|
|
|
|
|
* BTN_TOOL_RUBBER later, see #259
|
|
|
|
|
* -> We force a prox-out of the pen, trigger prox-in for eraser
|
|
|
|
|
* - BTN_TOOL_RUBBER on proximity in, but BTN_TOOL_PEN when
|
|
|
|
|
* the tip is down, see #702.
|
|
|
|
|
* -> We ignore BTN_TOOL_PEN
|
|
|
|
|
* In both cases the eraser is what we want, so we bias
|
|
|
|
|
* towards that.
|
2019-10-30 15:23:24 +10:00
|
|
|
*/
|
2019-06-16 19:37:37 -07:00
|
|
|
if (tablet->tool_state & (tablet->tool_state - 1)) {
|
2019-10-30 15:23:24 +10:00
|
|
|
doubled_up_new_tool_bit = tablet->tool_state ^ tablet->prev_tool_state;
|
2021-11-17 16:24:00 +10:00
|
|
|
|
|
|
|
|
/* The new tool is the pen. Ignore it */
|
|
|
|
|
if (doubled_up_new_tool_bit == bit(LIBINPUT_TABLET_TOOL_TYPE_PEN)) {
|
|
|
|
|
tablet->tool_state &= ~bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The new tool is some tool other than pen (usually eraser).
|
|
|
|
|
* We set the current tool state to zero, thus setting
|
|
|
|
|
* everything up for a prox out on the tool. Once that is set
|
|
|
|
|
* up, we change the tool state to be the new one we just got.
|
|
|
|
|
* When we re-process this function we now get the new tool
|
|
|
|
|
* as prox in. Importantly, we basically rely on nothing else
|
|
|
|
|
* happening in the meantime.
|
|
|
|
|
*/
|
2019-10-30 15:23:24 +10:00
|
|
|
tablet->tool_state = 0;
|
2019-04-05 14:58:56 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changed = tablet->tool_state ^ tablet->prev_tool_state;
|
|
|
|
|
type = ffs(changed) - 1;
|
|
|
|
|
state = !!(tablet->tool_state & bit(type));
|
|
|
|
|
|
|
|
|
|
tablet_update_tool(tablet, device, type, state);
|
|
|
|
|
|
|
|
|
|
/* The proximity timeout is only needed for BTN_TOOL_PEN, devices
|
|
|
|
|
* that require it don't do erasers */
|
|
|
|
|
if (type == LIBINPUT_TABLET_TOOL_TYPE_PEN) {
|
|
|
|
|
if (state) {
|
|
|
|
|
tablet_proximity_out_quirk_set_timer(tablet, time);
|
|
|
|
|
} else {
|
|
|
|
|
/* If we get a BTN_TOOL_PEN 0 when *not* injecting
|
|
|
|
|
* events it means the tablet will give us the right
|
|
|
|
|
* events after all and we can disable our
|
|
|
|
|
* timer-based proximity out.
|
|
|
|
|
*/
|
2020-03-22 21:21:52 +10:00
|
|
|
if (!tablet->quirks.proximity_out_in_progress)
|
|
|
|
|
tablet->quirks.need_to_force_prox_out = false;
|
|
|
|
|
|
2019-04-05 14:58:56 +10:00
|
|
|
libinput_timer_cancel(&tablet->quirks.prox_out_timer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tablet->prev_tool_state = tablet->tool_state;
|
|
|
|
|
|
2019-10-30 15:23:24 +10:00
|
|
|
if (doubled_up_new_tool_bit) {
|
|
|
|
|
tablet->tool_state = doubled_up_new_tool_bit;
|
|
|
|
|
return true; /* need to re-process */
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2019-04-05 14:58:56 +10:00
|
|
|
}
|
|
|
|
|
|
2019-09-26 09:59:47 +10:00
|
|
|
static struct libinput_tablet_tool *
|
|
|
|
|
tablet_get_current_tool(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
|
|
|
|
if (tablet->current_tool.type == LIBINPUT_TOOL_NONE)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return tablet_get_tool(tablet,
|
|
|
|
|
tablet->current_tool.type,
|
|
|
|
|
tablet->current_tool.id,
|
|
|
|
|
tablet->current_tool.serial);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
static void
|
|
|
|
|
tablet_flush(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device,
|
2015-08-04 12:37:40 +10:00
|
|
|
uint64_t time)
|
2014-06-05 23:20:36 -04:00
|
|
|
{
|
2018-02-02 11:24:55 +10:00
|
|
|
struct libinput_tablet_tool *tool;
|
2019-10-30 15:23:24 +10:00
|
|
|
bool process_tool_twice;
|
2018-02-02 11:24:55 +10:00
|
|
|
|
2019-10-30 15:23:24 +10:00
|
|
|
reprocess:
|
|
|
|
|
process_tool_twice = tablet_update_tool_state(tablet, device, time);
|
2014-06-26 21:31:50 -04:00
|
|
|
|
2019-09-26 09:59:47 +10:00
|
|
|
tool = tablet_get_current_tool(tablet);
|
2016-01-22 18:08:44 +10:00
|
|
|
if (!tool)
|
|
|
|
|
return; /* OOM */
|
|
|
|
|
|
2015-12-02 17:16:18 +10:00
|
|
|
if (tool->type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
|
|
|
|
|
tool->type == LIBINPUT_TABLET_TOOL_TYPE_LENS)
|
|
|
|
|
tablet_update_proximity_state(tablet, device, tool);
|
|
|
|
|
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) ||
|
|
|
|
|
tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE))
|
2015-02-26 13:55:08 +10:00
|
|
|
return;
|
|
|
|
|
|
2014-06-26 18:02:48 -04:00
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
|
2014-06-10 23:14:41 -04:00
|
|
|
/* Release all stylus buttons */
|
2016-02-10 09:24:51 +10:00
|
|
|
memset(tablet->button_state.bits,
|
2015-02-19 15:46:29 +10:00
|
|
|
0,
|
2016-02-10 09:24:51 +10:00
|
|
|
sizeof(tablet->button_state.bits));
|
2014-06-10 23:14:41 -04:00
|
|
|
tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
|
2015-11-11 14:03:05 +10:00
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT))
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
|
2025-03-31 12:16:52 +10:00
|
|
|
apply_pressure_range_configuration(tablet, tool, false);
|
2024-11-01 14:30:51 +10:00
|
|
|
} else if (!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA)) {
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
|
|
|
|
|
/* If we get into proximity outside the tablet area, we ignore
|
|
|
|
|
* that whole sequence of events even if we later move into
|
|
|
|
|
* the allowed area. This may be bad UX but it's complicated to
|
|
|
|
|
* implement so let's wait for someone to actually complain
|
|
|
|
|
* about it.
|
|
|
|
|
*
|
|
|
|
|
* We allow a margin of 3% (6mm on a 200mm tablet) to be "within"
|
|
|
|
|
* the area - there we clip to the area but do not ignore the
|
|
|
|
|
* sequence.
|
|
|
|
|
*/
|
|
|
|
|
const struct device_coords point = {
|
|
|
|
|
device->abs.absinfo_x->value,
|
|
|
|
|
device->abs.absinfo_y->value,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const double margin = 0.03;
|
|
|
|
|
if (is_inside_area(tablet, &point, margin)) {
|
|
|
|
|
tablet_mark_all_axes_changed(tablet, tool);
|
|
|
|
|
update_pressure_offset(tablet, device, tool);
|
|
|
|
|
detect_pressure_offset(tablet, device, tool);
|
|
|
|
|
detect_tool_contact(tablet, device, tool);
|
|
|
|
|
sanitize_tablet_axes(tablet, tool);
|
|
|
|
|
} else {
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_OUTSIDE_AREA);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
|
|
|
|
|
}
|
|
|
|
|
} else if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
|
|
|
|
|
update_pressure_offset(tablet, device, tool);
|
|
|
|
|
detect_tool_contact(tablet, device, tool);
|
|
|
|
|
sanitize_tablet_axes(tablet, tool);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-06 16:35:33 -04:00
|
|
|
}
|
|
|
|
|
|
2025-01-07 11:29:46 +10:00
|
|
|
if (!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA))
|
2024-11-01 14:30:51 +10:00
|
|
|
tablet_send_events(tablet, tool, device, time);
|
2025-01-07 11:29:46 +10:00
|
|
|
|
|
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
|
|
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_OUTSIDE_AREA);
|
|
|
|
|
|
|
|
|
|
tablet_reset_changed_axes(tablet);
|
|
|
|
|
|
|
|
|
|
tablet_change_to_left_handed(device);
|
|
|
|
|
tablet_apply_rotation(device);
|
|
|
|
|
tablet_change_area(device);
|
|
|
|
|
tablet_history_reset(tablet);
|
2024-11-01 14:30:51 +10:00
|
|
|
}
|
2019-10-30 15:23:24 +10:00
|
|
|
|
|
|
|
|
if (process_tool_twice)
|
|
|
|
|
goto reprocess;
|
2015-02-26 13:55:08 +10:00
|
|
|
}
|
2014-06-10 23:14:41 -04:00
|
|
|
|
2016-06-28 11:28:34 +10:00
|
|
|
static inline void
|
2018-09-28 11:47:32 +10:00
|
|
|
tablet_set_touch_device_enabled(struct tablet_dispatch *tablet,
|
|
|
|
|
enum evdev_arbitration_state which,
|
|
|
|
|
const struct phys_rect *rect,
|
2018-02-19 14:41:50 +10:00
|
|
|
uint64_t time)
|
2016-06-28 11:28:34 +10:00
|
|
|
{
|
2018-09-28 11:47:32 +10:00
|
|
|
struct evdev_device *touch_device = tablet->touch_device;
|
2016-06-28 11:28:34 +10:00
|
|
|
struct evdev_dispatch *dispatch;
|
|
|
|
|
|
|
|
|
|
if (touch_device == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-09-28 11:47:32 +10:00
|
|
|
tablet->arbitration = which;
|
2018-09-19 12:02:51 +10:00
|
|
|
|
2016-06-28 11:28:34 +10:00
|
|
|
dispatch = touch_device->dispatch;
|
2018-09-19 12:02:51 +10:00
|
|
|
if (dispatch->interface->touch_arbitration_toggle)
|
|
|
|
|
dispatch->interface->touch_arbitration_toggle(dispatch,
|
|
|
|
|
touch_device,
|
|
|
|
|
which,
|
2018-09-28 11:47:32 +10:00
|
|
|
rect,
|
2018-09-19 12:02:51 +10:00
|
|
|
time);
|
2016-06-28 11:28:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
tablet_toggle_touch_device(struct tablet_dispatch *tablet,
|
2018-02-19 14:41:50 +10:00
|
|
|
struct evdev_device *tablet_device,
|
|
|
|
|
uint64_t time)
|
2016-06-28 11:28:34 +10:00
|
|
|
{
|
2018-09-28 11:47:32 +10:00
|
|
|
enum evdev_arbitration_state which;
|
|
|
|
|
struct phys_rect r = {0};
|
|
|
|
|
struct phys_rect *rect = NULL;
|
2016-06-28 11:28:34 +10:00
|
|
|
|
2018-09-28 11:47:32 +10:00
|
|
|
if (tablet_has_status(tablet,
|
|
|
|
|
TABLET_TOOL_OUT_OF_RANGE) ||
|
|
|
|
|
tablet_has_status(tablet, TABLET_NONE) ||
|
|
|
|
|
tablet_has_status(tablet,
|
|
|
|
|
TABLET_TOOL_LEAVING_PROXIMITY) ||
|
|
|
|
|
tablet_has_status(tablet,
|
|
|
|
|
TABLET_TOOL_OUT_OF_PROXIMITY)) {
|
|
|
|
|
which = ARBITRATION_NOT_ACTIVE;
|
|
|
|
|
} else if (tablet->axes.tilt.x == 0) {
|
|
|
|
|
which = ARBITRATION_IGNORE_ALL;
|
|
|
|
|
} else if (tablet->arbitration != ARBITRATION_IGNORE_RECT) {
|
|
|
|
|
/* This enables rect-based arbitration, updates are sent
|
|
|
|
|
* elsewhere */
|
|
|
|
|
r = tablet_calculate_arbitration_rect(tablet);
|
|
|
|
|
rect = &r;
|
|
|
|
|
which = ARBITRATION_IGNORE_RECT;
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-06-28 11:28:34 +10:00
|
|
|
|
2018-09-28 11:47:32 +10:00
|
|
|
tablet_set_touch_device_enabled(tablet,
|
|
|
|
|
which,
|
|
|
|
|
rect,
|
2018-02-19 14:41:50 +10:00
|
|
|
time);
|
2016-06-28 11:28:34 +10:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 13:55:08 +10:00
|
|
|
static inline void
|
|
|
|
|
tablet_reset_state(struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
2020-02-06 19:09:14 +10:00
|
|
|
struct button_state zero = {0};
|
|
|
|
|
|
2014-06-10 23:14:41 -04:00
|
|
|
/* Update state */
|
|
|
|
|
memcpy(&tablet->prev_button_state,
|
|
|
|
|
&tablet->button_state,
|
|
|
|
|
sizeof(tablet->button_state));
|
2019-06-17 11:18:57 +10:00
|
|
|
tablet_unset_status(tablet, TABLET_TOOL_UPDATED);
|
2020-02-06 19:09:14 +10:00
|
|
|
|
|
|
|
|
if (memcmp(&tablet->button_state, &zero, sizeof(zero)) == 0)
|
|
|
|
|
tablet_unset_status(tablet, TABLET_BUTTONS_DOWN);
|
|
|
|
|
else
|
|
|
|
|
tablet_set_status(tablet, TABLET_BUTTONS_DOWN);
|
2014-06-05 23:20:36 -04:00
|
|
|
}
|
|
|
|
|
|
2016-12-22 12:11:43 +10:00
|
|
|
static void
|
|
|
|
|
tablet_proximity_out_quirk_timer_func(uint64_t now, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *tablet = data;
|
2018-01-15 16:16:37 -08:00
|
|
|
struct timeval tv = us2tv(now);
|
2016-12-22 12:11:43 +10:00
|
|
|
struct input_event events[2] = {
|
2018-01-15 16:16:37 -08:00
|
|
|
{ .input_event_sec = tv.tv_sec,
|
|
|
|
|
.input_event_usec = tv.tv_usec,
|
2016-12-22 12:11:43 +10:00
|
|
|
.type = EV_KEY,
|
|
|
|
|
.code = BTN_TOOL_PEN,
|
|
|
|
|
.value = 0 },
|
2018-01-15 16:16:37 -08:00
|
|
|
{ .input_event_sec = tv.tv_sec,
|
|
|
|
|
.input_event_usec = tv.tv_usec,
|
2016-12-22 12:11:43 +10:00
|
|
|
.type = EV_SYN,
|
|
|
|
|
.code = SYN_REPORT,
|
|
|
|
|
.value = 0 },
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-06 19:09:14 +10:00
|
|
|
if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ||
|
|
|
|
|
tablet_has_status(tablet, TABLET_BUTTONS_DOWN)) {
|
2019-09-29 23:35:09 +00:00
|
|
|
tablet_proximity_out_quirk_set_timer(tablet, now);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 12:11:43 +10:00
|
|
|
if (tablet->quirks.last_event_time > now - FORCED_PROXOUT_TIMEOUT) {
|
|
|
|
|
tablet_proximity_out_quirk_set_timer(tablet,
|
|
|
|
|
tablet->quirks.last_event_time);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 13:16:02 +10:00
|
|
|
evdev_log_debug(tablet->device, "tablet: forcing proximity after timeout\n");
|
|
|
|
|
|
2020-03-22 21:21:52 +10:00
|
|
|
tablet->quirks.proximity_out_in_progress = true;
|
2016-12-22 12:11:43 +10:00
|
|
|
ARRAY_FOR_EACH(events, e) {
|
|
|
|
|
tablet->base.interface->process(&tablet->base,
|
|
|
|
|
tablet->device,
|
|
|
|
|
e,
|
|
|
|
|
now);
|
|
|
|
|
}
|
2020-03-22 21:21:52 +10:00
|
|
|
tablet->quirks.proximity_out_in_progress = false;
|
2016-12-22 12:11:43 +10:00
|
|
|
|
|
|
|
|
tablet->quirks.proximity_out_forced = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
static void
|
|
|
|
|
tablet_process(struct evdev_dispatch *dispatch,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
struct input_event *e,
|
|
|
|
|
uint64_t time)
|
|
|
|
|
{
|
2017-01-30 18:01:09 +10:00
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
|
2014-06-05 23:20:36 -04:00
|
|
|
|
|
|
|
|
switch (e->type) {
|
|
|
|
|
case EV_ABS:
|
|
|
|
|
tablet_process_absolute(tablet, device, e, time);
|
|
|
|
|
break;
|
2015-02-20 11:41:06 +10:00
|
|
|
case EV_REL:
|
|
|
|
|
tablet_process_relative(tablet, device, e, time);
|
|
|
|
|
break;
|
2014-06-10 16:48:19 -04:00
|
|
|
case EV_KEY:
|
|
|
|
|
tablet_process_key(tablet, device, e, time);
|
|
|
|
|
break;
|
|
|
|
|
case EV_MSC:
|
|
|
|
|
tablet_process_misc(tablet, device, e, time);
|
|
|
|
|
break;
|
2014-06-05 23:20:36 -04:00
|
|
|
case EV_SYN:
|
|
|
|
|
tablet_flush(tablet, device, time);
|
2018-02-19 14:41:50 +10:00
|
|
|
tablet_toggle_touch_device(tablet, device, time);
|
2015-02-26 13:55:08 +10:00
|
|
|
tablet_reset_state(tablet);
|
2019-04-05 14:58:56 +10:00
|
|
|
tablet->quirks.last_event_time = time;
|
2014-06-05 23:20:36 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
2017-02-13 14:17:52 +10:00
|
|
|
evdev_log_error(device,
|
|
|
|
|
"Unexpected event type %s (%#x)\n",
|
|
|
|
|
libevdev_event_type_get_name(e->type),
|
|
|
|
|
e->type);
|
2014-06-05 23:20:36 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 11:28:34 +10:00
|
|
|
static void
|
|
|
|
|
tablet_suspend(struct evdev_dispatch *dispatch,
|
|
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
2017-01-30 18:01:09 +10:00
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
|
2018-02-05 11:27:09 +10:00
|
|
|
struct libinput *li = tablet_libinput_context(tablet);
|
2018-02-19 14:41:50 +10:00
|
|
|
uint64_t now = libinput_now(li);
|
2016-06-28 11:28:34 +10:00
|
|
|
|
2018-09-28 11:47:32 +10:00
|
|
|
tablet_set_touch_device_enabled(tablet,
|
|
|
|
|
ARBITRATION_NOT_ACTIVE,
|
|
|
|
|
NULL,
|
|
|
|
|
now);
|
2018-02-05 11:27:09 +10:00
|
|
|
|
|
|
|
|
if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
|
|
|
|
|
tablet_flush(tablet, device, libinput_now(li));
|
|
|
|
|
}
|
2016-06-28 11:28:34 +10:00
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
static void
|
|
|
|
|
tablet_destroy(struct evdev_dispatch *dispatch)
|
|
|
|
|
{
|
2017-01-30 18:01:09 +10:00
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
|
2021-02-22 19:52:40 +03:00
|
|
|
struct libinput_tablet_tool *tool;
|
2019-05-27 18:21:09 +10:00
|
|
|
struct libinput *li = tablet_libinput_context(tablet);
|
2014-08-07 19:00:52 -04:00
|
|
|
|
2016-12-22 12:11:43 +10:00
|
|
|
libinput_timer_cancel(&tablet->quirks.prox_out_timer);
|
|
|
|
|
libinput_timer_destroy(&tablet->quirks.prox_out_timer);
|
|
|
|
|
|
2025-03-31 11:37:22 +10:00
|
|
|
list_for_each(tool, &li->tool_list, link) {
|
|
|
|
|
ARRAY_FOR_EACH(tool->pressure.thresholds, threshold) {
|
|
|
|
|
if (threshold->tablet_id == tablet->tablet_id) {
|
|
|
|
|
threshold->tablet_id = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 19:52:40 +03:00
|
|
|
list_for_each_safe(tool, &tablet->tool_list, link) {
|
2015-11-16 16:35:03 +10:00
|
|
|
libinput_tablet_tool_unref(tool);
|
2014-08-07 19:00:52 -04:00
|
|
|
}
|
2014-06-05 23:20:36 -04:00
|
|
|
|
2019-05-27 18:21:09 +10:00
|
|
|
libinput_libwacom_unref(li);
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
free(tablet);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 12:40:56 +10:00
|
|
|
static void
|
|
|
|
|
tablet_setup_touch_arbitration(struct evdev_device *device,
|
|
|
|
|
struct evdev_device *new_device)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
|
|
|
|
|
|
2023-03-17 13:08:31 +10:00
|
|
|
/* We enable touch arbitration with the first touch screen/external
|
|
|
|
|
* touchpad we see. This may be wrong in some cases, so we have some
|
|
|
|
|
* heuristics in case we find a "better" device.
|
|
|
|
|
*/
|
|
|
|
|
if (tablet->touch_device != NULL) {
|
|
|
|
|
struct libinput_device_group *group1 = libinput_device_get_device_group(&device->base);
|
|
|
|
|
struct libinput_device_group *group2 = libinput_device_get_device_group(&new_device->base);
|
|
|
|
|
|
|
|
|
|
/* same phsical device? -> better, otherwise keep the one we have */
|
|
|
|
|
if (group1 != group2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* We found a better device, let's swap it out */
|
|
|
|
|
struct libinput *li = tablet_libinput_context(tablet);
|
|
|
|
|
tablet_set_touch_device_enabled(tablet,
|
|
|
|
|
ARBITRATION_NOT_ACTIVE,
|
|
|
|
|
NULL,
|
|
|
|
|
libinput_now(li));
|
|
|
|
|
evdev_log_debug(device,
|
|
|
|
|
"touch-arbitration: removing pairing for %s<->%s\n",
|
|
|
|
|
device->devname,
|
|
|
|
|
tablet->touch_device->devname);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 12:40:56 +10:00
|
|
|
evdev_log_debug(device,
|
|
|
|
|
"touch-arbitration: activated for %s<->%s\n",
|
|
|
|
|
device->devname,
|
|
|
|
|
new_device->devname);
|
|
|
|
|
tablet->touch_device = new_device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_setup_rotation(struct evdev_device *device,
|
|
|
|
|
struct evdev_device *new_device)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
|
2023-03-17 13:08:31 +10:00
|
|
|
struct libinput_device_group *group1 = libinput_device_get_device_group(&device->base);
|
|
|
|
|
struct libinput_device_group *group2 = libinput_device_get_device_group(&new_device->base);
|
|
|
|
|
|
|
|
|
|
if (tablet->rotation.touch_device == NULL && (group1 == group2)) {
|
|
|
|
|
evdev_log_debug(device,
|
|
|
|
|
"tablet-rotation: %s will rotate %s\n",
|
|
|
|
|
device->devname,
|
|
|
|
|
new_device->devname);
|
|
|
|
|
tablet->rotation.touch_device = new_device;
|
|
|
|
|
|
|
|
|
|
if (libinput_device_config_left_handed_get(&new_device->base)) {
|
|
|
|
|
tablet->rotation.touch_device_left_handed_state = true;
|
|
|
|
|
tablet_change_rotation(device, DO_NOTIFY);
|
|
|
|
|
}
|
2023-03-29 12:40:56 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 11:28:34 +10:00
|
|
|
static void
|
|
|
|
|
tablet_device_added(struct evdev_device *device,
|
|
|
|
|
struct evdev_device *added_device)
|
|
|
|
|
{
|
2019-05-03 15:56:54 +10:00
|
|
|
bool is_touchscreen, is_ext_touchpad;
|
2016-06-28 11:28:34 +10:00
|
|
|
|
2019-05-03 15:56:54 +10:00
|
|
|
is_touchscreen = evdev_device_has_capability(added_device,
|
|
|
|
|
LIBINPUT_DEVICE_CAP_TOUCH);
|
|
|
|
|
is_ext_touchpad = evdev_device_has_capability(added_device,
|
|
|
|
|
LIBINPUT_DEVICE_CAP_POINTER) &&
|
|
|
|
|
(added_device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD);
|
|
|
|
|
|
2023-03-29 12:40:56 +10:00
|
|
|
if (is_touchscreen || is_ext_touchpad)
|
|
|
|
|
tablet_setup_touch_arbitration(device, added_device);
|
|
|
|
|
|
|
|
|
|
if (is_ext_touchpad)
|
|
|
|
|
tablet_setup_rotation(device, added_device);
|
2016-06-28 11:28:34 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_device_removed(struct evdev_device *device,
|
|
|
|
|
struct evdev_device *removed_device)
|
|
|
|
|
{
|
2017-01-30 18:01:09 +10:00
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
|
2016-06-28 11:28:34 +10:00
|
|
|
|
|
|
|
|
if (tablet->touch_device == removed_device)
|
|
|
|
|
tablet->touch_device = NULL;
|
2019-05-03 15:56:54 +10:00
|
|
|
|
|
|
|
|
if (tablet->rotation.touch_device == removed_device) {
|
|
|
|
|
tablet->rotation.touch_device = NULL;
|
|
|
|
|
tablet->rotation.touch_device_left_handed_state = false;
|
|
|
|
|
tablet_change_rotation(device, DO_NOTIFY);
|
|
|
|
|
}
|
2016-06-28 11:28:34 +10:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 13:55:08 +10:00
|
|
|
static void
|
|
|
|
|
tablet_check_initial_proximity(struct evdev_device *device,
|
|
|
|
|
struct evdev_dispatch *dispatch)
|
|
|
|
|
{
|
2017-01-30 18:01:09 +10:00
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
|
2016-12-22 12:11:43 +10:00
|
|
|
struct libinput *li = tablet_libinput_context(tablet);
|
2015-02-26 13:55:08 +10:00
|
|
|
int code, state;
|
2015-11-16 15:39:07 +10:00
|
|
|
enum libinput_tablet_tool_type tool;
|
2015-02-26 13:55:08 +10:00
|
|
|
|
2017-12-18 14:41:14 +10:00
|
|
|
for (tool = LIBINPUT_TABLET_TOOL_TYPE_PEN;
|
|
|
|
|
tool <= LIBINPUT_TABLET_TOOL_TYPE_MAX;
|
|
|
|
|
tool++) {
|
2015-02-26 13:55:08 +10:00
|
|
|
code = tablet_tool_to_evcode(tool);
|
|
|
|
|
|
|
|
|
|
/* we only expect one tool to be in proximity at a time */
|
|
|
|
|
if (libevdev_fetch_event_value(device->evdev,
|
|
|
|
|
EV_KEY,
|
|
|
|
|
code,
|
|
|
|
|
&state) && state) {
|
2019-04-05 14:58:56 +10:00
|
|
|
tablet->tool_state = bit(tool);
|
|
|
|
|
tablet->prev_tool_state = bit(tool);
|
2015-02-26 13:55:08 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-05 14:58:56 +10:00
|
|
|
if (!tablet->tool_state)
|
2015-02-26 13:55:08 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
tablet_update_tool(tablet, device, tool, state);
|
2020-03-22 21:21:52 +10:00
|
|
|
if (tablet->quirks.need_to_force_prox_out)
|
|
|
|
|
tablet_proximity_out_quirk_set_timer(tablet, libinput_now(li));
|
2015-02-26 13:55:08 +10:00
|
|
|
|
2019-04-01 15:10:55 +10:00
|
|
|
tablet->current_tool.id =
|
2015-02-26 13:55:08 +10:00
|
|
|
libevdev_get_event_value(device->evdev,
|
|
|
|
|
EV_ABS,
|
|
|
|
|
ABS_MISC);
|
|
|
|
|
|
2016-02-02 13:23:03 +10:00
|
|
|
/* we can't fetch MSC_SERIAL from the kernel, so we set the serial
|
|
|
|
|
* to 0 for now. On the first real event from the device we get the
|
|
|
|
|
* serial (if any) and that event will be converted into a proximity
|
|
|
|
|
* event */
|
2019-04-01 15:10:55 +10:00
|
|
|
tablet->current_tool.serial = 0;
|
2015-02-26 13:55:08 +10:00
|
|
|
}
|
|
|
|
|
|
2019-05-03 15:56:54 +10:00
|
|
|
/* Called when the touchpad toggles to left-handed */
|
|
|
|
|
static void
|
|
|
|
|
tablet_left_handed_toggled(struct evdev_dispatch *dispatch,
|
|
|
|
|
struct evdev_device *device,
|
|
|
|
|
bool left_handed_enabled)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
|
|
|
|
|
|
|
|
|
|
if (!tablet->rotation.touch_device)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
evdev_log_debug(device,
|
|
|
|
|
"tablet-rotation: touchpad is %s\n",
|
|
|
|
|
left_handed_enabled ? "left-handed" : "right-handed");
|
|
|
|
|
|
|
|
|
|
/* Our left-handed config is independent even though rotation is
|
|
|
|
|
* locked. So we rotate when either device is left-handed. But it
|
|
|
|
|
* can only be actually changed when the device is in a neutral
|
|
|
|
|
* state, hence the want_rotate.
|
|
|
|
|
*/
|
|
|
|
|
tablet->rotation.touch_device_left_handed_state = left_handed_enabled;
|
|
|
|
|
tablet_change_rotation(device, DONT_NOTIFY);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
static struct evdev_dispatch_interface tablet_interface = {
|
2017-09-19 13:28:58 +10:00
|
|
|
.process = tablet_process,
|
|
|
|
|
.suspend = tablet_suspend,
|
|
|
|
|
.remove = NULL,
|
|
|
|
|
.destroy = tablet_destroy,
|
|
|
|
|
.device_added = tablet_device_added,
|
|
|
|
|
.device_removed = tablet_device_removed,
|
|
|
|
|
.device_suspended = NULL,
|
|
|
|
|
.device_resumed = NULL,
|
|
|
|
|
.post_added = tablet_check_initial_proximity,
|
2018-09-19 12:02:51 +10:00
|
|
|
.touch_arbitration_toggle = NULL,
|
|
|
|
|
.touch_arbitration_update_rect = NULL,
|
2017-09-19 13:45:22 +10:00
|
|
|
.get_switch_state = NULL,
|
2019-05-03 15:56:54 +10:00
|
|
|
.left_handed_toggle = tablet_left_handed_toggled,
|
2014-06-05 23:20:36 -04:00
|
|
|
};
|
|
|
|
|
|
2015-12-01 14:05:16 +10:00
|
|
|
static void
|
|
|
|
|
tablet_init_calibration(struct tablet_dispatch *tablet,
|
2024-06-19 11:50:52 +10:00
|
|
|
struct evdev_device *device,
|
|
|
|
|
bool is_display_tablet)
|
2015-12-01 14:05:16 +10:00
|
|
|
{
|
2024-06-19 11:50:52 +10:00
|
|
|
if (is_display_tablet || libevdev_has_property(device->evdev, INPUT_PROP_DIRECT))
|
2016-07-04 14:34:56 +10:00
|
|
|
evdev_init_calibration(device, &tablet->calibration);
|
2015-12-01 14:05:16 +10:00
|
|
|
}
|
|
|
|
|
|
2024-06-13 10:31:37 +10:00
|
|
|
static int
|
|
|
|
|
tablet_area_has_rectangle(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum libinput_config_status
|
|
|
|
|
tablet_area_set_rectangle(struct libinput_device *device,
|
|
|
|
|
const struct libinput_config_area_rectangle *rectangle)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *evdev = evdev_device(device);
|
|
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(evdev->dispatch);
|
|
|
|
|
|
|
|
|
|
if (rectangle->x1 >= rectangle->x2 || rectangle->y1 >= rectangle->y2)
|
|
|
|
|
return LIBINPUT_CONFIG_STATUS_INVALID;
|
|
|
|
|
|
|
|
|
|
if (rectangle->x1 < 0.0 || rectangle->x2 > 1.0 ||
|
|
|
|
|
rectangle->y1 < 0.0 || rectangle->y2 > 1.0)
|
|
|
|
|
return LIBINPUT_CONFIG_STATUS_INVALID;
|
|
|
|
|
|
|
|
|
|
tablet->area.want_rect = *rectangle;
|
|
|
|
|
|
|
|
|
|
tablet_change_area(evdev);
|
|
|
|
|
|
|
|
|
|
return LIBINPUT_CONFIG_STATUS_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct libinput_config_area_rectangle
|
|
|
|
|
tablet_area_get_rectangle(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct evdev_device *evdev = evdev_device(device);
|
|
|
|
|
struct tablet_dispatch *tablet = tablet_dispatch(evdev->dispatch);
|
|
|
|
|
|
|
|
|
|
return tablet->area.rect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct libinput_config_area_rectangle
|
|
|
|
|
tablet_area_get_default_rectangle(struct libinput_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct libinput_config_area_rectangle rect = {
|
|
|
|
|
0.0, 0.0, 1.0, 1.0,
|
|
|
|
|
};
|
|
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_init_area(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
tablet->area.rect = (struct libinput_config_area_rectangle) {
|
|
|
|
|
0.0, 0.0, 1.0, 1.0,
|
|
|
|
|
};
|
|
|
|
|
tablet->area.want_rect = tablet->area.rect;
|
|
|
|
|
tablet->area.x = *device->abs.absinfo_x;
|
|
|
|
|
tablet->area.y = *device->abs.absinfo_y;
|
|
|
|
|
|
|
|
|
|
if (!libevdev_has_property(device->evdev, INPUT_PROP_DIRECT)) {
|
|
|
|
|
device->base.config.area = &tablet->area.config;
|
|
|
|
|
tablet->area.config.has_rectangle = tablet_area_has_rectangle;
|
|
|
|
|
tablet->area.config.set_rectangle = tablet_area_set_rectangle;
|
|
|
|
|
tablet->area.config.get_rectangle = tablet_area_get_rectangle;
|
|
|
|
|
tablet->area.config.get_default_rectangle = tablet_area_get_default_rectangle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 17:16:18 +10:00
|
|
|
static void
|
|
|
|
|
tablet_init_proximity_threshold(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
/* This rules out most of the bamboos and other devices, we're
|
|
|
|
|
* pretty much down to
|
|
|
|
|
*/
|
|
|
|
|
if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_MOUSE) &&
|
|
|
|
|
!libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_LENS))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* 42 is the default proximity threshold the xf86-input-wacom driver
|
|
|
|
|
* uses for Intuos/Cintiq models. Graphire models have a threshold
|
|
|
|
|
* of 10 but since they haven't been manufactured in ages and the
|
|
|
|
|
* intersection of users having a graphire, running libinput and
|
|
|
|
|
* wanting to use the mouse/lens cursor tool is small enough to not
|
|
|
|
|
* worry about it for now. If we need to, we can introduce a udev
|
|
|
|
|
* property later.
|
|
|
|
|
*
|
|
|
|
|
* Value is in device coordinates.
|
|
|
|
|
*/
|
|
|
|
|
tablet->cursor_proximity_threshold = 42;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 15:26:49 +10:00
|
|
|
static uint32_t
|
|
|
|
|
tablet_accel_config_get_profiles(struct libinput_device *libinput_device)
|
|
|
|
|
{
|
|
|
|
|
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum libinput_config_status
|
|
|
|
|
tablet_accel_config_set_profile(struct libinput_device *libinput_device,
|
|
|
|
|
enum libinput_config_accel_profile profile)
|
|
|
|
|
{
|
|
|
|
|
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum libinput_config_accel_profile
|
|
|
|
|
tablet_accel_config_get_profile(struct libinput_device *libinput_device)
|
|
|
|
|
{
|
|
|
|
|
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum libinput_config_accel_profile
|
|
|
|
|
tablet_accel_config_get_default_profile(struct libinput_device *libinput_device)
|
|
|
|
|
{
|
|
|
|
|
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
tablet_init_accel(struct tablet_dispatch *tablet, struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
const struct input_absinfo *x, *y;
|
|
|
|
|
struct motion_filter *filter;
|
|
|
|
|
|
|
|
|
|
x = device->abs.absinfo_x;
|
|
|
|
|
y = device->abs.absinfo_y;
|
|
|
|
|
|
|
|
|
|
filter = create_pointer_accelerator_filter_tablet(x->resolution,
|
|
|
|
|
y->resolution);
|
2016-07-13 07:54:07 +10:00
|
|
|
if (!filter)
|
|
|
|
|
return -1;
|
2016-01-06 15:26:49 +10:00
|
|
|
|
2016-07-13 07:55:13 +10:00
|
|
|
evdev_device_init_pointer_acceleration(device, filter);
|
2016-01-06 15:26:49 +10:00
|
|
|
|
|
|
|
|
/* we override the profile hooks for accel configuration with hooks
|
|
|
|
|
* that don't allow selection of profiles */
|
|
|
|
|
device->pointer.config.get_profiles = tablet_accel_config_get_profiles;
|
|
|
|
|
device->pointer.config.set_profile = tablet_accel_config_set_profile;
|
|
|
|
|
device->pointer.config.get_profile = tablet_accel_config_get_profile;
|
|
|
|
|
device->pointer.config.get_default_profile = tablet_accel_config_get_default_profile;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-19 12:56:43 +10:00
|
|
|
static void
|
2024-10-29 09:46:05 +10:00
|
|
|
tablet_init_left_handed(struct evdev_device *device,
|
|
|
|
|
WacomDevice *wacom)
|
2015-02-19 12:56:43 +10:00
|
|
|
{
|
2024-10-29 09:46:05 +10:00
|
|
|
bool has_left_handed = true;
|
|
|
|
|
|
|
|
|
|
#if HAVE_LIBWACOM
|
|
|
|
|
has_left_handed = !wacom || libwacom_is_reversible(wacom);
|
|
|
|
|
#endif
|
|
|
|
|
if (has_left_handed)
|
2019-05-03 15:51:58 +10:00
|
|
|
evdev_init_left_handed(device,
|
|
|
|
|
tablet_change_to_left_handed);
|
2015-02-19 12:56:43 +10:00
|
|
|
}
|
|
|
|
|
|
2024-10-29 09:46:05 +10:00
|
|
|
static inline bool
|
|
|
|
|
tablet_is_display_tablet(WacomDevice *wacom)
|
2020-10-08 09:47:36 +10:00
|
|
|
{
|
|
|
|
|
#if HAVE_LIBWACOM
|
2024-10-29 20:17:00 +10:00
|
|
|
return !wacom ||
|
|
|
|
|
(libwacom_get_integration_flags(wacom) & (WACOM_DEVICE_INTEGRATED_SYSTEM|WACOM_DEVICE_INTEGRATED_DISPLAY));
|
2024-10-29 09:46:05 +10:00
|
|
|
#else
|
2024-10-29 20:17:00 +10:00
|
|
|
return true;
|
2024-10-29 09:46:05 +10:00
|
|
|
#endif
|
|
|
|
|
}
|
2024-06-19 11:50:52 +10:00
|
|
|
|
2024-10-29 09:46:05 +10:00
|
|
|
static inline bool
|
|
|
|
|
tablet_is_aes(struct evdev_device *device, WacomDevice *wacom)
|
|
|
|
|
{
|
|
|
|
|
#if HAVE_LIBWACOM
|
|
|
|
|
int vid = evdev_device_get_id_vendor(device);
|
2024-06-19 11:50:52 +10:00
|
|
|
/* Wacom-specific check for whether smoothing is required:
|
|
|
|
|
* libwacom keeps all the AES pens in a single group, so any device
|
|
|
|
|
* that supports AES pens will list all AES pens. 0x11 is one of the
|
|
|
|
|
* lenovo pens so we use that as the flag of whether the tablet
|
|
|
|
|
* is an AES tablet
|
|
|
|
|
*/
|
2024-10-29 09:46:05 +10:00
|
|
|
if (wacom && vid == VENDOR_ID_WACOM) {
|
2024-10-18 08:38:47 +10:00
|
|
|
int nstyli;
|
2024-10-29 09:46:05 +10:00
|
|
|
const int *stylus_ids = libwacom_get_supported_styli(wacom, &nstyli);
|
2024-10-18 08:38:47 +10:00
|
|
|
for (int i = 0; i < nstyli; i++) {
|
|
|
|
|
if (stylus_ids[i] == 0x11) {
|
2024-10-29 09:46:05 +10:00
|
|
|
return true;
|
2024-10-18 08:38:47 +10:00
|
|
|
}
|
2020-10-08 09:47:36 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-10-29 09:46:05 +10:00
|
|
|
|
|
|
|
|
return false;
|
2021-07-25 19:23:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tablet_init_smoothing(struct evdev_device *device,
|
2024-06-19 11:46:42 +10:00
|
|
|
struct tablet_dispatch *tablet,
|
|
|
|
|
bool is_aes)
|
2021-07-25 19:23:06 -07:00
|
|
|
{
|
|
|
|
|
size_t history_size = ARRAY_LENGTH(tablet->history.samples);
|
|
|
|
|
struct quirks_context *quirks = NULL;
|
|
|
|
|
struct quirks *q = NULL;
|
|
|
|
|
bool use_smoothing = true;
|
|
|
|
|
|
|
|
|
|
quirks = evdev_libinput_context(device)->quirks;
|
|
|
|
|
q = quirks_fetch_for_device(quirks, device->udev_device);
|
|
|
|
|
|
|
|
|
|
/* By default, always enable smoothing except on AES devices.
|
|
|
|
|
* AttrTabletSmoothing can override this, if necessary.
|
|
|
|
|
*/
|
|
|
|
|
if (!q || !quirks_get_bool(q, QUIRK_ATTR_TABLET_SMOOTHING, &use_smoothing))
|
2024-06-19 11:46:42 +10:00
|
|
|
use_smoothing = !is_aes;
|
2021-07-25 19:23:06 -07:00
|
|
|
|
|
|
|
|
/* Setting the history size to 1 means we never do any actual smoothing. */
|
|
|
|
|
if (!use_smoothing)
|
|
|
|
|
history_size = 1;
|
|
|
|
|
|
|
|
|
|
quirks_unref(q);
|
2020-10-08 09:47:36 +10:00
|
|
|
tablet->history.size = history_size;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 15:16:44 +10:00
|
|
|
static bool
|
2016-03-07 10:12:13 +10:00
|
|
|
tablet_reject_device(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct libevdev *evdev = device->evdev;
|
2016-11-04 12:50:35 +10:00
|
|
|
double w, h;
|
2017-10-26 10:10:04 +10:00
|
|
|
bool has_xy, has_pen, has_btn_stylus, has_size;
|
|
|
|
|
|
|
|
|
|
has_xy = libevdev_has_event_code(evdev, EV_ABS, ABS_X) &&
|
|
|
|
|
libevdev_has_event_code(evdev, EV_ABS, ABS_Y);
|
|
|
|
|
has_pen = libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN);
|
|
|
|
|
has_btn_stylus = libevdev_has_event_code(evdev, EV_KEY, BTN_STYLUS);
|
|
|
|
|
has_size = evdev_device_get_size(device, &w, &h) == 0;
|
|
|
|
|
|
|
|
|
|
if (has_xy && (has_pen || has_btn_stylus) && has_size)
|
2018-09-13 15:16:44 +10:00
|
|
|
return false;
|
2017-10-26 10:10:04 +10:00
|
|
|
|
|
|
|
|
evdev_log_bug_libinput(device,
|
2018-03-22 08:30:01 +10:00
|
|
|
"missing tablet capabilities:%s%s%s%s. "
|
2017-10-26 10:10:04 +10:00
|
|
|
"Ignoring this device.\n",
|
|
|
|
|
has_xy ? "" : " xy",
|
|
|
|
|
has_pen ? "" : " pen",
|
|
|
|
|
has_btn_stylus ? "" : " btn-stylus",
|
|
|
|
|
has_size ? "" : " resolution");
|
2018-09-13 15:16:44 +10:00
|
|
|
return true;
|
2016-03-07 10:12:13 +10:00
|
|
|
}
|
|
|
|
|
|
2024-01-16 16:10:59 +10:00
|
|
|
static void
|
|
|
|
|
tablet_fix_tilt(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct libevdev *evdev = device->evdev;
|
|
|
|
|
|
|
|
|
|
if (libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_X) !=
|
|
|
|
|
libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_Y)) {
|
|
|
|
|
libevdev_disable_event_code(evdev, EV_ABS, ABS_TILT_X);
|
|
|
|
|
libevdev_disable_event_code(evdev, EV_ABS, ABS_TILT_Y);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_X))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Wacom has three types of devices:
|
|
|
|
|
* - symmetrical: [-90, 90], like the ISDv4 524c
|
|
|
|
|
* - asymmetrical: [-64, 63], like the Cintiq l3HDT
|
|
|
|
|
* - zero-based: [0, 127], like the Cintiq 12WX
|
|
|
|
|
*
|
|
|
|
|
* Note how the latter two cases have an even range and thus do
|
|
|
|
|
* not have a logical center value. But this is tilt and at
|
|
|
|
|
* least in the asymmetrical case we assume that hardware zero
|
|
|
|
|
* means vertical. So we cheat and adjust the range depending
|
|
|
|
|
* on whether it's odd, then use the center value.
|
|
|
|
|
*
|
|
|
|
|
* Since it's always the max that's one too low let's go with that and
|
|
|
|
|
* fix it if we run into a device where that isn't the case.
|
|
|
|
|
*/
|
|
|
|
|
for (unsigned int axis = ABS_TILT_X; axis <= ABS_TILT_Y; axis++) {
|
|
|
|
|
struct input_absinfo abs = *libevdev_get_abs_info(evdev, axis);
|
|
|
|
|
|
|
|
|
|
/* Don't touch axes reporting radians */
|
|
|
|
|
if (abs.resolution != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if ((int)absinfo_range(&abs) % 2 == 1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
abs.maximum += 1;
|
|
|
|
|
libevdev_set_abs_info(evdev, axis, &abs);
|
|
|
|
|
|
|
|
|
|
evdev_log_debug(device,
|
|
|
|
|
"Adjusting %s range to [%d, %d]\n",
|
|
|
|
|
libevdev_event_code_get_name(EV_ABS, axis),
|
|
|
|
|
abs.minimum,
|
|
|
|
|
abs.maximum);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-10 12:11:00 +10:00
|
|
|
static int
|
|
|
|
|
tablet_init(struct tablet_dispatch *tablet,
|
|
|
|
|
struct evdev_device *device)
|
|
|
|
|
{
|
2025-02-17 15:29:26 +10:00
|
|
|
static unsigned int tablet_ids = 0;
|
2024-10-29 09:46:05 +10:00
|
|
|
struct libinput *li = evdev_libinput_context(device);
|
2017-09-11 10:32:42 +10:00
|
|
|
struct libevdev *evdev = device->evdev;
|
2016-02-10 12:11:00 +10:00
|
|
|
enum libinput_tablet_tool_axis axis;
|
2024-10-29 09:46:05 +10:00
|
|
|
int rc = -1;
|
|
|
|
|
WacomDevice *wacom = NULL;
|
|
|
|
|
#if HAVE_LIBWACOM
|
|
|
|
|
WacomDeviceDatabase *db = libinput_libwacom_ref(li);
|
|
|
|
|
if (db) {
|
|
|
|
|
char event_path[64];
|
|
|
|
|
snprintf(event_path,
|
|
|
|
|
sizeof(event_path),
|
|
|
|
|
"/dev/input/%s",
|
|
|
|
|
evdev_device_get_sysname(device));
|
|
|
|
|
wacom = libwacom_new_from_path(db, event_path, WFALLBACK_NONE, NULL);
|
|
|
|
|
if (!wacom) {
|
|
|
|
|
wacom = libwacom_new_from_usbid(db,
|
|
|
|
|
evdev_device_get_id_vendor(device),
|
|
|
|
|
evdev_device_get_id_product(device),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
if (!wacom) {
|
|
|
|
|
evdev_log_info(device,
|
|
|
|
|
"device \"%s\" (%04x:%04x) is not known to libwacom\n",
|
|
|
|
|
evdev_device_get_name(device),
|
|
|
|
|
evdev_device_get_id_vendor(device),
|
|
|
|
|
evdev_device_get_id_product(device));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2016-02-10 12:11:00 +10:00
|
|
|
|
2025-02-17 15:29:26 +10:00
|
|
|
tablet->tablet_id = ++tablet_ids;
|
2017-01-30 18:01:09 +10:00
|
|
|
tablet->base.dispatch_type = DISPATCH_TABLET;
|
2016-02-10 12:11:00 +10:00
|
|
|
tablet->base.interface = &tablet_interface;
|
|
|
|
|
tablet->device = device;
|
|
|
|
|
tablet->status = TABLET_NONE;
|
2019-04-01 15:10:55 +10:00
|
|
|
tablet->current_tool.type = LIBINPUT_TOOL_NONE;
|
2016-02-10 12:11:00 +10:00
|
|
|
list_init(&tablet->tool_list);
|
|
|
|
|
|
2016-03-07 10:12:13 +10:00
|
|
|
if (tablet_reject_device(device))
|
2024-10-29 09:46:05 +10:00
|
|
|
goto out;
|
2016-03-07 10:12:13 +10:00
|
|
|
|
2024-10-29 09:46:05 +10:00
|
|
|
bool is_aes = tablet_is_aes(device, wacom);
|
|
|
|
|
bool is_display_tablet = tablet_is_display_tablet(wacom);
|
2024-06-19 11:46:42 +10:00
|
|
|
|
2018-02-06 13:44:57 +10:00
|
|
|
if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN)) {
|
|
|
|
|
libevdev_enable_event_code(evdev, EV_KEY, BTN_TOOL_PEN, NULL);
|
|
|
|
|
tablet->quirks.proximity_out_forced = true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 13:45:34 +10:00
|
|
|
/* Our rotation code only works with Wacoms, let's wait until
|
|
|
|
|
* someone shouts */
|
|
|
|
|
if (evdev_device_get_id_vendor(device) != VENDOR_ID_WACOM) {
|
|
|
|
|
libevdev_disable_event_code(evdev, EV_KEY, BTN_TOOL_MOUSE);
|
|
|
|
|
libevdev_disable_event_code(evdev, EV_KEY, BTN_TOOL_LENS);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 16:10:59 +10:00
|
|
|
tablet_fix_tilt(tablet, device);
|
2024-06-19 11:50:52 +10:00
|
|
|
tablet_init_calibration(tablet, device, is_display_tablet);
|
2024-06-13 10:31:37 +10:00
|
|
|
tablet_init_area(tablet, device);
|
2016-02-10 12:11:00 +10:00
|
|
|
tablet_init_proximity_threshold(tablet, device);
|
|
|
|
|
rc = tablet_init_accel(tablet, device);
|
|
|
|
|
if (rc != 0)
|
2024-10-29 09:46:05 +10:00
|
|
|
goto out;
|
2016-02-10 12:11:00 +10:00
|
|
|
|
2020-05-22 11:39:49 +10:00
|
|
|
evdev_init_sendevents(device, &tablet->base);
|
2024-10-29 09:46:05 +10:00
|
|
|
tablet_init_left_handed(device, wacom);
|
2024-06-19 11:46:42 +10:00
|
|
|
tablet_init_smoothing(device, tablet, is_aes);
|
2016-02-10 12:11:00 +10:00
|
|
|
|
|
|
|
|
for (axis = LIBINPUT_TABLET_TOOL_AXIS_X;
|
|
|
|
|
axis <= LIBINPUT_TABLET_TOOL_AXIS_MAX;
|
|
|
|
|
axis++) {
|
|
|
|
|
if (tablet_device_has_axis(tablet, axis))
|
|
|
|
|
set_bit(tablet->axis_caps, axis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
|
|
|
|
|
|
2019-06-17 13:25:59 +10:00
|
|
|
/* We always enable the proximity out quirk, but disable it once a
|
|
|
|
|
device gives us the right event sequence */
|
|
|
|
|
tablet->quirks.need_to_force_prox_out = true;
|
|
|
|
|
|
2018-02-06 14:22:01 +10:00
|
|
|
libinput_timer_init(&tablet->quirks.prox_out_timer,
|
2024-10-29 09:46:05 +10:00
|
|
|
li,
|
2018-02-06 14:22:01 +10:00
|
|
|
"proxout",
|
|
|
|
|
tablet_proximity_out_quirk_timer_func,
|
|
|
|
|
tablet);
|
2016-12-22 12:11:43 +10:00
|
|
|
|
2024-10-29 09:46:05 +10:00
|
|
|
rc = 0;
|
|
|
|
|
out:
|
|
|
|
|
#if HAVE_LIBWACOM
|
|
|
|
|
if (wacom)
|
|
|
|
|
libwacom_destroy(wacom);
|
|
|
|
|
if (db)
|
|
|
|
|
libinput_libwacom_unref(li);
|
|
|
|
|
#endif
|
|
|
|
|
return rc;
|
2016-02-10 12:11:00 +10:00
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
struct evdev_dispatch *
|
|
|
|
|
evdev_tablet_create(struct evdev_device *device)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *tablet;
|
2019-05-27 18:21:09 +10:00
|
|
|
struct libinput *li = evdev_libinput_context(device);
|
|
|
|
|
|
|
|
|
|
libinput_libwacom_ref(li);
|
2014-06-05 23:20:36 -04:00
|
|
|
|
2018-05-28 10:38:12 +10:00
|
|
|
/* Stop false positives caused by the forced proximity code */
|
|
|
|
|
if (getenv("LIBINPUT_RUNNING_TEST_SUITE"))
|
|
|
|
|
FORCED_PROXOUT_TIMEOUT = 150 * 1000; /* µs */
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
tablet = zalloc(sizeof *tablet);
|
|
|
|
|
|
|
|
|
|
if (tablet_init(tablet, device) != 0) {
|
|
|
|
|
tablet_destroy(&tablet->base);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &tablet->base;
|
|
|
|
|
}
|