-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.h
75 lines (72 loc) · 2.53 KB
/
function.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
#include "action_layer.h"
#include "action_util.h"
#include "action.h"
enum function_id {
F_SWITCH_LAYOUT_QWERTY,
F_SWITCH_LAYOUT_DVORAK,
F_SWITCH_LAYOUT_COLEMAK,
F_SWITCH_LAYOUT_GAMER,
F_CTRL_QWERTY_FALLBACK,
};
uint32_t default_layer_state;
uint32_t qwerty_fallback_previous_state;
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt __attribute__ ((unused))) {
switch (id) {
/**
* TMK's built-in keymap switching is limited to a single default layer.
* These F_SWITCH_LAYOUT_* functions provide more customized keymap
* switching, including functional overlay layers such as SpaceFn and a
* special "gamer" (winkeyless) layer.
*/
case F_SWITCH_LAYOUT_QWERTY:
if (record->event.pressed) {
default_layer_set(1UL<<L_QWERTY);
layer_on(L_FN_SPACEFN);
layer_off(L_OVERLAY_GAMER);
clear_keyboard();
}
break;
case F_SWITCH_LAYOUT_DVORAK:
if (record->event.pressed) {
default_layer_set(1UL<<L_DVORAK);
layer_on(L_FN_SPACEFN);
layer_off(L_OVERLAY_GAMER);
clear_keyboard();
}
break;
case F_SWITCH_LAYOUT_COLEMAK:
if (record->event.pressed) {
default_layer_set(1UL<<L_COLEMAK);
layer_on(L_FN_SPACEFN);
layer_off(L_OVERLAY_GAMER);
clear_keyboard();
}
break;
case F_SWITCH_LAYOUT_GAMER:
if (record->event.pressed) {
default_layer_set(1UL<<L_QWERTY);
layer_off(L_FN_SPACEFN);
layer_on(L_OVERLAY_GAMER);
clear_keyboard();
}
break;
/**
* Temporarily revert the default layer to 0 (QWERTY) when the trigger
* key is pressed, then restore the previous default layer upon release.
*
* Useful for Dvorak users who want to be able to use Ctrl+C, Ctrl+V,
* etc. in the standard layout.
*/
case F_CTRL_QWERTY_FALLBACK:
if (record->event.pressed) {
qwerty_fallback_previous_state = default_layer_state;
default_layer_set(1UL<<L_QWERTY);
add_mods(MOD_LCTL);
} else {
default_layer_set(qwerty_fallback_previous_state);
del_mods(MOD_LCTL);
clear_keyboard();
}
break;
}
};