diff options
-rw-r--r-- | doc/keymap.md | 18 | ||||
-rw-r--r-- | tmk_core/common.mk | 4 | ||||
-rw-r--r-- | tmk_core/common/action.c | 33 | ||||
-rw-r--r-- | tmk_core/common/action.h | 18 | ||||
-rw-r--r-- | tmk_core/common/action_code.h | 8 |
5 files changed, 80 insertions, 1 deletions
diff --git a/doc/keymap.md b/doc/keymap.md index d1985e567..1285ad6cd 100644 --- a/doc/keymap.md +++ b/doc/keymap.md | |||
@@ -455,6 +455,24 @@ 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 is executed 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 | The configuration table is a simple 2-dimensional array to map from column/row to new column/row. Example `hand_swap_config` for Planck: | ||
462 | |||
463 | ``` | ||
464 | const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { | ||
465 | {{11, 0}, {10, 0}, {9, 0}, {8, 0}, {7, 0}, {6, 0}, {5, 0}, {4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}}, | ||
466 | {{11, 1}, {10, 1}, {9, 1}, {8, 1}, {7, 1}, {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}}, | ||
467 | {{11, 2}, {10, 2}, {9, 2}, {8, 2}, {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}}, | ||
468 | {{11, 3}, {10, 3}, {9, 3}, {8, 3}, {7, 3}, {6, 3}, {5, 3}, {4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}}, | ||
469 | }; | ||
470 | ``` | ||
471 | |||
472 | 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). | ||
473 | |||
474 | |||
475 | |||
458 | ## 3. Layer switching Example | 476 | ## 3. Layer switching Example |
459 | There are some ways to switch layer with 'Layer' actions. | 477 | There are some ways to switch layer with 'Layer' actions. |
460 | 478 | ||
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..0413b1a99 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 | ||
@@ -439,6 +465,13 @@ void process_action(keyrecord_t *record, action_t action) | |||
439 | break; | 465 | break; |
440 | #endif | 466 | #endif |
441 | case ACT_COMMAND: | 467 | case ACT_COMMAND: |
468 | switch (action.command.id) { | ||
469 | #ifdef ONEHAND_ENABLE | ||
470 | case CMD_SWAP_HANDS: | ||
471 | swap_hands = event.pressed; | ||
472 | break; | ||
473 | #endif | ||
474 | } | ||
442 | break; | 475 | break; |
443 | #ifndef NO_ACTION_FUNCTION | 476 | #ifndef NO_ACTION_FUNCTION |
444 | case ACT_FUNCTION: | 477 | case ACT_FUNCTION: |
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..95d2cbf3e 100644 --- a/tmk_core/common/action_code.h +++ b/tmk_core/common/action_code.h | |||
@@ -295,6 +295,10 @@ enum backlight_opt { | |||
295 | BACKLIGHT_STEP = 3, | 295 | BACKLIGHT_STEP = 3, |
296 | BACKLIGHT_LEVEL = 4, | 296 | BACKLIGHT_LEVEL = 4, |
297 | }; | 297 | }; |
298 | |||
299 | enum command_id { | ||
300 | CMD_SWAP_HANDS = 0x14, | ||
301 | }; | ||
298 | /* Macro */ | 302 | /* Macro */ |
299 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) | 303 | #define ACTION_MACRO(id) ACTION(ACT_MACRO, (id)) |
300 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) | 304 | #define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id)) |
@@ -306,7 +310,7 @@ enum backlight_opt { | |||
306 | #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) | 310 | #define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8) |
307 | #define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | (level)) | 311 | #define ACTION_BACKLIGHT_LEVEL(level) ACTION(ACT_BACKLIGHT, BACKLIGHT_LEVEL << 8 | (level)) |
308 | /* Command */ | 312 | /* Command */ |
309 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) | 313 | #define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (id)) |
310 | /* Function */ | 314 | /* Function */ |
311 | enum function_opts { | 315 | enum function_opts { |
312 | FUNC_TAP = 0x8, /* indciates function is tappable */ | 316 | FUNC_TAP = 0x8, /* indciates function is tappable */ |
@@ -314,5 +318,7 @@ enum function_opts { | |||
314 | #define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id)) | 318 | #define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id)) |
315 | #define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id)) | 319 | #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)) | 320 | #define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id)) |
321 | /* OneHand Support */ | ||
322 | #define ACTION_SWAP_HANDS() ACTION_COMMAND(CMD_SWAP_HANDS, 0) | ||
317 | 323 | ||
318 | #endif /* ACTION_CODE_H */ | 324 | #endif /* ACTION_CODE_H */ |