1/* 2 * Copyright © 2023 Red Hat, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24#include "config.h" 25 26#include "litest.h" 27#include "litest-int.h" 28 29static bool 30inverter(struct litest_device *dev, 31 double *x, double *y, 32 struct axis_replacement *axes) 33{ 34 /* Input data is in percent (0-100), so let's swap x and y around. 35 * With our matrix this should be undone by libinput later 36 * and the tablet behaves as if normal */ 37 *x = 100 - *x; 38 *y = 100 - *y; 39 40 /* let the generic code handle the event */ 41 return false; 42} 43 44static bool 45proximity_in_handler(struct litest_device *dev, 46 unsigned int tool_type, 47 double *x, double *y, 48 struct axis_replacement *axes) 49{ 50 /* let the generic code handle the event */ 51 return inverter(dev, x, y, axes); 52} 53 54static struct input_event proximity_in[] = { 55 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, 56 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, 57 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, 58 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, 59 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, 60 { .type = -1, .code = -1 }, 61}; 62 63static struct input_event proximity_out[] = { 64 { .type = EV_ABS, .code = ABS_X, .value = 0 }, 65 { .type = EV_ABS, .code = ABS_Y, .value = 0 }, 66 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, 67 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, 68 { .type = -1, .code = -1 }, 69}; 70 71static struct input_event motion[] = { 72 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, 73 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, 74 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, 75 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, 76 { .type = -1, .code = -1 }, 77}; 78 79static int 80get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) 81{ 82 switch (evcode) { 83 case ABS_PRESSURE: 84 *value = 100; 85 return 0; 86 } 87 return 1; 88} 89 90static struct litest_device_interface interface = { 91 .tablet_proximity_in = proximity_in_handler, 92 .tablet_tip_down = inverter, 93 .tablet_tip_up = inverter, 94 .tablet_motion = inverter, 95 96 .tablet_proximity_in_events = proximity_in, 97 .tablet_proximity_out_events = proximity_out, 98 .tablet_motion_events = motion, 99 100 .get_axis_default = get_axis_default, 101}; 102 103static struct input_absinfo absinfo[] = { 104 { ABS_X, 0, 29476, 4, 0, 100 }, 105 { ABS_Y, 0, 16624, 4, 0, 100 }, 106 { ABS_PRESSURE, 0, 1023, 0, 0, 0 }, 107 { .value = -1 }, 108}; 109 110static struct input_id input_id = { 111 .bustype = 0x3, 112 .vendor = 0x56a, 113 .product = 0x501e, 114 .version = 0x111, 115}; 116 117static int events[] = { 118 EV_KEY, BTN_TOOL_PEN, 119 EV_KEY, BTN_TOOL_RUBBER, 120 EV_KEY, BTN_TOUCH, 121 EV_KEY, BTN_STYLUS, 122 EV_KEY, BTN_STYLUS2, 123 INPUT_PROP_MAX, INPUT_PROP_DIRECT, 124 -1, -1, 125}; 126 127TEST_DEVICE("wacom-calibrated-tablet", 128 .type = LITEST_WACOM_CALIBRATED_TABLET, 129 .features = LITEST_TABLET|LITEST_PRECALIBRATED, 130 .interface = &interface, 131 132 .name = "Wacom MultiTouch Sensor Pen", 133 .id = &input_id, 134 .events = events, 135 .absinfo = absinfo, 136 .udev_properties = { 137 { "LIBINPUT_CALIBRATION_MATRIX", "-1 0 1 0 -1 1" }, 138 { NULL } 139 }, 140) 141