diff options
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_music.c | 12 | ||||
| -rw-r--r-- | quantum/process_keycode/process_tap_dance.c | 7 | ||||
| -rw-r--r-- | quantum/process_keycode/process_tap_dance.h | 1 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicode.c | 52 |
4 files changed, 61 insertions, 11 deletions
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index bae43943e..1e2648bff 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c | |||
| @@ -114,8 +114,18 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { | |||
| 114 | music_sequence_interval+=10; | 114 | music_sequence_interval+=10; |
| 115 | return false; | 115 | return false; |
| 116 | } | 116 | } |
| 117 | 117 | #define MUSIC_MODE_GUITAR | |
| 118 | |||
| 119 | #ifdef MUSIC_MODE_CHROMATIC | ||
| 120 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row)); | ||
| 121 | #elif defined(MUSIC_MODE_GUITAR) | ||
| 122 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 7)*5.0/12); | ||
| 123 | #elif defined(MUSIC_MODE_VIOLIN) | ||
| 124 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(float)(MATRIX_ROWS - record->event.key.row + 5)*7.0/12); | ||
| 125 | #else | ||
| 118 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row)); | 126 | float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row)); |
| 127 | #endif | ||
| 128 | |||
| 119 | if (record->event.pressed) { | 129 | if (record->event.pressed) { |
| 120 | play_note(freq, 0xF); | 130 | play_note(freq, 0xF); |
| 121 | if (music_sequence_recording) { | 131 | if (music_sequence_recording) { |
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index 6ae362c4c..403dca538 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c | |||
| @@ -43,12 +43,16 @@ static inline void process_tap_dance_action_on_dance_finished (qk_tap_dance_acti | |||
| 43 | if (action->state.finished) | 43 | if (action->state.finished) |
| 44 | return; | 44 | return; |
| 45 | action->state.finished = true; | 45 | action->state.finished = true; |
| 46 | add_mods(action->state.oneshot_mods); | ||
| 47 | send_keyboard_report(); | ||
| 46 | _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_dance_finished); | 48 | _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_dance_finished); |
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *action) | 51 | static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *action) |
| 50 | { | 52 | { |
| 51 | _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_reset); | 53 | _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_reset); |
| 54 | del_mods(action->state.oneshot_mods); | ||
| 55 | send_keyboard_report(); | ||
| 52 | } | 56 | } |
| 53 | 57 | ||
| 54 | bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | 58 | bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { |
| @@ -70,6 +74,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { | |||
| 70 | action->state.keycode = keycode; | 74 | action->state.keycode = keycode; |
| 71 | action->state.count++; | 75 | action->state.count++; |
| 72 | action->state.timer = timer_read(); | 76 | action->state.timer = timer_read(); |
| 77 | action->state.oneshot_mods = get_oneshot_mods(); | ||
| 73 | process_tap_dance_action_on_each_tap (action); | 78 | process_tap_dance_action_on_each_tap (action); |
| 74 | 79 | ||
| 75 | if (last_td && last_td != keycode) { | 80 | if (last_td && last_td != keycode) { |
| @@ -109,7 +114,7 @@ void matrix_scan_tap_dance () { | |||
| 109 | if (highest_td == -1) | 114 | if (highest_td == -1) |
| 110 | return; | 115 | return; |
| 111 | 116 | ||
| 112 | for (int i = 0; i <= highest_td; i++) { | 117 | for (int i = 0; i <= highest_td; i++) { |
| 113 | qk_tap_dance_action_t *action = &tap_dance_actions[i]; | 118 | qk_tap_dance_action_t *action = &tap_dance_actions[i]; |
| 114 | 119 | ||
| 115 | if (action->state.count && timer_elapsed (action->state.timer) > TAPPING_TERM) { | 120 | if (action->state.count && timer_elapsed (action->state.timer) > TAPPING_TERM) { |
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index f753cbba6..726752ecc 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | typedef struct | 9 | typedef struct |
| 10 | { | 10 | { |
| 11 | uint8_t count; | 11 | uint8_t count; |
| 12 | uint8_t oneshot_mods; | ||
| 12 | uint16_t keycode; | 13 | uint16_t keycode; |
| 13 | uint16_t timer; | 14 | uint16_t timer; |
| 14 | bool interrupted; | 15 | bool interrupted; |
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index cd3a610b4..9995ba9bd 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | #include "process_unicode.h" | 1 | #include "process_unicode.h" |
| 2 | #include "action_util.h" | ||
| 2 | 3 | ||
| 3 | static uint8_t input_mode; | 4 | static uint8_t input_mode; |
| 5 | uint8_t mods; | ||
| 4 | 6 | ||
| 5 | __attribute__((weak)) | 7 | __attribute__((weak)) |
| 6 | uint16_t hex_to_keycode(uint8_t hex) | 8 | uint16_t hex_to_keycode(uint8_t hex) |
| @@ -25,6 +27,19 @@ uint8_t get_unicode_input_mode(void) { | |||
| 25 | 27 | ||
| 26 | __attribute__((weak)) | 28 | __attribute__((weak)) |
| 27 | void unicode_input_start (void) { | 29 | void unicode_input_start (void) { |
| 30 | // save current mods | ||
| 31 | mods = keyboard_report->mods; | ||
| 32 | |||
| 33 | // unregister all mods to start from clean state | ||
| 34 | if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT); | ||
| 35 | if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT); | ||
| 36 | if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL); | ||
| 37 | if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL); | ||
| 38 | if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT); | ||
| 39 | if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT); | ||
| 40 | if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI); | ||
| 41 | if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI); | ||
| 42 | |||
| 28 | switch(input_mode) { | 43 | switch(input_mode) { |
| 29 | case UC_OSX: | 44 | case UC_OSX: |
| 30 | register_code(KC_LALT); | 45 | register_code(KC_LALT); |
| @@ -54,15 +69,25 @@ void unicode_input_start (void) { | |||
| 54 | __attribute__((weak)) | 69 | __attribute__((weak)) |
| 55 | void unicode_input_finish (void) { | 70 | void unicode_input_finish (void) { |
| 56 | switch(input_mode) { | 71 | switch(input_mode) { |
| 57 | case UC_OSX: | 72 | case UC_OSX: |
| 58 | case UC_WIN: | 73 | case UC_WIN: |
| 59 | unregister_code(KC_LALT); | 74 | unregister_code(KC_LALT); |
| 60 | break; | 75 | break; |
| 61 | case UC_LNX: | 76 | case UC_LNX: |
| 62 | register_code(KC_SPC); | 77 | register_code(KC_SPC); |
| 63 | unregister_code(KC_SPC); | 78 | unregister_code(KC_SPC); |
| 64 | break; | 79 | break; |
| 65 | } | 80 | } |
| 81 | |||
| 82 | // reregister previously set mods | ||
| 83 | if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT); | ||
| 84 | if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT); | ||
| 85 | if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL); | ||
| 86 | if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL); | ||
| 87 | if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT); | ||
| 88 | if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT); | ||
| 89 | if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI); | ||
| 90 | if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI); | ||
| 66 | } | 91 | } |
| 67 | 92 | ||
| 68 | void register_hex(uint16_t hex) { | 93 | void register_hex(uint16_t hex) { |
| @@ -116,7 +141,16 @@ bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { | |||
| 116 | const uint32_t* map = unicode_map; | 141 | const uint32_t* map = unicode_map; |
| 117 | uint16_t index = keycode & 0x7FF; | 142 | uint16_t index = keycode & 0x7FF; |
| 118 | uint32_t code = pgm_read_dword_far(&map[index]); | 143 | uint32_t code = pgm_read_dword_far(&map[index]); |
| 119 | if ((code > 0xFFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { | 144 | if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) { |
| 145 | // Convert to UTF-16 surrogate pair | ||
| 146 | code -= 0x10000; | ||
| 147 | uint32_t lo = code & 0x3ff; | ||
| 148 | uint32_t hi = (code & 0xffc00) >> 10; | ||
| 149 | unicode_input_start(); | ||
| 150 | register_hex32(hi + 0xd800); | ||
| 151 | register_hex32(lo + 0xdc00); | ||
| 152 | unicode_input_finish(); | ||
| 153 | } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { | ||
| 120 | // when character is out of range supported by the OS | 154 | // when character is out of range supported by the OS |
| 121 | unicode_map_input_error(); | 155 | unicode_map_input_error(); |
| 122 | } else { | 156 | } else { |
