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

@ -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;

@ -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);
};
};

Loading…
Cancel
Save