blob: a90f90cd341ff8cd71af5096de3b723ebb5ef97d [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
26#include <linux/input.h>
27#include <wayland-util.h>
Pekka Paalanencfa1f672012-08-03 14:38:59 +030028
29#define MAX_SLOTS 16
30
31enum evdev_event_type {
32 EVDEV_ABSOLUTE_MOTION = (1 << 0),
33 EVDEV_ABSOLUTE_MT_DOWN = (1 << 1),
34 EVDEV_ABSOLUTE_MT_MOTION = (1 << 2),
35 EVDEV_ABSOLUTE_MT_UP = (1 << 3),
36 EVDEV_RELATIVE_MOTION = (1 << 4),
37};
38
39enum evdev_device_capability {
40 EVDEV_KEYBOARD = (1 << 0),
41 EVDEV_BUTTON = (1 << 1),
42 EVDEV_MOTION_ABS = (1 << 2),
43 EVDEV_MOTION_REL = (1 << 3),
44 EVDEV_TOUCH = (1 << 4),
45};
46
Pekka Paalanen3eb47612012-08-06 14:57:08 +030047struct evdev_device {
Pekka Paalanen5618d6f2012-08-03 14:39:00 +030048 struct weston_seat *seat;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030049 struct wl_list link;
50 struct wl_event_source *source;
51 struct weston_output *output;
52 struct evdev_dispatch *dispatch;
53 char *devnode;
Pekka Paalanenbf639ab2012-08-03 14:39:07 +030054 char *devname;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030055 int fd;
56 struct {
57 int min_x, max_x, min_y, max_y;
58 int32_t x, y;
Rob Bradfordea23b282012-12-03 19:44:16 +000059
60 int apply_calibration;
61 float calibration[6];
Pekka Paalanencfa1f672012-08-03 14:38:59 +030062 } abs;
63
64 struct {
65 int slot;
66 int32_t x[MAX_SLOTS];
67 int32_t y[MAX_SLOTS];
68 } mt;
69 struct mtdev *mtdev;
70
71 struct {
72 wl_fixed_t dx, dy;
73 } rel;
74
75 enum evdev_event_type pending_events;
76 enum evdev_device_capability caps;
77
78 int is_mt;
79};
80
81/* copied from udev/extras/input_id/input_id.c */
82/* we must use this kernel-compatible implementation */
83#define BITS_PER_LONG (sizeof(unsigned long) * 8)
84#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
85#define OFF(x) ((x)%BITS_PER_LONG)
86#define BIT(x) (1UL<<OFF(x))
87#define LONG(x) ((x)/BITS_PER_LONG)
88#define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1)
89/* end copied */
90
91struct evdev_dispatch;
92
93struct evdev_dispatch_interface {
94 /* Process an evdev input event. */
95 void (*process)(struct evdev_dispatch *dispatch,
Pekka Paalanen3eb47612012-08-06 14:57:08 +030096 struct evdev_device *device,
Pekka Paalanencfa1f672012-08-03 14:38:59 +030097 struct input_event *event,
98 uint32_t time);
99
100 /* Destroy an event dispatch handler and free all its resources. */
101 void (*destroy)(struct evdev_dispatch *dispatch);
102};
103
104struct evdev_dispatch {
105 struct evdev_dispatch_interface *interface;
106};
107
108struct evdev_dispatch *
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300109evdev_touchpad_create(struct evdev_device *device);
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300110
Tiago Vignattice03ec32011-12-19 01:14:03 +0200111void
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300112evdev_led_update(struct evdev_device *device, enum weston_led leds);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300113
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300114struct evdev_device *
115evdev_device_create(struct weston_seat *seat, const char *path, int device_fd);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300116
117void
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300118evdev_device_destroy(struct evdev_device *device);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300119
120void
121evdev_notify_keyboard_focus(struct weston_seat *seat,
122 struct wl_list *evdev_devices);
123
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300124#endif /* EVDEV_H */