The Pedigree Project 0.1
KeymapManager.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef MACHINE_KEYMAP_MANAGER_H
21#define MACHINE_KEYMAP_MANAGER_H
22
23#include "pedigree/kernel/Spinlock.h"
24#include "pedigree/kernel/compiler.h"
25#include "pedigree/kernel/processor/types.h"
26#include "pedigree/kernel/utilities/Tree.h"
27
31class EXPORTED_PUBLIC KeymapManager {
32 public:
35
37 virtual ~KeymapManager();
38
41 return m_Instance;
42 }
43
45 void useKeymap(uint8_t* pSparseTable, uint8_t* pDataTable);
46
48 bool useCompiledKeymap(uint32_t* pCompiledKeymap, size_t keymapLength);
49
52 bool handleHidModifier(uint8_t keyCode, bool bDown);
53
57 uint64_t resolveHidKeycode(uint8_t keyCode);
58
59 enum EscapeState {
60 EscapeNone = 0,
61 EscapeE0,
62 EscapeE1,
63 };
64
66 uint8_t convertPc102ScancodeToHidKeycode(uint8_t scancode, EscapeState& escape);
67
69 struct KeymapEntry {
70 enum Flags { Special = 0x80000000 };
71 uint32_t flags;
72 uint32_t value;
73 };
74
76 KeymapEntry* getKeymapEntry(bool bCtrl, bool bShift, bool bAlt, bool bAltGr, uint8_t nCombinator,
77 uint8_t keyCode);
78
79 private:
80 enum IndexModifiers { IndexCtrl = 1, IndexShift = 2, IndexAlt = 4, IndexAltGr = 8 };
81
84 HidCapsLock = 0x39,
85 HidLeftCtrl = 0xE0,
86 HidLeftShift = 0xE1,
87 HidLeftAlt = 0xE2,
88 HidLeftGui = 0xE3,
89 HidRightCtrl = 0xE4,
90 HidRightShift = 0xE5,
91 HidRightAlt = 0xE6,
92 HidRightGui = 0xE7,
93 };
94
96 struct SparseEntry {
97 enum Flags { DataFlag = 0x8000 };
98 uint16_t left;
99 uint16_t right;
100 };
101
104
107 KeymapEntry* m_pDataTable;
108
111 bool m_bLeftShift;
112 bool m_bLeftAlt;
113 bool m_bRightCtrl;
114 bool m_bRightShift;
115 bool m_bRightAlt;
116
119
122
125 struct KeyState {
127 uint64_t key;
128
130 uint64_t nLeftTicks;
131 };
132
135
141
145};
146
147#endif
static KeymapManager m_Instance
Static instance.
static KeymapManager & instance()
Singleton design.
Spinlock m_KeyLock
bool m_bLeftCtrl
State of the modifiers, true if down, false if up.
HidModifiers
HID keycodes corresponding to modifiers.
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)
SparseEntry * m_pSparseTable
The sparse and data tables for the current keymap.
bool m_bCapsLock
True if caps lock is on.
A key/value dictionary.
Definition Tree.h:33
uint64_t key
The resolved key.
uint64_t nLeftTicks
The time left until the next key repeat.
Structure representing an entry in the keymap table.
Structure representing an entry in the sparse table.