blob: 10f9724e11c5eaddc5e8f272c84a0589a014474b [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 {
Neil Robertsdaf7d472013-09-24 12:09:03 +010034 EVDEV_NONE,
Neil Robertsbe336c82013-09-24 20:05:07 +010035 EVDEV_ABSOLUTE_TOUCH_DOWN,
Neil Robertsdaf7d472013-09-24 12:09:03 +010036 EVDEV_ABSOLUTE_MOTION,
Neil Robertsbe336c82013-09-24 20:05:07 +010037 EVDEV_ABSOLUTE_TOUCH_UP,
Neil Robertsdaf7d472013-09-24 12:09:03 +010038 EVDEV_ABSOLUTE_MT_DOWN,
39 EVDEV_ABSOLUTE_MT_MOTION,
40 EVDEV_ABSOLUTE_MT_UP,
41 EVDEV_RELATIVE_MOTION,
Pekka Paalanencfa1f672012-08-03 14:38:59 +030042};
43
Jonas Ådahld6e1c342013-10-17 23:04:05 +020044enum evdev_device_seat_capability {
45 EVDEV_SEAT_POINTER = (1 << 0),
46 EVDEV_SEAT_KEYBOARD = (1 << 1),
47 EVDEV_SEAT_TOUCH = (1 << 2)
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;
Kristian Høgsberg17bccae2014-01-16 16:46:28 -080056 struct wl_listener output_destroy_listener;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030057 char *devnode;
Pekka Paalanenbf639ab2012-08-03 14:39:07 +030058 char *devname;
Kristian Høgsberg8ca95442014-01-09 16:41:58 -080059 char *output_name;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030060 int fd;
61 struct {
62 int min_x, max_x, min_y, max_y;
Kristian Høgsberg2fce4802014-01-08 16:21:24 -080063 uint32_t seat_slot;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030064 int32_t x, y;
Rob Bradfordea23b282012-12-03 19:44:16 +000065
66 int apply_calibration;
67 float calibration[6];
Pekka Paalanencfa1f672012-08-03 14:38:59 +030068 } abs;
69
70 struct {
71 int slot;
Neil Robertsdaf7d472013-09-24 12:09:03 +010072 struct {
73 int32_t x, y;
Kristian Høgsberg2fce4802014-01-08 16:21:24 -080074 uint32_t seat_slot;
Neil Robertsdaf7d472013-09-24 12:09:03 +010075 } slots[MAX_SLOTS];
Pekka Paalanencfa1f672012-08-03 14:38:59 +030076 } mt;
77 struct mtdev *mtdev;
78
79 struct {
80 wl_fixed_t dx, dy;
81 } rel;
82
Neil Robertsdaf7d472013-09-24 12:09:03 +010083 enum evdev_event_type pending_event;
Jonas Ådahld6e1c342013-10-17 23:04:05 +020084 enum evdev_device_seat_capability seat_caps;
Pekka Paalanencfa1f672012-08-03 14:38:59 +030085
86 int is_mt;
87};
88
89/* copied from udev/extras/input_id/input_id.c */
90/* we must use this kernel-compatible implementation */
91#define BITS_PER_LONG (sizeof(unsigned long) * 8)
92#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
93#define OFF(x) ((x)%BITS_PER_LONG)
94#define BIT(x) (1UL<<OFF(x))
95#define LONG(x) ((x)/BITS_PER_LONG)
96#define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1)
97/* end copied */
98
Kristian Høgsberg2f07ef62013-02-16 14:29:24 -050099#define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
100
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300101struct evdev_dispatch;
102
103struct evdev_dispatch_interface {
104 /* Process an evdev input event. */
105 void (*process)(struct evdev_dispatch *dispatch,
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300106 struct evdev_device *device,
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300107 struct input_event *event,
108 uint32_t time);
109
110 /* Destroy an event dispatch handler and free all its resources. */
111 void (*destroy)(struct evdev_dispatch *dispatch);
112};
113
114struct evdev_dispatch {
115 struct evdev_dispatch_interface *interface;
116};
117
118struct evdev_dispatch *
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300119evdev_touchpad_create(struct evdev_device *device);
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300120
Tiago Vignattice03ec32011-12-19 01:14:03 +0200121void
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300122evdev_led_update(struct evdev_device *device, enum weston_led leds);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300123
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300124struct evdev_device *
125evdev_device_create(struct weston_seat *seat, const char *path, int device_fd);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300126
127void
Kristian Høgsberg17bccae2014-01-16 16:46:28 -0800128evdev_device_set_output(struct evdev_device *device,
129 struct weston_output *output);
130void
Pekka Paalanen3eb47612012-08-06 14:57:08 +0300131evdev_device_destroy(struct evdev_device *device);
Pekka Paalanen88594b62012-08-03 14:39:05 +0300132
133void
134evdev_notify_keyboard_focus(struct weston_seat *seat,
135 struct wl_list *evdev_devices);
136
Pekka Paalanencfa1f672012-08-03 14:38:59 +0300137#endif /* EVDEV_H */