1 /*
2 * Copyright © 2014 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 #include <assert.h>
29
30 static bool
touch_down(struct litest_device * d,unsigned int slot,double x,double y)31 touch_down(struct litest_device *d, unsigned int slot, double x, double y)
32 {
33 assert(slot == 0);
34
35 litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
36 litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
37 litest_event(d, EV_SYN, SYN_REPORT, 0);
38
39 return true; /* we handled the event */
40 }
41
42 static bool
touch_move(struct litest_device * d,unsigned int slot,double x,double y)43 touch_move(struct litest_device *d, unsigned int slot, double x, double y)
44 {
45 assert(slot == 0);
46
47 litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
48 litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
49 litest_event(d, EV_SYN, SYN_REPORT, 0);
50
51 return true; /* we handled the event */
52 }
53
54 static bool
touch_up(struct litest_device * d,unsigned int slot)55 touch_up(struct litest_device *d, unsigned int slot)
56 {
57 assert(slot == 0);
58 litest_event(d, EV_SYN, SYN_REPORT, 0);
59
60 return true; /* we handled the event */
61 }
62
63 static struct litest_device_interface interface = {
64 .touch_down = touch_down,
65 .touch_move = touch_move,
66 .touch_up = touch_up,
67 };
68
69 static struct input_absinfo absinfo[] = {
70 { ABS_X, 0, 800, 0, 0, 0 },
71 { ABS_Y, 0, 800, 0, 0, 0 },
72 { .value = -1 },
73 };
74
75 static struct input_id input_id = {
76 .bustype = 0x01,
77 .vendor = 0x5853,
78 .product = 0xfffe,
79 };
80
81 static int events[] = {
82 EV_KEY, BTN_LEFT,
83 EV_KEY, BTN_RIGHT,
84 EV_KEY, BTN_MIDDLE,
85 EV_KEY, BTN_SIDE,
86 EV_KEY, BTN_EXTRA,
87 EV_KEY, BTN_FORWARD,
88 EV_KEY, BTN_BACK,
89 EV_KEY, BTN_TASK,
90 EV_REL, REL_WHEEL,
91 -1, -1,
92 };
93
94 TEST_DEVICE("xen-pointer",
95 .type = LITEST_XEN_VIRTUAL_POINTER,
96 .features = LITEST_WHEEL | LITEST_BUTTON | LITEST_ABSOLUTE,
97 .interface = &interface,
98
99 .name = "Xen Virtual Pointer",
100 .id = &input_id,
101 .events = events,
102 .absinfo = absinfo,
103 )
104