2014-06-05 23:20:36 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 Red Hat, Inc.
|
|
|
|
|
* Copyright © 2014 Stephen Chandler "Lyude" Paul
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and
|
|
|
|
|
* its documentation for any purpose is hereby granted without fee, provided
|
|
|
|
|
* that the above copyright notice appear in all copies and that both that
|
|
|
|
|
* copyright notice and this permission notice appear in supporting
|
|
|
|
|
* documentation, and that the name of the copyright holders not be used in
|
|
|
|
|
* advertising or publicity pertaining to distribution of the software
|
|
|
|
|
* without specific, written prior permission. The copyright holders make
|
|
|
|
|
* no representations about the suitability of this software for any
|
|
|
|
|
* purpose. It is provided "as is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
|
* FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
|
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
|
|
|
|
* CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef EVDEV_TABLET_H
|
|
|
|
|
#define EVDEV_TABLET_H
|
|
|
|
|
|
|
|
|
|
#include "evdev.h"
|
|
|
|
|
|
2015-11-16 15:36:30 +10:00
|
|
|
#define LIBINPUT_TABLET_TOOL_AXIS_NONE 0
|
2015-02-19 10:59:46 +10:00
|
|
|
#define LIBINPUT_TOOL_NONE 0
|
2015-11-16 15:40:43 +10:00
|
|
|
#define LIBINPUT_TABLET_TOOL_TYPE_MAX LIBINPUT_TABLET_TOOL_TYPE_LENS
|
2015-02-10 11:29:34 +10:00
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
enum tablet_status {
|
|
|
|
|
TABLET_NONE = 0,
|
2014-06-10 16:48:19 -04:00
|
|
|
TABLET_AXES_UPDATED = 1 << 0,
|
2014-06-26 21:31:52 -04:00
|
|
|
TABLET_BUTTONS_PRESSED = 1 << 1,
|
|
|
|
|
TABLET_BUTTONS_RELEASED = 1 << 2,
|
2015-11-11 13:44:02 +10:00
|
|
|
TABLET_TOOL_IN_CONTACT = 1 << 3,
|
2014-06-26 21:31:52 -04:00
|
|
|
TABLET_TOOL_LEAVING_PROXIMITY = 1 << 4,
|
|
|
|
|
TABLET_TOOL_OUT_OF_PROXIMITY = 1 << 5,
|
2015-11-11 14:03:05 +10:00
|
|
|
TABLET_TOOL_ENTERING_PROXIMITY = 1 << 6,
|
|
|
|
|
TABLET_TOOL_ENTERING_CONTACT = 1 << 7,
|
|
|
|
|
TABLET_TOOL_LEAVING_CONTACT = 1 << 8,
|
2015-12-02 17:16:18 +10:00
|
|
|
TABLET_TOOL_OUT_OF_RANGE = 1 << 9,
|
2014-06-10 23:14:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct button_state {
|
2016-02-10 09:24:51 +10:00
|
|
|
unsigned char bits[NCHARS(KEY_CNT)];
|
2014-06-05 23:20:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct tablet_dispatch {
|
|
|
|
|
struct evdev_dispatch base;
|
|
|
|
|
struct evdev_device *device;
|
2015-11-11 14:03:05 +10:00
|
|
|
unsigned int status;
|
2015-11-16 15:36:30 +10:00
|
|
|
unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
|
2016-01-06 16:16:46 +10:00
|
|
|
struct tablet_axes axes;
|
2015-11-16 15:36:30 +10:00
|
|
|
unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
|
2016-04-12 08:36:48 +10:00
|
|
|
int current_value[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1];
|
|
|
|
|
int prev_value[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1];
|
2014-06-10 16:48:19 -04:00
|
|
|
|
2014-08-07 19:00:52 -04:00
|
|
|
/* Only used for tablets that don't report serial numbers */
|
|
|
|
|
struct list tool_list;
|
|
|
|
|
|
2014-06-10 23:14:41 -04:00
|
|
|
struct button_state button_state;
|
|
|
|
|
struct button_state prev_button_state;
|
|
|
|
|
|
2015-11-16 15:39:07 +10:00
|
|
|
enum libinput_tablet_tool_type current_tool_type;
|
2015-02-19 14:56:34 +10:00
|
|
|
uint32_t current_tool_id;
|
2014-06-10 16:48:19 -04:00
|
|
|
uint32_t current_tool_serial;
|
2015-12-02 17:16:18 +10:00
|
|
|
|
|
|
|
|
uint32_t cursor_proximity_threshold;
|
2016-07-04 14:34:56 +10:00
|
|
|
|
|
|
|
|
struct libinput_device_config_calibration calibration;
|
2016-06-28 11:28:34 +10:00
|
|
|
|
|
|
|
|
/* The paired touch device on devices with both pen & touch */
|
|
|
|
|
struct evdev_device *touch_device;
|
2014-06-05 23:20:36 -04:00
|
|
|
};
|
|
|
|
|
|
2017-01-30 18:01:09 +10:00
|
|
|
static inline struct tablet_dispatch*
|
|
|
|
|
tablet_dispatch(struct evdev_dispatch *dispatch)
|
|
|
|
|
{
|
|
|
|
|
struct tablet_dispatch *t;
|
|
|
|
|
|
|
|
|
|
evdev_verify_dispatch_type(dispatch, DISPATCH_TABLET);
|
|
|
|
|
|
|
|
|
|
return container_of(dispatch, t, base);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 15:35:40 +10:00
|
|
|
static inline enum libinput_tablet_tool_axis
|
2014-06-05 23:20:36 -04:00
|
|
|
evcode_to_axis(const uint32_t evcode)
|
|
|
|
|
{
|
2015-11-16 15:35:40 +10:00
|
|
|
enum libinput_tablet_tool_axis axis;
|
2014-06-05 23:20:36 -04:00
|
|
|
|
|
|
|
|
switch (evcode) {
|
|
|
|
|
case ABS_X:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_X;
|
2014-06-05 23:20:36 -04:00
|
|
|
break;
|
|
|
|
|
case ABS_Y:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_Y;
|
2014-06-05 23:20:36 -04:00
|
|
|
break;
|
2015-02-18 11:40:55 +10:00
|
|
|
case ABS_Z:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z;
|
2015-02-18 11:40:55 +10:00
|
|
|
break;
|
2014-06-06 20:31:38 -04:00
|
|
|
case ABS_DISTANCE:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE;
|
2014-06-06 20:31:38 -04:00
|
|
|
break;
|
|
|
|
|
case ABS_PRESSURE:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE;
|
2014-06-06 20:31:38 -04:00
|
|
|
break;
|
|
|
|
|
case ABS_TILT_X:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_X;
|
2014-06-06 20:31:38 -04:00
|
|
|
break;
|
|
|
|
|
case ABS_TILT_Y:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y;
|
2014-06-06 20:31:38 -04:00
|
|
|
break;
|
2015-02-17 13:04:06 +10:00
|
|
|
case ABS_WHEEL:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_SLIDER;
|
2015-02-17 13:04:06 +10:00
|
|
|
break;
|
2014-06-05 23:20:36 -04:00
|
|
|
default:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_NONE;
|
2014-06-05 23:20:36 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return axis;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 15:35:40 +10:00
|
|
|
static inline enum libinput_tablet_tool_axis
|
2015-02-20 11:41:06 +10:00
|
|
|
rel_evcode_to_axis(const uint32_t evcode)
|
|
|
|
|
{
|
2015-11-16 15:35:40 +10:00
|
|
|
enum libinput_tablet_tool_axis axis;
|
2015-02-20 11:41:06 +10:00
|
|
|
|
|
|
|
|
switch (evcode) {
|
|
|
|
|
case REL_WHEEL:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL;
|
2015-02-20 11:41:06 +10:00
|
|
|
break;
|
|
|
|
|
default:
|
2015-11-16 15:36:30 +10:00
|
|
|
axis = LIBINPUT_TABLET_TOOL_AXIS_NONE;
|
2015-02-20 11:41:06 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return axis;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
static inline uint32_t
|
2015-11-16 15:35:40 +10:00
|
|
|
axis_to_evcode(const enum libinput_tablet_tool_axis axis)
|
2014-06-05 23:20:36 -04:00
|
|
|
{
|
|
|
|
|
uint32_t evcode;
|
|
|
|
|
|
|
|
|
|
switch (axis) {
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_X:
|
2014-06-05 23:20:36 -04:00
|
|
|
evcode = ABS_X;
|
|
|
|
|
break;
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_Y:
|
2014-06-05 23:20:36 -04:00
|
|
|
evcode = ABS_Y;
|
|
|
|
|
break;
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE:
|
2014-06-06 20:31:38 -04:00
|
|
|
evcode = ABS_DISTANCE;
|
|
|
|
|
break;
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE:
|
2014-06-06 20:31:38 -04:00
|
|
|
evcode = ABS_PRESSURE;
|
|
|
|
|
break;
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_TILT_X:
|
2014-06-06 20:31:38 -04:00
|
|
|
evcode = ABS_TILT_X;
|
|
|
|
|
break;
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y:
|
2014-06-06 20:31:38 -04:00
|
|
|
evcode = ABS_TILT_Y;
|
|
|
|
|
break;
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z:
|
2015-02-18 11:40:55 +10:00
|
|
|
evcode = ABS_Z;
|
|
|
|
|
break;
|
2015-11-16 15:36:30 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_AXIS_SLIDER:
|
2015-02-17 13:04:06 +10:00
|
|
|
evcode = ABS_WHEEL;
|
|
|
|
|
break;
|
2014-06-05 23:20:36 -04:00
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return evcode;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 13:55:08 +10:00
|
|
|
static inline int
|
2015-11-16 15:39:07 +10:00
|
|
|
tablet_tool_to_evcode(enum libinput_tablet_tool_type type)
|
2015-02-26 13:55:08 +10:00
|
|
|
{
|
|
|
|
|
int code;
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
2015-11-16 15:40:43 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PEN: code = BTN_TOOL_PEN; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_ERASER: code = BTN_TOOL_RUBBER; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break;
|
2015-11-26 06:37:56 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break;
|
2015-11-16 15:40:43 +10:00
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break;
|
2015-02-26 13:55:08 +10:00
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return code;
|
|
|
|
|
}
|
2015-12-01 11:07:57 +10:00
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
|
tablet_tool_type_to_string(enum libinput_tablet_tool_type type)
|
|
|
|
|
{
|
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PEN: str = "pen"; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_ERASER: str = "eraser"; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: str = "brush"; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: str = "pencil"; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: str = "airbrush"; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: str = "mouse"; break;
|
|
|
|
|
case LIBINPUT_TABLET_TOOL_TYPE_LENS: str = "lens"; break;
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-09 11:15:51 +10:00
|
|
|
static inline struct libinput *
|
|
|
|
|
tablet_libinput_context(const struct tablet_dispatch *tablet)
|
|
|
|
|
{
|
|
|
|
|
return evdev_libinput_context(tablet->device);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-05 23:20:36 -04:00
|
|
|
#endif
|