The Pedigree Project 0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes | List of all members
KeymapManager Class Reference

#include <KeymapManager.h>

+ Collaboration diagram for KeymapManager:

Classes

struct  KeymapEntry
 Structure representing an entry in the keymap table. More...
 
struct  KeyState
 
struct  SparseEntry
 Structure representing an entry in the sparse table. More...
 

Public Types

enum  EscapeState { EscapeNone = 0 , EscapeE0 , EscapeE1 }
 

Public Member Functions

 KeymapManager ()
 Default constructor.
 
virtual ~KeymapManager ()
 Default destructor.
 
void useKeymap (uint8_t *pSparseTable, uint8_t *pDataTable)
 Changes the current keymap to the given one.
 
bool useCompiledKeymap (uint32_t *pCompiledKeymap, size_t keymapLength)
 Changes the current keymap to the given (compiled) one.
 
bool handleHidModifier (uint8_t keyCode, bool bDown)
 
uint64_t resolveHidKeycode (uint8_t keyCode)
 
uint8_t convertPc102ScancodeToHidKeycode (uint8_t scancode, EscapeState &escape)
 Converts a pc102 scancode into a HID keycode.
 
KeymapEntry * getKeymapEntry (bool bCtrl, bool bShift, bool bAlt, bool bAltGr, uint8_t nCombinator, uint8_t keyCode)
 Returns the keymap entry corresponding to given keycode and modifiers.
 

Static Public Member Functions

static KeymapManager & instance ()
 Singleton design.
 

Private Types

enum  IndexModifiers { IndexCtrl = 1 , IndexShift = 2 , IndexAlt = 4 , IndexAltGr = 8 }
 
enum  HidModifiers {
  HidCapsLock = 0x39 , HidLeftCtrl = 0xE0 , HidLeftShift = 0xE1 , HidLeftAlt = 0xE2 ,
  HidLeftGui = 0xE3 , HidRightCtrl = 0xE4 , HidRightShift = 0xE5 , HidRightAlt = 0xE6 ,
  HidRightGui = 0xE7
}
 HID keycodes corresponding to modifiers. More...
 

Private Attributes

SparseEntry * m_pSparseTable
 The sparse and data tables for the current keymap.
 
KeymapEntry * m_pDataTable
 
bool m_bLeftCtrl
 State of the modifiers, true if down, false if up.
 
bool m_bLeftShift
 
bool m_bLeftAlt
 
bool m_bRightCtrl
 
bool m_bRightShift
 
bool m_bRightAlt
 
bool m_bCapsLock
 True if caps lock is on.
 
uint8_t m_nCombinator
 Index of the current active combinator, if any.
 
Tree< uint8_t, KeyState * > m_KeyStates
 Current key states (for periodic callbacks while a key is down)
 
Spinlock m_KeyLock
 
bool m_bHaveLoadedKeymap
 

Static Private Attributes

static KeymapManager m_Instance
 Static instance.
 

Detailed Description

Global manager for keymaps

Definition at line 31 of file KeymapManager.h.

Member Enumeration Documentation

◆ EscapeState

enum KeymapManager::EscapeState

Definition at line 59 of file KeymapManager.h.

◆ HidModifiers

HID keycodes corresponding to modifiers.

Definition at line 83 of file KeymapManager.h.

◆ IndexModifiers

enum KeymapManager::IndexModifiers
private

Definition at line 80 of file KeymapManager.h.

Constructor & Destructor Documentation

◆ KeymapManager()

KeymapManager::KeymapManager ( )

Default constructor.

Definition at line 41 of file KeymapManager.cc.

References m_pSparseTable.

◆ ~KeymapManager()

KeymapManager::~KeymapManager ( )
virtual

Default destructor.

Definition at line 60 of file KeymapManager.cc.

Member Function Documentation

◆ convertPc102ScancodeToHidKeycode()

uint8_t KeymapManager::convertPc102ScancodeToHidKeycode ( uint8_t  scancode,
EscapeState &  escape 
)

Converts a pc102 scancode into a HID keycode.

Definition at line 317 of file KeymapManager.cc.

Referenced by X86Keyboard::scancodeToAscii().

+ Here is the caller graph for this function:

◆ getKeymapEntry()

KeymapManager::KeymapEntry * KeymapManager::getKeymapEntry ( bool  bCtrl,
bool  bShift,
bool  bAlt,
bool  bAltGr,
uint8_t  nCombinator,
uint8_t  keyCode 
)

Returns the keymap entry corresponding to given keycode and modifiers.

Definition at line 239 of file KeymapManager.cc.

References m_pSparseTable.

Referenced by resolveHidKeycode().

+ Here is the caller graph for this function:

◆ handleHidModifier()

bool KeymapManager::handleHidModifier ( uint8_t  keyCode,
bool  bDown 
)

