aboutsummaryrefslogtreecommitdiff
path: root/src/evdev.h
blob: 0cd021eb80b64566e43e1da991766611a2ef34d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * Copyright © 2006 Zephaniah E. Hull
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Soft-
 * ware"), to deal in the Software without restriction, including without
 * limitation the rights to use, copy, modify, merge, publish, distribute,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, provided that the above copyright
 * notice(s) and this permission notice appear in all copies of the Soft-
 * ware and that both the above copyright notice(s) and this permission
 * notice appear in supporting documentation.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
 * MANCE OF THIS SOFTWARE.
 *
 * Except as contained in this notice, the name of a copyright holder shall
 * not be used in advertising or otherwise to promote the sale, use or
 * other dealings in this Software without prior written authorization of
 * the copyright holder.
 *
 * Author:  Zephaniah E. Hull (warp@aehallh.com)
 */
/*
 * Copyright © 2004 Red Hat, Inc.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of Red Hat
 * not be used in advertising or publicity pertaining to distribution
 * of the software without specific, written prior permission.  Red
 * Hat makes no representations about the suitability of this software
 * for any purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * RED HAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 * NO EVENT SHALL RED HAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  Kristian Høgsberg (krh@redhat.com)
 */
 
#ifndef EVDEV_BRAIN_H_
#define EVDEV_BRAIN_H_
 
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
 
#include <linux/input.h>
#include <xf86Xinput.h>
 
#define BITS_PER_LONG (sizeof(long) * 8)
#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
#define OFF(x)  ((x)%BITS_PER_LONG)
#define LONG(x) ((x)/BITS_PER_LONG)
#define BIT(x) (1UL<<((x)%BITS_PER_LONG))
#define test_bit(bit, array)    ((array[LONG(bit)] >> OFF(bit)) & 1)
 
/* 2.4 compatibility */
#ifndef EVIOCGSW
 
#include <sys/time.h>
#include <sys/ioctl.h>
#include <asm/types.h>
 
#define EVIOCGSW(len) _IOC(_IOC_READ, 'E'0x1b, len) /* get all switch states */
 
#define EV_SW 0x05
#endif
 
#ifndef EVIOCGRAB
#define EVIOCGRAB _IOW('E'0x90int)
#endif
 
#ifndef BTN_TASK
#define BTN_TASK 0x117
#endif
 
#ifndef EV_SYN
#define EV_SYN EV_RST
#endif
/* end compat */
 
#include <X11/extensions/XKB.h>
#include <X11/extensions/XKBstr.h>
 
 
/*
 * Switch events
 */
 
#define EV_SW_0 0x00
#define EV_SW_1 0x01
#define EV_SW_2 0x02
#define EV_SW_3 0x03
#define EV_SW_4 0x04
#define EV_SW_5 0x05
#define EV_SW_6 0x06
#define EV_SW_7 0x07
#define EV_SW_MAX 0x0f
 
#define EV_BUS_GSC 0x1A
 
#define EVDEV_MAXBUTTONS 128
 
typedef struct _evdevState {
    Bool can_grab;
    Bool sync;
    int real_buttons;
    int buttons;
    CARD8 buttonMap[EVDEV_MAXBUTTONS];
 
    int mode; /* Either Absolute or Relative. */
 
    int abs_axes;
    int abs_n; /* Which abs_v is current, and which is previous. */
    int abs_v[2][ABS_MAX];
    int abs_min[ABS_MAX];
    int abs_max[ABS_MAX];
    int absMap[ABS_MAX];
    Bool abs_scale;
    int abs_scale_x;
    int abs_scale_y;
    int abs_screen; /* Screen number for this device. */
 
    int rel_axes;
    int rel_v[REL_MAX];
    CARD8 relToBtnMap[REL_MAX][2];
    int relMap[REL_MAX];
 
    Bool keys;
    char *xkb_rules;
    char *xkb_model;
    char *xkb_layout;
    char *xkb_variant;
    char *xkb_options;
    XkbComponentNamesRec xkbnames;
} evdevStateRec, *evdevStatePtr;
 
typedef struct _evdevDevice {
    const char *name;
    const char *phys;
    const char *device;
    int seen;
 
    InputInfoPtr pInfo;
    int (*callback)(DeviceIntPtr cb_data, int what);
 
    evdevStateRec state;
 
    struct _evdevDevice *next;
} evdevDeviceRec, *evdevDevicePtr;
 
typedef struct _evdevDriver {
    const char *name;
    const char *phys;
    const char *device;
 
    InputDriverPtr drv;
    IDevPtr dev;
    Bool (*callback)(struct _evdevDriver *driver, evdevDevicePtr device);
    evdevDevicePtr devices;
    Bool configured;
 
    struct _evdevDriver *next;
} evdevDriverRec, *evdevDriverPtr;
 
int evdevGetFDForDevice (evdevDevicePtr driver);
Bool evdevStart (InputDriverPtr drv);
Bool evdevNewDriver (evdevDriverPtr driver);
 
int EvdevBtnInit (DeviceIntPtr device);
int EvdevBtnOn (DeviceIntPtr device);
int EvdevBtnOff (DeviceIntPtr device);
int EvdevBtnNew(InputInfoPtr pInfo);
void EvdevBtnProcess (InputInfoPtr pInfo, struct input_event *ev);
void EvdevBtnPostFakeClicks(InputInfoPtr pInfo, int button, int count);
 
int EvdevAbsInit (DeviceIntPtr device);
int EvdevAbsOn (DeviceIntPtr device);
int EvdevAbsOff (DeviceIntPtr device);
int EvdevAbsNew(InputInfoPtr pInfo);
void EvdevAbsProcess (InputInfoPtr pInfo, struct input_event *ev);
void EvdevAbsSyn (InputInfoPtr pInfo);
 
int EvdevRelInit (DeviceIntPtr device);
int EvdevRelOn (DeviceIntPtr device);
int EvdevRelOff (DeviceIntPtr device);
int EvdevRelNew(InputInfoPtr pInfo);
void EvdevRelProcess (InputInfoPtr pInfo, struct input_event *ev);
void EvdevRelSyn (InputInfoPtr pInfo);
 
int EvdevKeyInit (DeviceIntPtr device);
int EvdevKeyNew (InputInfoPtr pInfo);
int EvdevKeyOn (DeviceIntPtr device);
int EvdevKeyOff (DeviceIntPtr device);
void EvdevKeyProcess (InputInfoPtr pInfo, struct input_event *ev);
 
#endif /* LNX_EVDEV_H_ */