diff options
| -rw-r--r-- | doc/keymap.md | 29 | ||||
| -rw-r--r-- | keyboards/ergodox/infinity/infinity.c | 24 | ||||
| -rw-r--r-- | keyboards/planck/keymaps/experimental/Makefile | 1 | ||||
| -rw-r--r-- | keyboards/planck/keymaps/experimental/keymap.c | 8 | ||||
| -rw-r--r-- | keyboards/planck/planck.c | 10 | ||||
| -rw-r--r-- | keyboards/preonic/preonic.c | 11 | ||||
| -rw-r--r-- | tmk_core/common.mk | 4 | ||||
| -rw-r--r-- | tmk_core/common/action.c | 82 | ||||
| -rw-r--r-- | tmk_core/common/action.h | 18 | ||||
| -rw-r--r-- | tmk_core/common/action_code.h | 28 |
10 files changed, 210 insertions, 5 deletions
diff --git a/doc/keymap.md b/doc/keymap.md index d1985e567..6f2a663fc 100644 --- a/doc/keymap.md +++ b/doc/keymap.md | |||
| @@ -455,6 +455,35 @@ Turn the backlight on and off without changing level. | |||
| 455 | 455 | ||
| 456 | 456 | ||
| 457 | 457 | ||
| 458 | ### 2.6 Swap-Hands Action | ||
| 459 | The swap-hands action allows support for one-handed keyboards without requiring a separate layer. Set `ONEHAND_ENABLE` in the Makefile and define a `hand_swap_config` entry in your keymap. Now whenever the `ACTION_SWAP_HANDS` command key is pressed the keyboard is mirrored. For instance, to type "Hello, World" on QWERTY you would type `^Ge^s^s^w^c W^wr^sd` | ||
| 460 | |||
| 461 | ### 2.6.1 Configuration | ||
| 462 | The configuration table is a simple 2-dimensional array to map from column/row to new column/row. Example `hand_swap_config` for Planck: | ||
| 463 | |||
| 464 | ``` | ||
| 465 | const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { | ||
| 466 | {{11, 0}, {10, 0}, {9, 0}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}}, | ||
| 467 | {{11, 1}, {10, 1}, {9, 1}, {8, 1}, {7, 1}, {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}}, | ||
| 468 | {{11, 2}, {10, 2}, {9, 2}, {8, 2}, {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}}, | ||
| 469 | {{11, 3}, {10, 3}, {9, 3}, {8, 3}, {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}}, | ||
| 470 | }; | ||
| 471 | ``` | ||
| 472 | |||
| 473 | Note that the array indices are reversed same as the matrix and the values are of type `keypos_t` which is `{col, row}` and all values are zero-based. In the example above, `hand_swap_config[2][4]` (third row, fifth column) would return {7, 2} (third row, eighth column). | ||
| 474 | |||
| 475 | ### 2.6.2 Advanced Swap Commands | ||
| 476 | - **`ACTION_SWAP_HANDS()`** Swaps hands when pressed, returns to normal when released (momentary). | ||
| 477 | - **`ACTION_SWAP_HANDS_TOGGLE()`** Toggles swap on and off with every keypress. | ||
| 478 | - **`ACTION_SWAP_HANDS_TAP_TOGGLE()`** Toggles with a tap; momentary when held. | ||
| 479 | - **`ACTION_SWAP_HANDS_TAP_KEY(key)`** Sends `key` with a tap; momentary swap when held. | ||
| 480 | - **`ACTION_SWAP_HANDS_ON_OFF()`** Alias for `ACTION_SWAP_HANDS()` | ||
| 481 | - **`ACTION_SWAP_HANDS_OFF_ON()`** Momentarily turns off swap. | ||
| 482 | - **`ACTION_SWAP_HANDS_ON()`** Turns on swapping and leaves it on. | ||
| 483 | - **`ACTION_SWAP_HANDS_OFF()`** Turn off swapping and leaves it off. Good for returning to a known state. | ||
| 484 | |||
| 485 | |||
| 486 | |||
| 458 | ## 3. Layer switching Example | 487 | ## 3. Layer switching Example |
| 459 | There are some ways to switch layer with 'Layer' actions. | 488 | There are some ways to switch layer with 'Layer' actions. |
| 460 | 489 | ||
diff --git a/keyboards/ergodox/infinity/infinity.c b/keyboards/ergodox/infinity/infinity.c index f89e046d0..c5793385f 100644 --- a/keyboards/ergodox/infinity/infinity.c +++ b/keyboards/ergodox/infinity/infinity.c | |||
| @@ -130,3 +130,27 @@ void ergodox_right_led_3_off(void){ | |||
| 130 | 130 | ||
| 131 | void ergodox_right_led_off(uint8_t led){ | 131 | void ergodox_right_led_off(uint8_t led){ |
| 132 | } | 132 | } |
| 133 | |||
| 134 | #ifdef ONEHAND_ENABLE | ||
| 135 | __attribute__ ((weak)) | ||
| 136 | const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { | ||
| 137 | {{0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 9}}, | ||
| 138 | {{0, 10}, {1, 10}, {2, 10}, {3, 10}, {4, 10}}, | ||
| 139 | {{0, 11}, {1, 11}, {2, 11}, {3, 11}, {4, 11}}, | ||
| 140 | {{0, 12}, {1, 12}, {2, 12}, {3, 12}, {4, 12}}, | ||
| 141 | {{0, 13}, {1, 13}, {2, 13}, {3, 13}, {4, 13}}, | ||
| 142 | {{0, 14}, {1, 14}, {2, 14}, {3, 14}, {4, 14}}, | ||
| 143 | {{0, 15}, {1, 15}, {2, 15}, {3, 15}, {4, 15}}, | ||
| 144 | {{0, 16}, {1, 16}, {2, 16}, {3, 16}, {4, 16}}, | ||
| 145 | {{0, 17}, {1, 17}, {2, 17}, {3, 17}, {4, 17}}, | ||
| 146 | {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}}, | ||
| 147 | {{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}}, | ||
| 148 | {{0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}}, | ||
| 149 | {{0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}}, | ||
| 150 | {{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}}, | ||
| 151 | {{0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}}, | ||
| 152 | {{0, 6}, {1, 6}, {2, 6}, {3, 6}, {4, 6}}, | ||
| 153 | {{0, 7}, {1, 7}, {2, 7}, {3, 7}, {4, 7}}, | ||
| 154 | {{0, 8}, {1, 8}, {2, 8}, {3, 8}, {4, 8}}, | ||
| 155 | }; | ||
| 156 | #endif | ||
diff --git a/keyboards/planck/keymaps/experimental/Makefile b/keyboards/planck/keymaps/experimental/Makefile index 877c4aed0..3a8250a9b 100644 --- a/keyboards/planck/keymaps/experimental/Makefile +++ b/keyboards/planck/keymaps/experimental/Makefile | |||
| @@ -16,6 +16,7 @@ AUDIO_ENABLE = no # Audio output on port C6 | |||
| 16 | UNICODE_ENABLE = no # Unicode | 16 | UNICODE_ENABLE = no # Unicode |
| 17 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID | 17 | BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID |
| 18 | RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. | 18 | RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight. Do not enable this with audio at the same time. |
| 19 | ONEHAND_ENABLE = yes # Enable one-hand typing | ||
| 19 | 20 | ||
| 20 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 21 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 21 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 22 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
diff --git a/keyboards/planck/keymaps/experimental/keymap.c b/keyboards/planck/keymaps/experimental/keymap.c index 2c1270094..569dbcc8a 100644 --- a/keyboards/planck/keymaps/experimental/keymap.c +++ b/keyboards/planck/keymaps/experimental/keymap.c | |||
| @@ -70,7 +70,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 70 | {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, | 70 | {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC}, |
| 71 | {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, | 71 | {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT}, |
| 72 | {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, | 72 | {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, |
| 73 | {KC_LEAD, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} | 73 | {KC_LEAD, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_FN0, KC_FN0, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} |
| 74 | }, | 74 | }, |
| 75 | 75 | ||
| 76 | /* Colemak | 76 | /* Colemak |
| @@ -88,7 +88,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 88 | {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, | 88 | {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC}, |
| 89 | {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, | 89 | {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT}, |
| 90 | {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, | 90 | {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT }, |
| 91 | {KC_LEAD, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} | 91 | {KC_LEAD, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_FN0, KC_FN0, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} |
| 92 | }, | 92 | }, |
| 93 | 93 | ||
| 94 | /* Dvorak | 94 | /* Dvorak |
| @@ -106,7 +106,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 106 | {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, | 106 | {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC}, |
| 107 | {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, | 107 | {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH}, |
| 108 | {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, | 108 | {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT }, |
| 109 | {KC_LEAD, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} | 109 | {KC_LEAD, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_FN0, KC_FN0, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT} |
| 110 | }, | 110 | }, |
| 111 | 111 | ||
| 112 | /* Lower | 112 | /* Lower |
| @@ -186,7 +186,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |||
| 186 | }; | 186 | }; |
| 187 | 187 | ||
| 188 | const uint16_t PROGMEM fn_actions[] = { | 188 | const uint16_t PROGMEM fn_actions[] = { |
| 189 | 189 | ACTION_SWAP_HANDS_TAP_KEY(KC_SPC), | |
| 190 | }; | 190 | }; |
| 191 | 191 | ||
| 192 | #ifdef AUDIO_ENABLE | 192 | #ifdef AUDIO_ENABLE |
diff --git a/keyboards/planck/planck.c b/keyboards/planck/planck.c index 8d70bb4e5..645b450d1 100644 --- a/keyboards/planck/planck.c +++ b/keyboards/planck/planck.c | |||
| @@ -1,5 +1,15 @@ | |||
| 1 | #include "planck.h" | 1 | #include "planck.h" |
| 2 | 2 | ||
| 3 | #ifdef ONEHAND_ENABLE | ||
| 4 | __attribute__ ((weak)) | ||
| 5 | const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { | ||
| 6 | {{11, 0}, {10, 0}, {9, 0}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}}, | ||
| 7 | {{11, 1}, {10, 1}, {9, 1}, {8, 1}, {7, 1}, {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}}, | ||
| 8 | {{11, 2}, {10, 2}, {9, 2}, {8, 2}, {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}}, | ||
| 9 | {{11, 3}, {10, 3}, {9, 3}, {8, 3}, {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}}, | ||
| 10 | }; | ||
| 11 | #endif | ||
| 12 | |||
| 3 | void matrix_init_kb(void) { | 13 | void matrix_init_kb(void) { |
| 4 | // Turn status LED on | 14 | // Turn status LED on |
| 5 | DDRE |= (1<<6); | 15 | DDRE |= (1<<6); |
diff --git a/keyboards/preonic/preonic.c b/keyboards/preonic/preonic.c index 889c3fc8f..d9c119b8d 100644 --- a/keyboards/preonic/preonic.c +++ b/keyboards/preonic/preonic.c | |||
| @@ -1,5 +1,16 @@ | |||
| 1 | #include "preonic.h" | 1 | #include "preonic.h" |
| 2 | 2 | ||
| 3 | #ifdef ONEHAND_ENABLE | ||
| 4 | __attribute__ ((weak)) | ||
| 5 | const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { | ||
| 6 | {{11, 0}, {10, 0}, {9, 0}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}}, | ||
| 7 | {{11, 1}, {10, 1}, {9, 1}, {8, 1}, {7, 1}, {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}}, | ||
| 8 | {{11, 2}, {10, 2}, {9, 2}, {8, 2}, {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}}, | ||
| 9 | {{11, 3}, {10, 3}, {9, 3}, {8, 3}, {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}}, | ||
| 10 | {{11, 4}, {10, 4}, {9, 4}, {8, 4}, {7, 4}, {6, 4}, {5, 4}, {4, 4}, {3, 4}, {2, 4}, {1, 4}, {0, 4}}, | ||
| 11 | }; | ||
| 12 | #endif | ||
| 13 | |||
| 3 | void matrix_init_kb(void) { | 14 | void matrix_init_kb(void) { |
| 4 | 15 | ||
| 5 | // Turn status LED on | 16 | // Turn status LED on |
diff --git a/tmk_core/common.mk b/tmk_core/common.mk index aa05b9491..429c57143 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk | |||
| @@ -85,6 +85,10 @@ ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) | |||
| 85 | OPT_DEFS += -DBLUETOOTH_ENABLE | 85 | OPT_DEFS += -DBLUETOOTH_ENABLE |
| 86 | endif | 86 | endif |
| 87 | 87 | ||
| 88 | ifeq ($(strip $(ONEHAND_ENABLE)), yes) | ||
| 89 | OPT_DEFS += -DONEHAND_ENABLE | ||
| 90 | endif | ||
| 91 | |||
| 88 | ifeq ($(strip $(KEYMAP_SECTION_ENABLE)), yes) | 92 | ifeq ($(strip $(KEYMAP_SECTION_ENABLE)), yes) |
| 89 | OPT_DEFS += -DKEYMAP_SECTION_ENABLE | 93 | OPT_DEFS += -DKEYMAP_SECTION_ENABLE |
| 90 | 94 | ||
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index be6dea2b7..08ef22eb9 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c | |||
| @@ -41,6 +41,12 @@ void action_exec(keyevent_t event) | |||
| 41 | dprint("EVENT: "); debug_event(event); dprintln(); | 41 | dprint("EVENT: "); debug_event(event); dprintln(); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | #ifdef ONEHAND_ENABLE | ||
| 45 | if (!IS_NOEVENT(event)) { | ||
| 46 | process_hand_swap(&event); | ||
| 47 | } | ||
| 48 | #endif | ||
| 49 | |||
| 44 | keyrecord_t record = { .event = event }; | 50 | keyrecord_t record = { .event = event }; |
| 45 | 51 | ||
| 46 | #ifndef NO_ACTION_TAPPING | 52 | #ifndef NO_ACTION_TAPPING |
| @@ -53,6 +59,26 @@ void action_exec(keyevent_t event) | |||
| 53 | #endif | 59 | #endif |
| 54 | } | 60 | } |
| 55 | 61 | ||
| 62 | #ifdef ONEHAND_ENABLE | ||
| 63 | bool swap_hands = false; | ||
| 64 | |||
| 65 | void process_hand_swap(keyevent_t *event) { | ||
| 66 | static swap_state_row_t swap_state[MATRIX_ROWS]; | ||
| 67 | |||
| 68 | keypos_t pos = event->key; | ||
| 69 | swap_state_row_t col_bit = (swap_state_row_t)1<<pos.col; | ||
| 70 | bool do_swap = event->pressed ? swap_hands : | ||
| 71 | swap_state[pos.row] & (col_bit); | ||
| 72 | |||
| 73 | if (do_swap) { | ||
| 74 | event->key = hand_swap_config[pos.row][pos.col]; | ||
| 75 | swap_state[pos.row] |= col_bit; | ||
| 76 | } else { | ||
| 77 | swap_state[pos.row] &= ~(col_bit); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | #endif | ||
| 81 | |||
| 56 | #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) | 82 | #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) |
| 57 | bool disable_action_cache = false; | 83 | bool disable_action_cache = false; |
| 58 | 84 | ||
| @@ -440,6 +466,54 @@ void process_action(keyrecord_t *record, action_t action) | |||
| 440 | #endif | 466 | #endif |
| 441 | case ACT_COMMAND: | 467 | case ACT_COMMAND: |
| 442 | break; | 468 | break; |
| 469 | #ifdef ONEHAND_ENABLE | ||
| 470 | case ACT_SWAP_HANDS: | ||
| 471 | switch (action.swap.code) { | ||
| 472 | case OP_SH_TOGGLE: | ||
| 473 | if (event.pressed) { | ||
| 474 | swap_hands = !swap_hands; | ||
| 475 | } | ||
| 476 | break; | ||
| 477 | case OP_SH_ON_OFF: | ||
| 478 | swap_hands = event.pressed; | ||
| 479 | break; | ||
| 480 | case OP_SH_OFF_ON: | ||
| 481 | swap_hands = !event.pressed; | ||
| 482 | break; | ||
| 483 | case OP_SH_ON: | ||
| 484 | if (!event.pressed) { | ||
| 485 | swap_hands = true; | ||
| 486 | } | ||
| 487 | break; | ||
| 488 | case OP_SH_OFF: | ||
| 489 | if (!event.pressed) { | ||
| 490 | swap_hands = false; | ||
| 491 | } | ||
| 492 | break; | ||
| 493 | #ifndef NO_ACTION_TAPPING | ||
| 494 | case OP_SH_TAP_TOGGLE: | ||
| 495 | /* tap toggle */ | ||
| 496 | if (tap_count > 0) { | ||
| 497 | if (!event.pressed) { | ||
| 498 | swap_hands = !swap_hands; | ||
| 499 | } | ||
| 500 | } else { | ||
| 501 | swap_hands = event.pressed; | ||
| 502 | } | ||
| 503 | break; | ||
| 504 | default: | ||
| 505 | if (tap_count > 0) { | ||
| 506 | if (event.pressed) { | ||
| 507 | register_code(action.swap.code); | ||
| 508 | } else { | ||
| 509 | unregister_code(action.swap.code); | ||
| 510 | } | ||
| 511 | } else { | ||
| 512 | swap_hands = event.pressed; | ||
| 513 | } | ||
| 514 | #endif | ||
| 515 | } | ||
| 516 | #endif | ||
| 443 | #ifndef NO_ACTION_FUNCTION | 517 | #ifndef NO_ACTION_FUNCTION |
| 444 | case ACT_FUNCTION: | 518 | case ACT_FUNCTION: |
| 445 | action_function(record, action.func.id, action.func.opt); | 519 | action_function(record, action.func.id, action.func.opt); |
| @@ -652,6 +726,13 @@ bool is_tap_key(keypos_t key) | |||
| 652 | return true; | 726 | return true; |
| 653 | } | 727 | } |
| 654 | return false; | 728 | return false; |
| 729 | case ACT_SWAP_HANDS: | ||
| 730 | switch (action.swap.code) { | ||
| 731 | case 0x00 ... 0xdf: | ||
| 732 | case OP_SH_TAP_TOGGLE: | ||
| 733 | return true; | ||
| 734 | } | ||
| 735 | return false; | ||
| 655 | case ACT_MACRO: | 736 | case ACT_MACRO: |
| 656 | case ACT_FUNCTION: | 737 | case ACT_FUNCTION: |
| 657 | if (action.func.opt & FUNC_TAP) { return true; } | 738 | if (action.func.opt & FUNC_TAP) { return true; } |
| @@ -692,6 +773,7 @@ void debug_action(action_t action) | |||
| 692 | case ACT_MACRO: dprint("ACT_MACRO"); break; | 773 | case ACT_MACRO: dprint("ACT_MACRO"); break; |
| 693 | case ACT_COMMAND: dprint("ACT_COMMAND"); break; | 774 | case ACT_COMMAND: dprint("ACT_COMMAND"); break; |
| 694 | case ACT_FUNCTION: dprint("ACT_FUNCTION"); break; | 775 | case ACT_FUNCTION: dprint("ACT_FUNCTION"); break; |
| 776 | case ACT_SWAP_HANDS: dprint("ACT_SWAP_HANDS"); break; | ||
| 695 | default: dprint("UNKNOWN"); break; | 777 | default: dprint("UNKNOWN"); break; |
| 696 | } | 778 | } |
| 697 | dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff); | 779 | dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff); |
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index e8aa12a7c..b9bdfe642 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h | |||
| @@ -65,6 +65,24 @@ bool process_record_quantum(keyrecord_t *record); | |||
| 65 | #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) | 65 | #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) |
| 66 | extern bool disable_action_cache; | 66 | extern bool disable_action_cache; |
| 67 | #endif | 67 | #endif |
| 68 | |||
| 69 | /* Code for handling one-handed key modifiers. */ | ||
| 70 | #ifdef ONEHAND_ENABLE | ||
| 71 | extern bool swap_hands; | ||
| 72 | extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS]; | ||
| 73 | #if (MATRIX_COLS <= 8) | ||
| 74 | typedef uint8_t swap_state_row_t; | ||
| 75 | #elif (MATRIX_COLS <= 16) | ||
| 76 | typedef uint16_t swap_state_row_t; | ||
| 77 | #elif (MATRIX_COLS <= 32) | ||
| 78 | typedef uint32_t swap_state_row_t; | ||
| 79 | #else | ||
| 80 | #error "MATRIX_COLS: invalid value" | ||
| 81 | #endif | ||
| 82 | |||
| 83 | void process_hand_swap(keyevent_t *record); | ||
| 84 | #endif | ||
| 85 | |||
| 68 | void process_record_nocache(keyrecord_t *record); | 86 | void process_record_nocache(keyrecord_t *record); |
| 69 | void process_record(keyrecord_t *record); | 87 | void process_record(keyrecord_t *record); |
| 70 | void process_action(keyrecord_t *record, action_t action); | 88 | void process_action(keyrecord_t *record, action_t action); |
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h index ca729aaec..33da35f35 100644 --- a/tmk_core/common/action_code.h +++ b/tmk_core/common/action_code.h | |||
| @@ -108,6 +108,8 @@ enum action_kind_id { | |||
| 108 | /* Other Keys */ | 108 | /* Other Keys */ |
| 109 | ACT_USAGE = 0b0100, | 109 | ACT_USAGE = 0b0100, |
| 110 | ACT_MOUSEKEY = 0b0101, | 110 | ACT_MOUSEKEY = 0b0101, |
| 111 | /* One-hand Support */ | ||
| 112 | ACT_SWAP_HANDS = 0b0110, | ||
| 111 | /* Layer Actions */ | 113 | /* Layer Actions */ |
| 112 | ACT_LAYER = 0b1000, | 114 | ACT_LAYER = 0b1000, |
| 113 | ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */ | 115 | ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */ |
| @@ -178,6 +180,11 @@ typedef union { | |||
| 178 | uint8_t opt :4; | 180 | uint8_t opt :4; |
| 179 | uint8_t kind :4; | 181 | uint8_t kind :4; |
| 180 | } func; | 182 | } func; |
| 183 | struct action_swap { | ||
| 184 | uint8_t code :8; | ||
| 185 | uint8_t opt :4; | ||
| 186 | uint8_t kind :4; | ||
| 187 | } swap; | ||
| 181 | } action_t; | 188 | } action_t; |
| 182 | 189 | ||
| 183 | 190 | ||
| @@ -295,6 +302,7 @@ enum backlight_opt { | |||
| 295 | BACKLIGHT_STEP = 3, | 302 | BACKLIGHT_STEP = 3, |
| 296 | BACKLIGHT_LEVEL = 4, | 303 | BACKLIGHT_LEVEL = 4, |
| 297 | }; | 304 | }; |
| 305 | |||
| 298 | /* Macro */ | 306 | /* Macro */ |
| 299 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) | 307 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) |
| 300 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) | 308 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) |
| @@ -306,7 +314,7 @@ enum backlight_opt { | |||
| 306 | #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) | 314 | #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) |
| 307 | #define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | (level)) | 315 | #define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | (level)) |
| 308 | /* Command */ | 316 | /* Command */ |
| 309 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) | 317 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (id)) |
| 310 | /* Function */ | 318 | /* Function */ |
| 311 | enum function_opts { | 319 | enum function_opts { |
| 312 | FUNC_TAP = 0x8, /* indciates function is tappable */ | 320 | FUNC_TAP = 0x8, /* indciates function is tappable */ |
| @@ -314,5 +322,23 @@ enum function_opts { | |||
| 314 | #define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id)) | 322 | #define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id)) |
| 315 | #define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id)) | 323 | #define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id)) |
| 316 | #define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id)) | 324 | #define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id)) |
| 325 | /* OneHand Support */ | ||
| 326 | enum swap_hands_pram_tap_op { | ||
| 327 | OP_SH_TOGGLE = 0xF0, | ||
| 328 | OP_SH_TAP_TOGGLE, | ||
| 329 | OP_SH_ON_OFF, | ||
| 330 | OP_SH_OFF_ON, | ||
| 331 | OP_SH_OFF, | ||
| 332 | OP_SH_ON, | ||
| 333 | }; | ||
| 334 | |||
| 335 | #define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF() | ||
| 336 | #define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE) | ||
| 337 | #define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE) | ||
| 338 | #define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key) | ||
| 339 | #define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF) | ||
| 340 | #define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON) | ||
| 341 | #define ACTION_SWAP_HANDS_ON() ACTION(ACT_SWAP_HANDS, OP_SH_ON) | ||
| 342 | #define ACTION_SWAP_HANDS_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_OFF) | ||
| 317 | 343 | ||
| 318 | #endif /* ACTION_CODE_H */ | 344 | #endif /* ACTION_CODE_H */ |
