aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action.c82
-rw-r--r--tmk_core/common/action.h18
-rw-r--r--tmk_core/common/action_code.h28
3 files changed, 127 insertions, 1 deletions
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
63bool swap_hands = false;
64
65void 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)
57bool disable_action_cache = false; 83bool 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)
66extern bool disable_action_cache; 66extern bool disable_action_cache;
67#endif 67#endif
68
69/* Code for handling one-handed key modifiers. */
70#ifdef ONEHAND_ENABLE
71extern bool swap_hands;
72extern const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
73#if (MATRIX_COLS <= 8)
74typedef uint8_t swap_state_row_t;
75#elif (MATRIX_COLS <= 16)
76typedef uint16_t swap_state_row_t;
77#elif (MATRIX_COLS <= 32)
78typedef uint32_t swap_state_row_t;
79#else
80#error "MATRIX_COLS: invalid value"
81#endif
82
83void process_hand_swap(keyevent_t *record);
84#endif
85
68void process_record_nocache(keyrecord_t *record); 86void process_record_nocache(keyrecord_t *record);
69void process_record(keyrecord_t *record); 87void process_record(keyrecord_t *record);
70void process_action(keyrecord_t *record, action_t action); 88void 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 */
311enum function_opts { 319enum 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 */
326enum 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 */