From ef6bc728dd1fe7c0139dae4bc71dba3ad98db8ff Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 16 Jun 2018 13:20:04 +0200 Subject: [PATCH] examples/AppSwitcher: Move the holding to loop() For a while now, Kaleidoscope does nothing if keys are idle. This example relied on events being fired in the idle case too. So instead of relying on that, move the holding logic to `loop()`. Signed-off-by: Gergely Nagy --- examples/AppSwitcher/AppSwitcher.ino | 1 + examples/AppSwitcher/Macros.cpp | 17 ++++++++++++----- examples/AppSwitcher/Macros.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/examples/AppSwitcher/AppSwitcher.ino b/examples/AppSwitcher/AppSwitcher.ino index 03933667..fc01408e 100644 --- a/examples/AppSwitcher/AppSwitcher.ino +++ b/examples/AppSwitcher/AppSwitcher.ino @@ -64,5 +64,6 @@ void setup() { } void loop() { + macroAppSwitchLoop(); Kaleidoscope.loop(); } diff --git a/examples/AppSwitcher/Macros.cpp b/examples/AppSwitcher/Macros.cpp index 8055a3d7..af9bdba4 100644 --- a/examples/AppSwitcher/Macros.cpp +++ b/examples/AppSwitcher/Macros.cpp @@ -41,11 +41,6 @@ const macro_t *macroAppSwitch(uint8_t keyState) { if (keyToggledOff(keyState)) { return MACRO(U(Tab), Dr(mod)); } - // Key is not pressed, and was not just released. - // if appSwitchActive is true, we continue holding Alt. - if (appSwitchActive) { - return MACRO(Dr(mod)); - } // otherwise we do nothing return MACRO_NONE; } @@ -55,3 +50,15 @@ const macro_t *macroAppCancel(uint8_t keyState) { appSwitchActive = false; return MACRO_NONE; } + +void macroAppSwitchLoop() { + Key mod = Key_LeftAlt; + + if (HostOS.os() == H::OSX) + mod = Key_LeftGui; + + // if appSwitchActive is true, we continue holding Alt. + if (appSwitchActive) { + handleKeyswitchEvent(mod, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED); + } +} diff --git a/examples/AppSwitcher/Macros.h b/examples/AppSwitcher/Macros.h index f6f6f581..91207e0a 100644 --- a/examples/AppSwitcher/Macros.h +++ b/examples/AppSwitcher/Macros.h @@ -28,3 +28,4 @@ enum { const macro_t *macroAppSwitch(uint8_t keyState); const macro_t *macroAppCancel(uint8_t keyState); +void macroAppSwitchLoop();