From cbec7c1b1af3256194826c3ea7375668f0279edf Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 19 Jan 2017 11:21:13 +0100 Subject: [PATCH] More reliable modifier tracking Instead of tracking the modifiers in a loop hook, track them in the event handler. We catch all modifiers, even injected ones. This makes things more reliable, because the loop hook can also catch modifiers that TopsyTurvy injected, which is not desirable. Oh, yeah, we do not catch TopsyTurvy-injected modifiers, because we use the Keyboard singleton directly, instead of injecting the keys back into the workflow. This reduces the jitter described in #1, but does not fix it on its own. Signed-off-by: Gergely Nagy --- src/Akela/TopsyTurvy.cpp | 21 +++++---------------- src/Akela/TopsyTurvy.h | 3 --- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/Akela/TopsyTurvy.cpp b/src/Akela/TopsyTurvy.cpp index 31ae9cc4..5df183f3 100644 --- a/src/Akela/TopsyTurvy.cpp +++ b/src/Akela/TopsyTurvy.cpp @@ -31,7 +31,6 @@ namespace Akela { void TopsyTurvy::begin (void) { event_handler_hook_add (this->eventHandlerHook); - loop_hook_add (this->loopHook); } void @@ -42,13 +41,11 @@ namespace Akela { void TopsyTurvy::on (void) { event_handler_hook_replace (this->noOpHook, this->eventHandlerHook); - loop_hook_replace (this->noOpLoopHook, this->loopHook); } void TopsyTurvy::off (void) { event_handler_hook_replace (this->eventHandlerHook, this->noOpHook); - loop_hook_replace (this->loopHook, this->noOpLoopHook); } Key @@ -56,19 +53,6 @@ namespace Akela { return mappedKey; } - void - TopsyTurvy::noOpLoopHook (bool postClear) { - } - - void - TopsyTurvy::loopHook (bool postClear) { - if (postClear) - return; - - bitWrite (topsyTurvyModState, 0, Keyboard.isModifierActive (Key_LShift.keyCode)); - bitWrite (topsyTurvyModState, 1, Keyboard.isModifierActive (Key_RShift.keyCode)); - } - Key TopsyTurvy::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) { if (keyState & TOPSYTURVY) @@ -77,6 +61,11 @@ namespace Akela { if (!topsyTurvyList) return mappedKey; + if (mappedKey.raw == Key_LShift.raw) + bitWrite (topsyTurvyModState, 0, key_is_pressed (keyState)); + if (mappedKey.raw == Key_RShift.raw) + bitWrite (topsyTurvyModState, 1, key_is_pressed (keyState)); + if (!key_is_pressed (keyState) && !key_was_pressed (keyState)) return mappedKey; diff --git a/src/Akela/TopsyTurvy.h b/src/Akela/TopsyTurvy.h index bc4fabb3..d62e828f 100644 --- a/src/Akela/TopsyTurvy.h +++ b/src/Akela/TopsyTurvy.h @@ -38,9 +38,6 @@ namespace Akela { static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static Key noOpHook (Key, byte row, byte col, uint8_t keyState); - - static void loopHook (bool postClear); - static void noOpLoopHook (bool postClear); }; };