From 660f6b3b727384b8dfa3fef69bb9f2cff33c1ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Rom=C3=A3o?= Date: Wed, 26 Jul 2023 19:20:11 -0300 Subject: [PATCH] rewrite sentence case --- .../fauxberry/keymaps/rafaelromao/keymap.c | 11 --- .../rommana/keymaps/rafaelromao/keymap.c | 11 --- .../wizza/keymaps/rafaelromao/keymap.c | 11 --- .../bm40hsrgb/keymaps/rafaelromao/keymap.c | 11 --- .../users/rafaelromao/definitions/keycodes.h | 1 - .../rafaelromao/definitions/keymap_blocks.h | 10 -- .../rafaelromao/features/sentence_case.c | 93 +++++++++---------- .../rafaelromao/features/sentence_case.h | 7 ++ src/qmk/users/rafaelromao/features/tapdance.c | 18 ++-- src/qmk/users/rafaelromao/features/tapdance.h | 1 + src/qmk/users/rafaelromao/rafaelromao.c | 12 +-- 11 files changed, 64 insertions(+), 122 deletions(-) diff --git a/src/qmk/keyboards/handwired/rafaelromao/fauxberry/keymaps/rafaelromao/keymap.c b/src/qmk/keyboards/handwired/rafaelromao/fauxberry/keymaps/rafaelromao/keymap.c index 59a4f3f9..317b7c57 100644 --- a/src/qmk/keyboards/handwired/rafaelromao/fauxberry/keymaps/rafaelromao/keymap.c +++ b/src/qmk/keyboards/handwired/rafaelromao/fauxberry/keymaps/rafaelromao/keymap.c @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ____RAISE_L4_____ , XXXXXXX , XXXXXXX , ____RAISE_R4_____), // |___________________________________________________________________________________________________| - [_SEN_CASE] = LAYOUT_wrapper( - // |___________________________________________________________________________________________________| - ___________________SEN_CASE____L1____ , XXXXXXX , XXXXXXX , _________SEN_CASE____R1______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - ___________________SEN_CASE____L2______________ , ___________________SEN_CASE____R2______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - XXXXXXX , _________SEN_CASE____L3______________ , ___________________SEN_CASE____R3____ , XXXXXXX , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - __SEN_CASE____L4_ , XXXXXXX , XXXXXXX , __SEN_CASE____R4_), - // |___________________________________________________________________________________________________| - [_FIXED_NAV] = LAYOUT_wrapper( // |___________________________________________________________________________________________________| ___________________NAVIGATION_L1_____ , XXXXXXX , XXXXXXX , _________NAVIGATION_R1_______________ , diff --git a/src/qmk/keyboards/handwired/rafaelromao/rommana/keymaps/rafaelromao/keymap.c b/src/qmk/keyboards/handwired/rafaelromao/rommana/keymaps/rafaelromao/keymap.c index a8b9cb58..d2d765d5 100644 --- a/src/qmk/keyboards/handwired/rafaelromao/rommana/keymaps/rafaelromao/keymap.c +++ b/src/qmk/keyboards/handwired/rafaelromao/rommana/keymaps/rafaelromao/keymap.c @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ____RAISE_L4_____ , ____RAISE_R4_____), // |___________________________________________________________________________________________________| - [_SEN_CASE] = LAYOUT_wrapper( - // |___________________________________________________________________________________________________| - ___________________SEN_CASE____L1____ , _________SEN_CASE____R1______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - ___________________SEN_CASE____L2______________ , ___________________SEN_CASE____R2______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - _________SEN_CASE____L3______________ , ___________________SEN_CASE____R3____ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - __SEN_CASE____L4_ , __SEN_CASE____R4_), - // |___________________________________________________________________________________________________| - [_FIXED_NAV] = LAYOUT_wrapper( // |___________________________________________________________________________________________________| ___________________NAVIGATION_L1_____ , _________NAVIGATION_R1_______________ , diff --git a/src/qmk/keyboards/handwired/rafaelromao/wizza/keymaps/rafaelromao/keymap.c b/src/qmk/keyboards/handwired/rafaelromao/wizza/keymaps/rafaelromao/keymap.c index 45639f6b..f916512f 100644 --- a/src/qmk/keyboards/handwired/rafaelromao/wizza/keymaps/rafaelromao/keymap.c +++ b/src/qmk/keyboards/handwired/rafaelromao/wizza/keymaps/rafaelromao/keymap.c @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ____RAISE_L4_____ , ____RAISE_R4_____), // |___________________________________________________________________________________________________| - [_SEN_CASE] = LAYOUT_wrapper( - // |___________________________________________________________________________________________________| - ___________________SEN_CASE____L1____ , _________SEN_CASE____R1______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - ___________________SEN_CASE____L2______________ , ___________________SEN_CASE____R2______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - _________SEN_CASE____L3______________ , ___________________SEN_CASE____R3____ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - __SEN_CASE____L4_ , __SEN_CASE____R4_), - // |___________________________________________________________________________________________________| - [_FIXED_NAV] = LAYOUT_wrapper( // |___________________________________________________________________________________________________| ___________________NAVIGATION_L1_____ , _________NAVIGATION_R1_______________ , diff --git a/src/qmk/keyboards/kprepublic/bm40hsrgb/keymaps/rafaelromao/keymap.c b/src/qmk/keyboards/kprepublic/bm40hsrgb/keymaps/rafaelromao/keymap.c index e81d133e..41ef6a21 100644 --- a/src/qmk/keyboards/kprepublic/bm40hsrgb/keymaps/rafaelromao/keymap.c +++ b/src/qmk/keyboards/kprepublic/bm40hsrgb/keymaps/rafaelromao/keymap.c @@ -98,17 +98,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { XXXXXXX , XXXXXXX , XXXXXXX , ____RAISE_L4_____ , XXXXXXX , ____RAISE_R4_____ , XXXXXXX , XXXXXXX , XXXXXXX), // |_______________________________________________________________________________________________________________________| - [_SEN_CASE] = LAYOUT_wrapper( - // |_______________________________________________________________________________________________________________________| - ___________________SEN_CASE____L1____ , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , _________SEN_CASE____R1______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - ___________________SEN_CASE____L2______________ , XXXXXXX , XXXXXXX , ___________________SEN_CASE____R2______________ , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - XXXXXXX , _________SEN_CASE____L3______________ , XXXXXXX , XXXXXXX , ___________________SEN_CASE____R3____ , XXXXXXX , - // |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------| - XXXXXXX , XXXXXXX , XXXXXXX , __SEN_CASE____L4_ , XXXXXXX , __SEN_CASE____R4_ , XXXXXXX , XXXXXXX , XXXXXXX), - // |_______________________________________________________________________________________________________________________| - [_FIXED_NAV] = LAYOUT_wrapper( // |_______________________________________________________________________________________________________________________| ___________________NAVIGATION_L1_____ , XXXXXXX , XXXXXXX , XXXXXXX , XXXXXXX , _________NAVIGATION_R1_______________ , diff --git a/src/qmk/users/rafaelromao/definitions/keycodes.h b/src/qmk/users/rafaelromao/definitions/keycodes.h index b646403c..d763357c 100644 --- a/src/qmk/users/rafaelromao/definitions/keycodes.h +++ b/src/qmk/users/rafaelromao/definitions/keycodes.h @@ -199,7 +199,6 @@ enum { #define RAI_TAC LT(_RAISE, TG_ACNT) #define RAI_SPC LT(_RAISE, KC_SPC) #define RAI_ACT OSL(_ACCENT) // Hold behavior is implemented in intercepted code -#define MED_OSF LT(_MEDIA, OS_LSFT) // Hold and tap behaviors are implemented in intercepted code #define MAC_KCD LT(_MACROS, KC_D) #define MAC_KCI LT(_MACROS, KC_I) diff --git a/src/qmk/users/rafaelromao/definitions/keymap_blocks.h b/src/qmk/users/rafaelromao/definitions/keymap_blocks.h index f603160e..eb2cb4f2 100644 --- a/src/qmk/users/rafaelromao/definitions/keymap_blocks.h +++ b/src/qmk/users/rafaelromao/definitions/keymap_blocks.h @@ -79,16 +79,6 @@ #define ___________________RAISE_R3__________ TD_TILD , TD_SLSH , KC_ASTR , TD_NOT #define ____RAISE_R4_____ _______ , _______ -#define ___________________SEN_CASE____L1____ _______ , _______ , _______ , _______ -#define ___________________SEN_CASE____L2______________ _______ , _______ , _______ , _______ , _______ -#define _________SEN_CASE____L3______________ _______ , _______ , _______ , _______ -#define __SEN_CASE____L4_ NAV_CAN , LOW_NSE - -#define _________SEN_CASE____R1______________ _______ , _______ , _______ , _______ -#define ___________________SEN_CASE____R2______________ _______ , _______ , _______ , _______ , _______ -#define ___________________SEN_CASE____R3____ _______ , _______ , _______ , _______ -#define __SEN_CASE____R4_ _______ , MED_OSF - #define ___________________MEDIA_L1__________ _______ , MC_ESC , MC_SAVE , HYPR_G #define ___________________MEDIA_L2____________________ HYPR_D , KC_LSFT , KC_LCTL , KC_LGUI , HYPR_W #define _________MEDIA_L3____________________ KC_RALT , HYPR_C , KC_LALT , HYPR_V diff --git a/src/qmk/users/rafaelromao/features/sentence_case.c b/src/qmk/users/rafaelromao/features/sentence_case.c index 16df459d..9d3b76db 100644 --- a/src/qmk/users/rafaelromao/features/sentence_case.c +++ b/src/qmk/users/rafaelromao/features/sentence_case.c @@ -2,63 +2,58 @@ #include "sentence_case.h" -process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *record) { - bool isOneShotLockedShift = get_oneshot_locked_mods() & MOD_MASK_SHIFT; - bool isOneShotShift = isOneShotLockedShift || get_oneshot_mods() & MOD_MASK_SHIFT; +sentence_case_t sentence_case = {.state = SENTENCE_CASE_NONE}; - switch (keycode) { - case NAV_CAN: - if (record->tap.count == 0) { - if (record->event.pressed) { - disable_oneshot_layer(); - layer_on(_NAVIGATION); - } else { - layer_off(_NAVIGATION); - } - } else { - if (record->event.pressed) { - disable_smart_case(); - clear_shift(); - } - } - return PROCESS_RECORD_RETURN_FALSE; +void start_sentence_case(void) { + // Called after . ? and ! + sentence_case.state = SENTENCE_CASE_STARTED; +} - case LOW_NSE: - if (record->tap.count == 0) { - if (record->event.pressed) { - disable_oneshot_layer(); - layer_on(_LOWER); - } else { - layer_off(_LOWER); +process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + switch (keycode) { + // Navigation + case KC_HOME: + case KC_END: + case KC_LEFT: + case KC_RIGHT: + if (sentence_case.state == SENTENCE_CASE_STARTED) { + clear_shift(); + sentence_case.state = SENTENCE_CASE_NONE; + return PROCESS_RECORD_CONTINUE; } - } else { - if (record->event.pressed) { + } + } + if (record->tap.count && record->event.pressed) { + uint16_t key = extract_base_tapping_keycode(keycode); + switch (key) { + // Space + case KC_SPC: + if (sentence_case.state == SENTENCE_CASE_STARTED) { tap_code(KC_SPC); - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); add_oneshot_mods(MOD_LSFT); + sentence_case.state = SENTENCE_CASE_STARTED; + return PROCESS_RECORD_RETURN_FALSE; } - } - return PROCESS_RECORD_RETURN_FALSE; - - case MED_OSF: - if (record->tap.count == 0) { - if (record->event.pressed) { - layer_on(_MEDIA); - } else { - layer_off(_MEDIA); + } + switch (keycode) { + // Cancel + case NAV_REP: + case QK_REP: + if (sentence_case.state == SENTENCE_CASE_STARTED) { + clear_shift(); + sentence_case.state = SENTENCE_CASE_NONE; + return PROCESS_RECORD_RETURN_FALSE; } - } else { - if (record->event.pressed) { - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); - if (!isOneShotShift) { - add_oneshot_mods(MOD_LSFT); - } + // One Shot Shift + case MED_CAS: + if (sentence_case.state == SENTENCE_CASE_STARTED) { + add_oneshot_mods(MOD_LSFT); + return PROCESS_RECORD_RETURN_FALSE; } - } - return PROCESS_RECORD_RETURN_FALSE; + default: + sentence_case.state = SENTENCE_CASE_NONE; + } } - return PROCESS_RECORD_CONTINUE; } diff --git a/src/qmk/users/rafaelromao/features/sentence_case.h b/src/qmk/users/rafaelromao/features/sentence_case.h index 60fc038b..c58b21f5 100644 --- a/src/qmk/users/rafaelromao/features/sentence_case.h +++ b/src/qmk/users/rafaelromao/features/sentence_case.h @@ -5,4 +5,11 @@ #include "../definitions/process_record.h" #include "custom_oneshot.h" +typedef enum { SENTENCE_CASE_NONE, SENTENCE_CASE_STARTED } sentence_case_state_t; + +typedef struct { + sentence_case_state_t state; +} sentence_case_t; + +void start_sentence_case(void); process_record_result_t process_sentence_case(uint16_t keycode, keyrecord_t *record); diff --git a/src/qmk/users/rafaelromao/features/tapdance.c b/src/qmk/users/rafaelromao/features/tapdance.c index 88e778c8..8879c276 100644 --- a/src/qmk/users/rafaelromao/features/tapdance.c +++ b/src/qmk/users/rafaelromao/features/tapdance.c @@ -371,8 +371,7 @@ void td_ques(tap_dance_state_t *state, void *user_data) { case TD_SINGLE_TAP: tap_code16(KC_QUES); #ifdef LEADER_ENABLE - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); + start_sentence_case(); #endif break; case TD_DOUBLE_SINGLE_TAP: @@ -384,8 +383,7 @@ void td_ques(tap_dance_state_t *state, void *user_data) { tap_code(KC_END); tap_code16(KC_QUES); #ifdef LEADER_ENABLE - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); + start_sentence_case(); #endif break; default: @@ -433,16 +431,14 @@ void td_not(tap_dance_state_t *state, void *user_data) { case TD_SINGLE_TAP: tap_code16(KC_EXLM); #ifdef LEADER_ENABLE - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); + start_sentence_case(); #endif break; case TD_SINGLE_HOLD: tap_code(KC_END); tap_code16(KC_EXLM); #ifdef LEADER_ENABLE - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); + start_sentence_case(); #endif break; case TD_DOUBLE_TAP: @@ -484,8 +480,7 @@ void td_dot(tap_dance_state_t *state, void *user_data) { case TD_SINGLE_TAP: tap_code(KC_DOT); #ifdef LEADER_ENABLE - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); + start_sentence_case(); #endif break; case TD_DOUBLE_SINGLE_TAP: @@ -502,8 +497,7 @@ void td_dot(tap_dance_state_t *state, void *user_data) { tap_code16(KC_END); tap_code(KC_DOT); #ifdef LEADER_ENABLE - set_oneshot_layer(_SEN_CASE, ONESHOT_START); - reset_oneshot_timer(); + start_sentence_case(); #endif break; default: diff --git a/src/qmk/users/rafaelromao/features/tapdance.h b/src/qmk/users/rafaelromao/features/tapdance.h index 39484846..bb1bbfb3 100644 --- a/src/qmk/users/rafaelromao/features/tapdance.h +++ b/src/qmk/users/rafaelromao/features/tapdance.h @@ -8,6 +8,7 @@ #include "dynamic_macro.h" #include "macros.h" #include "accents.h" +#include "sentence_case.h" typedef enum { TD_NONE, diff --git a/src/qmk/users/rafaelromao/rafaelromao.c b/src/qmk/users/rafaelromao/rafaelromao.c index 5347b008..2b7e1201 100644 --- a/src/qmk/users/rafaelromao/rafaelromao.c +++ b/src/qmk/users/rafaelromao/rafaelromao.c @@ -32,8 +32,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { break; }; - // Process Repeat Key - switch (process_repeat(keycode, record)) { +#ifdef LEADER_ENABLE + // Process Sentence Case + switch (process_sentence_case(keycode, record)) { case PROCESS_RECORD_RETURN_TRUE: return true; case PROCESS_RECORD_RETURN_FALSE: @@ -41,10 +42,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { default: break; }; +#endif -#ifdef LEADER_ENABLE - // Process Sentence Case - switch (process_sentence_case(keycode, record)) { + // Process Repeat Key + switch (process_repeat(keycode, record)) { case PROCESS_RECORD_RETURN_TRUE: return true; case PROCESS_RECORD_RETURN_FALSE: @@ -52,7 +53,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { default: break; }; -#endif // Process custom_shift switch (process_custom_shift(keycode, record)) {