1/*
2 * Copyright 1995-1999 by Frederic Lepied, France. <Lepied@XFree86.org>
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is  hereby granted without fee, provided that
6 * 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  Frederic   Lepied not  be  used  in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific,  written      prior  permission.     Frederic  Lepied   makes  no
11 * representations about the suitability of this software for any purpose.  It
12 * is provided "as is" without express or implied warranty.
13 *
14 * FREDERIC  LEPIED DISCLAIMS ALL   WARRANTIES WITH REGARD  TO  THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED   WARRANTIES OF MERCHANTABILITY  AND   FITNESS, IN NO
16 * EVENT  SHALL FREDERIC  LEPIED BE   LIABLE   FOR ANY  SPECIAL, INDIRECT   OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA  OR PROFITS, WHETHER  IN  AN ACTION OF  CONTRACT,  NEGLIGENCE OR OTHER
19 * TORTIOUS  ACTION, ARISING    OUT OF OR   IN  CONNECTION  WITH THE USE    OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 */
23
24/*
25 * Copyright (c) 2000-2002 by The XFree86 Project, Inc.
26 *
27 * Permission is hereby granted, free of charge, to any person obtaining a
28 * copy of this software and associated documentation files (the "Software"),
29 * to deal in the Software without restriction, including without limitation
30 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
31 * and/or sell copies of the Software, and to permit persons to whom the
32 * Software is furnished to do so, subject to the following conditions:
33 *
34 * The above copyright notice and this permission notice shall be included in
35 * all copies or substantial portions of the Software.
36 *
37 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
40 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
41 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
42 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43 * OTHER DEALINGS IN THE SOFTWARE.
44 *
45 * Except as contained in this notice, the name of the copyright holder(s)
46 * and author(s) shall not be used in advertising or otherwise to promote
47 * the sale, use or other dealings in this Software without prior written
48 * authorization from the copyright holder(s) and author(s).
49 */
50
51#ifndef _xf86Xinput_h
52#define _xf86Xinput_h
53
54#include "xf86.h"
55#include "xf86str.h"
56#include "inputstr.h"
57#include <X11/extensions/XI.h>
58#include <X11/extensions/XIproto.h>
59#include "XIstubs.h"
60
61/* Input device flags */
62#define XI86_ALWAYS_CORE	0x04    /* device always controls the pointer */
63/* the device sends Xinput and core pointer events */
64#define XI86_SEND_CORE_EVENTS	XI86_ALWAYS_CORE
65/* 0x08 is reserved for legacy XI86_SEND_DRAG_EVENTS, do not use for now */
66/* server-internal only */
67#define XI86_DEVICE_DISABLED    0x10    /* device was disabled before vt switch */
68#define XI86_SERVER_FD		0x20	/* fd is managed by xserver */
69
70/* Input device driver capabilities */
71#define XI86_DRV_CAP_SERVER_FD	0x01
72
73/* This holds the input driver entry and module information. */
74typedef struct _InputDriverRec {
75    int driverVersion;
76    const char *driverName;
77    void (*Identify) (int flags);
78    int (*PreInit) (struct _InputDriverRec * drv,
79                    struct _InputInfoRec * pInfo, int flags);
80    void (*UnInit) (struct _InputDriverRec * drv,
81                    struct _InputInfoRec * pInfo, int flags);
82    void *module;
83    const char **default_options;
84    int capabilities;
85} InputDriverRec, *InputDriverPtr;
86
87/* This is to input devices what the ScrnInfoRec is to screens. */
88
89struct _InputInfoRec {
90    struct _InputInfoRec *next;
91    char *name;
92    char *driver;
93
94    int flags;
95
96    Bool (*device_control) (DeviceIntPtr device, int what);
97    void (*read_input) (struct _InputInfoRec * local);
98    int (*control_proc) (struct _InputInfoRec * local, xDeviceCtl * control);
99    int (*switch_mode) (ClientPtr client, DeviceIntPtr dev, int mode);
100    int (*set_device_valuators)
101     (struct _InputInfoRec * local,
102      int *valuators, int first_valuator, int num_valuators);
103
104    int fd;
105    int major;
106    int minor;
107    DeviceIntPtr dev;
108    void *private;
109    const char *type_name;
110    InputDriverPtr drv;
111    void *module;
112    XF86OptionPtr options;
113    InputAttributes *attrs;
114};
115
116/* xf86Globals.c */
117extern InputInfoPtr xf86InputDevs;
118
119/* xf86Xinput.c */
120extern _X_EXPORT void xf86PostMotionEvent(DeviceIntPtr device, int is_absolute,
121                                          int first_valuator, int num_valuators,
122                                          ...);
123extern _X_EXPORT void xf86PostMotionEventP(DeviceIntPtr device, int is_absolute,
124                                           int first_valuator,
125                                           int num_valuators,
126                                           const int *valuators);
127extern _X_EXPORT void xf86PostMotionEventM(DeviceIntPtr device, int is_absolute,
128                                           const ValuatorMask *mask);
129extern _X_EXPORT void xf86PostProximityEvent(DeviceIntPtr device, int is_in,
130                                             int first_valuator,
131                                             int num_valuators, ...);
132extern _X_EXPORT void xf86PostProximityEventP(DeviceIntPtr device, int is_in,
133                                              int first_valuator,
134                                              int num_valuators,
135                                              const int *valuators);
136extern _X_EXPORT void xf86PostProximityEventM(DeviceIntPtr device, int is_in,
137                                              const ValuatorMask *mask);
138extern _X_EXPORT void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute,
139                                          int button, int is_down,
140                                          int first_valuator, int num_valuators,
141                                          ...);
142extern _X_EXPORT void xf86PostButtonEventP(DeviceIntPtr device, int is_absolute,
143                                           int button, int is_down,
144                                           int first_valuator,
145                                           int num_valuators,
146                                           const int *valuators);
147extern _X_EXPORT void xf86PostButtonEventM(DeviceIntPtr device, int is_absolute,
148                                           int button, int is_down,
149                                           const ValuatorMask *mask);
150extern _X_EXPORT void xf86PostKeyEvent(DeviceIntPtr device,
151                                       unsigned int key_code, int is_down);
152extern _X_EXPORT void xf86PostKeyEventM(DeviceIntPtr device,
153                                        unsigned int key_code, int is_down);
154extern _X_EXPORT void xf86PostKeyEventP(DeviceIntPtr device,
155                                        unsigned int key_code, int is_down);
156extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device,
157                                            unsigned int key_code, int is_down);
158extern _X_EXPORT void xf86PostTouchEvent(DeviceIntPtr dev, uint32_t touchid,
159                                         uint16_t type, uint32_t flags,
160                                         const ValuatorMask *mask);
161extern _X_EXPORT void xf86PostGesturePinchEvent(DeviceIntPtr dev, uint16_t type,
162                                                uint16_t num_touches,
163                                                uint32_t flags,
164                                                double delta_x, double delta_y,
165                                                double delta_unaccel_x,
166                                                double delta_unaccel_y,
167                                                double scale, double delta_angle);
168extern _X_EXPORT void xf86PostGestureSwipeEvent(DeviceIntPtr dev, uint16_t type,
169                                                uint16_t num_touches,
170                                                uint32_t flags,
171                                                double delta_x, double delta_y,
172                                                double delta_unaccel_x,
173                                                double delta_unaccel_y);
174
175extern _X_EXPORT InputInfoPtr xf86FirstLocalDevice(void);
176extern _X_EXPORT int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max,
177                                   int from_min);
178extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo,
179                                               XF86OptionPtr options);
180extern _X_EXPORT Bool xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum,
181                                                 Atom label, int minval,
182                                                 int maxval, int resolution,
183                                                 int min_res, int max_res,
184                                                 int mode);
185extern _X_EXPORT void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum);
186extern _X_EXPORT void xf86AddEnabledDevice(InputInfoPtr pInfo);
187extern _X_EXPORT void xf86RemoveEnabledDevice(InputInfoPtr pInfo);
188extern _X_EXPORT void xf86DisableDevice(DeviceIntPtr dev, Bool panic);
189extern _X_EXPORT void xf86EnableDevice(DeviceIntPtr dev);
190extern _X_EXPORT void xf86InputEnableVTProbe(void);
191
192/* not exported */
193int xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL is_auto);
194InputInfoPtr xf86AllocateInput(void);
195
196/* xf86Helper.c */
197extern _X_EXPORT void xf86AddInputDriver(InputDriverPtr driver, void *module,
198                                         int flags);
199extern _X_EXPORT void xf86DeleteInputDriver(int drvIndex);
200extern _X_EXPORT InputDriverPtr xf86LookupInputDriver(const char *name);
201extern _X_EXPORT InputInfoPtr xf86LookupInput(const char *name);
202extern _X_EXPORT void xf86DeleteInput(InputInfoPtr pInp, int flags);
203extern _X_EXPORT void xf86MotionHistoryAllocate(InputInfoPtr pInfo);
204extern _X_EXPORT void
205xf86IDrvMsgVerb(InputInfoPtr dev,
206                MessageType type, int verb, const char *format, ...)
207_X_ATTRIBUTE_PRINTF(4, 5);
208extern _X_EXPORT void
209xf86IDrvMsg(InputInfoPtr dev, MessageType type, const char *format, ...)
210_X_ATTRIBUTE_PRINTF(3, 4);
211extern _X_EXPORT void
212xf86VIDrvMsgVerb(InputInfoPtr dev,
213                 MessageType type, int verb, const char *format, va_list args)
214_X_ATTRIBUTE_PRINTF(4, 0);
215
216extern _X_EXPORT void xf86AddInputEventDrainCallback(CallbackProcPtr callback,
217                                                     void *param);
218extern _X_EXPORT void xf86RemoveInputEventDrainCallback(CallbackProcPtr callback,
219                                                        void *param);
220
221/* xf86Option.c */
222extern _X_EXPORT void
223xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts);
224
225#endif                          /* _xf86Xinput_h */
226