aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDidier Loiseau <didierloiseau+git@gmail.com>2016-02-26 00:53:30 +0100
committerDidier Loiseau <didierloiseau+git@gmail.com>2016-04-02 18:16:31 +0200
commitfbf1333d87aa4487692f068881ab1ce46fa79be5 (patch)
tree75045219590cddf0451ab7b54d78ef0f6d25d686
parent7840e69bfaee1d67de273c235b532d6f20c905a9 (diff)
downloadqmk_firmware-fbf1333d87aa4487692f068881ab1ce46fa79be5.tar.gz
qmk_firmware-fbf1333d87aa4487692f068881ab1ce46fa79be5.zip
BÉPO over CSA: unicode support
- implement easy way to define and send unicode characters on Windows - define 3 characters not available in CSA: - en dash: – - em dash: — - ellipsis: …
-rw-r--r--keyboard/ergodox_ez/keymaps/bepo/keymap.c59
1 files changed, 54 insertions, 5 deletions
diff --git a/keyboard/ergodox_ez/keymaps/bepo/keymap.c b/keyboard/ergodox_ez/keymaps/bepo/keymap.c
index 64fac7f9b..b08b47217 100644
--- a/keyboard/ergodox_ez/keymaps/bepo/keymap.c
+++ b/keyboard/ergodox_ez/keymaps/bepo/keymap.c
@@ -19,6 +19,13 @@ enum layers {
19#define IS_CA_MULT_ENABLED() (default_layer_state & (1 << LR_CSA)) 19#define IS_CA_MULT_ENABLED() (default_layer_state & (1 << LR_CSA))
20 20
21enum macros { 21enum macros {
22 // Characters that do not exist in CSA and must be implemented based on unicode support
23 // Note: these are intentionally declared first to be used as indexes in spec_chars below
24 UC_NDSH, // –
25 UC_MDSH, // —
26 UC_ELPS, // …
27 END_UC, // indicates the last unicode character macro
28 // other macros
22 M_TGCM, // toggle CA-mult 29 M_TGCM, // toggle CA-mult
23 M_CMSFT, // toggle shift on CA-mult 30 M_CMSFT, // toggle shift on CA-mult
24 // macros for characters that need to be un-shifted in LR_CA_MULT_SHIFT 31 // macros for characters that need to be un-shifted in LR_CA_MULT_SHIFT
@@ -43,6 +50,15 @@ enum macros {
43 M_FNLR, 50 M_FNLR,
44}; 51};
45 52
53const uint16_t unicode_chars[] = {
54 [UC_NDSH] = L'–',
55 [UC_MDSH] = L'—',
56 [UC_ELPS] = L'…',
57};
58
59/* shortcut for unicod character macros */
60#define MUC(name) M(UC_##name)
61
46const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 62const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
47/* Basic layer 63/* Basic layer
48 * 64 *
@@ -164,13 +180,13 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
164 * "////" indicates that the key is disabled (unsupported bépo character) 180 * "////" indicates that the key is disabled (unsupported bépo character)
165 * 181 *
166 * ,--------------------------------------------------. ,--------------------------------------------------. 182 * ,--------------------------------------------------. ,--------------------------------------------------.
167 * | ////// | //// | < | > | [ | ] | | | | ^ | //// | //// | //// | //// | ////// | 183 * | | | < | > | [ | ] | | | | ^ | //// | //// | //// | //// | ////// |
168 * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------| 184 * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
169 * | | | |dead '| & | œ |dead `| | | | //// | //// | //// | //// | //// | ////// | 185 * | | | |dead '| & | œ |dead `| | | | //// | //// | //// | //// | //// | ////// |
170 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| 186 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
171 * | ////// | æ | ù |dead "| € | //// |------| |------| //// | //// | //// | //// | //// | ////// | 187 * | ////// | æ | ù |dead "| € | //// |------| |------| //// | //// | //// | //// | //// | ////// |
172 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| 188 * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
173 * | | \ | { | } | //// | ~ | | | | //// | //// | //// | //// | //// | | 189 * | | \ | { | } | | ~ | | | | //// | //// | //// | //// | //// | |
174 * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------' 190 * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
175 * | | | | | | | | //// | | //// | | 191 * | | | | | | | | //// | | //// | |
176 * `----------------------------------' `-----------------------------------' 192 * `----------------------------------' `-----------------------------------'
@@ -184,10 +200,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
184 */ 200 */
185[LR_CSA_AGR] = KEYMAP( 201[LR_CSA_AGR] = KEYMAP(
186 // left hand 202 // left hand
187 KC_NO, KC_NO, CM_LESS, CM_GRTR, CM_LBRC, CM_RBRC, KC_TRNS, 203 MUC(NDSH),MUC(MDSH),CM_LESS, CM_GRTR, CM_LBRC, CM_RBRC, KC_TRNS,
188 KC_TRNS, CM_PIPE, CM_DACT, KC_AMPR, CM_OE, CM_DGRV, KC_TRNS, 204 KC_TRNS, CM_PIPE, CM_DACT, KC_AMPR, CM_OE, CM_DGRV, KC_TRNS,
189 KC_NO, CM_AE, CM_UGRV, CM_DTRM, CM_EURO, KC_NO, 205 KC_NO, CM_AE, CM_UGRV, CM_DTRM, CM_EURO, KC_NO,
190 KC_TRNS, CM_BSLS, CM_LCBR, CM_RCBR, KC_NO, CM_TILD, KC_TRNS, 206 KC_TRNS, CM_BSLS, CM_LCBR, CM_RCBR, MUC(ELPS),CM_TILD, KC_TRNS,
191 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, 207 KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
192 208
193 KC_TRNS, KC_TRNS, 209 KC_TRNS, KC_TRNS,
@@ -305,10 +321,43 @@ void release_shift(void) {
305 unregister_code(KC_LSHIFT); 321 unregister_code(KC_LSHIFT);
306} 322}
307 323
324uint16_t hextokeycode(int hex) {
325 if (hex == 0x0) {
326 return KC_P0;
327 } else if (hex < 0xA) {
328 return KC_P1 + (hex - 0x1);
329 } else {
330 return KC_A + (hex - 0xA);
331 }
332}
333
334void send_unicode(uint16_t unicode)
335{
336 // For more info on how this works per OS, see here: https://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input
337 // Implemented for Windows:
338 // Pressing ALT followed by + followed by the unicode code point in hex.
339 // Requires registry key HKEY_CURRENT_USER\Control Panel\Input Method\EnableHexNumpad set to String 1
340 register_code(KC_LALT);
341 register_code(KC_PPLS);
342 unregister_code(KC_PPLS);
343
344 for (int i = 12; i >= 0; i -= 4) {
345 register_code(hextokeycode((unicode >> i) & 0xF));
346 unregister_code(hextokeycode((unicode >> i) & 0xF));
347 }
348
349 unregister_code(KC_LALT);
350}
351
308const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) 352const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
309{ 353{
310 // MACRODOWN only works in this function 354 // MACRODOWN only works in this function
311 switch(id) { 355 switch(id) {
356 case 0 ... END_UC:
357 if (record->event.pressed) {
358 send_unicode(unicode_chars[id]);
359 }
360 break;
312 case M_TGCM: 361 case M_TGCM:
313 if (record->event.pressed) { 362 if (record->event.pressed) {
314 default_layer_xor(1 << LR_CSA); 363 default_layer_xor(1 << LR_CSA);
@@ -364,7 +413,7 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
364 break; 413 break;
365 case M_DBL0: 414 case M_DBL0:
366 if (record->event.pressed) { 415 if (record->event.pressed) {
367 return MACRO( I(25), T(P0), T(P0), END ); 416 return MACRO( I(25), T(P0), T(P0), END );
368 } 417 }
369 break; 418 break;
370 case M_FNLR: 419 case M_FNLR: