blob: 7edcce6ee5b8a22b9e61e60372d709704c28ebd9 [file] [log] [blame]
Tiago Vignattice03ec32011-12-19 01:14:03 +02001/*
Pekka Paalanencfa1f672012-08-03 14:38:59 +03002 * Copyright © 2011, 2012 Intel Corporation
Tiago Vignattice03ec32011-12-19 01:14:03 +02003 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
Pekka Paalanencfa1f672012-08-03 14:38:59 +030023#ifndef EVDEV_H
24#define EVDEV_H
25
Daniel Stone8e7a8bd2013-08-15 01:10:24 +010026#include "config.h"
27
Pekka Paalanencfa1f672012-08-03 14:38:59 +030028#include <linux/input.h>
29#include <wayland-util.h>
Pekka Paalanencfa1f672012-08-03 14:38:59 +030030
31#define MAX_SLOTS 16
32
33enum evdev_event_type {
34 EVDEV_ABSOLUTE_MOTION = (1 << 0),
35 EVDEV_ABSOLUTE_MT_DOWN = (1 << 1),
36 EVDEV_ABSOLUTE_MT_MOTION = (1 << 2),
37 EVDEV_ABSOLUTE_MT_UP = (1 << 3),
38 EVDEV_RELATIVE_MOTION = (1 << 4),
Neil Robertsf65c4862013-09-20 15:03:29 +010039 EVDEV_SYN_OR_SLOT = (1 << 5),
Pekka Paalanencfa1f672012-08-03 14:38:59 +030040};
41
42enum evdev_device_capability {
43 EVDEV_KEYBOARD = (1 << 0),
44 EVDEV_BUTTON = (1 << 1),
45 EVDEV_MOTION_ABS = (1 << 2),
46 EVDEV_MOTION_REL = (1 << 3),
47 EVDEV_TOUCH = (1 << 4),
48};
49
Pekka Paalanen3eb47612012-08-06 14:57:08 +030050struct evdev_device {
Pekka Paalanen5618d6f2012-08-03 14:39:00 +030051 struct weston_seat *seat;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030052 struct wl_list link;
53 struct wl_event_source *source;
54 struct weston_output *output;
55 struct evdev_dispatch *dispatch;
56 char *devnode;
Pekka Paalanenbf639ab2012-08-03 14:39:07 +030057 char *devname;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030058 int fd;
59 struct {
60 int min_x, max_x, min_y, max_y;
61 int32_t x, y;
Rob Bradfordea23b282012-12-03 19:44:16 +000062
63 int apply_calibration;
64 float calibration[6];
Pekka Paalanencfa1f672012-08-03 14:38:59 +030065 } abs;
66
67 struct {
68 int slot;
69 int32_t x[MAX_SLOTS];
70 int32_t y[MAX_SLOTS];
71 } mt;
72 struct mtdev *mtdev;
73
74 struct {
75 wl_fixed_t dx, dy;
76 } rel;
77
78 enum evdev_event_type pending_events;
79 enum evdev_device_capability caps;
80
81 int is_mt;
82};
83
84/* copied from udev/extras/input_id/input_id.c */
85/* we must use this kernel-compatible implementation */
86#define BITS_PER_LONG (sizeof(unsigned long) * 8)
87#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
88#define OFF(x) ((x)%BITS_PER_LONG)
89#define BIT(x) (1UL<<OFF(x))
90#define LONG(x) ((x)/BITS_PER_LONG)
91#define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1)
92/* end copied */
93
Kristian Høgsberg2f07ef62013-02-16 14:29:24 -050094#define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
95
Pekka Paalanencfa1f672012-08-03 14:38:59 +030096struct evdev_dispatch;
97
98struct evdev_dispatch_interface {
99 /* Process an evdev input event. */
100 void (*process)(struct evdev_dispatch *dispatch,
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300101 struct evdev_device *device,
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300102 struct input_event *event,
103 uint32_t time);
104
105 /* Destroy an event dispatch handler and free all its resources. */
106 void (*destroy)(struct evdev_dispatch *dispatch);
107};
108
109struct evdev_dispatch {
110 struct evdev_dispatch_interface *interface;
111};
112
113struct evdev_dispatch *
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300114evdev_touchpad_create(struct evdev_device *device);
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300115
Tiago Vignattice03ec32011-12-19 01:14:03 +0200116void
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300117evdev_led_update(struct evdev_device *device, enum weston_led leds);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300118
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300119struct evdev_device *
120evdev_device_create(struct weston_seat *seat, const char *path, int device_fd);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300121
122void
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300123evdev_device_destroy(struct evdev_device *device);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300124
125void
126evdev_notify_keyboard_focus(struct weston_seat *seat,
127 struct wl_list *evdev_devices);
128
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300129#endif /* EVDEV_H */