diff options
Diffstat (limited to 'tmk_core/common')
-rw-r--r-- | tmk_core/common/action.c | 27 | ||||
-rw-r--r-- | tmk_core/common/action_code.h | 2 | ||||
-rw-r--r-- | tmk_core/common/action_layer.c | 2 | ||||
-rw-r--r-- | tmk_core/common/action_layer.h | 15 | ||||
-rw-r--r-- | tmk_core/common/action_util.c | 54 | ||||
-rw-r--r-- | tmk_core/common/action_util.h | 8 | ||||
-rw-r--r-- | tmk_core/common/keyboard.c | 9 | ||||
-rw-r--r-- | tmk_core/common/report.h | 2 | ||||
-rw-r--r-- | tmk_core/common/sendchar_null.c | 2 |
9 files changed, 115 insertions, 6 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index e5e9e27052..3b1268dc94 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -98,6 +98,11 @@ void action_exec(keyevent_t event) { if (has_oneshot_mods_timed_out()) { clear_oneshot_mods(); } +# ifdef SWAP_HANDS_ENABLE + if (has_oneshot_swaphands_timed_out()) { + clear_oneshot_swaphands(); + } +# endif # endif #endif @@ -165,6 +170,8 @@ void process_record_tap_hint(keyrecord_t *record) { # ifdef SWAP_HANDS_ENABLE case ACT_SWAP_HANDS: switch (action.swap.code) { + case OP_SH_ONESHOT: + break; case OP_SH_TAP_TOGGLE: default: swap_hands = !swap_hands; @@ -224,7 +231,11 @@ void process_action(keyrecord_t *record, action_t action) { #ifndef NO_ACTION_ONESHOT bool do_release_oneshot = false; // notice we only clear the one shot layer if the pressed key is not a modifier. - if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)) { + if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code) +# ifdef SWAP_HANDS_ENABLE + && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT) +# endif + ) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); do_release_oneshot = !is_oneshot_layer_active(); } @@ -593,6 +604,14 @@ void process_action(keyrecord_t *record, action_t action) { swap_hands = false; } break; + case OP_SH_ONESHOT: + if (event.pressed) { + set_oneshot_swaphands(); + } else { + release_oneshot_swaphands(); + } + break; + # ifndef NO_ACTION_TAPPING case OP_SH_TAP_TOGGLE: /* tap toggle */ @@ -681,6 +700,12 @@ void process_action(keyrecord_t *record, action_t action) { # endif #endif +#ifdef SWAP_HANDS_ENABLE + if (event.pressed && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)) { + use_oneshot_swaphands(); + } +#endif + #ifndef NO_ACTION_ONESHOT /* Because we switch layers after a oneshot event, we need to release the * key before we leave the layer or no key up event will be generated. diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h index f80b7a782e..eea554ff21 100644 --- a/tmk_core/common/action_code.h +++ b/tmk_core/common/action_code.h @@ -294,11 +294,13 @@ enum swap_hands_param_tap_op { OP_SH_OFF_ON, OP_SH_OFF, OP_SH_ON, + OP_SH_ONESHOT, }; #define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF() #define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE) #define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE) +#define ACTION_SWAP_HANDS_ONESHOT() ACTION(ACT_SWAP_HANDS, OP_SH_ONESHOT) #define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key) #define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF) #define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON) diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 81f86f0f34..af2d7d964b 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -257,7 +257,7 @@ uint8_t layer_switch_get_layer(keypos_t key) { layer_state_t layers = layer_state | default_layer_state; /* check top layer first */ - for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) { + for (int8_t i = MAX_LAYER - 1; i >= 0; i--) { if (layers & (1UL << i)) { action = action_for_key(i, key); if (action.code != ACTION_TRANSPARENT) { diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index c283d26232..16922c1ff9 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -23,12 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #if defined(LAYER_STATE_8BIT) typedef uint8_t layer_state_t; +# define MAX_LAYER_BITS 3 +# ifndef MAX_LAYER +# define MAX_LAYER 8 +# endif # define get_highest_layer(state) biton(state) #elif defined(LAYER_STATE_16BIT) typedef uint16_t layer_state_t; +# define MAX_LAYER_BITS 4 +# ifndef MAX_LAYER +# define MAX_LAYER 16 +# endif # define get_highest_layer(state) biton16(state) #else typedef uint32_t layer_state_t; +# define MAX_LAYER_BITS 5 +# ifndef MAX_LAYER +# define MAX_LAYER 32 +# endif # define get_highest_layer(state) biton32(state) #endif @@ -96,8 +108,7 @@ layer_state_t layer_state_set_kb(layer_state_t state); /* pressed actions cache */ #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) -/* The number of bits needed to represent the layer number: log2(32). */ -# define MAX_LAYER_BITS 5 + void update_source_layers_cache(keypos_t key, uint8_t layer); uint8_t read_source_layers_cache(keypos_t key); #endif diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 335aa36e62..371acfa610 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -83,9 +83,63 @@ static int8_t oneshot_layer_data = 0; inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } +# ifdef SWAP_HANDS_ENABLE +enum { + SHO_OFF, + SHO_ACTIVE, // Swap hands button was pressed, and we didn't send any swapped keys yet + SHO_PRESSED, // Swap hands button is currently pressed + SHO_USED, // Swap hands button is still pressed, and we already sent swapped keys +} swap_hands_oneshot = SHO_OFF; +# endif + # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) static uint16_t oneshot_layer_time = 0; inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); } +# ifdef SWAP_HANDS_ENABLE +static uint16_t oneshot_swaphands_time = 0; +inline bool has_oneshot_swaphands_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= ONESHOT_TIMEOUT && !(swap_hands_oneshot >= SHO_PRESSED); } +# endif +# endif + +# ifdef SWAP_HANDS_ENABLE + +void set_oneshot_swaphands(void) { + swap_hands_oneshot = SHO_PRESSED; + swap_hands = true; +# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) + oneshot_swaphands_time = timer_read(); + if (oneshot_layer_time != 0) { + oneshot_layer_time = oneshot_swaphands_time; + } +# endif +} + +void release_oneshot_swaphands(void) { + if (swap_hands_oneshot == SHO_PRESSED) { + swap_hands_oneshot = SHO_ACTIVE; + } + if (swap_hands_oneshot == SHO_USED) { + clear_oneshot_swaphands(); + } +} + +void use_oneshot_swaphands(void) { + if (swap_hands_oneshot == SHO_PRESSED) { + swap_hands_oneshot = SHO_USED; + } + if (swap_hands_oneshot == SHO_ACTIVE) { + clear_oneshot_swaphands(); + } +} + +void clear_oneshot_swaphands(void) { + swap_hands_oneshot = SHO_OFF; + swap_hands = false; +# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) + oneshot_swaphands_time = 0; +# endif +} + # endif /** \brief Set oneshot layer diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index 1ce03ed0e4..5dd8393da4 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h @@ -77,6 +77,7 @@ void reset_oneshot_layer(void); bool is_oneshot_layer_active(void); uint8_t get_oneshot_layer_state(void); bool has_oneshot_layer_timed_out(void); +bool has_oneshot_swaphands_timed_out(void); void oneshot_locked_mods_changed_user(uint8_t mods); void oneshot_locked_mods_changed_kb(uint8_t mods); @@ -88,6 +89,13 @@ void oneshot_layer_changed_kb(uint8_t layer); /* inspect */ uint8_t has_anymod(void); +#ifdef SWAP_HANDS_ENABLE +void set_oneshot_swaphands(void); +void release_oneshot_swaphands(void); +void use_oneshot_swaphands(void); +void clear_oneshot_swaphands(void); +#endif + #ifdef __cplusplus } #endif diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index a767d9c877..53d08959e8 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -213,6 +213,13 @@ void keyboard_setup(void) { */ __attribute__((weak)) bool is_keyboard_master(void) { return true; } +/** \brief should_process_keypress + * + * Override this function if you have a condition where keypresses processing should change: + * - splits where the slave side needs to process for rgb/oled functionality + */ +__attribute__((weak)) bool should_process_keypress(void) { return is_keyboard_master(); } + /** \brief keyboard_init * * FIXME: needs doc @@ -292,7 +299,7 @@ void keyboard_task(void) { matrix_scan(); #endif - if (is_keyboard_master()) { + if (should_process_keypress()) { for (uint8_t r = 0; r < MATRIX_ROWS; r++) { matrix_row = matrix_get_row(r); matrix_change = matrix_row ^ matrix_prev[r]; diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 61ef6ea66c..c2b1b7c710 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -69,6 +69,8 @@ enum consumer_usages { AL_CALCULATOR = 0x192, AL_LOCAL_BROWSER = 0x194, AL_LOCK = 0x19E, + AL_CONTROL_PANEL = 0x19F, + AL_ASSISTANT = 0x1CB, // 15.16 Generic GUI Application Controls AC_MINIMIZE = 0x206, AC_SEARCH = 0x221, diff --git a/tmk_core/common/sendchar_null.c b/tmk_core/common/sendchar_null.c index f6cab1b9d1..fb67f70866 100644 --- a/tmk_core/common/sendchar_null.c +++ b/tmk_core/common/sendchar_null.c @@ -16,4 +16,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "sendchar.h" -int8_t sendchar(uint8_t c) { return 0; } +__attribute__((weak)) int8_t sendchar(uint8_t c) { return 0; } |