IOHIKeyboardMapper.h [plain text]
#ifndef _IOHIKEYBOARDMAPPER_H
#define _IOHIKEYBOARDMAPPER_H
#include <IOKit/hidsystem/ev_keymap.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; } 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 stickyKeys_Modifier_KeyBits;
StickyKeys_ModifierInfo stickyKeys_StuckModifiers[kMAX_MODIFIERS];
IOInterruptEventSource *stickyKeysMouseClickEventSource;
UInt16 slowKeys_State;
UInt32 slowKeys_Delay_MS;
IOTimerEventSource *slowKeysTimerEventSource;
UInt8 slowKeys_Aborted_Key;
UInt8 slowKeys_Current_Key;
kbdBitVector slowKeys_Current_KeyBits;
IOHIDKeyboardDevice * hidKeyboardNub;
};
ExpansionData * _reserved;
#define _f12Eject_State _reserved->f12Eject_State
#define _eject_Delay_MS _reserved->eject_Delay_MS
#define _ejectTimerEventSource _reserved->ejectTimerEventSource
#define _stickyKeys_Modifier_KeyBits _reserved->stickyKeys_Modifier_KeyBits
#define _stickyKeys_StuckModifiers _reserved->stickyKeys_StuckModifiers
#define _stickyKeysMouseClickEventSource _reserved->stickyKeysMouseClickEventSource
#define _slowKeys_State _reserved->slowKeys_State
#define _slowKeys_Delay_MS _reserved->slowKeys_Delay_MS
#define _slowKeysTimerEventSource _reserved->slowKeysTimerEventSource
#define _slowKeys_Aborted_Key _reserved->slowKeys_Aborted_Key
#define _slowKeys_Current_Key _reserved->slowKeys_Current_Key
#define _slowKeys_Current_KeyBits _reserved->slowKeys_Current_KeyBits
#define _hidKeyboardNub _reserved->hidKeyboardNub
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 makeParamProperty( OSDictionary * dict, const char * key,
const void * bytes, unsigned int length );
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);
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);
bool stickyKeysModifierToggleCheck(
StickyKeys_ToggleInfo * toggleInfo,
UInt8 key,
bool keyDown,
kbdBitVector keyBits);
void stickyKeysNonModifierKey (UInt8 key, bool keyDown, kbdBitVector keyBits, bool mouseClick = false);
void stickyKeysModifierKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
bool stickyKeysFilterKey (UInt8 key, bool keyDown, kbdBitVector keyBits);
static void stickyKeysMouseDown(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