IOHIKeyboardMapper.h [plain text]
#ifndef _IOHIKEYBOARDMAPPER_H
#define _IOHIKEYBOARDMAPPER_H
#include <IOKit/hidsystem/ev_keymap.h>
#include <IOKit/hidsystem/IOLLEvent.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/IOInterruptEventSource.h>
class IOHIKeyboard;
class IOHIDSystem;
typedef UInt32 * kbdBitVector;
#define EVK_BITS_PER_UNIT 32
#define EVK_BITS_MASK 31
#define EVK_BITS_SHIFT 5 // 1<<5 == 32, for cheap divide
#define EVK_KEYDOWN(n, bits) \
(bits)[((n)>>EVK_BITS_SHIFT)] |= (1 << ((n) & EVK_BITS_MASK))
#define EVK_KEYUP(n, bits) \
(bits)[((n)>>EVK_BITS_SHIFT)] &= ~(1 << ((n) & EVK_BITS_MASK))
#define EVK_IS_KEYDOWN(n, bits) \
(((bits)[((n)>>EVK_BITS_SHIFT)] & (1 << ((n) & EVK_BITS_MASK))) != 0)
#define kMAX_MODIFIERS 5
#define kNUM_SHIFTS_TO_ACTIVATE 5
#define kDEFAULT_SHIFTEXPIREINTERVAL 30000
enum
{
kState_Disabled_Flag = 0x0001, kState_ShiftActivates_Flag = 0x0002, kState_On = 0x0004, kState_On_ModifiersDown = 0x0008,
kState_Mask = 0x00FF, };
typedef struct _stickyKeys_ToggleInfo
{
IOByteCount size;
unsigned toggleModifier;
unsigned repetitionsToToggle;
AbsoluteTime expireInterval;
unsigned currentCount;
AbsoluteTime deadlines[1];
} StickyKeys_ToggleInfo;
enum
{
kModifier_DidPerformModifiy = 0x01,
kModifier_DidKeyUp = 0x02,
kModifier_Locked = 0x04,
};
typedef struct _stickyKeys_ModifierInfo
{
UInt8 key; UInt8 state; UInt8 leftModBit; } StickyKeys_ModifierInfo;
class IOHIDKeyboardDevice;
class IOHIKeyboardMapper : public OSObject
{
OSDeclareDefaultStructors(IOHIKeyboardMapper);
private:
IOHIKeyboard * _delegate; bool _mappingShouldBeFreed; NXParsedKeyMapping _parsedMapping; IOHIDSystem * _hidSystem;
struct ExpansionData {
UInt16 f12Eject_State;
UInt32 eject_Delay_MS;
IOTimerEventSource *ejectTimerEventSource;
kbdBitVector cached_KeyBits;
StickyKeys_ModifierInfo stickyKeys_StuckModifiers[kMAX_MODIFIERS];
IOInterruptEventSource *stickyKeysMouseClickEventSource;
IOInterruptEventSource *stickyKeysSetFnStateEventSource;
OSDictionary *offFnParamDict;
OSDictionary *onFnParamDict;
UInt16 slowKeys_State;
UInt32 slowKeys_Delay_MS;
IOTimerEventSource *slowKeysTimerEventSource;
UInt8 slowKeys_Aborted_Key;
UInt8 slowKeys_Current_Key;
UInt32 specialKeyModifierFlags;
bool supportsF12Eject;
SInt32 modifierSwap_Modifiers[NX_NUMMODIFIERS];
unsigned char * cachedAlphaLockModDefs;
};
ExpansionData * _reserved;
public:
static IOHIKeyboardMapper * keyboardMapper(
IOHIKeyboard * delegate,
const UInt8 * mapping,
UInt32 mappingLength,
bool mappingShouldBeFreed );
virtual bool init(IOHIKeyboard * delegate,
const UInt8 * mapping,
UInt32 mappingLength,
bool mappingShouldBeFreed);
virtual void free();
virtual const UInt8 * mapping();
virtual UInt32 mappingLength();
virtual bool serialize(OSSerialize *s) const;
virtual void translateKeyCode(UInt8 key, bool keyDown, kbdBitVector keyBits);
virtual UInt8 getParsedSpecialKey(UInt8 logical);
virtual void setKeyboardTarget (IOService * keyboardTarget);
virtual bool updateProperties (void);
virtual IOReturn setParamProperties (OSDictionary * dict);
virtual void keyEventPostProcess (void);
private:
static void makeNumberParamProperty( OSDictionary * dict, const char * key,
unsigned long long number, unsigned int bits );
virtual bool parseKeyMapping(const UInt8 * mapping,
UInt32 mappingLength,
NXParsedKeyMapping * parsedMapping) const;
virtual void calcModBit(int bit, kbdBitVector keyBits);
virtual void doModCalc(int key, kbdBitVector keyBits);
virtual void doCharGen(int keyCode, bool down);
private:
void rawTranslateKeyCode (UInt8 key, bool keyDown, kbdBitVector keyBits);
bool modifierSwapFilterKey(UInt8 * key);
UInt32 _stickyKeys_State;
int _stickyKeys_NumModifiersDown;
UInt8 _stickyKeys_Modifiers[kMAX_MODIFIERS];
StickyKeys_ToggleInfo * _stickyKeys_ShiftToggle;
StickyKeys_ToggleInfo * _stickyKeys_OptionToggle;
bool _stateDirty;
OSDictionary * _onParamDict;
OSDictionary * _offParamDict;
bool stickyKeysinit (void);
void stickyKeysfree (void);
static StickyKeys_ToggleInfo * stickyKeysAllocToggleInfo (unsigned maxCount);
static void stickyKeysFreeToggleInfo (StickyKeys_ToggleInfo * toggleInfo);
bool createParamDicts (void);
void postKeyboardSpecialEvent (unsigned subtype, unsigned eventType=NX_SYSDEFINED);
bool stickyKeysModifierToggleCheck(
StickyKeys_ToggleInfo * toggleInfo,
UInt8 key,
bool keyDown,
kbdBitVector keyBits,
bool mouseClick = false);
void stickyKeysNonModifierKey (UInt8 key, bool keyDown, kbdBitVector keyBits, bool mouseClick = false);
bool stickyKeysModifierKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
bool stickyKeysFilterKey (UInt8 key, bool keyDown, kbdBitVector keyBits, bool mouseClick = false);
static void stickyKeysMouseUp(IOHIKeyboardMapper *owner, IOEventSource *sender);
void stickyKeysCleanup();
static void stickyKeysSetFnState(IOHIKeyboardMapper *owner, IOEventSource *sender);
private:
bool f12EjectFilterKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
static void performF12Eject(IOHIKeyboardMapper *owner, IOTimerEventSource *sender);
private:
bool slowKeysFilterKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
static void slowKeysPostProcess (IOHIKeyboardMapper *owner, IOTimerEventSource *sender);
public:
OSMetaClassDeclareReservedUsed(IOHIKeyboardMapper, 0);
virtual IOReturn message( UInt32 type, IOService * provider, void * argument = 0 );
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 1);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 2);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 3);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 4);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 5);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 6);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 7);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 8);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 9);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 10);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 11);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 12);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 13);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 14);
OSMetaClassDeclareReservedUnused(IOHIKeyboardMapper, 15);
};
#endif // _IOHIKEYBOARDMAPPER_H