Chameleon

Chameleon Svn Source Tree

Root/branches/rewrite/i386/include/IOKit/hidsystem/IOHIKeyboardMapper.h

Source at commit 1129 created 12 years 11 months ago.
By meklort, Change options.o so that it reloads the system config as well. Also change it so that it uses that config for variables (NOTE: if the calue exists in chameleonConfig, it's used instead.
1/*
2 * @APPLE_LICENSE_HEADER_START@
3 *
4 * Copyright (c) 1999-2003 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 _IOHIKEYBOARDMAPPER_H
24#define _IOHIKEYBOARDMAPPER_H
25
26#include <IOKit/hidsystem/ev_keymap.h>
27#include <IOKit/hidsystem/IOLLEvent.h>
28#include <IOKit/IOTimerEventSource.h>
29#include <IOKit/IOInterruptEventSource.h>
30
31class IOHIKeyboard;
32class IOHIDSystem;
33
34/*
35 * Key ip/down state is tracked in a bit list. Bits are set
36 * for key-down, and cleared for key-up. The bit vector and macros
37 * for it's manipulation are defined here.
38 */
39
40typedefUInt32 * kbdBitVector;
41
42#define EVK_BITS_PER_UNIT32
43#define EVK_BITS_MASK31
44#define EVK_BITS_SHIFT5// 1<<5 == 32, for cheap divide
45
46#define EVK_KEYDOWN(n, bits) \
47(bits)[((n)>>EVK_BITS_SHIFT)] |= (1 << ((n) & EVK_BITS_MASK))
48
49#define EVK_KEYUP(n, bits) \
50(bits)[((n)>>EVK_BITS_SHIFT)] &= ~(1 << ((n) & EVK_BITS_MASK))
51
52#define EVK_IS_KEYDOWN(n, bits) \
53(((bits)[((n)>>EVK_BITS_SHIFT)] & (1 << ((n) & EVK_BITS_MASK))) != 0)
54
55/* the maximum number of modifier keys sticky keys can hold at once */
56#define kMAX_MODIFIERS5
57
58/* the number of shift keys in a row that must be depressed to toggle state */
59#define kNUM_SHIFTS_TO_ACTIVATE5
60
61/* the number of milliseconds all the shifts must be pressed in - 30 seconds (30000 mS)*/
62#define kDEFAULT_SHIFTEXPIREINTERVAL30000
63
64
65// sticky keys state flags
66enum
67{
68 kState_Disabled_Flag= 0x0001,// disabled and will do nothing until this is changed
69 kState_ShiftActivates_Flag= 0x0002,// the 'on' gesture (5 shifts) will activate
70 kState_On= 0x0004,// currently on, will hold down modifiers when pressed
71 kState_On_ModifiersDown= 0x0008,// one or more modifiers being held down
72
73 kState_Mask= 0x00FF,// mask for all states
74};
75
76typedef struct _stickyKeys_ToggleInfo
77{
78// size of this allocation
79IOByteCountsize;
80
81// which modifier key we are tracking (using NX_WHICHMODMASK)
82unsignedtoggleModifier;
83
84// the number of times the modifier must be pressed to toggle
85unsignedrepetitionsToToggle;
86
87// how long the user has to press the modifier repetitionsToToggle times
88// the default is 30 seconds
89AbsoluteTimeexpireInterval;
90
91// the number of times the modifier used within the alloted time
92unsignedcurrentCount;
93
94// the times that the last shift must occer for this one to be used
95// this array will actually be of size repetitionsToToggle
96AbsoluteTimedeadlines[1];
97} StickyKeys_ToggleInfo;
98
99// Flags for each sticky key modifier
100// This will allow for chording of keys
101// and for key locking
102enum
103{
104 kModifier_DidPerformModifiy= 0x01,
105 kModifier_DidKeyUp= 0x02,
106 kModifier_Locked= 0x04,
107};
108typedef struct _stickyKeys_ModifierInfo
109{
110UInt8key;// Key code of the sticky modifier
111 UInt8state;// The state of the sticky modifier
112 UInt8leftModBit;// System Mod bit of the sticky modifier
113} StickyKeys_ModifierInfo;
114
115class IOHIDKeyboardDevice;
116
117class IOHIKeyboardMapper : public OSObject
118{
119 OSDeclareDefaultStructors(IOHIKeyboardMapper);
120
121private:
122IOHIKeyboard *_delegate;// KeyMap delegate
123bool_mappingShouldBeFreed;// true if map can be IOFree'd
124NXParsedKeyMapping_parsedMapping;// current system-wide keymap
125IOHIDSystem *_hidSystem;// target of IOHIKeyboard (should be IOHIDSystem)
126
127// binary compatibility padding
128 struct ExpansionData {
129
130 // This is for F12 eject
131UInt16 f12Eject_State;
132UInt32 eject_Delay_MS;
133IOTimerEventSource *ejectTimerEventSource;
134
135 // This is for sticky keys
136 kbdBitVectorcached_KeyBits;
137 StickyKeys_ModifierInfo stickyKeys_StuckModifiers[kMAX_MODIFIERS];
138 IOInterruptEventSource *stickyKeysMouseClickEventSource;
139 IOInterruptEventSource*stickyKeysSetFnStateEventSource;
140 // The following should really be statics, but placing here
141 // to match design by predecesor.
142 OSDictionary*offFnParamDict;
143 OSDictionary*onFnParamDict;
144
145 // This is for SlowKeys
146 UInt16slowKeys_State;
147 UInt32 slowKeys_Delay_MS;
148 IOTimerEventSource*slowKeysTimerEventSource;
149
150 // stored for slowKeysPostProcess
151 UInt8slowKeys_Aborted_Key;
152 UInt8slowKeys_Current_Key;
153
154 UInt32specialKeyModifierFlags;
155
156 boolsupportsF12Eject;
157
158 SInt32 modifierSwap_Modifiers[NX_NUMMODIFIERS];
159
160unsigned char * cachedAlphaLockModDefs;
161 };
162 ExpansionData * _reserved; // Reserved for future use. (Internal use only)
163
164public:
165static IOHIKeyboardMapper * keyboardMapper(
166IOHIKeyboard * delegate,
167const UInt8 * mapping,
168UInt32 mappingLength,
169bool mappingShouldBeFreed );
170
171virtual bool init(IOHIKeyboard * delegate,
172const UInt8 * mapping,
173 UInt32 mappingLength,
174 bool mappingShouldBeFreed);
175virtual void free();
176
177virtual const UInt8 * mapping();
178virtual UInt32 mappingLength();
179virtual bool serialize(OSSerialize *s) const;
180
181virtual void translateKeyCode(UInt8 key, bool keyDown, kbdBitVector keyBits);
182virtual UInt8 getParsedSpecialKey(UInt8 logical); //retrieve a key from _parsedMapping
183
184virtualvoidsetKeyboardTarget (IOService * keyboardTarget);
185
186virtual bool updateProperties (void);
187virtual IOReturn setParamProperties (OSDictionary * dict);
188
189// keyEventPostProcess is called while a lock is not held, so a recursive
190// call back into HIKeyboard is possible
191virtual void keyEventPostProcess (void);
192
193private:
194static void makeNumberParamProperty( OSDictionary * dict, const char * key,
195 unsigned long long number, unsigned int bits );
196
197
198virtual bool parseKeyMapping(const UInt8 * mapping,
199 UInt32 mappingLength,
200 NXParsedKeyMapping * parsedMapping) const;
201
202virtual void calcModBit(int bit, kbdBitVector keyBits);
203virtual void doModCalc(int key, kbdBitVector keyBits);
204virtual void doCharGen(int keyCode, bool down);
205
206/* sticky keys functionality */
207private:
208// original translateKeyCode
209void rawTranslateKeyCode (UInt8 key, bool keyDown, kbdBitVector keyBits);
210 bool modifierSwapFilterKey(UInt8 * key);
211
212// the current state of stickyKeys
213UInt32 _stickyKeys_State;
214
215// the number of modifiers being held down by stickyKeys
216int _stickyKeys_NumModifiersDown;
217
218 //////////////////////////////////////////////////////////////
219 // THE FOLLOWING CLASS VARIABLE HAS BEEN DEPRECATED
220 //
221 // PLEASE USE _stickyKeys_StuckModifiers
222 //
223UInt8 _stickyKeys_Modifiers[kMAX_MODIFIERS];
224 //////////////////////////////////////////////////////////////
225
226// contains the info needed to keep track of shift repetitions
227StickyKeys_ToggleInfo * _stickyKeys_ShiftToggle;
228
229// contains the info needed to keep track of option repetitions
230StickyKeys_ToggleInfo * _stickyKeys_OptionToggle;
231
232// dictionaries with cached on and off states, used to set params when state changes
233bool_stateDirty;
234OSDictionary *_onParamDict;
235OSDictionary *_offParamDict;
236
237// init/free vars
238bool stickyKeysinit (void);
239void stickyKeysfree (void);
240
241// allocate/free a StickyKeys_ToggleInfo struct
242static StickyKeys_ToggleInfo * stickyKeysAllocToggleInfo (unsigned maxCount);
243static void stickyKeysFreeToggleInfo (StickyKeys_ToggleInfo * toggleInfo);
244
245// create on/off dicts as part of init
246bool createParamDicts (void);
247
248// post special keyboard events thru the event system
249void postKeyboardSpecialEvent (unsigned subtype, unsigned eventType=NX_SYSDEFINED);
250
251// check any modifier to see if it is pressed 5 times
252// based on StickyKeys_ToggleInfo
253bool stickyKeysModifierToggleCheck(
254StickyKeys_ToggleInfo * toggleInfo,
255UInt8 key,
256bool keyDown,
257kbdBitVector keyBits,
258 bool mouseClick = false);
259
260// non-modifier key pressed
261void stickyKeysNonModifierKey (UInt8 key, bool keyDown, kbdBitVector keyBits, bool mouseClick = false);
262
263// modifier key pressed (shift, command, option, control)
264bool stickyKeysModifierKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
265
266// main entry point, called for all keys (returns true if key handled)
267bool stickyKeysFilterKey (UInt8 key, bool keyDown, kbdBitVector keyBits, bool mouseClick = false);
268
269 // called by interrupt event source to inform sticky keys of mouse down event
270 static void stickyKeysMouseUp(IOHIKeyboardMapper *owner, IOEventSource *sender);
271
272void stickyKeysCleanup();
273
274 // called by interrupt event source to restore prior fn state
275static void stickyKeysSetFnState(IOHIKeyboardMapper *owner, IOEventSource *sender);
276
277 /* F12 Eject Functionality */
278private:
279
280 // Determining f12 eject key press
281 // Returns true if f12 held down for a predetermined period of time.
282 bool f12EjectFilterKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
283
284 // Timer function for eject
285 static void performF12Eject(IOHIKeyboardMapper *owner, IOTimerEventSource *sender);
286
287 /* SlowKeys Functionality */
288private:
289 // Slow keys methods
290 bool slowKeysFilterKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
291
292 static void slowKeysPostProcess (IOHIKeyboardMapper *owner, IOTimerEventSource *sender);
293
294
295public:
296 OSMetaClassDeclareReservedUsed(IOHIKeyboardMapper, 0);
297 virtual IOReturn message( UInt32 type, IOService * provider, void * argument = 0 );
298
299// binary compatibility padding
300 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 1);
301 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 2);
302 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 3);
303 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 4);
304 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 5);
305 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 6);
306 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 7);
307 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 8);
308 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 9);
309 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 10);
310 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 11);
311 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 12);
312 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 13);
313 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 14);
314 OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 15);
315};
316
317#endif _IOHIKEYBOARDMAPPER_H
318
319/*
320 * HISTORICAL NOTE:
321 * The "delegate" object had to respond to the following protocol;
322 * this protocol has since been merged into the IOHIKeyboard class.
323 *
324 * @protocol KeyMapDelegate
325 *
326 * - keyboardEvent:(unsigned)eventType
327 * flags:(unsigned)flags
328 *keyCode:(unsigned)keyCode
329 *charCode:(unsigned)charCode
330 *charSet:(unsigned)charSet
331 *originalCharCode:(unsigned)origCharCode
332 *originalCharSet:(unsigned)origCharSet;
333 *
334 * - keyboardSpecialEvent:(unsigned)eventType
335 *flags :(unsigned)flags
336 *keyCode:(unsigned)keyCode
337 *specialty:(unsigned)flavor;
338 *
339 * - updateEventFlags:(unsigned)flags;// Does not generate events
340 *
341 * - (unsigned)eventFlags;// Global event flags
342 * - (unsigned)deviceFlags;// per-device event flags
343 * - setDeviceFlags:(unsigned)flags;// Set device event flags
344 * - (bool)alphaLock;// current alpha-lock state
345 * - setAlphaLock:(bool)val;// Set current alpha-lock state
346 * - (bool)charKeyActive;// Is a character gen. key down?
347 * - setCharKeyActive:(bool)val;// Note that a char gen key is down.
348 *
349 * @end
350 */
351

Archive Download this file

Revision: 1129