-
Notifications
You must be signed in to change notification settings - Fork 0
/
hrm.h
77 lines (62 loc) · 2.45 KB
/
hrm.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
#pragma once
#include "caps_word.h"
#include "keycode.h"
#include "quantum.h"
#include "timer.h"
#include "layout.h"
#ifndef HRM_IDLE_DELAY
#define HRM_IDLE_DELAY (150)
#endif
#ifndef HRM_USE_INNER
#define HM_EACH() \
HM_ITER(HM_A) \
HM_ITER(HM_R) \
HM_ITER(HM_S) \
HM_ITER(HM_T) \
HM_ITER(HM_N) \
HM_ITER(HM_E) \
HM_ITER(HM_I) \
HM_ITER(HM_O)
#else
#define HM_EACH() \
HM_ITER(HM_R) \
HM_ITER(HM_S) \
HM_ITER(HM_T) \
HM_ITER(HM_G) \
HM_ITER(HM_M) \
HM_ITER(HM_N) \
HM_ITER(HM_E) \
HM_ITER(HM_I)
#endif
static uint32_t idle_timer;
// Alias to get tap code of HRM keycode
#define HRM_TAP_CODE(kc) (QK_MOD_TAP_GET_TAP_KEYCODE(kc))
bool process_hrm(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
#define HM_ITER(x) case x:
HM_EACH()
#undef HM_ITER
if (record->event.pressed) {
if (timer_elapsed32(idle_timer) < HRM_IDLE_DELAY) {
if (is_caps_word_on()) {
add_weak_mods(MOD_BIT(KC_LSFT));
}
tap_code(HRM_TAP_CODE(keycode));
return false;
}
}
else if ((get_mods() & MOD_BIT(keycode)) == 0) {
idle_timer = timer_read32();
}
break;
// Specifically because I do Escape -> another key very quickly.
case KC_ESCAPE:
if (!record->event.pressed)
idle_timer = timer_read32() - HRM_IDLE_DELAY;
default:
if (!record->event.pressed)
idle_timer = timer_read32();
}
return true;
}
#define IS_IDLE (timer_elapsed32(idle_timer) >= HRM_IDLE_DELAY)