From 1b29d0d71b80feac7feef551b27a2141194fb9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Rom=C3=A3o?= Date: Sat, 25 May 2024 15:23:13 -0300 Subject: [PATCH] implement magic-h in QMK --- .../users/rafaelromao/definitions/keycodes.c | 7 +- .../users/rafaelromao/definitions/keycodes.h | 11 +- .../rafaelromao/definitions/keymap_blocks.h | 6 +- src/qmk/users/rafaelromao/features/accents.c | 42 +-- src/qmk/users/rafaelromao/features/combos.c | 8 +- .../rafaelromao/features/sentence_case.c | 5 +- .../users/rafaelromao/features/smart_case.c | 5 +- .../users/rafaelromao/features/smart_thumbs.c | 244 +++--------------- .../users/rafaelromao/features/smart_thumbs.h | 1 + src/qmk/users/rafaelromao/features/tapdance.c | 5 - src/qmk/users/rafaelromao/features/taphold.c | 15 +- 11 files changed, 82 insertions(+), 267 deletions(-) diff --git a/src/qmk/users/rafaelromao/definitions/keycodes.c b/src/qmk/users/rafaelromao/definitions/keycodes.c index a3cf5e1a..ccebe85d 100644 --- a/src/qmk/users/rafaelromao/definitions/keycodes.c +++ b/src/qmk/users/rafaelromao/definitions/keycodes.c @@ -83,4 +83,9 @@ bool is_shift_macro_keycode(uint16_t keycode) { bool is_accent_macro_keycode(uint16_t keycode) { return keycode > ACCENT_MACRO_START && keycode < ACCENT_MACRO_END; -} \ No newline at end of file +} + +bool is_shifted(void) { + return get_mods() & MOD_MASK_SHIFT || get_oneshot_mods() & MOD_MASK_SHIFT || + get_oneshot_locked_mods() & MOD_MASK_SHIFT; +} diff --git a/src/qmk/users/rafaelromao/definitions/keycodes.h b/src/qmk/users/rafaelromao/definitions/keycodes.h index f686c861..360ce8b0 100644 --- a/src/qmk/users/rafaelromao/definitions/keycodes.h +++ b/src/qmk/users/rafaelromao/definitions/keycodes.h @@ -108,7 +108,6 @@ enum { // Begin macros used to write text STR_MACRO_START, - MC_NG, MC_EY, MC_HY, MC_OU, MC_COM, MC_AO, MC_ES, MC_OES, MC_FIX_I, MC_BTIC, MC_DQUO, MC_SQUO, MC_CIRC, MC_TILD, MC_ORDO, MC_ORDA, MC_EUR, MC_LTE, MC_GTE, MC_DDS, MC_ENT, MC_TAB, MC_ESC, MC_ESCC, TG_NUMC, MC_EXLM, MC_QUES, MC_ESAV, MC_SENT, MC_DEG, MC_DELW, MC_LY, @@ -122,7 +121,7 @@ enum { // Start macros for accented letters ACCENT_MACRO_START, - MC_GV_A, MC_CR_A, MC_SQ_A, MC_QU, + MC_GV_A, MC_CR_A, MC_SQ_A, MC_QU, MC_AH, MC_SQ_U, MC_CR_O, MC_SQ_O, MC_SQ_I, MC_CR_E, MC_SQ_C, MC_SQ_E, MC_TL_A, MC_TL_O, @@ -161,9 +160,10 @@ enum { #define RCTLT_A RCTL_T(KC_A) #define LALTT_P LALT_T(KC_P) -#define RALTT_H RALT_T(KC_H) #define RALTT_F RALT_T(KC_F) +#define ALT_MAG RALT_T(KC_H) + #define LGUIT_T LGUI_T(KC_T) #define RGUIT_R RGUI_T(KC_R) @@ -178,8 +178,8 @@ enum { #define NAV_F12 LT(_NAVIGATION, KC_F12) #define NAV_AT LT(_NAVIGATION, KC_AT) -#define NAV_STI LT(_NAVIGATION, MC_STIN) // Hold behavior is implemented in intercepted code -#define NAV_MAG LT(_NAVIGATION, MAGIC) +#define NAV_STI LT(_NAVIGATION, MC_STIN) // Tap behavior is implemented in intercepted code +#define NAV_Q LT(_NAVIGATION, KC_Q) #define NAV_REP LT(_NAVIGATION, REPEAT) #define FNA_REP LT(_FIXED_NAV, REPEAT) @@ -216,5 +216,6 @@ uint16_t extract_tapping_keycode(uint16_t keycode); bool is_string_macro_keycode(uint16_t keycode); bool is_shift_macro_keycode(uint16_t keycode); bool is_accent_macro_keycode(uint16_t keycode); +bool is_shifted(void); // clang-format on \ No newline at end of file diff --git a/src/qmk/users/rafaelromao/definitions/keymap_blocks.h b/src/qmk/users/rafaelromao/definitions/keymap_blocks.h index ddba6001..c16626c0 100644 --- a/src/qmk/users/rafaelromao/definitions/keymap_blocks.h +++ b/src/qmk/users/rafaelromao/definitions/keymap_blocks.h @@ -12,7 +12,7 @@ #define ________ALPHA1_R1____________________ KC_L , KC_O , KC_U , KC_Y #define __________________ALPHA1_R2____________________ KC_Z , RGUIT_R , RCTLT_A , RSFTT_E , SHO_KCI -#define __________________ALPHA1_R3__________ KC_J , RALTT_H , TD_COMM , TD_DOT +#define __________________ALPHA1_R3__________ KC_J , ALT_MAG , TD_COMM , TD_DOT #define ___ALPHA1_R4_____ RAI_A2 , MED_CAS #define ___________________LOWER_L1__________ XXXXXXX , TD_LCBR , TD_RCBR , TD_BSLS @@ -75,10 +75,10 @@ #define ___________________NOMOD_R3__________ KC_J , KC_H , KC_COMM , KC_DOT #define ____NOMOD_R4_____ OSL_A2 , OS_LSFT -#define ___________________ALPHA2_L1_________ XXXXXXX , KC_Q , MC_QU , KC_K +#define ___________________ALPHA2_L1_________ XXXXXXX , KC_H , MC_QU , KC_K #define ___________________ALPHA2_L2___________________ KC_Y , KC_Z , KC_X , KC_W , XXXXXXX #define _________ALPHA2_L3___________________ KC_J , MC_SQ_C , KC_V , XXXXXXX -#define ____ALPHA2_L4____ NAV_MAG , OS_SYM +#define ____ALPHA2_L4____ NAV_Q , OS_SYM #define _________ALPHA2_R1___________________ MC_CR_O , MC_CR_E , MC_CR_A , XXXXXXX #define ___________________ALPHA2_R2___________________ XXXXXXX , MC_TL_A , MC_SQ_E , MC_SQ_A , MC_SQ_I diff --git a/src/qmk/users/rafaelromao/features/accents.c b/src/qmk/users/rafaelromao/features/accents.c index ae0bd335..11cf6495 100644 --- a/src/qmk/users/rafaelromao/features/accents.c +++ b/src/qmk/users/rafaelromao/features/accents.c @@ -85,47 +85,9 @@ process_record_result_t process_ngrams(uint16_t keycode, bool isShifted) { tap_code(KC_Q); tap_code(KC_U); return PROCESS_RECORD_RETURN_FALSE; - case MC_ES: - tap_code(KC_E); - tap_code(KC_S); - return PROCESS_RECORD_RETURN_FALSE; - case MC_AO: - process_accents(MC_TL_A, NULL); - tap_code(KC_O); - return PROCESS_RECORD_RETURN_FALSE; - case MC_OES: - process_accents(MC_TL_O, NULL); - tap_code(KC_E); - tap_code(KC_S); - return PROCESS_RECORD_RETURN_FALSE; - case MC_NG: - tap_code(KC_N); - tap_code(KC_G); - return PROCESS_RECORD_RETURN_FALSE; - case MC_LY: - tap_code(KC_L); - tap_code(KC_Y); - return PROCESS_RECORD_RETURN_FALSE; - case MC_EY: - tap_code(KC_E); - tap_code(KC_Y); - return PROCESS_RECORD_RETURN_FALSE; - case MC_HY: + case MC_AH: + tap_code(KC_A); tap_code(KC_H); - tap_code(KC_Y); - return PROCESS_RECORD_RETURN_FALSE; - case MC_OU: - tap_code(KC_O); - tap_code(KC_U); - return PROCESS_RECORD_RETURN_FALSE; - case MC_COM: - tap_code(KC_C); - tap_code(KC_O); - tap_code(KC_M); - return PROCESS_RECORD_RETURN_FALSE; - case MC_FIX_I: - tap_code(KC_BSPC); - SEND_STRING("I' "); return PROCESS_RECORD_RETURN_FALSE; } diff --git a/src/qmk/users/rafaelromao/features/combos.c b/src/qmk/users/rafaelromao/features/combos.c index 2617a711..0c03acf4 100644 --- a/src/qmk/users/rafaelromao/features/combos.c +++ b/src/qmk/users/rafaelromao/features/combos.c @@ -23,20 +23,20 @@ const uint16_t PROGMEM l_rom_tab_combo[] = {RALTT_F, LEA_KCC, LALTT_P, COMBO_END const uint16_t PROGMEM r_rom_x_combo[] = {KC_L, KC_O, COMBO_END}; const uint16_t PROGMEM r_rom_z_combo[] = {RGUIT_R, RCTLT_A, COMBO_END}; -const uint16_t PROGMEM r_rom_j_combo[] = {RALTT_H, TD_COMM, COMBO_END}; +const uint16_t PROGMEM r_rom_j_combo[] = {ALT_MAG, TD_COMM, COMBO_END}; const uint16_t PROGMEM r_rom_y_combo[] = {RCTLT_A, RSFTT_E, COMBO_END}; const uint16_t PROGMEM r_rom_d_combo[] = {KC_L, KC_O, KC_U, COMBO_END}; const uint16_t PROGMEM r_rom_p_combo[] = {RGUIT_R, RCTLT_A, RSFTT_E, COMBO_END}; const uint16_t PROGMEM r_rom_cop_combo[] = {RAI_A2, RGUIT_R, RCTLT_A, COMBO_END}; -const uint16_t PROGMEM r_rom_pas_combo[] = {RAI_A2, RALTT_H, TD_COMM, COMBO_END}; +const uint16_t PROGMEM r_rom_pas_combo[] = {RAI_A2, ALT_MAG, TD_COMM, COMBO_END}; const uint16_t PROGMEM r_rom_sal_combo[] = {RAI_A2, TD_COMM, TD_DOT, COMBO_END}; const uint16_t PROGMEM r_rom_scp_combo[] = {RAI_A2, RGUIT_R, RCTLT_A, RSFTT_E, COMBO_END}; -const uint16_t PROGMEM r_rom_spa_combo[] = {RAI_A2, RALTT_H, TD_COMM, TD_DOT, COMBO_END}; +const uint16_t PROGMEM r_rom_spa_combo[] = {RAI_A2, ALT_MAG, TD_COMM, TD_DOT, COMBO_END}; const uint16_t PROGMEM r_rom_ent_combo[] = {RAI_A2, RCTLT_A, RSFTT_E, COMBO_END}; const uint16_t PROGMEM r_rom_bsp_combo[] = {KC_O, KC_U, COMBO_END}; const uint16_t PROGMEM r_rom_tab_combo[] = {RAI_A2, KC_O, KC_U, COMBO_END}; const uint16_t PROGMEM r_rom_sco_combo[] = {TD_COMM, TD_DOT, COMBO_END}; -const uint16_t PROGMEM r_rom_sent_combo[] = {RALTT_H, TD_COMM, TD_DOT, COMBO_END}; +const uint16_t PROGMEM r_rom_sent_combo[] = {ALT_MAG, TD_COMM, TD_DOT, COMBO_END}; // Alpha 2 diff --git a/src/qmk/users/rafaelromao/features/sentence_case.c b/src/qmk/users/rafaelromao/features/sentence_case.c index ee47dde8..c75a2329 100644 --- a/src/qmk/users/rafaelromao/features/sentence_case.c +++ b/src/qmk/users/rafaelromao/features/sentence_case.c @@ -26,11 +26,12 @@ process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *rec // Process macros switch (keycode) { // Skip dot and comma - case TD_DOT: case TD_COMM: + case TD_DOT: sentence_case.state = SENTENCE_CASE_NONE; return PROCESS_RECORD_CONTINUE; // Process alpha macros + case MC_AH: case MC_QU: add_oneshot_mods(MOD_LSFT); sentence_case.state = SENTENCE_CASE_NONE; @@ -61,11 +62,11 @@ process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *rec switch (keycode) { // Continue to Alpha2 layer case RAI_A2: + case OSL_A2: return PROCESS_RECORD_CONTINUE; // Cancel case NAV_REP: case FNA_REP: - case NAV_MAG: case QK_REP: if (sentence_case.state != SENTENCE_CASE_NONE) { clear_shift(); diff --git a/src/qmk/users/rafaelromao/features/smart_case.c b/src/qmk/users/rafaelromao/features/smart_case.c index 70e3dcf8..0963ba2a 100644 --- a/src/qmk/users/rafaelromao/features/smart_case.c +++ b/src/qmk/users/rafaelromao/features/smart_case.c @@ -153,10 +153,11 @@ process_record_result_t process_smart_case(uint16_t keycode, keyrecord_t *record } // Extend, process or break case switch (keycode) { + case OSL_A2: case RAI_A2: case NAV_REP: case FNA_REP: - case NAV_MAG: + case ALT_MAG: case MED_CAS: start_smart_case_timer(); return PROCESS_RECORD_CONTINUE; @@ -244,12 +245,12 @@ process_record_result_t process_smart_case(uint16_t keycode, keyrecord_t *record break; } default: - disable_smart_case(); if (is_shift_macro_keycode(key)) { process_macros(key, NULL); } else if (is_accent_macro_keycode(key)) { process_accents(key, NULL); } else { + disable_smart_case(); tap_code16(key); } return PROCESS_RECORD_RETURN_FALSE; diff --git a/src/qmk/users/rafaelromao/features/smart_thumbs.c b/src/qmk/users/rafaelromao/features/smart_thumbs.c index db1c8637..589bb371 100644 --- a/src/qmk/users/rafaelromao/features/smart_thumbs.c +++ b/src/qmk/users/rafaelromao/features/smart_thumbs.c @@ -52,7 +52,7 @@ bool check_disable_oneshot(uint16_t keycode) { case MED_CAS: case NAV_REP: case FNA_REP: - case NAV_MAG: + case ALT_MAG: case OS_LSFT: return false; default: @@ -106,7 +106,7 @@ bool remember_last_key_user(uint16_t keycode, keyrecord_t *record, uint8_t *reme case MED_CAS: case NAV_REP: case FNA_REP: - case NAV_MAG: + case ALT_MAG: return false; } custom_repeat_key_timer = timer_read(); @@ -126,39 +126,17 @@ void action_tap(uint16_t keycode) { action_tapping_process(make_keyevent(false, keycode)); } -bool process_alternate_repeat_for_macros(uint16_t keycode) { - uint16_t next_key = keycode; - switch (keycode) { - case MC_GV_A: - next_key = MC_QU; - break; - case MC_SQ_A: - case MC_SQ_E: - case MC_SQ_I: - case MC_SQ_O: - case MC_SQ_U: - next_key = KC_V; - break; - case MC_CR_A: - next_key = KC_N; - break; - case MC_CR_E: - next_key = KC_E; - break; - case MC_CR_O: - next_key = KC_O; - break; - case MC_TL_A: - next_key = KC_O; - break; - case MC_TL_O: - next_key = MC_ES; +void process_repeat(uint16_t keycode) { + uint16_t next_key = extract_tapping_keycode(keycode); + switch (next_key) { + case KC_H: + next_key = MC_AH; break; case MC_SQ_C: - next_key = MC_AO; + next_key = OSL_A2; break; case MC_QU: - next_key = KC_E; + next_key = MC_CR_E; break; case MC_SQUO: next_key = KC_V; @@ -166,210 +144,71 @@ bool process_alternate_repeat_for_macros(uint16_t keycode) { } if (next_key != keycode) { action_tap(next_key); - return true; + } else { + action_tap(QK_REP); } - return false; } -bool process_alternate_repeat_for_alphas(uint16_t keycode) { - uint16_t next_key = keycode; - switch (keycode) { - case KC_A: - next_key = KC_V; - break; - case KC_H: - next_key = MC_OES; - break; - case KC_I: - next_key = MC_NG; - break; - case KC_J: - next_key = MC_SQ_A; - break; - case KC_K: - next_key = MC_EY; - break; - case KC_U: - next_key = KC_Y; - break; - case KC_V: - case KC_X: - next_key = MC_SQ_A; +void process_magic(uint16_t keycode) { + uint16_t next_key = extract_tapping_keycode(keycode); + switch (next_key) { + case MC_TL_A: + case MC_TL_O: + case MC_CR_A: + next_key = KC_NO; break; - case KC_W: - next_key = MC_HY; + case MC_GV_A: + next_key = MC_QU; break; - case KC_Y: - next_key = MC_OU; + case MC_QU: + next_key = OSL_A2; break; case KC_DOT: - next_key = MC_COM; - break; - } - if (next_key != keycode) { - action_tap(next_key); - return true; - } - return false; -} - -void process_repeat(uint16_t keycode) { - uint16_t key = extract_tapping_keycode(keycode); - if (!custom_repeat_key_expired()) { - if (process_alternate_repeat_for_macros(key)) { - return; - } - if (process_alternate_repeat_for_alphas(key)) { - return; - } - } - action_tap(QK_REP); -} - -bool process_magic_for_macros(uint16_t keycode) { - uint16_t next_key = keycode; - switch (keycode) { - case MC_GV_A: - next_key = MC_QU; + next_key = KC_SLSH; break; + case KC_A: + case KC_E: + case KC_I: + case KC_O: + case KC_U: case MC_SQ_E: - next_key = KC_U; - break; case MC_SQ_A: case MC_SQ_O: - next_key = KC_X; - break; case MC_SQ_I: case MC_SQ_U: - next_key = KC_Z; - break; - case MC_CR_A: - next_key = KC_M; - break; case MC_CR_E: - next_key = KC_X; - break; case MC_CR_O: + case MC_SQUO: next_key = KC_V; break; - case MC_TL_A: - next_key = KC_O; - break; - case MC_TL_O: - next_key = KC_E; - break; - case MC_SQ_C: - next_key = MC_OES; - break; - case MC_QU: - next_key = MC_SQ_I; - break; - } - if (next_key != keycode) { - action_tap(next_key); - return true; - } - return false; -} - -bool process_magic_for_alphas(uint16_t keycode) { - uint16_t next_key = keycode; - switch (keycode) { - case KC_A: - next_key = KC_O; - break; case KC_B: - next_key = KC_Y; - break; - case KC_C: - next_key = KC_S; - break; case KC_D: - next_key = KC_Y; - break; - case KC_E: - next_key = KC_U; - break; + case KC_M: case KC_F: next_key = KC_Y; break; + case MC_SQ_C: case KC_H: - next_key = KC_R; - break; - case KC_I: - next_key = MC_FIX_I; - break; case KC_J: - next_key = MC_TL_A; - break; case KC_K: - next_key = KC_W; - break; - case KC_L: - next_key = KC_H; - break; - case KC_M: - next_key = KC_S; - break; - case KC_N: - next_key = KC_F; - break; - case KC_P: - next_key = KC_T; - break; - case KC_R: - next_key = MC_LY; - break; - case KC_S: - next_key = KC_C; - break; - case KC_T: - next_key = KC_W; - break; - case KC_U: - next_key = KC_E; - break; case KC_V: case KC_X: - next_key = MC_SQ_I; - break; case KC_Z: - next_key = MC_SQ_A; - break; - case KC_W: - next_key = KC_K; - break; - case KC_DOT: - next_key = KC_SLSH; + next_key = OSL_A2; break; } - if (next_key != keycode) { + if (next_key != keycode && next_key != extract_tapping_keycode(keycode)) { action_tap(next_key); - return true; - } - return false; -} - -void process_magic(uint16_t keycode) { - uint16_t key = extract_tapping_keycode(keycode); - if (process_magic_for_macros(key)) { - return; - } - if (process_magic_for_alphas(key)) { - return; + } else { + action_tap(KC_H); } - action_tap(QK_REP); } -void activate_repeat_or_magic_key(uint16_t keycode) { - switch (keycode) { - case NAV_MAG: - process_magic(get_last_keycode()); - break; - case NAV_REP: - case FNA_REP: - process_repeat(get_last_keycode()); - break; +void activate_repeat_or_magic_key(bool isMagic) { + if (isMagic) { + process_magic(get_last_keycode()); + } else { + process_repeat(get_last_keycode()); } } @@ -415,10 +254,9 @@ process_record_result_t process_smart_thumbs(uint16_t keycode, keyrecord_t *reco } case NAV_REP: case FNA_REP: - case NAV_MAG: if (record->tap.count > 0) { if (record->event.pressed) { - activate_repeat_or_magic_key(keycode); + activate_repeat_or_magic_key(false); return PROCESS_RECORD_RETURN_FALSE; } } diff --git a/src/qmk/users/rafaelromao/features/smart_thumbs.h b/src/qmk/users/rafaelromao/features/smart_thumbs.h index 524124c7..848f7978 100644 --- a/src/qmk/users/rafaelromao/features/smart_thumbs.h +++ b/src/qmk/users/rafaelromao/features/smart_thumbs.h @@ -23,3 +23,4 @@ void check_repeat_key_timeout(void); void clear_repeat_key(void); process_record_result_t process_smart_thumbs(uint16_t keycode, keyrecord_t *record); +void activate_repeat_or_magic_key(bool isMagic); \ No newline at end of file diff --git a/src/qmk/users/rafaelromao/features/tapdance.c b/src/qmk/users/rafaelromao/features/tapdance.c index c4b2bbf1..8b1a73a8 100644 --- a/src/qmk/users/rafaelromao/features/tapdance.c +++ b/src/qmk/users/rafaelromao/features/tapdance.c @@ -37,11 +37,6 @@ __attribute__((weak)) td_state_t dance_state(tap_dance_state_t *state) { return TD_UNKNOWN; } -bool is_shifted(void) { - return get_mods() & MOD_MASK_SHIFT || get_oneshot_mods() & MOD_MASK_SHIFT || - get_oneshot_locked_mods() & MOD_MASK_SHIFT; -} - void td_open_parentesis(tap_dance_state_t *state, void *user_data) { tap_state.state = dance_state(state); switch (tap_state.state) { diff --git a/src/qmk/users/rafaelromao/features/taphold.c b/src/qmk/users/rafaelromao/features/taphold.c index 91e167d7..e0cfbe00 100644 --- a/src/qmk/users/rafaelromao/features/taphold.c +++ b/src/qmk/users/rafaelromao/features/taphold.c @@ -7,7 +7,7 @@ uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { case LOW_SPC: case RAI_SPC: case RAI_A2: - case NAV_MAG: + case NAV_Q: case NAV_REP: case FNA_REP: case MED_CAS: @@ -23,7 +23,7 @@ uint16_t get_quick_tap_term(uint16_t keycode, keyrecord_t *record) { case LOW_SPC: case RAI_SPC: case RAI_A2: - case NAV_MAG: + case NAV_Q: case NAV_REP: case FNA_REP: case MED_CAS: @@ -120,6 +120,17 @@ process_record_result_t process_taphold(uint16_t keycode, keyrecord_t *record) { return PROCESS_RECORD_RETURN_FALSE; } break; + + case ALT_MAG: + if (record->event.pressed && record->tap.count) { + if (is_shifted()) { + tap_code(KC_H); + } else { + activate_repeat_or_magic_key(true); + } + return PROCESS_RECORD_RETURN_FALSE; + } + break; } return PROCESS_RECORD_CONTINUE; } \ No newline at end of file