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 <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 684db7bd02
commit d010846280

@ -23,14 +23,13 @@
namespace kaleidoscope { namespace kaleidoscope {
uint8_t TopsyTurvy::mod_state_; uint8_t TopsyTurvy::mod_state_;
bool TopsyTurvy::is_active_; uint8_t TopsyTurvy::last_pressed_position_;
TopsyTurvy::TopsyTurvy(void) { TopsyTurvy::TopsyTurvy(void) {
} }
void TopsyTurvy::begin(void) { void TopsyTurvy::begin(void) {
event_handler_hook_use(eventHandlerHook); event_handler_hook_use(eventHandlerHook);
loop_hook_use(loopHook);
} }
Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) { 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) if (mapped_key < ranges::TT_FIRST || mapped_key > ranges::TT_LAST)
return mapped_key; return mapped_key;
if (is_active_) if (key_toggled_on(key_state))
last_pressed_position_ = row * COLS + col;
else {
if (last_pressed_position_ != row * COLS + col)
return Key_NoKey; return Key_NoKey;
}
is_active_ = true;
Key new_key = {.raw = mapped_key.raw - ranges::TT_FIRST}; Key new_key = {.raw = mapped_key.raw - ranges::TT_FIRST};
if (new_key.raw == Key_NoKey.raw) 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; return Key_NoKey;
} }
void TopsyTurvy::loopHook(bool is_post_clear) {
is_active_ = false;
}
} }
kaleidoscope::TopsyTurvy TopsyTurvy; kaleidoscope::TopsyTurvy TopsyTurvy;

@ -32,10 +32,9 @@ class TopsyTurvy: public KaleidoscopePlugin {
void begin(void) final; void begin(void) final;
private: private:
static uint8_t mod_state_; 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 Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
static void loopHook(bool is_post_clear);
}; };
} }

Loading…
Cancel
Save