forked from filterpaper/qmk_userspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combos.h
72 lines (59 loc) · 2.11 KB
/
combos.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
// Copyright 2021 @filterpaper
// SPDX-License-Identifier: GPL-2.0+
/* Adapted from Jane Bernhardt's Combos on Steroids (http://combos.gboards.ca/)
This file will build QMK's combo source with preprocessor substitution
using COMBOS_DEF file macros in the following format:
COMB(name, keycode_shortcut, combo_sequence...)
SUBS(name, "string to send", combo_sequence...)
COMB are simple keycode shortcuts. Use two or more combo keys to activate
a keycode, like volume up using Y+U: COMB(KC_VOLU, KC_VOLU, KC_Y, KC_U)
Keycodes can be used as names, they are prefixed to avoid conflict.
SUBS are string substitution combos. It can be used to send strings like
this W+H to send a string: SUBS(which, "which ", KC_W, KC_H)
For custom functions, use COMB with custom keycodes that can be matched
in process_record_user()
Usage: add '#include "combos.h"' to keymap.c / user source, or
'SRC += combos.c' to rules.mk
*/
#define COMBOS_DEF "combos.def"
// Combo code building macros
#define C_ENUM(name, val, ...) cmb_##name,
#define C_DATA(name, val, ...) uint16_t const name##_combo[] PROGMEM = {__VA_ARGS__, COMBO_END};
#define C_TYPE(name, val, ...) [cmb_##name] = COMBO(name##_combo, val),
#define A_TYPE(name, val, ...) [cmb_##name] = COMBO_ACTION(name##_combo),
#define P_SSTR(name, val, ...) case cmb_##name: if (pressed) { SEND_STRING(val); } break;
#define UNUSED(...)
// Enumerate combo list with prefixed names
#undef COMB
#undef SUBS
#define COMB C_ENUM
#define SUBS C_ENUM
enum combos {
#include COMBOS_DEF
COMBO_LENGTH
};
uint16_t COMBO_LEN = COMBO_LENGTH;
// Create combo name array in PROGMEM with key sequences
#undef COMB
#undef SUBS
#define COMB C_DATA
#define SUBS C_DATA
#include COMBOS_DEF
// Fill array with combo type and shortcuts
#undef COMB
#undef SUBS
#define COMB C_TYPE
#define SUBS A_TYPE
combo_t key_combos[] = {
#include COMBOS_DEF
};
// Fill combo event function with send string or function calls
#undef COMB
#undef SUBS
#define COMB UNUSED
#define SUBS P_SSTR
void process_combo_event(uint16_t combo_index, bool pressed) {
switch (combo_index) {
#include COMBOS_DEF
}
}