2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
24 * EventDriver.h - Exported Interface Event Driver object.
26 * The EventDriver is a pseudo-device driver.
29 * 19 Mar 1992 Mike Paquette at NeXT
31 * 4 Aug 1993 Erik Kay at NeXT
35 #ifndef _IOHIDSYSTEM_H
36 #define _IOHIDSYSTEM_H
38 #include <IOKit/IOTimerEventSource.h>
39 #include <IOKit/IOService.h>
40 #include <IOKit/IOUserClient.h>
41 #include <IOKit/IOWorkLoop.h>
42 #include <IOKit/IOCommandQueue.h>
43 #include <IOKit/IOBufferMemoryDescriptor.h>
44 #include <IOKit/pwr_mgt/IOPM.h>
45 #include <IOKit/graphics/IOGraphicsDevice.h>
46 #include <IOKit/hidsystem/IOHIDevice.h>
47 #include <IOKit/hidsystem/IOHIDShared.h>
48 #include <IOKit/hidsystem/IOHIDTypes.h>
49 #include <IOKit/hidsystem/IOLLEvent.h>
50 #include "ev_keymap.h" /* For NX_NUM_SCANNED_SPECIALKEYS */
52 typedef void (*IOHIDAction
)(OSObject
*, void *);
54 class IOHIDSystem
: public IOService
56 OSDeclareDefaultStructors(IOHIDSystem
);
58 friend class IOHIDUserClient
;
59 friend class IOHIDParamUserClient
;
64 IOWorkLoop
* workLoop
;
65 IOTimerEventSource
* timerES
;
66 IOCommandQueue
* cmdQ
;
67 IOUserClient
* serverConnect
;
68 IOUserClient
* paramConnect
;
69 IONotifier
* publishNotify
;
71 // Ports on which we hold send rights
72 mach_port_t eventPort
; // Send msg here when event queue
74 mach_port_t _specialKeyPort
[NX_NUM_SCANNED_SPECIALKEYS
]; // Special key msgs
75 void *eventMsg
; // Msg to be sent to Window Server.
77 // Shared memory area information
78 IOBufferMemoryDescriptor
* globalMemory
;
79 vm_offset_t shmem_addr
; // kernel address of shared memory
80 vm_size_t shmem_size
; // size of shared memory
82 // Pointers to structures which occupy the shared memory area.
83 volatile void *evs
; // Pointer to private driver shmem
84 volatile EvGlobals
*evg
; // Pointer to EvGlobals (shmem)
85 // Internal variables related to the shared memory area
86 int lleqSize
; // # of entries in low-level queue
87 // FIXME: why is this ivar lleqSize an ivar? {Dan]
90 vm_size_t evScreenSize
; // Byte size of evScreen array
91 void *evScreen
; // array of screens known to driver
92 volatile void *lastShmemPtr
; // Pointer used to index thru shmem
93 // while assigning shared areas to
95 int screens
; // running total of allocated screens
96 UInt32 cursorScreens
; // bit mask of screens with cursor present
97 UInt32 cursorPinScreen
;// a screen to pin against
98 Bounds cursorPin
; // Range to which cursor is pinned
99 // while on this screen.
100 Bounds workSpace
; // Bounds of full workspace.
101 // Event Status state - This includes things like event timestamps,
102 // time til screen dim, and related things manipulated through the
105 Point pointerLoc
; // Current pointing device location
106 // The value leads evg->cursorLoc.
107 Point pointerDelta
; // The cumulative pointer delta values since
108 // previous mouse move event was posted
109 Point clickLoc
; // location of last mouse click
110 Point clickSpaceThresh
; // max mouse delta to be a doubleclick
111 int clickState
; // Current click state
112 unsigned char lastPressure
; // last pressure seen
113 bool lastProximity
; // last proximity state seen
115 SInt32 curVolume
; // Value of volume setting.
116 SInt32 dimmedBrightness
;// Value of screen brightness when autoDim
118 SInt32 curBright
; // The current brightness is cached here while
119 // the driver is open. This number is always
120 // the user-specified brightness level; if the
121 // screen is autodimmed, the actual brightness
122 // level in the monitor will be less.
123 SInt32 autoDimmed
; // Is screen currently autodimmed?
124 bool evOpenCalled
; // Has the driver been opened?
125 bool evInitialized
; // Has the first-open-only initialization run?
126 bool eventsOpen
; // Boolean: has evmmap been called yet?
127 bool cursorStarted
; // periodic events running?
128 bool cursorEnabled
; // cursor positioning ok?
129 bool cursorCoupled
; // cursor positioning on pointer moves ok?
131 short leftENum
; // Unique ID for last left down event
132 short rightENum
; // Unique ID for last right down event
134 // The periodic event mechanism timestamps and state
135 // are recorded here.
136 AbsoluteTime thisPeriodicRun
;
137 AbsoluteTime periodicEventDelta
;// Time between periodic events
138 // todo: make infinite
139 AbsoluteTime clickTime
; // Timestamps used to determine doubleclicks
140 AbsoluteTime clickTimeThresh
;
141 AbsoluteTime autoDimPeriod
; // How long since last user action before
142 // we autodim screen? User preference item,
143 // set by InitMouse and evsioctl
144 AbsoluteTime autoDimTime
; // Time value when we will autodim screen,
145 // if autoDimmed is 0.
146 // Set in LLEventPost.
148 AbsoluteTime waitSustain
; // Sustain time before removing cursor
149 AbsoluteTime waitSusTime
; // Sustain counter
150 AbsoluteTime waitFrameRate
; // Ticks per wait cursor frame
151 AbsoluteTime waitFrameTime
; // Wait cursor frame timer
153 AbsoluteTime postedVBLTime
; // Used to post mouse events once per frame
154 AbsoluteTime lastEventTime
;
155 AbsoluteTime lastMoveTime
;
159 // Flags used in scheduling periodic event callbacks
160 bool needSetCursorPosition
;
161 bool needToKickEventConsumer
;
162 IOLock
* kickConsumerLock
;
165 IOService
* displayManager
; // points to display manager
166 IOPMPowerFlags displayState
;
169 inline short getUniqueEventNum();
171 virtual IOReturn
powerStateDidChangeTo ( IOPMPowerFlags
, unsigned long, IOService
*);
173 void _resetMouseParameters();
174 void _resetKeyboardParameters();
176 /* Initialize the shared memory area */
178 /* Dispatch low level events through shared memory to the WindowServer */
179 void postEvent(int what
,
180 /* at */ Point
* location
,
181 /* atTime */ AbsoluteTime ts
,
182 /* withData */ NXEventData
* myData
);
183 /* Dispatch mechanisms for screen state changes */
185 /* command */ EvCmd evcmd
);
186 /* Dispatch mechanism for special key press */
187 void evSpecialKeyMsg(unsigned key
,
188 /* direction */ unsigned dir
,
189 /* flags */ unsigned f
,
190 /* level */ unsigned l
);
191 /* Message the event consumer to process posted events */
192 void kickEventConsumer();
193 IOReturn
sendWorkLoopCommand(OSObject
* target
,
196 static void _doPerformInIOThread( void* self
,
201 static void _periodicEvents(IOHIDSystem
* self
,
202 IOTimerEventSource
*timer
);
204 static void _performSpecialKeyMsg(IOHIDSystem
* self
,
205 struct evioSpecialKeyMsg
*msg
);
206 static void _performKickEventConsumer(IOHIDSystem
* self
,void *);
208 static bool publishNotificationHandler( IOHIDSystem
* self
,
209 void * ref
, IOService
* newService
);
213 * The following methods were part of the IOHIDSystem(Input) category;
214 * the declarations have now been merged directly into this class.
216 * Exported Interface Event Driver object input services.
220 // Schedule next periodic run based on current event system state.
221 void scheduleNextPeriodicEvent();
222 // Message invoked to run periodic events. This method runs in the workloop.
223 void periodicEvents(IOTimerEventSource
*timer
);
224 // Start the cursor running.
226 // Repin cursor location.
228 // Wait Cursor machinery.
229 void showWaitCursor();
230 void hideWaitCursor();
231 void animateWaitCursor();
232 void changeCursor(int frame
);
233 // Return screen number a point lies on.
234 int pointToScreen(Point
* p
);
235 // Set the undimmed brightness.
236 void setBrightness(int b
);
237 // Return undimmed brightness.
239 // Set the dimmed brightness.
240 void setAutoDimBrightness(int b
);
241 // Return dimmed brightness.
242 int autoDimBrightness();
243 // Return the current brightness.
244 int currentBrightness();
247 // Return display brightness to normal.
250 void forceAutoDimState(bool dim
);
251 // Audio volume control.
252 void setAudioVolume(int v
);
253 // Audio volume control, from ext user.
254 void setUserAudioVolume(int v
);
255 // Return audio volume.
257 // Propagate state out to screens.
258 inline void setBrightness();
260 inline void showCursor();
261 inline void hideCursor();
262 inline void moveCursor();
263 // Claim ownership of event sources.
264 void attachDefaultEventSources();
265 // Give up ownership of event sources.
266 void detachEventSources();
267 bool registerEventSource(IOHIDevice
* source
);
269 // Set abs cursor position.
270 void setCursorPosition(Point
* newLoc
, bool external
);
271 void _setButtonState(int buttons
,
272 /* atTime */ AbsoluteTime ts
);
273 void _setCursorPosition(Point
* newLoc
, bool external
);
275 void _postMouseMoveEvent(int what
,
277 AbsoluteTime theClock
);
279 /* END HISTORICAL NOTE */
282 static IOHIDSystem
* instance(); /* Return the current instance of the */
283 /* EventDriver, or 0 if none. */
285 virtual bool init(OSDictionary
* properties
= 0);
286 virtual IOHIDSystem
* probe(IOService
* provider
,
288 virtual bool start(IOService
* provider
);
289 virtual IOReturn
message(UInt32 type
, IOService
* provider
,
293 virtual IOWorkLoop
*getWorkLoop() const;
295 virtual IOReturn
evOpen(void);
296 virtual IOReturn
evClose(void);
298 virtual bool updateProperties(void);
299 virtual IOReturn
setParamProperties(OSDictionary
* dict
);
300 virtual bool serializeProperties( OSSerialize
* s
) const;
302 /* Create the shared memory area */
303 virtual IOReturn
createShmem(void*,void*,void*,void*,void*,void*);
304 /* Set the port for event available notify msg */
305 virtual void setEventPort(mach_port_t port
);
306 /* Set the port for the special key keypress msg */
307 virtual IOReturn
setSpecialKeyPort(
308 /* keyFlavor */ int special_key
,
309 /* keyPort */ mach_port_t key_port
);
310 virtual mach_port_t
specialKeyPort(int special_key
);
313 virtual IOReturn
newUserClient(task_t owningTask
,
314 /* withToken */ void * security_id
,
315 /* ofType */ UInt32 type
,
316 /* client */ IOUserClient
** handler
);
320 * The following methods were part of the IOHIPointingEvents protocol;
321 * the declarations have now been merged directly into this class.
325 /* Mouse event reporting */
326 virtual void relativePointerEvent(int buttons
,
329 /* atTime */ AbsoluteTime ts
);
331 /* Tablet event reporting */
332 virtual void absolutePointerEvent(int buttons
,
333 /* at */ Point
* newLoc
,
334 /* withBounds */ Bounds
* bounds
,
335 /* inProximity */ bool proximity
,
336 /* withPressure */ int pressure
,
337 /* withAngle */ int stylusAngle
,
338 /* atTime */ AbsoluteTime ts
);
340 /* Mouse scroll wheel event reporting */
341 virtual void scrollWheelEvent(short deltaAxis1
,
347 virtual void tabletEvent(NXEventData
*tabletData
,
350 virtual void proximityEvent(NXEventData
*proximityData
,
355 * The following methods were part of the IOHIKeyboardEvents protocol;
356 * the declarations have now been merged directly into this class.
360 virtual void keyboardEvent(unsigned eventType
,
361 /* flags */ unsigned flags
,
362 /* keyCode */ unsigned key
,
363 /* charCode */ unsigned charCode
,
364 /* charSet */ unsigned charSet
,
365 /* originalCharCode */ unsigned origCharCode
,
366 /* originalCharSet */ unsigned origCharSet
,
367 /* keyboardType */ unsigned keyboardType
,
368 /* repeat */ bool repeat
,
369 /* atTime */ AbsoluteTime ts
);
371 virtual void keyboardSpecialEvent( unsigned eventType
,
372 /* flags */ unsigned flags
,
373 /* keyCode */ unsigned key
,
374 /* specialty */ unsigned flavor
,
375 /* guid */ UInt64 guid
,
376 /* repeat */ bool repeat
,
377 /* atTime */ AbsoluteTime ts
);
379 virtual void updateEventFlags(unsigned flags
); /* Does not generate events */
387 * statics for upstream callouts
390 void _scaleLocationToCurrentScreen(Point
*location
, Bounds
*bounds
); // Should this one be public???
392 static void _relativePointerEvent( IOHIDSystem
* self
,
396 /* atTime */ AbsoluteTime ts
);
398 /* Tablet event reporting */
399 static void _absolutePointerEvent(IOHIDSystem
* self
,
401 /* at */ Point
* newLoc
,
402 /* withBounds */ Bounds
* bounds
,
403 /* inProximity */ bool proximity
,
404 /* withPressure */ int pressure
,
405 /* withAngle */ int stylusAngle
,
406 /* atTime */ AbsoluteTime ts
);
408 /* Mouse scroll wheel event reporting */
409 static void _scrollWheelEvent(IOHIDSystem
*self
,
415 static void _tabletEvent(IOHIDSystem
*self
,
416 NXEventData
*tabletData
,
419 static void _proximityEvent(IOHIDSystem
*self
,
420 NXEventData
*proximityData
,
423 static void _keyboardEvent( IOHIDSystem
* self
,
425 /* flags */ unsigned flags
,
426 /* keyCode */ unsigned key
,
427 /* charCode */ unsigned charCode
,
428 /* charSet */ unsigned charSet
,
429 /* originalCharCode */ unsigned origCharCode
,
430 /* originalCharSet */ unsigned origCharSet
,
431 /* keyboardType */ unsigned keyboardType
,
432 /* repeat */ bool repeat
,
433 /* atTime */ AbsoluteTime ts
);
434 static void _keyboardSpecialEvent( IOHIDSystem
* self
,
436 /* flags */ unsigned flags
,
437 /* keyCode */ unsigned key
,
438 /* specialty */ unsigned flavor
,
439 /* guid */ UInt64 guid
,
440 /* repeat */ bool repeat
,
441 /* atTime */ AbsoluteTime ts
);
442 static void _updateEventFlags( IOHIDSystem
* self
,
443 unsigned flags
); /* Does not generate events */
448 * The following methods were part of the IOUserClient protocol;
449 * the declarations have now been merged directly into this class.
454 virtual IOReturn
setEventsEnable(void*,void*,void*,void*,void*,void*);
455 virtual IOReturn
setCursorEnable(void*,void*,void*,void*,void*,void*);
456 virtual IOReturn
extPostEvent(void*,void*,void*,void*,void*,void*);
457 virtual IOReturn
extSetMouseLocation(void*,void*,void*,void*,void*,void*);
458 virtual IOReturn
extGetButtonEventNum(void*,void*,void*,void*,void*,void*);
462 * The following methods were part of the IOScreenRegistration protocol;
463 * the declarations have now been merged directly into this class.
465 * Methods exported by the EventDriver for display systems.
467 * The screenRegister protocol is used by frame buffer drivers to register
468 * themselves with the Event Driver. These methods are called in response
469 * to an _IOGetParameterInIntArray() call with "IO_Framebuffer_Register" or
470 * "IO_Framebuffer_Unregister".
474 virtual int registerScreen(IOGraphicsDevice
* instance
,
475 /* bounds */ Bounds
* bp
);
476 // /* shmem */ void ** addr,
477 // /* size */ int * size)
478 virtual void unregisterScreen(int index
);
482 * The following methods were part of the IOWorkspaceBounds protocol;
483 * the declarations have now been merged directly into this class.
485 * Absolute position input devices and some specialized output devices
486 * may need to know the bounding rectangle for all attached displays.
487 * The following method returns a Bounds* for the workspace. Please note
488 * that the bounds are kept as signed values, and that on a multi-display
489 * system the minx and miny values may very well be negative.
493 virtual Bounds
* workspaceBounds();
495 /* END HISTORICAL NOTES */
498 #endif /* !_IOHIDSYSTEM_H */