mouse.h revision dd4cbfe8
1/*
2 * Copyright (c) 1999-2003 by The XFree86 Project, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Except as contained in this notice, the name of the copyright holder(s)
23 * and author(s) shall not be used in advertising or otherwise to promote
24 * the sale, use or other dealings in this Software without prior written
25 * authorization from the copyright holder(s) and author(s).
26 */
27
28/* Public interface to OS-specific mouse support. */
29
30#ifndef _XF86OSMOUSE_H_
31#define _XF86OSMOUSE_H_
32
33#include "xf86Xinput.h"
34
35#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 12
36#define COLLECT_INPUT_OPTIONS(pInfo, options) xf86CollectInputOptions((pInfo), (options), NULL)
37#else
38#define COLLECT_INPUT_OPTIONS(pInfo, options) xf86CollectInputOptions((pInfo), (options))
39#endif
40
41
42/* Mouse interface classes */
43#define MSE_NONE	0x00
44#define MSE_SERIAL	0x01		/* serial port */
45#define MSE_BUS		0x02		/* old bus mouse */
46#define MSE_PS2		0x04		/* standard read-only PS/2 */
47#define MSE_XPS2	0x08		/* extended PS/2 */
48#define MSE_AUTO	0x10		/* auto-detect (PnP) */
49#define MSE_MISC	0x20		/* The OS layer will identify the
50					 * specific protocol names that are
51					 * supported for this class. */
52
53/* Mouse Protocol IDs. */
54typedef enum {
55    PROT_UNKNOWN = -2,
56    PROT_UNSUP = -1,		/* protocol is not supported */
57    PROT_MS = 0,
58    PROT_MSC,
59    PROT_MM,
60    PROT_LOGI,
61    PROT_LOGIMAN,
62    PROT_MMHIT,
63    PROT_GLIDE,
64    PROT_IMSERIAL,
65    PROT_THINKING,
66    PROT_ACECAD,
67    PROT_VALUMOUSESCROLL,
68    PROT_PS2,
69    PROT_GENPS2,
70    PROT_IMPS2,
71    PROT_EXPPS2,
72    PROT_THINKPS2,
73    PROT_MMPS2,
74    PROT_GLIDEPS2,
75    PROT_NETPS2,
76    PROT_NETSCPS2,
77    PROT_BM,
78    PROT_AUTO,
79    PROT_SYSMOUSE,
80    PROT_WSMOUSE,
81    PROT_VUID,
82    PROT_NUMPROTOS	/* This must always be last. */
83} MouseProtocolID;
84
85struct _MouseDevRec;
86
87typedef int (*GetInterfaceTypesProc)(void);
88typedef const char **(*BuiltinNamesProc)(void);
89typedef Bool (*CheckProtocolProc)(const char *protocol);
90typedef Bool (*BuiltinPreInitProc)(InputInfoPtr pInfo, const char *protocol,
91				   int flags);
92typedef const char *(*DefaultProtocolProc)(void);
93typedef const char *(*SetupAutoProc)(InputInfoPtr pInfo, int *protoPara);
94typedef void (*SetResProc)(InputInfoPtr pInfo, const char* protocol, int rate,
95			   int res);
96typedef const char *(*FindDeviceProc)(InputInfoPtr pInfo, const char *protocol,
97				      int flags);
98typedef const char *(*GuessProtocolProc)(InputInfoPtr pInfo, int flags);
99
100/*
101 * OSMouseInfoRec is used to pass information from the OSMouse layer to the
102 * OS-independent mouse driver.
103 */
104typedef struct {
105	GetInterfaceTypesProc	SupportedInterfaces;
106	BuiltinNamesProc	BuiltinNames;
107	CheckProtocolProc	CheckProtocol;
108	BuiltinPreInitProc	PreInit;
109	DefaultProtocolProc	DefaultProtocol;
110	SetupAutoProc		SetupAuto;
111	SetResProc		SetPS2Res;
112	SetResProc		SetBMRes;
113	SetResProc		SetMiscRes;
114	FindDeviceProc		FindDevice;
115	GuessProtocolProc	GuessProtocol;
116} OSMouseInfoRec, *OSMouseInfoPtr;
117
118/*
119 * SupportedInterfaces: Returns the mouse interface types that the OS support.
120 *		If MSE_MISC is returned, then the BuiltinNames and
121 *		CheckProtocol should be set.
122 *
123 * BuiltinNames: Returns the names of the protocols that are fully handled
124 *		in the OS-specific code.  These are names that don't appear
125 *		directly in the main "mouse" driver.
126 *
127 * CheckProtocol: Checks if the protocol name given is supported by the
128 *		OS.  It should return TRUE for both "builtin" protocols and
129 *		protocols of type MSE_MISC that are supported by the OS.
130 *
131 * PreInit:	The PreInit function for protocols that are builtin.  This
132 *		function is passed the protocol name.
133 *
134 * DefaultProtocol: Returns the name of a default protocol that should be used
135 *		for the OS when none has been supplied in the config file.
136 *		This should only be set when there is a reasonable default.
137 *
138 * SetupAuto:	This function can be used to do OS-specific protocol
139 *		auto-detection.  It returns the name of the detected protocol,
140 *		or NULL when detection fails.  It may also adjust one or more
141 *		of the "protoPara" values for the detected protocol by setting
142 *		then to something other than -1.  SetupAuto gets called in two
143 *		ways.  The first is before any devices have been opened.  This
144 *		can be used when the protocol "Auto" always maps to a single
145 *		protocol type.  The second is with the device open, allowing
146 *		OS-specific probing to be done.
147 *
148 * SetPS2Res:	Set the resolution and sample rate for MSE_PS2 and MSE_XPS2
149 *		protocol types.
150 *
151 * SetBMRes:	Set the resolution and sample rate for MSE_BM protocol types.
152 *
153 * SetMiscRes:	Set the resolution and sample rate for MSE_MISC protocol types.
154 *
155 * FindDevice:	This function gets called when no Device has been specified
156 *		in the config file.  OS-specific methods may be used to guess
157 * 		which input device to use.  This function is called after the
158 *		pre-open attempts at protocol discovery are done, but before
159 * 		the device is open.  I.e., after the first SetupAuto() call,
160 *		after the DefaultProtocol() call, but before the PreInit()
161 *		call.  Available protocol information may be used in locating
162 *		the default input device.
163 *
164 * GuessProtocol: A last resort attempt at guessing the mouse protocol by
165 *		whatever OS-specific means might be available.  OS-independent
166 *		things should be in the mouse driver.  This function gets
167 *		called after the mouse driver's OS-independent methods have
168 *		failed.
169 */
170
171extern OSMouseInfoPtr OSMouseInit(int flags);
172
173/* Z axis mapping */
174#define MSE_NOZMAP	0
175#define MSE_MAPTOX	-1
176#define MSE_MAPTOY	-2
177#define MSE_MAPTOZ	-3
178#define MSE_MAPTOW	-4
179
180/* Generalize for other axes. */
181#define MSE_NOAXISMAP	MSE_NOZMAP
182
183#define MSE_MAXBUTTONS	24
184#define MSE_DFLTBUTTONS	 3
185
186/*
187 * Mouse device record.  This is shared by the mouse driver and the OSMouse
188 * layer.
189 */
190
191typedef void (*checkMovementsProc)(InputInfoPtr,int, int);
192typedef void (*autoProbeProc)(InputInfoPtr, Bool, Bool);
193typedef Bool (*collectDataProc)(struct _MouseDevRec *, unsigned char);
194typedef Bool (*dataGoodProc)(struct _MouseDevRec *);
195
196typedef void (*PostMseEventProc)(InputInfoPtr pInfo, int buttons,
197			      int dx, int dy, int dz, int dw);
198typedef void (*MouseCommonOptProc)(InputInfoPtr pInfo);
199
200typedef struct _MouseDevRec {
201    PtrCtrlProcPtr	Ctrl;
202    PostMseEventProc	PostEvent;
203    MouseCommonOptProc	CommonOptions;
204    DeviceIntPtr	device;
205    const char *	protocol;
206    MouseProtocolID	protocolID;
207    MouseProtocolID	oldProtocolID; /* hack */
208    int			class;
209    int			mseModel;
210    int			baudRate;
211    int			oldBaudRate;
212    int			sampleRate;
213    int			lastButtons;
214    int			buttons;	/* # of buttons */
215    int			emulateState;	/* automata state for 2 button mode */
216    Bool		emulate3Buttons;
217    Bool		emulate3ButtonsSoft;
218    int			emulate3Timeout;/* Timeout for 3 button emulation */
219    Bool		chordMiddle;
220    Bool                flipXY;
221    int                 invX;
222    int                 invY;
223    int			resolution;
224    int			negativeZ;	/* button mask */
225    int			positiveZ;	/* button mask */
226    int			negativeW;	/* button mask */
227    int			positiveW;	/* button mask */
228    pointer		buffer;		/* usually an XISBuffer* */
229    int			protoBufTail;
230    unsigned char	protoBuf[8];
231    unsigned char	protoPara[8];
232    unsigned char	inSync;		/* driver in sync with datastream */
233    pointer		mousePriv;	/* private area */
234    InputInfoPtr	pInfo;
235    Bool		emulate3Pending;/* timer waiting */
236    CARD32		emulate3Expires;/* time to fire emulation code */
237    Bool		emulateWheel;
238    int			wheelInertia;
239    int			wheelButton;
240    int			negativeX;	/* Button values.  Unlike the Z and */
241    int			positiveX;	/* W equivalents, these are button  */
242    int			negativeY;	/* values rather than button masks. */
243    int			positiveY;
244    int			wheelYDistance;
245    int			wheelXDistance;
246    Bool		autoProbe;
247    checkMovementsProc  checkMovements;
248    autoProbeProc	autoProbeMouse;
249    collectDataProc	collectData;
250    dataGoodProc	dataGood;
251    int			angleOffset;
252    pointer		pDragLock;	/* drag lock area */
253    int			xisbscale;	/* buffer size for 1 event */
254    int			wheelButtonTimeout;/* Timeout for the wheel button emulation */
255    CARD32		wheelButtonExpires;
256    int			doubleClickSourceButtonMask;
257    int			doubleClickTargetButton;
258    int			doubleClickTargetButtonMask;
259    int			doubleClickOldSourceState;
260    int			lastMappedButtons;
261    int			buttonMap[MSE_MAXBUTTONS];
262} MouseDevRec, *MouseDevPtr;
263
264#endif /* _XF86OSMOUSE_H_ */
265