-
Notifications
You must be signed in to change notification settings - Fork 0
/
my.c
332 lines (313 loc) · 8.73 KB
/
my.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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include "ergodox_ez.h"
#include "util_user.h"
#include "action.h"
// To use japanese input specific keys on Windows,
// OS's layout should be jis layout
// even I prefer us layout for symbol keys.
#include "keymap_jp.h"
#include "my.h"
#ifndef NO_JAPANESE
#include "raw_hid.h"
#include "kana.h"
#include "kana_chord.h"
#include "ime.h"
#endif
#define SFT_LT(kc) LT(L_SHIFT, kc)
#define NUM_SIGN_T(kc) LT(L_NUM_SIGN, kc)
#define FN_T(kc) LT(L_FN, kc)
// click (left, middle, right)
#define KC_LCLK KC_BTN1
#define KC_MCLK KC_BTN3
#define KC_RCLK KC_BTN2
#ifdef ENABLE_STABLE_LAYER
#define STABLE DF(L_STABLE)
#else
#define STABLE CLEAR
#endif
void matrix_scan_user(void) {
#ifndef NO_JAPANESE
// matrix_scan_kana();
#endif
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
keyevent_t event = record->event;
switch(keycode) {
case CLEAR:
if(event.pressed) {
clear_mods();
layer_clear();
#ifndef NO_JAPANESE
reset_ime();
#endif
}
return false;
#ifndef NO_JAPANESE
case RCTL_T(KC_TAB):
case LCTL_T(KC_ESC):
case LALT_T(KC_COMM):
case RALT_T(KC_DOT):
case LGUI_T(KC_SCLN):
case LSFT_T(KC_SPC):
case RSFT_T(KC_SPC):
case NUM_SIGN_T(KC_ENT):
case FN_T(HIRAGANA):
case FN_T(KATAKANA):
case LCTL_T(JP_AT):
case RCTL_T(KC_7):
case LALT_T(JP_COLN):
case RALT_T(KC_8):
case RGUI_T(KC_9):
{
uint16_t keycode_8 = keycode & 0xFF;
// use default process other than KANA layer
if(!is_default_layer_kana()) return true;
// use default process for mod
if(record->tap.count > 0) {
return process_ime(keycode_8, record);
}
return true;
}
#endif
// recover shift that truncated in MOD_T() macro
case RGUI_T(JP_QUOT):
case LGUI_T(JP_GRV):
// use default process for mod
if(record->tap.count > 0) {
uint16_t keycode_8 = keycode & 0xFF;
if(event.pressed) {
if(!is_default_layer_kana()) {
add_mods(MOD_LSFT);
register_code(keycode_8);
}
else {
return process_ime(LSFT(keycode_8), record);
}
}
else {
if(!is_default_layer_kana()) {
unregister_code(keycode_8);
del_mods(MOD_LSFT);
}
else {
return process_ime(LSFT(keycode_8), record);
}
}
return false;
}
return true;
default:
break;
}
#ifndef NO_JAPANESE
if(!process_ime(keycode, record)) return false;
#endif
return true;
}
void led_set_user(uint8_t usb_led) {
ergodox_led_all_set(LED_BRIGHTNESS_LO);
if(biton32(default_layer_state) != L_KANA) {
if(IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) ergodox_right_led_2_on();
else ergodox_right_led_2_off();
}
// if(IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) ergodox_right_led_1_on();
// else ergodox_right_led_1_off();
// if(IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) ergodox_right_led_3_on();
// else ergodox_right_led_3_off();
}
#ifdef ENABLE_STABLE_LAYER
layer_state_t default_layer_state_set_user(layer_state_t state) {
ergodox_led_all_set(LED_BRIGHTNESS_LO);
uint8_t layer = biton32(state);
// if(layer == L_STABLE) ergodox_right_led_1_on();
return state;
}
#endif
#ifndef NO_JAPANESE
void raw_hid_receive(uint8_t *data, uint8_t length) {
uint8_t *command_id = &(data[0]);
switch(*command_id) {
case id_im_off:
on_im_off();
break;
case id_im_on:
on_im_on();
break;
}
}
#endif
#ifndef NO_JAPANESE
void im_state_set_user(uint8_t state) {
ergodox_led_all_set(LED_BRIGHTNESS_LO);
uint8_t layer = biton32(default_layer_state);
if(layer == L_KANA) {
if(is_practice_mode()) {
ergodox_right_led_1_off();
ergodox_right_led_3_on();
}
else {
switch(state) {
case IM_STATE_HIRAGANA_DIRECT:
ergodox_right_led_1_on();
ergodox_right_led_3_on();
break;
case IM_STATE_KATAKANA_DIRECT:
ergodox_right_led_1_on();
ergodox_right_led_2_on();
break;
default:
ergodox_right_led_1_on();
ergodox_right_led_2_off();
ergodox_right_led_3_off();
break;
}
}
}
else {
ergodox_right_led_1_off();
ergodox_right_led_3_off();
}
}
#endif
void suspend_power_down_user(void) {
ergodox_led_all_off();
}
void suspend_wakeup_init_user(void) {
default_layer_state_set_user(default_layer_state);
}
uint16_t additional_kana_chord(uint32_t kana_chord) {
if(kana_chord == BIT_CONSONANT_G) {
return KANA_GA;
}
else if(kana_chord == BIT_CONSONANT_Z) {
return KANA_ZI;
}
else if(kana_chord == BIT_CONSONANT_D) {
return KANA_DA;
}
else if(kana_chord == BIT_CONSONANT_B) {
return KANA_BA;
}
else if(kana_chord == BIT_CONSONANT_DH) {
return KANA_DE;
}
else if(kana_chord == BIT_CONSONANT_X) {
return KANA_DO;
}
return KC_NO;
}
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[L_BASE] = LAYOUT_ergodox(
// left hand
KC_WH_L, KC_WH_R, LGUI_T(KC_SCLN), LALT_T(KC_COMM), LCTL_T(KC_ESC), FN_T(KC_Z), KC_INS,
KC_WH_U, KC_WH_D, KC_K, KC_I, KC_N, KC_F, KC_DEL,
KC_RCLK, KC_LCLK, KC_Y, KC_E, KC_S, KC_M,
KC_F5, KC_MCLK, KC_J, KC_U, KC_H, KC_P, KC_BSPC,
KC_WBAK, KC_WFWD, KC_NO, JP_LPRN, JP_RPRN,
// thumb
KC_NO, KC_NO,
KC_NO,
LSFT_T(KC_SPC), NUM_SIGN_T(KC_ENT), S(KC_CAPS),
// right hand
CLEAR, FN_T(KC_Q), RCTL_T(KC_TAB), RALT_T(KC_DOT), RGUI_T(JP_QUOT), KC_HOME, KC_END,
KC_SLSH, KC_W, KC_R, KC_O, KC_V, KC_LEFT, KC_RGHT,
KC_C, KC_T, KC_A, KC_B, KC_DOWN, KC_UP,
JP_DQT, KC_G, KC_L, KC_D, KC_X, KC_PGDN, KC_PGUP,
JP_MINS, JP_UNDS, KC_NO, KC_NO, CLEAR,
// thumb
KC_NO, KC_NO,
KC_NO,
JP_ZHTG, NUM_SIGN_T(KC_ENT), RSFT_T(KC_SPC)
),
#ifdef ENABLE_STABLE_LAYER
[L_STABLE] = LAYOUT_ergodox(
// left hand
KC_TRNS, FN_T(KC_TRNS), LGUI_T(KC_TRNS), LALT_T(KC_TRNS), LCTL_T(KC_TRNS), KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
LSFT_T(KC_SPC), KC_TRNS, KC_TRNS,
// right hand
KC_TRNS, KC_TRNS, RCTL_T(KC_TRNS), RALT_T(KC_TRNS), RGUI_T(KC_TRNS), FN_T(KC_TRNS), DF(L_BASE),
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
KC_TRNS, KC_TRNS, RSFT_T(KC_SPC)
),
#endif
#ifndef NO_JAPANESE
[L_KANA] = LAYOUT_ergodox(
// left hand
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, FN_T(HIRAGANA), KC_TRNS,
KC_TRNS, KC_TRNS, KANA_TU, VOWEL_I(KANA_I), VOWEL_E(KANA_RU), VOWEL_YE(KANA_MA), KC_TRNS,
KC_TRNS, KC_TRNS, KANA_DE, VOWEL_O(KANA_NO), VOWEL_A(KANA_NN), VOWEL_YA(KANA_KU),
KC_TRNS, KC_TRNS, KANA_ZSLSH, VOWEL_YO(KANA_KO), VOWEL_U(KANA_U), VOWEL_YU(KANA_XTU), KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
KC_TRNS, KC_TRNS, KC_CAPS,
// right hand
KC_TRNS, FN_T(KATAKANA), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, CONSONANT_P(KANA_SU), CONSONANT_T(KANA_TA), CONSONANT_S(KANA_SI), KANA_MO, KC_TRNS, KC_TRNS,
CONSONANT_M(KANA_NI), CONSONANT_R(KANA_TE), CONSONANT_K(KANA_KA), KANA_GA, KC_TRNS, KC_TRNS,
KC_TRNS, CONSONANT_N(KANA_NA), CONSONANT_A(KANA_TO), CONSONANT_H(KANA_HA), KANA_ZDOT, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS
),
#endif
[L_NUM_SIGN] = LAYOUT_ergodox(
// left hand
KC_TRNS, KC_TRNS, LGUI_T(JP_GRV), LALT_T(JP_COLN), LCTL_T(JP_AT), KC_TRNS, KC_NO,
KC_TRNS, KC_TRNS, JP_BSLS, JP_QUES, JP_PLUS, JP_ASTR, KC_TRNS,
KC_TRNS, KC_TRNS, JP_TILD, JP_EXLM, JP_EQL, JP_AMPR,
KC_TRNS, KC_TRNS, JP_CIRC, JP_LT, JP_GT, JP_PIPE, KC_TRNS,
KC_TRNS, KC_TRNS, KC_NO, JP_LCBR, JP_RCBR,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS,
// right hand
KC_TRNS, KC_TRNS, RCTL_T(KC_7), RALT_T(KC_8), RGUI_T(KC_9), KC_TRNS, KC_TRNS,
KC_TRNS, JP_DLR, KC_4, KC_5, KC_6, KC_TRNS, KC_TRNS,
JP_HASH, KC_1, KC_2, KC_3, KC_TRNS, KC_TRNS,
KC_TRNS, JP_PERC, KC_0, KC_COMM, KC_DOT, KC_TRNS, KC_TRNS,
JP_LBRC, JP_RBRC, KC_NO, KC_NO, KC_NO,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
PRACTICE_MODE, KC_TRNS, KC_TRNS
),
[L_FN] = LAYOUT_ergodox(
// left hand
KC_NO, KC_NO, KC_LGUI, KC_LALT, KC_LCTL, KC_TRNS, KC_NO,
KC_NO, KC_SLCK, KC_KANA, KC_MHEN, KC_HENK, KC_NO, KC_TRNS,
KC_APP, KC_NO, KC_NO, KC_NO, KC_PSCR, KC_NO,
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_PAUS, KC_TRNS,
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
KC_LSFT, KC_TRNS, KC_TRNS,
// right hand
KC_TRNS, KC_TRNS, RCTL_T(KC_F7), RALT_T(KC_F8), RGUI_T(KC_F9), KC_MPRV, KC_MNXT,
KC_TRNS, KC_NO, KC_F4, KC_F5, KC_F6, KC_MUTE, KC_MPLY,
KC_NO, KC_F1, KC_F2, KC_F3, KC_VOLD, KC_VOLU,
KC_TRNS, KC_NO, KC_F10, KC_F11, KC_F12, KC_BRID, KC_BRIU,
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
// thumb
KC_TRNS, KC_TRNS,
KC_TRNS,
PRACTICE_MODE, KC_TRNS, KC_TRNS
),
};