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
|
// Copyright 2022 Artjoms Rizihs (@artjomsR)
// SPDX-License-Identifier: GPL-2.0-or-later
#include "art.h"
#include "string_funcs.h"
#include "string.h"
bool mac_ctrl_on;
int char_to_bspace;
int char_to_del;
enum combo_events {
HOMEROW_UP,
HOMEROW_LEFT,
HOMEROW_RIGHT,
HOMEROW_DOWN,
HOMEROW_PREV_WORD,
HOMEROW_NEXT_WORD,
HOMEROW_HOME,
HOMEROW_END,
ED_F1,
ED_F2,
ED_F3,
ED_F4,
ED_F5,
ED_F6,
ED_F7,
ED_F8,
ED_F9,
ED_F10,
ED_F11,
ED_F12,
ED_PSCREEN,
ED_ENTER,
ED_CS_ENTER,
BSPC_LSFT_CLEAR
};
const uint16_t PROGMEM combo_up[] = {KC_W, KC_R, COMBO_END};
const uint16_t PROGMEM combo_left[] = {KC_S, KC_E, COMBO_END};
const uint16_t PROGMEM combo_right[] = {KC_F, KC_E, COMBO_END};
const uint16_t PROGMEM combo_down[] = {KC_S, KC_F, COMBO_END};
const uint16_t PROGMEM combo_prev_word[] = {KC_S, KC_LCTL, COMBO_END};
const uint16_t PROGMEM combo_next_word[] = {KC_F, KC_LCTL, COMBO_END};
const uint16_t PROGMEM combo_end[] = {KC_W, KC_E, COMBO_END};
const uint16_t PROGMEM combo_home[] = {KC_E, KC_R, COMBO_END};
const uint16_t PROGMEM combo_enter[] = {KC_BSPC, KC_INS, COMBO_END};
const uint16_t PROGMEM combo_f1[] = {KC_1, KC_Q, COMBO_END};
const uint16_t PROGMEM combo_f2[] = {KC_2, KC_W, COMBO_END};
const uint16_t PROGMEM combo_f3[] = {KC_3, KC_E, COMBO_END};
const uint16_t PROGMEM combo_f4[] = {KC_4, KC_R, COMBO_END};
const uint16_t PROGMEM combo_f5[] = {KC_5, KC_T, COMBO_END};
const uint16_t PROGMEM combo_f6[] = {KC_6, KC_Y, COMBO_END};
const uint16_t PROGMEM combo_f7[] = {KC_7, KC_U, COMBO_END};
const uint16_t PROGMEM combo_f8[] = {KC_8, KC_I, COMBO_END};
const uint16_t PROGMEM combo_f9[] = {KC_9, KC_O, COMBO_END};
const uint16_t PROGMEM combo_f10[] = {KC_0, KC_P, COMBO_END};
const uint16_t PROGMEM combo_f11[] = {LT(GIT,KC_SLSH), KC_RSFT, COMBO_END};
const uint16_t PROGMEM combo_f12[] = {KC_RALT, KC_RCTL, COMBO_END};
const uint16_t PROGMEM combo_pscreen[] = {TO(WORKMAN), KC_RALT, COMBO_END};
const uint16_t PROGMEM done_sm[] = {KC_LEFT, KC_RIGHT, COMBO_END};
const uint16_t PROGMEM clear_line_combo[] = {KC_BSPC, KC_LSFT, COMBO_END};
combo_t key_combos[] = {
[HOMEROW_UP] = COMBO(combo_up, KC_UP),
[HOMEROW_LEFT] = COMBO(combo_left, KC_LEFT),
[HOMEROW_RIGHT] = COMBO(combo_right, KC_RIGHT),
[HOMEROW_DOWN] = COMBO(combo_down, KC_DOWN),
[HOMEROW_PREV_WORD] = COMBO_ACTION(combo_prev_word),
[HOMEROW_NEXT_WORD] = COMBO_ACTION(combo_next_word),
[HOMEROW_HOME] = COMBO(combo_end, KC_HOME),
[HOMEROW_END] = COMBO(combo_home, KC_END),
#if defined(KEYBOARD_ktec_ergodone)
[ED_ENTER] = COMBO(combo_enter, KC_ENTER),
[ED_F1] = COMBO(combo_f1, KC_F1),
[ED_F2] = COMBO(combo_f2, KC_F2),
[ED_F3] = COMBO(combo_f3, KC_F3),
[ED_F4] = COMBO(combo_f4, KC_F4),
[ED_F5] = COMBO(combo_f5, KC_F5),
[ED_F6] = COMBO(combo_f6, KC_F6),
[ED_F7] = COMBO(combo_f7, KC_F7),
[ED_F8] = COMBO(combo_f8, KC_F8),
[ED_F9] = COMBO(combo_f9, KC_F9),
[ED_F10] = COMBO(combo_f10, KC_F10),
[ED_F11] = COMBO(combo_f11, KC_F11),
[ED_F12] = COMBO(combo_f12, KC_F12),
[ED_PSCREEN] = COMBO(combo_pscreen, KC_PRINT_SCREEN),
[ED_CS_ENTER] = COMBO_ACTION(done_sm),
#endif
[BSPC_LSFT_CLEAR] = COMBO_ACTION(clear_line_combo),
};
void process_combo_event(uint16_t combo_index, bool pressed) {
switch(combo_index) {
case HOMEROW_PREV_WORD:
if (pressed) {
if (is_win) {
tap_code16(C(KC_LEFT));
} else {
tap_code16(A(KC_LEFT));
}
}
break;
case HOMEROW_NEXT_WORD:
if (pressed) {
if (is_win) {
tap_code16(C(KC_RIGHT));
} else {
tap_code16(A(KC_RIGHT));
}
}
break;
case BSPC_LSFT_CLEAR:
if (pressed) {
tap_code16(KC_END);
tap_code16(S(KC_HOME));
tap_code16(KC_BSPC);
}
break;
case ED_CS_ENTER:
if (pressed) {
tap_code16(C(S(KC_ENTER)));
}
break;
}
}
bool combo_should_trigger(uint16_t combo_index, combo_t *combo, uint16_t keycode, keyrecord_t *record) {
return !layer_state_is(BASE);
}
bool is_mac_with_base_layer_off(void) {
return !is_win && !layer_state_is(BASE);
}
void switch_lang(void) {
if (is_win) {
SEND_STRING(SS_LALT(SS_TAP(X_LSFT)));
} else {
send_string(lang_switch_combo);
wait_ms(10);
}
}
void press_n_times(int times, uint16_t key) {
for (int i=0; i<times; i++) {
// wait_ms(TYPING_INTERVAL);
tap_code16(key);
}
}
bool handle_del_bspace(void) {
if (char_to_bspace > 1 || char_to_del > 0) {
layer_off(GIT_C);
layer_off(GIT_R);
layer_off(GIT_S);
press_n_times(char_to_bspace, KC_BACKSPACE);
char_to_bspace = 1;
press_n_times(char_to_del, KC_DEL);
char_to_del = 0;
return false;
}
if (is_mac_with_base_layer_off()) {
uint8_t mod_state = get_mods() & MOD_MASK_CTRL;
if (get_mods() & mod_state) {
del_mods(mod_state);
add_mods(MOD_LALT);
mac_ctrl_on = true;
}
}
return true;
}
void send_string_with_translation(char *string) {
#if WORKMAN_TO_QWERTY_HW_MAPPING
if (layer_state_is(WORKMAN)) {
int isUpperCase = 0;
for (int i = 0; i < strlen(string); i++) {
char toPrint = string[i];
if (isupper(toPrint)) {
if (toPrint == 'P') {
SEND_STRING(":");
continue;
}
isUpperCase = 1;
toPrint = tolower(toPrint);
}
switch (toPrint) {
case ':':
toPrint = 'I';
break;
case 'w':
toPrint = 'd';
break;
case 'e':
toPrint = 'r';
break;
case 'r':
toPrint = 'w';
break;
case 't':
toPrint = 'b';
break;
case 'y':
toPrint = 'j';
break;
case 'u':
toPrint = 'f';
break;
case 'i':
toPrint = 'u';
break;
case 'o':
toPrint = 'p';
break;
case 'p':
toPrint = ';';
break;
case 'd':
toPrint = 'h';
break;
case 'f':
toPrint = 't';
break;
case 'h':
toPrint = 'y';
break;
case 'j':
toPrint = 'n';
break;
case 'k':
toPrint = 'e';
break;
case 'l':
toPrint = 'o';
break;
case ';':
toPrint = 'i';
break;
case 'b':
toPrint = 'm';
break;
case 'n':
toPrint = 'k';
break;
case 'm':
toPrint = 'l';
break;
}
if (isUpperCase) {
isUpperCase = 0;
toPrint = toupper(toPrint);
}
send_char(toPrint);
}
} else {
send_string(string);
}
#else
send_string(string);
#endif
}
void send_string_remembering_length(char *string) {
send_string_with_translation(string);
char_to_bspace = strlen(string);
}
void send_shifted_strings(char *string1, char *string2) {
if (get_mods() & MOD_MASK_SHIFT) {
clear_mods();
send_string_remembering_length(string2);
} else {
send_string_remembering_length(string1);
}
}
void send_shifted_strings_add(char *string1, char *string2) {
bool shifted = get_mods() & MOD_MASK_SHIFT;
clear_mods();
send_string_remembering_length(string1);
if (shifted) {
send_string(string2);
char_to_bspace = strlen(string1) + strlen(string2);
}
}
|