If the given keycode is a modifier, applies it and returns true, otherwise it returns false.

Definition at line 134 of file KeymapManager.cc.

References m_bCapsLock, and m_bLeftCtrl.

Referenced by HidInputManager::keyDown().

+ Here is the caller graph for this function:

◆ instance()

static KeymapManager & KeymapManager::instance ( )
inlinestatic

Singleton design.

Definition at line 40 of file KeymapManager.h.

Referenced by HidInputManager::keyDown(), HidInputManager::keyUp(), and X86Keyboard::scancodeToAscii().

+ Here is the caller graph for this function:

◆ resolveHidKeycode()

uint64_t KeymapManager::resolveHidKeycode ( uint8_t  keyCode)

Resolves a HID keycode using the current keymap and returns a "real" character in UTF-32 format, plus modifier flags in the top 32-bits.

Definition at line 157 of file KeymapManager.cc.

References getKeymapEntry(), m_bCapsLock, m_bLeftCtrl, and m_nCombinator.

Referenced by HidInputManager::keyDown(), X86Keyboard::scancodeToAscii(), useCompiledKeymap(), and useKeymap().

+ Here is the caller graph for this function:

◆ useCompiledKeymap()

bool KeymapManager::useCompiledKeymap ( uint32_t *  pCompiledKeymap,
size_t  keymapLength 
)

Changes the current keymap to the given (compiled) one.

Definition at line 91 of file KeymapManager.cc.

References HidInputManager::instance(), m_bHaveLoadedKeymap, m_pSparseTable, resolveHidKeycode(), and HidInputManager::updateKeys().

◆ useKeymap()

void KeymapManager::useKeymap ( uint8_t *  pSparseTable,
uint8_t *  pDataTable 
)

Changes the current keymap to the given one.

Definition at line 62 of file KeymapManager.cc.

References HidInputManager::instance(), m_bHaveLoadedKeymap, m_pSparseTable, resolveHidKeycode(), and HidInputManager::updateKeys().

Member Data Documentation

◆ m_bCapsLock

bool KeymapManager::m_bCapsLock
private

True if caps lock is on.

Definition at line 118 of file KeymapManager.h.

Referenced by handleHidModifier(), and resolveHidKeycode().

◆ m_bHaveLoadedKeymap

bool KeymapManager::m_bHaveLoadedKeymap
private

Whether or not we've loaded a new keymap. Used to figure out if we can safely free the old keymap data.

Definition at line 144 of file KeymapManager.h.

Referenced by useCompiledKeymap(), and useKeymap().

◆ m_bLeftAlt

bool KeymapManager::m_bLeftAlt
private

Definition at line 112 of file KeymapManager.h.

◆ m_bLeftCtrl

bool KeymapManager::m_bLeftCtrl
private

State of the modifiers, true if down, false if up.

Definition at line 110 of file KeymapManager.h.

Referenced by handleHidModifier(), and resolveHidKeycode().

◆ m_bLeftShift

bool KeymapManager::m_bLeftShift
private

Definition at line 111 of file KeymapManager.h.

◆ m_bRightAlt

bool KeymapManager::m_bRightAlt
private

Definition at line 115 of file KeymapManager.h.

◆ m_bRightCtrl

bool KeymapManager::m_bRightCtrl
private

Definition at line 113 of file KeymapManager.h.

◆ m_bRightShift

bool KeymapManager::m_bRightShift
private

Definition at line 114 of file KeymapManager.h.

◆ m_Instance

KeymapManager KeymapManager::m_Instance
staticprivate

Static instance.

Definition at line 103 of file KeymapManager.h.

◆ m_KeyLock

Spinlock KeymapManager::m_KeyLock
private

Spinlock for work on keys.

Note
Using a Spinlock here because a lot of our work will happen in the middle of an IRQ where it's potentially dangerous to reschedule (which may happen with a Mutex or Semaphore).

Definition at line 140 of file KeymapManager.h.

◆ m_KeyStates

Tree<uint8_t, KeyState*> KeymapManager::m_KeyStates
private

Current key states (for periodic callbacks while a key is down)

Definition at line 134 of file KeymapManager.h.

◆ m_nCombinator

uint8_t KeymapManager::m_nCombinator
private

Index of the current active combinator, if any.

Definition at line 121 of file KeymapManager.h.

Referenced by resolveHidKeycode().

◆ m_pDataTable

KeymapEntry* KeymapManager::m_pDataTable
private

Definition at line 107 of file KeymapManager.h.

◆ m_pSparseTable

SparseEntry* KeymapManager::m_pSparseTable
private

The sparse and data tables for the current keymap.

Definition at line 106 of file KeymapManager.h.

Referenced by getKeymapEntry(), KeymapManager(), useCompiledKeymap(), and useKeymap().


The documentation for this class was generated from the following files: