From d010846280c093d0e95bec2229c9b82512ff60ce Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 8 Jun 2017 15:16:44 +0200 Subject: [PATCH] Instead of repeating the highest index, repeat the last one To mimic the normal repeat, track the last topsy key that was pressed, and if there are multiple ones active, ignore anything but the youngest. This makes it possible to hold multiple topsy keys, and have the last one repeat. It does not handle the topsy+normal chording case, though. But this fixes #4 in a better way. Signed-off-by: Gergely Nagy --- src/Kaleidoscope/TopsyTurvy.cpp | 17 +++++++---------- src/Kaleidoscope/TopsyTurvy.h | 3 +-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Kaleidoscope/TopsyTurvy.cpp b/src/Kaleidoscope/TopsyTurvy.cpp index 4d0ce21f..1310df56 100644 --- a/src/Kaleidoscope/TopsyTurvy.cpp +++ b/src/Kaleidoscope/TopsyTurvy.cpp @@ -23,14 +23,13 @@ namespace kaleidoscope { uint8_t TopsyTurvy::mod_state_; -bool TopsyTurvy::is_active_; +uint8_t TopsyTurvy::last_pressed_position_; TopsyTurvy::TopsyTurvy(void) { } void TopsyTurvy::begin(void) { event_handler_hook_use(eventHandlerHook); - loop_hook_use(loopHook); } Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { @@ -48,10 +47,12 @@ Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key if (mapped_key < ranges::TT_FIRST || mapped_key > ranges::TT_LAST) return mapped_key; - if (is_active_) - return Key_NoKey; - - is_active_ = true; + if (key_toggled_on(key_state)) + last_pressed_position_ = row * COLS + col; + else { + if (last_pressed_position_ != row * COLS + col) + return Key_NoKey; + } Key new_key = {.raw = mapped_key.raw - ranges::TT_FIRST}; if (new_key.raw == Key_NoKey.raw) @@ -82,10 +83,6 @@ Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key return Key_NoKey; } -void TopsyTurvy::loopHook(bool is_post_clear) { - is_active_ = false; -} - } kaleidoscope::TopsyTurvy TopsyTurvy; diff --git a/src/Kaleidoscope/TopsyTurvy.h b/src/Kaleidoscope/TopsyTurvy.h index d3441399..f97f665c 100644 --- a/src/Kaleidoscope/TopsyTurvy.h +++ b/src/Kaleidoscope/TopsyTurvy.h @@ -32,10 +32,9 @@ class TopsyTurvy: public KaleidoscopePlugin { void begin(void) final; private: static uint8_t mod_state_; - static bool is_active_; + static uint8_t last_pressed_position_; static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state); - static void loopHook(bool is_post_clear); }; }