1/* 2 * Copyright © 2019 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 29struct priv { 30 unsigned int tool; 31}; 32 33static bool 34create(struct litest_device *d) 35{ 36 d->private = zalloc(sizeof(struct priv)); 37 return true; /* we want litest to create our device */ 38} 39 40static struct input_event proximity_in[] = { 41 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, 42 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, 43 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, 44 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 }, 45 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, 46 { .type = -1, .code = -1 }, 47}; 48 49static struct input_event proximity_out[] = { 50 { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 }, 51 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, 52 { .type = -1, .code = -1 }, 53}; 54 55static struct input_event motion[] = { 56 { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, 57 { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, 58 { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN }, 59 { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, 60 { .type = -1, .code = -1 }, 61}; 62 63static int 64get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value) 65{ 66 switch (evcode) { 67 case ABS_PRESSURE: 68 *value = 4000; 69 return 0; 70 case ABS_TILT_X: 71 case ABS_TILT_Y: 72 abort(); 73 } 74 return 1; 75} 76 77static bool prox_in(struct litest_device *d, 78 unsigned int tool_type, 79 double *x, double *y, 80 struct axis_replacement *axes) 81{ 82 struct priv *priv = d->private; 83 priv->tool = tool_type; 84 85 return false; 86} 87 88static bool prox_out(struct litest_device *d, unsigned int tool_type) 89{ 90 struct priv *priv = d->private; 91 priv->tool = 0; 92 93 return false; 94} 95 96static bool 97tip_down(struct litest_device *d, 98 double *x, double *y, 99 struct axis_replacement *axes) 100{ 101 litest_event(d, EV_KEY, BTN_TOOL_PEN, 1); 102 return false; /* use the default behavior otherwise */ 103} 104 105static bool 106tip_up(struct litest_device *d, 107 double* x, double *y, 108 struct axis_replacement *axes) 109{ 110 struct priv *priv = d->private; 111 if (priv->tool != BTN_TOOL_PEN) 112 litest_event(d, EV_KEY, BTN_TOOL_PEN, 0); 113 return false; /* use the default behavior otherwise */ 114} 115 116static struct litest_device_interface interface = { 117 .tablet_proximity_in_events = proximity_in, 118 .tablet_proximity_out_events = proximity_out, 119 .tablet_motion_events = motion, 120 121 .tablet_proximity_in = prox_in, 122 .tablet_proximity_out = prox_out, 123 .tablet_tip_down = tip_down, 124 .tablet_tip_up = tip_up, 125 126 .get_axis_default = get_axis_default, 127}; 128 129static struct input_absinfo absinfo[] = { 130 { ABS_X, 0, 30931, 0, 0, 100 }, 131 { ABS_Y, 0, 17399, 0, 0, 100 }, 132 /* This pen has tilt, but doesn't send events */ 133 { ABS_TILT_X, -90, 90, 0, 0, 57 }, 134 { ABS_TILT_Y, -90, 90, 0, 0, 57 }, 135 { ABS_PRESSURE, 0, 4095, 0, 0, 0 }, 136 { .value = -1 }, 137}; 138 139static struct input_id input_id = { 140 .bustype = 0x3, 141 .vendor = 0x2d1f, /* Note: this is Wacom's Android VID */ 142 .product = 0x524c, 143}; 144 145static int events[] = { 146 EV_KEY, BTN_TOOL_PEN, 147 EV_KEY, BTN_TOOL_RUBBER, 148 EV_KEY, BTN_TOUCH, 149 EV_KEY, BTN_STYLUS, 150 EV_KEY, BTN_STYLUS2, 151 INPUT_PROP_MAX, INPUT_PROP_DIRECT, 152 -1, -1, 153}; 154 155TEST_DEVICE("wacom-isdv4-524c-tablet", 156 .type = LITEST_WACOM_ISDV4_524C_PEN, 157 .features = LITEST_TABLET|LITEST_HOVER, 158 .interface = &interface, 159 160 .name = "Wacom Co.,Ltd. Pen and multitouch sensor Stylus", 161 .id = &input_id, 162 .events = events, 163 .absinfo = absinfo, 164 .create = create, 165) 166