diff options
author | QMK Bot <hello@qmk.fm> | 2021-04-10 00:38:17 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2021-04-10 00:38:17 +0000 |
commit | 29d537ce7b9b9770d99b0244793b6bc159d8a435 (patch) | |
tree | 6286d9e012bd89a4e267a23f41f1c31cf0b63d24 /users | |
parent | 688fb1999b339d20ba8cd173d6dc7c53754d4ba0 (diff) | |
parent | 3dbb7f261dab573a3b55390394444ac3ceb3d257 (diff) |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'users')
-rw-r--r-- | users/edvorakjp/edvorakjp.c | 28 | ||||
-rw-r--r-- | users/edvorakjp/edvorakjp.h | 86 | ||||
-rw-r--r-- | users/edvorakjp/edvorakjp_process_record.c | 122 | ||||
-rw-r--r-- | users/edvorakjp/edvorakjp_status.c | 58 | ||||
-rw-r--r-- | users/edvorakjp/edvorakjp_tap_dance.c | 90 |
5 files changed, 191 insertions, 193 deletions
diff --git a/users/edvorakjp/edvorakjp.c b/users/edvorakjp/edvorakjp.c index 892ce4be3b..d0cd106fff 100644 --- a/users/edvorakjp/edvorakjp.c +++ b/users/edvorakjp/edvorakjp.c @@ -1,32 +1,22 @@ #include "edvorakjp.h" void matrix_init_user(void) { - edvorakjp_status_init(); - matrix_init_keymap(); + edvorakjp_status_init(); + matrix_init_keymap(); } -__attribute__ ((weak)) -void matrix_init_keymap() {} +__attribute__((weak)) void matrix_init_keymap() {} uint32_t layer_state_set_user(uint32_t state) { - state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST); - return layer_state_set_keymap(state); + state = update_tri_layer_state(state, L_EDVORAKJP_LOWER, L_EDVORAKJP_RAISE, L_EDVORAKJP_ADJUST); + return layer_state_set_keymap(state); } -__attribute__ ((weak)) -uint32_t layer_state_set_keymap(uint32_t state) { - return state; -} +__attribute__((weak)) uint32_t layer_state_set_keymap(uint32_t state) { return state; } bool process_record_user(uint16_t keycode, keyrecord_t *record) { - return process_record_keymap(keycode, record) &&\ - process_record_edvorakjp_swap_scln(keycode, record) &&\ - process_record_edvorakjp_config(keycode, record) &&\ - process_record_layer(keycode, record) &&\ - process_record_ime(keycode, record); + bool process_record_user_result = process_record_keymap(keycode, record) && process_record_edvorakjp_swap_scln(keycode, record) && process_record_edvorakjp_config(keycode, record) && process_record_layer(keycode, record) && process_record_ime(keycode, record); + return process_record_user_result; } -__attribute__ ((weak)) -bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { - return true; -} +__attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } diff --git a/users/edvorakjp/edvorakjp.h b/users/edvorakjp/edvorakjp.h index 688cdeffb3..5f20762c65 100644 --- a/users/edvorakjp/edvorakjp.h +++ b/users/edvorakjp/edvorakjp.h @@ -1,54 +1,76 @@ -#ifndef EDVORAKJP -#define EDVORAKJP +#pragma once #include "quantum.h" #include "action_layer.h" #define EECONFIG_EDVORAK (uint8_t *)20 +// clang-format off +#define __EDVORAKJP_BASE_L1__ KC_QUOTE, KC_COMMA, KC_DOT, KC_Y, KC_Q +#define __EDVORAKJP_BASE_L2__ KC_A, LALT_T(KC_O), LGUI_T(KC_E), LCTL_T(KC_I), KC_U +#define __EDVORAKJP_BASE_L3__ KC_SCOLON, KC_X, KC_C, KC_V, KC_Z + +#define __EDVORAKJP_BASE_R1__ KC_F, KC_G, KC_R, KC_W, KC_P +#define __EDVORAKJP_BASE_R2__ KC_D, RSFT_T(KC_T), RGUI_T(KC_N), RALT_T(KC_S), KC_M +#define __EDVORAKJP_BASE_R3__ KC_H, KC_J, KC_K, KC_L, KC_B + +#define __EDVORAKJP_NUMBER_L__ KC_1, LALT_T(KC_2), LGUI_T(KC_3), LCTL_T(KC_4), KC_5 +#define __EDVORAKJP_NUMBER_R__ KC_6, RSFT_T(KC_7), RGUI_T(KC_8), RALT_T(KC_9), KC_0 + +#define __EDVORAKJP_FUNCTION_L__ KC_F1, KC_F2, LALT_T(KC_F3), LGUI_T(KC_F4), LCTL_T(KC_F5), KC_F6 +#define __EDVORAKJP_FUNCTION_R__ KC_F7, RSFT_T(KC_F8), RGUI_T(KC_F9), RALT_T(KC_F10), KC_F11, KC_F12 + +#define __EDVORAKJP_SYMBOL_L__ KC_EXCLAIM, KC_AT, KC_HASH, KC_DOLLAR +#define __EDVORAKJP_SYMBOL_R__ KC_PERCENT, KC_CIRCUMFLEX, KC_AMPERSAND, KC_ASTERISK + +#define __EDVORAKJP_BRACKET_L__ KC_LEFT_CURLY_BRACE, KC_LBRACKET, KC_LEFT_PAREN +#define __EDVORAKJP_BRACKET_R__ KC_RIGHT_PAREN, KC_RBRACKET, KC_RIGHT_CURLY_BRACE + +#define __EDVORAKJP_PAGE__ KC_HOME, KC_PGDOWN, KC_PGUP, KC_END +#define __EDVORAKJP_CURSOR__ KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT + +#define LA_TAB LALT_T(KC_TAB) +#define LS_SPC LSFT_T(KC_SPACE) +#define RC_BSPC RCTL_T(KC_BSPACE) +#define RC_DEL RCTL_T(KC_DELETE) +#define RG_ENT RGUI_T(KC_ENTER) + +#define LOWER_TD TD(TD_EDVORAKJP_LOWER) +#define RAISE_TD TD(TD_EDVORAKJP_RAISE) +// clang-format on + extern keymap_config_t keymap_config; enum edvorakjp_layers { - _EDVORAK = 0, - _LOWER, - _RAISE, - _ADJUST, - _EXTRA, + L_EDVORAKJP_BASE = 0, + L_EDVORAKJP_LOWER, + L_EDVORAKJP_RAISE, + L_EDVORAKJP_ADJUST, + L_EDVORAKJP_EXTRA, }; enum edvorakjp_keycodes { - EDVORAK = SAFE_RANGE, - LOWER, - RAISE, - KC_MAC, - KC_WIN, - KC_JPN, - KC_ENG, - NEW_SAFE_RANGE + KC_EDVORAKJP_LOWER = SAFE_RANGE, + KC_EDVORAKJP_RAISE, + KC_MAC, + KC_WIN, + KC_JPN, + KC_ENG, + NEW_SAFE_RANGE, }; -#define KC_LC(k) LCTL_T(KC_##k) -#define KC_LS(k) LSFT_T(KC_##k) -#define KC_LA(k) LALT_T(KC_##k) -#define KC_LG(k) LGUI_T(KC_##k) -#define KC_RC(k) RCTL_T(KC_##k) -#define KC_RS(k) RSFT_T(KC_##k) -#define KC_RG(k) RGUI_T(KC_##k) -#define KC_RA(k) RALT_T(KC_##k) - enum tap_dance_code { - TD_LOWER = 0, - TD_RAISE + TD_EDVORAKJP_LOWER = 0, + TD_EDVORAKJP_RAISE, }; // base -void dvorakj_layer_off(void); -void matrix_init_user(void); -void matrix_init_keymap(void); +void matrix_init_user(void); +void matrix_init_keymap(void); uint32_t layer_state_set_user(uint32_t state); uint32_t layer_state_set_keymap(uint32_t state); -bool process_record_user(uint16_t keycode, keyrecord_t *record); -bool process_record_keymap(uint16_t keycode, keyrecord_t *record); +bool process_record_user(uint16_t keycode, keyrecord_t *record); +bool process_record_keymap(uint16_t keycode, keyrecord_t *record); // status void edvorakjp_status_init(void); @@ -66,5 +88,3 @@ bool process_record_edvorakjp_swap_scln(uint16_t keycode, keyrecord_t *record); bool process_record_edvorakjp_config(uint16_t keycode, keyrecord_t *record); bool process_record_layer(uint16_t keycode, keyrecord_t *record); bool process_record_ime(uint16_t keycode, keyrecord_t *record); - -#endif // EDVORAKJP diff --git a/users/edvorakjp/edvorakjp_process_record.c b/users/edvorakjp/edvorakjp_process_record.c index ecc8db9363..ac821c3935 100644 --- a/users/edvorakjp/edvorakjp_process_record.c +++ b/users/edvorakjp/edvorakjp_process_record.c @@ -9,81 +9,81 @@ static uint16_t time_on_pressed; */ bool process_record_edvorakjp_swap_scln(uint16_t keycode, keyrecord_t *record) { #ifdef SWAP_SCLN - static const uint8_t shift_bits = MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT); - static uint8_t last_mods_status; - if (keycode == KC_SCLN) { - if (record->event.pressed) { - last_mods_status = get_mods(); + static const uint8_t shift_bits = MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT); + static uint8_t last_mods_status; + if (keycode == KC_SCLN) { + if (record->event.pressed) { + last_mods_status = get_mods(); - // invert shift_bits - if (last_mods_status & shift_bits) { - set_mods(last_mods_status & ~shift_bits); - } else { - set_mods(last_mods_status | MOD_BIT(KC_LSFT)); - } - } else { - set_mods(last_mods_status); - last_mods_status = 0; + // invert shift_bits + if (last_mods_status & shift_bits) { + set_mods(last_mods_status & ~shift_bits); + } else { + set_mods(last_mods_status | MOD_BIT(KC_LSFT)); + } + } else { + set_mods(last_mods_status); + last_mods_status = 0; + } } - } #endif - return true; + return true; } bool process_record_edvorakjp_config(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { - case KC_MAC: - case KC_WIN: - if (record->event.pressed) { - set_enable_kc_lang(keycode == KC_MAC); - } - return false; - } - return true; + switch (keycode) { + case KC_MAC: + case KC_WIN: + if (record->event.pressed) { + set_enable_kc_lang(keycode == KC_MAC); + } + return false; + } + return true; } bool process_record_layer(uint16_t keycode, keyrecord_t *record) { #if TAP_DANCE_ENABLE != yes - switch (keycode) { - case LOWER: - if (record->event.pressed) { - layer_on(_LOWER); - time_on_pressed = record->event.time; - } else { - layer_off(_LOWER); + switch (keycode) { + case KC_EDVORAKJP_LOWER: + if (record->event.pressed) { + layer_on(L_EDVORAKJP_LOWER); + time_on_pressed = record->event.time; + } else { + layer_off(L_EDVORAKJP_LOWER); - if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) { - set_japanese_mode(false); - } - time_on_pressed = 0; - } - return false; - case RAISE: - if (record->event.pressed) { - layer_on(_RAISE); - time_on_pressed = record->event.time; - } else { - layer_off(_RAISE); + if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) { + set_japanese_mode(false); + } + time_on_pressed = 0; + } + return false; + case KC_EDVORAKJP_RAISE: + if (record->event.pressed) { + layer_on(L_EDVORAKJP_RAISE); + time_on_pressed = record->event.time; + } else { + layer_off(L_EDVORAKJP_RAISE); - if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) { - set_japanese_mode(true); - } - time_on_pressed = 0; - } - return false; - } + if (TIMER_DIFF_16(record->event.time, time_on_pressed) < TAPPING_TERM) { + set_japanese_mode(true); + } + time_on_pressed = 0; + } + return false; + } #endif - return true; + return true; } bool process_record_ime(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { - case KC_JPN: - case KC_ENG: - if (record->event.pressed) { - set_japanese_mode(keycode == KC_JPN); - } - return false; - } - return true; + switch (keycode) { + case KC_JPN: + case KC_ENG: + if (record->event.pressed) { + set_japanese_mode(keycode == KC_JPN); + } + return false; + } + return true; } diff --git a/users/edvorakjp/edvorakjp_status.c b/users/edvorakjp/edvorakjp_status.c index 128fc3bd28..c8a06c2255 100644 --- a/users/edvorakjp/edvorakjp_status.c +++ b/users/edvorakjp/edvorakjp_status.c @@ -2,63 +2,55 @@ #include "edvorakjp.h" typedef union { - uint8_t raw; - struct { - bool enable_kc_lang; // for macOS - }; + uint8_t raw; + struct { + bool enable_kc_lang; // for macOS + }; } edvorakjp_config_t; static edvorakjp_config_t edvorakjp_config; typedef struct { - bool japanese_mode; + bool japanese_mode; } edvorakjp_state_t; static edvorakjp_state_t edvorakjp_state; /* * private methods */ -uint8_t eeconfig_read_edvorakjp(void) { - return eeprom_read_byte(EECONFIG_EDVORAK); -} +uint8_t eeconfig_read_edvorakjp(void) { return eeprom_read_byte(EECONFIG_EDVORAK); } -void eeconfig_update_edvorakjp(uint8_t val) { - eeprom_update_byte(EECONFIG_EDVORAK, val); -} +void eeconfig_update_edvorakjp(uint8_t val) { eeprom_update_byte(EECONFIG_EDVORAK, val); } /* * public methods */ void edvorakjp_status_init(void) { - edvorakjp_state.japanese_mode = false; - edvorakjp_config.raw = eeconfig_read_edvorakjp(); + edvorakjp_state.japanese_mode = false; + edvorakjp_config.raw = eeconfig_read_edvorakjp(); } -bool get_enable_kc_lang(void) { - return edvorakjp_config.enable_kc_lang; -} +bool get_enable_kc_lang(void) { return edvorakjp_config.enable_kc_lang; } void set_enable_kc_lang(bool new_state) { - edvorakjp_config.enable_kc_lang = new_state; - eeconfig_update_edvorakjp(edvorakjp_config.raw); + edvorakjp_config.enable_kc_lang = new_state; + eeconfig_update_edvorakjp(edvorakjp_config.raw); } -bool get_japanese_mode(void) { - return edvorakjp_state.japanese_mode; -} +bool get_japanese_mode(void) { return edvorakjp_state.japanese_mode; } void set_japanese_mode(bool new_state) { - edvorakjp_state.japanese_mode = new_state; - if (edvorakjp_state.japanese_mode) { - if (edvorakjp_config.enable_kc_lang) { - SEND_STRING(SS_TAP(X_LANG1)); - } else { - SEND_STRING(SS_LALT("`")); - } - } else { - if (edvorakjp_config.enable_kc_lang) { - SEND_STRING(SS_TAP(X_LANG2)); + edvorakjp_state.japanese_mode = new_state; + if (edvorakjp_state.japanese_mode) { + if (edvorakjp_config.enable_kc_lang) { + SEND_STRING(SS_TAP(X_LANG1)); + } else { + SEND_STRING(SS_LALT("`")); + } } else { - SEND_STRING(SS_LALT("`")); + if (edvorakjp_config.enable_kc_lang) { + SEND_STRING(SS_TAP(X_LANG2)); + } else { + SEND_STRING(SS_LALT("`")); + } } - } } diff --git a/users/edvorakjp/edvorakjp_tap_dance.c b/users/edvorakjp/edvorakjp_tap_dance.c index d5369f9266..cee10de693 100644 --- a/users/edvorakjp/edvorakjp_tap_dance.c +++ b/users/edvorakjp/edvorakjp_tap_dance.c @@ -2,72 +2,68 @@ #include "process_keycode/process_tap_dance.h" enum tap_state { - NONE = 0, - SINGLE_TAP = 1, - DOUBLE_TAP = 2, - HOLD + NONE = 0, + SINGLE_TAP = 1, + DOUBLE_TAP = 2, + HOLD, }; typedef struct { - uint8_t lower; - uint8_t raise; + uint8_t lower; + uint8_t raise; } td_status_t; static td_status_t td_status = {NONE, NONE}; -int cur_dance(qk_tap_dance_state_t *state) { - if (state->interrupted || !state->pressed) { - return state->count == 1 ? SINGLE_TAP : DOUBLE_TAP; - } else { - return HOLD; - } +uint8_t cur_dance(qk_tap_dance_state_t *state) { + if (state->interrupted || !state->pressed) { + return state->count == 1 ? SINGLE_TAP : DOUBLE_TAP; + } else { + return HOLD; + } } void td_lower_finished(qk_tap_dance_state_t *state, void *user_data) { - td_status.lower = cur_dance(state); - switch(td_status.lower) { - case SINGLE_TAP: - set_japanese_mode(false); - break; - case DOUBLE_TAP: - set_japanese_mode(false); - register_code(KC_ESC); - break; - case HOLD: - break; - } - layer_on(_LOWER); + td_status.lower = cur_dance(state); + switch (td_status.lower) { + case SINGLE_TAP: + set_japanese_mode(false); + break; + case DOUBLE_TAP: + set_japanese_mode(false); + register_code(KC_ESC); + break; + } + layer_on(L_EDVORAKJP_LOWER); } void td_lower_reset(qk_tap_dance_state_t *state, void *user_data) { - if (td_status.lower == DOUBLE_TAP) { - unregister_code(KC_ESC); - } - layer_off(_LOWER); - td_status.lower = NONE; + switch (td_status.lower) { + case DOUBLE_TAP: + unregister_code(KC_ESC); + break; + } + layer_off(L_EDVORAKJP_LOWER); + td_status.lower = NONE; } void td_raise_finished(qk_tap_dance_state_t *state, void *user_data) { - td_status.raise = cur_dance(state); - switch(td_status.raise) { - case DOUBLE_TAP: - // same as single - case SINGLE_TAP: - set_japanese_mode(true); - break; - case HOLD: - break; - } - layer_on(_RAISE); + td_status.raise = cur_dance(state); + switch (td_status.raise) { + case DOUBLE_TAP: + // same as single + case SINGLE_TAP: + set_japanese_mode(true); + break; + } + layer_on(L_EDVORAKJP_RAISE); } void td_raise_reset(qk_tap_dance_state_t *state, void *user_data) { - layer_off(_RAISE); - td_status.raise = NONE; + layer_off(L_EDVORAKJP_RAISE); + td_status.raise = NONE; } qk_tap_dance_action_t tap_dance_actions[] = { - [TD_LOWER] = - ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_lower_finished, td_lower_reset, 100), - [TD_RAISE] = - ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_raise_finished, td_raise_reset, 100) + [TD_EDVORAKJP_LOWER] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_lower_finished, td_lower_reset, 150), + [TD_EDVORAKJP_RAISE] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_raise_finished, td_raise_reset, 150), }; |