-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeymap.h
387 lines (312 loc) · 7.87 KB
/
keymap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// keymap.h
#ifndef _KEYMAP_H
# define _KEYMAP_H
# include "keyboard.h"
# include "function.h"
# include <vector>
///
class Action
{
public:
///
enum Type {
Type_key, ///
Type_keySeq, ///
Type_function, ///
};
private:
Action(const Action &i_action);
public:
Action() { }
///
virtual ~Action() { }
///
virtual Type getType() const = 0;
/// create clone
virtual Action *clone() const = 0;
/// stream output
virtual tostream &output(tostream &i_ost) const = 0;
};
///
tostream &operator<<(tostream &i_ost, const Action &i_action);
///
class ActionKey : public Action
{
public:
///
const ModifiedKey m_modifiedKey;
private:
ActionKey(const ActionKey &i_actionKey);
public:
///
ActionKey(const ModifiedKey &i_mk);
///
virtual Type getType() const;
/// create clone
virtual Action *clone() const;
/// stream output
virtual tostream &output(tostream &i_ost) const;
};
class KeySeq;
///
class ActionKeySeq : public Action
{
public:
KeySeq * const m_keySeq; ///
private:
ActionKeySeq(const ActionKeySeq &i_actionKeySeq);
public:
///
ActionKeySeq(KeySeq *i_keySeq);
///
virtual Type getType() const;
/// create clone
virtual Action *clone() const;
/// stream output
virtual tostream &output(tostream &i_ost) const;
};
///
class ActionFunction : public Action
{
public:
FunctionData * const m_functionData; /// function data
const Modifier m_modifier; /// modifier for &Sync
private:
ActionFunction(const ActionFunction &i_actionFunction);
public:
///
ActionFunction(FunctionData *i_functionData,
Modifier i_modifier = Modifier());
///
virtual ~ActionFunction();
///
virtual Type getType() const;
/// create clone
virtual Action *clone() const;
/// stream output
virtual tostream &output(tostream &i_ost) const;
};
///
class KeySeq
{
public:
typedef std::vector<Action *> Actions; ///
private:
Actions m_actions; ///
tstringi m_name; ///
Modifier::Type m_mode; /** Either Modifier::Type_KEYSEQ
or Modifier::Type_ASSIGN */
private:
///
void copy();
///
void clear();
public:
///
KeySeq(const tstringi &i_name);
///
KeySeq(const KeySeq &i_ks);
///
~KeySeq();
///
const Actions &getActions() const {
return m_actions;
}
///
KeySeq &operator=(const KeySeq &i_ks);
/// add
KeySeq &add(const Action &i_action);
/// get the first modified key of this key sequence
ModifiedKey getFirstModifiedKey() const;
///
const tstringi &getName() const {
return m_name;
}
/// stream output
friend tostream &operator<<(tostream &i_ost, const KeySeq &i_ks);
///
bool isCorrectMode(Modifier::Type i_mode) {
return m_mode <= i_mode;
}
///
void setMode(Modifier::Type i_mode) {
if (m_mode < i_mode)
m_mode = i_mode;
ASSERT( m_mode == Modifier::Type_KEYSEQ ||
m_mode == Modifier::Type_ASSIGN);
}
///
Modifier::Type getMode() const {
return m_mode;
}
};
///
class Keymap
{
public:
///
enum Type {
Type_keymap, /// this is keymap
Type_windowAnd, /// this is window &&
Type_windowOr, /// this is window ||
};
///
enum AssignOperator {
AO_new, /// =
AO_add, /// +=
AO_sub, /// -=
AO_overwrite, /// !, !!
};
///
enum AssignMode {
AM_notModifier, /// not modifier
AM_normal, /// normal modifier
AM_true, /** ! true modifier(doesn't
generate scan code) */
AM_oneShot, /// !! one shot modifier
AM_oneShotRepeatable, /// !!! one shot modifier
};
/// key assignment
class KeyAssignment
{
public:
ModifiedKey m_modifiedKey; ///
KeySeq *m_keySeq; ///
public:
///
KeyAssignment(const ModifiedKey &i_modifiedKey, KeySeq *i_keySeq)
: m_modifiedKey(i_modifiedKey), m_keySeq(i_keySeq) { }
///
KeyAssignment(const KeyAssignment &i_o)
: m_modifiedKey(i_o.m_modifiedKey), m_keySeq(i_o.m_keySeq) { }
///
bool operator<(const KeyAssignment &i_o) const {
return m_modifiedKey < i_o.m_modifiedKey;
}
};
/// modifier assignments
class ModAssignment
{
public:
AssignOperator m_assignOperator; ///
AssignMode m_assignMode; ///
Key *m_key; ///
};
typedef std::list<ModAssignment> ModAssignments; ///
/// parameter for describe();
class DescribeParam
{
private:
typedef std::list<ModifiedKey> DescribedKeys;
typedef std::list<const Keymap *> DescribedKeymap;
friend class Keymap;
private:
DescribedKeys m_dk;
DescribedKeymap m_dkeymap;
bool m_doesDescribeModifiers;
public:
DescribeParam() : m_doesDescribeModifiers(true) { }
};
private:
/// key assignments (hashed by first scan code)
typedef std::list<KeyAssignment> KeyAssignments;
enum {
HASHED_KEY_ASSIGNMENT_SIZE = 32, ///
};
private:
KeyAssignments m_hashedKeyAssignments[HASHED_KEY_ASSIGNMENT_SIZE]; ///
/// modifier assignments
ModAssignments m_modAssignments[Modifier::Type_ASSIGN];
Type m_type; /// type
tstringi m_name; /// keymap name
tregex m_windowClass; /// window class name regexp
tregex m_windowTitle; /// window title name regexp
KeySeq *m_defaultKeySeq; /// default keySeq
Keymap *m_parentKeymap; /// parent keymap
private:
///
KeyAssignments &getKeyAssignments(const ModifiedKey &i_mk);
///
const KeyAssignments &getKeyAssignments(const ModifiedKey &i_mk) const;
public:
///
Keymap(Type i_type,
const tstringi &i_name,
const tstringi &i_windowClass,
const tstringi &i_windowTitle,
KeySeq *i_defaultKeySeq,
Keymap *i_parentKeymap);
/// add a key assignment;
void addAssignment(const ModifiedKey &i_mk, KeySeq *i_keySeq);
/// add modifier
void addModifier(Modifier::Type i_mt, AssignOperator i_ao,
AssignMode i_am, Key *i_key);
/// search
const KeyAssignment *searchAssignment(const ModifiedKey &i_mk) const;
/// get
const KeySeq *getDefaultKeySeq() const {
return m_defaultKeySeq;
}
///
Keymap *getParentKeymap() const {
return m_parentKeymap;
}
///
const tstringi &getName() const {
return m_name;
}
/// does same window
bool doesSameWindow(const tstringi i_className,
const tstringi &i_titleName);
/// adjust modifier
void adjustModifier(Keyboard &i_keyboard);
/// get modAssignments
const ModAssignments &getModAssignments(Modifier::Type i_mt) const {
return m_modAssignments[i_mt];
}
/// describe
void describe(tostream &i_ost, DescribeParam *i_dp) const;
/// set default keySeq and parent keymap if default keySeq has not been set
bool setIfNotYet(KeySeq *i_keySeq, Keymap *i_parentKeymap);
};
/// stream output
extern tostream &operator<<(tostream &i_ost, const Keymap *i_keymap);
///
class Keymaps
{
public:
typedef std::list<Keymap *> KeymapPtrList; ///
private:
typedef std::list<Keymap> KeymapList; ///
private:
KeymapList m_keymapList; /** pointer into keymaps may
exist */
public:
///
Keymaps();
/// search by name
Keymap *searchByName(const tstringi &i_name);
/// search window
void searchWindow(KeymapPtrList *o_keymapPtrList,
const tstringi &i_className,
const tstringi &i_titleName);
/// add keymap
Keymap *add(const Keymap &i_keymap);
/// adjust modifier
void adjustModifier(Keyboard &i_keyboard);
};
///
class KeySeqs
{
private:
typedef std::list<KeySeq> KeySeqList; ///
private:
KeySeqList m_keySeqList; ///
public:
/// add a named keyseq (name can be empty)
KeySeq *add(const KeySeq &i_keySeq);
/// search by name
KeySeq *searchByName(const tstringi &i_name);
};
#endif // !_KEYMAP_H