forked from ratoru/qmk_keymap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.c
162 lines (148 loc) · 4.75 KB
/
source.c
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
#include "source.h"
#include "features/select_word.h"
#include "features/layer_lock.h"
#include "features/swapper.h"
bool sw_tab_active = false;
bool sw_control_tab_active = false;
bool sw_backtick_active = false;
bool process_record_user(uint16_t keycode, keyrecord_t* record) {
if (!process_select_word(keycode, record, SELWORD)) { return false; }
if (!process_layer_lock(keycode, record, LLOCK)) { return false; }
// Adds functionality to switch apps and windows.
update_swapper(
&sw_tab_active, KC_LGUI, KC_TAB, SW_TAB,
keycode, record
);
update_swapper(
&sw_control_tab_active, KC_LCTL, KC_TAB, SW_CTAB,
keycode, record
);
update_swapper(
&sw_backtick_active, KC_LGUI, KC_GRAVE, SW_BTICK,
keycode, record
);
switch (keycode) {
case UPDIR: // Types ../ to go up a directory on the shell.
if (record->event.pressed) {
SEND_STRING("../");
}
return false;
#ifdef RGBLIGHT_ENABLE
case RGBT_NE:
if (record->event.pressed) {
rgblight_toggle_noeeprom();
}
return false;
case RGB_IB_NE:
if (record->event.pressed) {
rgblight_increase_val_noeeprom();
}
return false;
case RGB_DB_NE:
if (record->event.pressed) {
rgblight_decrease_val_noeeprom();
}
return false;
#endif
}
return true;
}
// ---- Home Row Mods "Timeless" Config ----
#if defined (PERMISSIVE_HOLD_PER_KEY) || defined (HOLD_ON_OTHER_KEY_PRESS_PER_KEY) || defined (TAP_INTERVAL_MS)
static uint16_t next_keycode;
static keyrecord_t next_record;
bool pre_process_record_user(uint16_t keycode, keyrecord_t *record) {
// Instant Tap Config
static uint16_t prev_keycode;
if (record->event.pressed) {
// Store the previous keycode for instant tap decision
prev_keycode = next_keycode;
// Cache the next input for mod-tap decisions
next_keycode = keycode;
next_record = *record;
}
// Match home row mod-tap keys when it is not preceded by a Layer key
if (IS_HOMEROW(record) && IS_QK_MOD_TAP(keycode) && !IS_QK_LAYER_TAP(prev_keycode)) {
// Tap the mod-tap key instantly when it follows a short interval
if (record->event.pressed && last_input_activity_elapsed() < TAP_INTERVAL_MS) {
record->keycode = keycode & 0xff;
action_tapping_process(*record);
return false;
} else { // Send the base keycode key up event
keyrecord_t base_record = *record;
base_record.keycode = keycode & 0xff;
base_record.event.pressed = false;
action_tapping_process(base_record);
}
}
return true;
}
#endif
#ifdef PERMISSIVE_HOLD_PER_KEY
bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) {
// Hold Control and Shift with a nested key tap on the opposite hand
return IS_BILATERAL_TAP(record, next_record);
}
#endif
#ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) {
// Replace the mod-tap key with its base keycode when
// tapped with another key on the same hand
if (IS_UNILATERAL_TAP(record, next_record)) {
record->keycode = keycode & 0xff;
process_record(record);
record->event.pressed = false;
process_record(record);
return true;
}
// Hold layer with another key press
else if (IS_QK_LAYER_TAP(keycode) && QK_LAYER_TAP_GET_LAYER(keycode)) {
return true;
}
return false;
}
#endif
#ifdef RGBLIGHT_ENABLE
void keyboard_pre_init_user(void) {
// Set our LED pin as output
setPinOutput(24);
// Turn the LED off
// (Due to technical reasons, high is off and low is on)
writePinHigh(24);
}
void keyboard_post_init_user(void) {
rgblight_enable_noeeprom(); // Enables RGB, without saving settings
rgblight_sethsv_noeeprom(HSV_PINK);
rgblight_mode_noeeprom(1);
}
layer_state_t layer_state_set_user(layer_state_t state) {
switch (get_highest_layer(state)) {
case 1:
rgblight_sethsv_noeeprom (HSV_MAGENTA);
break;
case 2:
rgblight_sethsv_noeeprom (HSV_BLUE);
break;
case 3:
rgblight_sethsv_noeeprom (HSV_GOLD);
break;
case 4:
rgblight_sethsv_noeeprom (HSV_GREEN);
break;
default: // for any other layers, or the default layer
rgblight_sethsv_noeeprom (HSV_PINK);
break;
}
return state;
};
void suspend_power_down_user(void) {
// code will run multiple times while keyboard is suspended
rgblight_disable_noeeprom();
}
void suspend_wakeup_init_user(void) {
// code will run on keyboard wakeup
rgblight_enable_noeeprom();
rgblight_sethsv_noeeprom(HSV_PINK);
rgblight_mode_noeeprom(1);
}
#endif