1/*
2 * @APPLE_LICENSE_HEADER_START@
3 *
4 * Copyright (c) 1999-2009 Apple Computer, Inc.  All Rights Reserved.
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23#ifndef _IOHIPOINTING_H
24#define _IOHIPOINTING_H
25
26#include <IOKit/hidsystem/IOHIPointing.h>
27#include <IOKit/hidsystem/IOHIDevice.h>
28#include <IOKit/hidsystem/IOHIDTypes.h>
29
30/* Start Action Definitions */
31
32/*
33 * HISTORICAL NOTE:
34 *   The following entry points were part of the IOHIPointingEvents
35 *   protocol.
36 */
37typedef void (*RelativePointerEventAction)(OSObject * target,
38                        /* buttons */      int        buttons,
39                        /* deltaX */       int        dx,
40                        /* deltaY */       int        dy,
41                        /* atTime */       AbsoluteTime ts);
42
43typedef void (*AbsolutePointerEventAction)(OSObject * target,
44                        /* buttons */      int        buttons,
45                        /* at */           IOGPoint * newLoc,
46                        /* withBounds */   IOGBounds *bounds,
47                        /* inProximity */  bool       proximity,
48                        /* withPressure */ int        pressure,
49                        /* withAngle */    int        stylusAngle,
50                        /* atTime */       AbsoluteTime ts);
51
52typedef void (*ScrollWheelEventAction)(OSObject * target,
53                                       short      deltaAxis1,
54                                       short      deltaAxis2,
55                                       short      deltaAxis3,
56                                       AbsoluteTime ts);
57
58/* Event Callback Definitions */
59
60typedef void (*RelativePointerEventCallback)(
61                        /* target */       OSObject * target,
62                        /* buttons */      int        buttons,
63                        /* deltaX */       int        dx,
64                        /* deltaY */       int        dy,
65                        /* atTime */       AbsoluteTime ts,
66                        /* sender */       OSObject * sender,
67                        /* refcon */       void *     refcon);
68
69typedef void (*AbsolutePointerEventCallback)(
70                        /* target */       OSObject * target,
71                        /* buttons */      int        buttons,
72                        /* at */           IOGPoint * newLoc,
73                        /* withBounds */   IOGBounds *bounds,
74                        /* inProximity */  bool       proximity,
75                        /* withPressure */ int        pressure,
76                        /* withAngle */    int        stylusAngle,
77                        /* atTime */       AbsoluteTime ts,
78                        /* sender */       OSObject * sender,
79                        /* refcon */       void *     refcon);
80
81typedef void (*ScrollWheelEventCallback)(
82                        /* target */       OSObject * target,
83                        /* delta1 */       short      deltaAxis1,
84                        /* delta2 */       short      deltaAxis2,
85                        /* delta3 */       short      deltaAxis3,
86                        /* fixedDelta1 */  IOFixed    fixedDelta1,
87                        /* fixedDelta2 */  IOFixed    fixedDelta2,
88                        /* fixedDelta3 */  IOFixed    fixedDelta3,
89                        /* pointDelta1 */  SInt32     pointDelta1,
90                        /* pointDelta2 */  SInt32     pointDelta2,
91                        /* pointDelta3 */  SInt32     pointDelta3,
92                        /* reserved */     SInt32     options,
93                        /* atTime */       AbsoluteTime ts,
94                        /* sender */       OSObject * sender,
95                        /* refcon */       void *     refcon);
96
97/* End Action Definitions */
98
99/* Default accel level parameters */
100#define EV_DEFAULTPOINTERACCELLEVEL 0x0000b000
101#define EV_DEFAULTSCROLLACCELLEVEL  0x00005000
102
103class IOHIDPointingDevice;
104struct ScrollAccelInfo;
105
106class IOHIPointing : public IOHIDevice
107{
108    OSDeclareDefaultStructors(IOHIPointing);
109
110    friend class IOHITablet;
111    friend class IOHIDPointing;
112
113private:
114    IOLock *		_deviceLock;  // Lock for all device access
115    int			_buttonMode;  // The "handedness" of the pointer
116    IOFixed		_acceleration;
117    bool		_convertAbsoluteToRelative;
118    bool		_contactToMove;
119    bool		_hadContact;
120    IOGPoint    _previousLocation;
121    UInt8		_pressureThresholdToClick;	// A scale factor of 0 to 255 to determine how much pressure is necessary to generate a primary mouse click - a value of 255 means no click will be generated
122    void *		_scaleSegments;
123    IOItemCount		_scaleSegCount;
124    IOFixed		_fractX;
125    IOFixed		_fractY;
126
127    OSObject *                 _relativePointerEventTarget;
128    RelativePointerEventAction _relativePointerEventAction;
129    OSObject *                 _absolutePointerEventTarget;
130    AbsolutePointerEventAction _absolutePointerEventAction;
131    OSObject *                 _scrollWheelEventTarget;
132    ScrollWheelEventAction     _scrollWheelEventAction;
133
134    struct ExpansionData;
135
136    ExpansionData *  _reserved;
137
138    void    setPointingMode(UInt32 accelerateMode);
139    UInt32  getPointingMode ();
140    void    setScrollType(UInt32 scrollType);
141    UInt32  getScrollType();
142
143    void dispatchScrollWheelEventWithAccelInfo(
144                                SInt32              deltaAxis1,
145                                SInt32              deltaAxis2,
146                                SInt32              deltaAxis3,
147                                ScrollAccelInfo *   info,
148                                AbsoluteTime        ts);
149
150
151protected:
152  virtual void dispatchRelativePointerEvent(int        dx,
153                                            int        dy,
154                                            UInt32     buttonState,
155                                            AbsoluteTime ts);
156
157  virtual void dispatchAbsolutePointerEvent(IOGPoint *	newLoc,
158                                            IOGBounds *	bounds,
159                                            UInt32	buttonState,
160                                            bool	proximity,
161                                            int		pressure,
162                                            int		pressureMin,
163                                            int		pressureMax,
164                                            int		stylusAngle,
165                                            AbsoluteTime	ts);
166
167  virtual void dispatchScrollWheelEvent(short deltaAxis1,
168                                        short deltaAxis2,
169                                        short deltaAxis3,
170                                        AbsoluteTime ts);
171
172public:
173  virtual bool init(OSDictionary * properties = 0);
174  virtual bool start(IOService * provider);
175  virtual void free();
176
177  virtual bool open(IOService *                client,
178		    IOOptionBits	       options,
179                    RelativePointerEventAction rpeAction,
180                    AbsolutePointerEventAction apeAction,
181                    ScrollWheelEventAction     sweAction);
182
183  bool open(        IOService *				client,
184                    IOOptionBits			options,
185                    void *,
186                    RelativePointerEventCallback	rpeCallback,
187                    AbsolutePointerEventCallback	apeCallback,
188                    ScrollWheelEventCallback		sweCallback);
189
190  virtual void close(IOService * client, IOOptionBits );
191  virtual IOReturn message( UInt32 type, IOService * provider,
192                              void * argument = 0 );
193
194  virtual IOHIDKind hidKind();
195  virtual bool 	    updateProperties( void );
196  virtual IOReturn  setParamProperties( OSDictionary * dict );
197  virtual IOReturn  powerStateWillChangeTo( IOPMPowerFlags powerFlags,
198                        unsigned long newState, IOService * device);
199  virtual IOReturn  powerStateDidChangeTo( IOPMPowerFlags powerFlags,
200                        unsigned long newState, IOService * device);
201
202protected: // for subclasses to implement
203  virtual OSData *    copyAccelerationTable();
204  virtual IOItemCount buttonCount();
205  virtual IOFixed     resolution();
206
207  // RY: Adding method to copy scroll wheel accel table.
208  // Unfortunately, we don't have any padding, so this
209  // is going to be non-virtual.
210  /*virtual*/ OSData * copyScrollAccelerationTable();
211
212private:
213  virtual bool resetPointer();
214  virtual void scalePointer(int * dxp, int * dyp);
215    virtual void setupForAcceleration(IOFixed accl);
216
217  // RY: Adding methods to support scroll wheel accel.
218  // Unfortunately, we don't have any padding, so these
219  // are going to be non-virtual.
220  /*virtual*/ bool 	resetScroll();
221  /*virtual*/ void 	setupScrollForAcceleration(IOFixed accl);
222
223  // RY: We have to make sure that subclasses that will
224  // take advantage of this have their defined resolution
225  // in their property table.
226  /*virtual*/ IOFixed	scrollResolutionForType(SInt32 type=-1);
227  /*virtual*/ IOFixed   scrollReportRate();
228  /*virtual*/ OSData *  copyScrollAccelerationTableForType(SInt32 type=-1);
229
230private:
231  static void _relativePointerEvent( IOHIPointing * self,
232				    int        buttons,
233                       /* deltaX */ int        dx,
234                       /* deltaY */ int        dy,
235                       /* atTime */ AbsoluteTime ts);
236
237  /* Tablet event reporting */
238  static void _absolutePointerEvent(IOHIPointing * self,
239				    int        buttons,
240                 /* at */           IOGPoint * newLoc,
241                 /* withBounds */   IOGBounds *bounds,
242                 /* inProximity */  bool       proximity,
243                 /* withPressure */ int        pressure,
244                 /* withAngle */    int        stylusAngle,
245                 /* atTime */       AbsoluteTime ts);
246
247  /* Mouse scroll wheel event reporting */
248  static void _scrollWheelEvent(IOHIPointing *self,
249                                short deltaAxis1,
250                                short deltaAxis2,
251                                short deltaAxis3,
252                                AbsoluteTime ts);
253
254};
255
256#endif /* !_IOHIPOINTING_H */
257