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 
32 {
33  public:
35  KeymapManager();
36 
38  virtual ~KeymapManager();
39 
42  {
43  return m_Instance;
44  }
45 
47  void useKeymap(uint8_t *pSparseTable, uint8_t *pDataTable);
48 
50  bool useCompiledKeymap(uint32_t *pCompiledKeymap, size_t keymapLength);
51 
54  bool handleHidModifier(uint8_t keyCode, bool bDown);
55 
59  uint64_t resolveHidKeycode(uint8_t keyCode);
60 
61  enum EscapeState
62  {
63  EscapeNone = 0,
64  EscapeE0,
65  EscapeE1,
66  };
67 
69  uint8_t
70  convertPc102ScancodeToHidKeycode(uint8_t scancode, EscapeState &escape);
71 
73  struct KeymapEntry
74  {
75  enum Flags
76  {
77  Special = 0x80000000
78  };
79  uint32_t flags;
80  uint32_t value;
81  };
82 
84  KeymapEntry *getKeymapEntry(
85  bool bCtrl, bool bShift, bool bAlt, bool bAltGr, uint8_t nCombinator,
86  uint8_t keyCode);
87 
88  private:
89  enum IndexModifiers
90  {
91  IndexCtrl = 1,
92  IndexShift = 2,
93  IndexAlt = 4,
94  IndexAltGr = 8
95  };
96 
99  {
100  HidCapsLock = 0x39,
101  HidLeftCtrl = 0xE0,
102  HidLeftShift = 0xE1,
103  HidLeftAlt = 0xE2,
104  HidLeftGui = 0xE3,
105  HidRightCtrl = 0xE4,
106  HidRightShift = 0xE5,
107  HidRightAlt = 0xE6,
108  HidRightGui = 0xE7,
109  };
110 
112  struct SparseEntry
113  {
114  enum Flags
115  {
116  DataFlag = 0x8000
117  };
118  uint16_t left;
119  uint16_t right;
120  };
121 
124 
127  KeymapEntry *m_pDataTable;
128 
131  bool m_bLeftShift;
132  bool m_bLeftAlt;
133  bool m_bRightCtrl;
134  bool m_bRightShift;
135  bool m_bRightAlt;
136 
139 
141  uint8_t m_nCombinator;
142 
145  struct KeyState
146  {
148  uint64_t key;
149 
151  uint64_t nLeftTicks;
152  };
153 
156 
162 
166 };
167 
168 #endif
Spinlock m_KeyLock
uint64_t key
The resolved key.
static KeymapManager & instance()
Singleton design.
Definition: KeymapManager.h:41
bool m_bCapsLock
True if caps lock is on.
static KeymapManager m_Instance
Static instance.
uint8_t m_nCombinator
Index of the current active combinator, if any.
uint64_t nLeftTicks
The time left until the next key repeat.
A key/value dictionary.
Definition: Tree.h:33
Structure representing an entry in the sparse table.
bool m_bHaveLoadedKeymap
SparseEntry * m_pSparseTable
The sparse and data tables for the current keymap.
HidModifiers
HID keycodes corresponding to modifiers.
Definition: KeymapManager.h:98
bool m_bLeftCtrl
State of the modifiers, true if down, false if up.
Tree< uint8_t, KeyState * > m_KeyStates
Current key states (for periodic callbacks while a key is down)
Structure representing an entry in the keymap table.
Definition: KeymapManager.h:73