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
|
#include "eeprom.h"
#include "edvorakjp.h"
bool japanese_mode;
uint16_t time_on_pressed;
edvorakjp_config_t edvorakjp_config;
uint8_t eeconfig_read_edvorakjp(void) {
return eeprom_read_byte(EECONFIG_EDVORAK);
}
void eeconfig_update_edvorakjp(uint8_t val) {
eeprom_update_byte(EECONFIG_EDVORAK, val);
}
void dvorakj_layer_off(void) {
layer_off(_EDVORAKJ1);
layer_off(_EDVORAKJ2);
}
void update_japanese_mode(bool new_state) {
japanese_mode = new_state;
if (japanese_mode) {
if (edvorakjp_config.enable_kc_lang) {
SEND_STRING(SS_TAP(X_LANG1));
} else {
SEND_STRING(SS_LALT("`"));
}
} else {
dvorakj_layer_off();
if (edvorakjp_config.enable_kc_lang) {
SEND_STRING(SS_TAP(X_LANG2));
} else {
SEND_STRING(SS_LALT("`"));
}
}
}
void matrix_init_user(void) {
japanese_mode = false;
time_on_pressed = 0;
edvorakjp_config.raw = eeconfig_read_edvorakjp();
matrix_init_keymap();
}
__attribute__ ((weak))
void matrix_init_keymap() {}
uint32_t layer_state_set_user(uint32_t state) {
state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
return layer_state_set_keymap(state);
}
__attribute__ ((weak))
uint32_t layer_state_set_keymap(uint32_t state) {
return state;
}
/*
* Each process_record_* methods defined here are
* return false if handle edvorak_keycodes, or return true others.
*/
__attribute__ ((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}
bool process_record_edvorakjp_ext(uint16_t keycode, keyrecord_t *record) {
if (!(edvorakjp_config.enable_jp_extra_layer &&\
(default_layer_state == 1UL<<_EDVORAK) &&\
japanese_mode &&\
record->event.pressed)) {
return true;
}
// consonant keys
// layer_on(J1) or layer_on(J2) are defined based on key positions.
switch (keycode) {
// right hand's left side w/o N
case KC_F:
case KC_G:
case KC_R:
case KC_D:
case KC_T:
case KC_B:
case KC_H:
case KC_J:
layer_on(_EDVORAKJ1);
register_code(keycode);
unregister_code(keycode);
return false;
// N: toggle layer
case KC_N:
biton32(layer_state) == _EDVORAK ? layer_on(_EDVORAKJ1) : dvorakj_layer_off();
register_code(keycode);
unregister_code(keycode);
return false;
// left hand and right hand's right side
case KC_X:
case KC_C:
case KC_V:
case KC_Z:
case KC_P:
case KC_Y:
case KC_W:
case KC_Q:
case KC_S:
case KC_M:
case KC_K:
case KC_L:
layer_on(_EDVORAKJ2);
register_code(keycode);
unregister_code(keycode);
return false;
}
// vowel keys, symbol keys and modifier keys
dvorakj_layer_off();
switch (keycode) {
// combination vowel keys
case KC_AI:
SEND_STRING("ai");
return false;
case KC_OU:
SEND_STRING("ou");
return false;
case KC_EI:
SEND_STRING("ei");
return false;
case KC_ANN:
SEND_STRING("ann");
return false;
case KC_ONN:
SEND_STRING("onn");
return false;
case KC_ENN:
SEND_STRING("enn");
return false;
case KC_INN:
SEND_STRING("inn");
return false;
case KC_UNN:
SEND_STRING("unn");
return false;
// AOEIU and other (symbol, modifier) keys
default:
return true;
}
}
bool process_record_edvorakjp_config(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_MAC:
edvorakjp_config.enable_kc_lang = true;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
case KC_WIN:
edvorakjp_config.enable_kc_lang = false;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
case KC_EXTON:
edvorakjp_config.enable_jp_extra_layer = true;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
case KC_EXTOFF:
edvorakjp_config.enable_jp_extra_layer = false;
eeconfig_update_edvorakjp(edvorakjp_config.raw);
return false;
}
return true;
}
bool process_record_layer(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case EDVORAK:
if (record->event.pressed) {
set_single_persistent_default_layer(_EDVORAK);
}
return false;
case QWERTY:
if (record->event.pressed) {
dvorakj_layer_off();
set_single_persistent_default_layer(_QWERTY);
}
return false;
case LOWER:
if (record->event.pressed) {
layer_on(_LOWER);
time_on_pressed = record->event.time;
} else {
layer_off(_LOWER);
if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) {
update_japanese_mode(false);
}
time_on_pressed = 0;
}
return false;
case RAISE:
if (record->event.pressed) {
layer_on(_RAISE);
time_on_pressed = record->event.time;
} else {
layer_off(_RAISE);
if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) {
update_japanese_mode(true);
}
time_on_pressed = 0;
}
return false;
default:
return true;
}
}
bool process_record_ime(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_JPN:
if (record->event.pressed) {
update_japanese_mode(true);
}
return false;
case KC_ENG:
if (record->event.pressed) {
update_japanese_mode(false);
}
return false;
default:
return true;
}
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return process_record_keymap(keycode, record) &&\
process_record_edvorakjp_ext(keycode, record) &&\
process_record_edvorakjp_config(keycode, record) &&\
process_record_layer(keycode, record) &&\
process_record_ime(keycode, record);
}
|