diff options
| author | Fred Silberberg <fred@silberberg.xyz> | 2019-02-24 17:57:16 -0500 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-02-24 14:57:16 -0800 |
| commit | 6f30a6b4079684742c147741b98414b1b2350b0b (patch) | |
| tree | 7111640fff952b88302c2bdf9eb39a0c6671fd4b /users/333fred | |
| parent | a69e4406d4ab0a43077bc130dabda536b4fda9ab (diff) | |
| download | qmk_firmware-6f30a6b4079684742c147741b98414b1b2350b0b.tar.gz qmk_firmware-6f30a6b4079684742c147741b98414b1b2350b0b.zip | |
[Keymap] Added a key to handle copy/paste in and out of a terminal (#5205)
Diffstat (limited to 'users/333fred')
| -rw-r--r-- | users/333fred/333fred.c | 37 | ||||
| -rw-r--r-- | users/333fred/333fred.h | 7 |
2 files changed, 37 insertions, 7 deletions
diff --git a/users/333fred/333fred.c b/users/333fred/333fred.c index 12ee9e7d7..3b2b36d02 100644 --- a/users/333fred/333fred.c +++ b/users/333fred/333fred.c | |||
| @@ -9,7 +9,7 @@ typedef enum { | |||
| 9 | static tap_dance_state_enum tap_dance_state; | 9 | static tap_dance_state_enum tap_dance_state; |
| 10 | static bool tap_dance_active = false; | 10 | static bool tap_dance_active = false; |
| 11 | 11 | ||
| 12 | void tap_dance_layer_finished(qk_tap_dance_state_t *state, void *user_data) { | 12 | void tap_dance_sym_vim_finished(qk_tap_dance_state_t *state, void *user_data) { |
| 13 | // Determine the current state | 13 | // Determine the current state |
| 14 | if (state->count == 1) { | 14 | if (state->count == 1) { |
| 15 | if (state->interrupted || state->pressed == 0) tap_dance_state = SINGLE_TAP; | 15 | if (state->interrupted || state->pressed == 0) tap_dance_state = SINGLE_TAP; |
| @@ -38,8 +38,7 @@ void tap_dance_layer_finished(qk_tap_dance_state_t *state, void *user_data) { | |||
| 38 | } | 38 | } |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | 41 | void tap_dance_sym_vim_reset(qk_tap_dance_state_t *state, void *user_data) { | |
| 42 | void tap_dance_layer_reset(qk_tap_dance_state_t *state, void *user_data) { | ||
| 43 | switch(tap_dance_state) { | 42 | switch(tap_dance_state) { |
| 44 | case SINGLE_TAP: | 43 | case SINGLE_TAP: |
| 45 | clear_oneshot_layer_state(ONESHOT_PRESSED); | 44 | clear_oneshot_layer_state(ONESHOT_PRESSED); |
| @@ -53,8 +52,38 @@ void tap_dance_layer_reset(qk_tap_dance_state_t *state, void *user_data) { | |||
| 53 | } | 52 | } |
| 54 | } | 53 | } |
| 55 | 54 | ||
| 55 | void tap_dance_copy_paste_finished(qk_tap_dance_state_t *state, void *user_data) { | ||
| 56 | bool is_paste = state->count == 2; | ||
| 57 | // If either the one-shot shift is set, or if shift is being held, count as shift being held. | ||
| 58 | // We'll clear the one-shot shift if it was held | ||
| 59 | uint8_t one_shot_mods = get_oneshot_mods(); | ||
| 60 | bool is_shift = false; | ||
| 61 | |||
| 62 | if (get_mods() & MOD_MASK_SHIFT) { | ||
| 63 | is_shift = true; | ||
| 64 | } else if (one_shot_mods & MOD_MASK_SHIFT) { | ||
| 65 | set_oneshot_mods(one_shot_mods & ~MOD_MASK_SHIFT); | ||
| 66 | is_shift = true; | ||
| 67 | } | ||
| 68 | |||
| 69 | if (is_paste) { | ||
| 70 | if (is_shift) { | ||
| 71 | SEND_STRING(SS_LSFT(SS_TAP(X_INSERT))); | ||
| 72 | } else { | ||
| 73 | SEND_STRING(SS_LCTRL("v")); | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | if (is_shift) { | ||
| 77 | SEND_STRING(SS_LCTRL(SS_TAP(X_INSERT))); | ||
| 78 | } else { | ||
| 79 | SEND_STRING(SS_LCTRL("c")); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 56 | qk_tap_dance_action_t tap_dance_actions[] = { | 84 | qk_tap_dance_action_t tap_dance_actions[] = { |
| 57 | [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_layer_finished, tap_dance_layer_reset) | 85 | [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_sym_vim_finished, tap_dance_sym_vim_reset), |
| 86 | [TD_COPY_PASTE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_copy_paste_finished, NULL) | ||
| 58 | }; | 87 | }; |
| 59 | 88 | ||
| 60 | void tap_dance_process_record(uint16_t keycode) { | 89 | void tap_dance_process_record(uint16_t keycode) { |
diff --git a/users/333fred/333fred.h b/users/333fred/333fred.h index 443930a6b..0e6c6a196 100644 --- a/users/333fred/333fred.h +++ b/users/333fred/333fred.h | |||
| @@ -13,9 +13,10 @@ | |||
| 13 | 13 | ||
| 14 | // Tap dance config shared between my keyboards | 14 | // Tap dance config shared between my keyboards |
| 15 | enum tap_dance_declarations { | 15 | enum tap_dance_declarations { |
| 16 | TD_SYM_VIM = 0 | 16 | TD_SYM_VIM = 0, |
| 17 | TD_COPY_PASTE, | ||
| 17 | }; | 18 | }; |
| 18 | 19 | ||
| 19 | void tap_dance_layer_finished(qk_tap_dance_state_t*, void*); | 20 | void tap_dance_sym_vim_finished(qk_tap_dance_state_t*, void*); |
| 20 | void tap_dance_layer_reset(qk_tap_dance_state_t*, void*); | 21 | void tap_dance_sym_vim_reset(qk_tap_dance_state_t*, void*); |
| 21 | void tap_dance_process_record(uint16_t); | 22 | void tap_dance_process_record(uint16_t); |
