diff --git a/src/Kaleidoscope/OneShot.cpp b/src/Kaleidoscope/OneShot.cpp index 40e9cbb9..5c639490 100644 --- a/src/Kaleidoscope/OneShot.cpp +++ b/src/Kaleidoscope/OneShot.cpp @@ -26,9 +26,9 @@ namespace KaleidoscopePlugins { uint32_t OneShot::startTime = 0; uint16_t OneShot::timeOut = 2500; uint16_t OneShot::holdTimeOut = 250; - uint16_t OneShot::State = 0; - uint16_t OneShot::stickyState = 0; - uint16_t OneShot::pressedState = 0; + OneShot::state_t OneShot::State; + OneShot::state_t OneShot::stickyState; + OneShot::state_t OneShot::pressedState; uint32_t OneShot::leftMask; uint32_t OneShot::rightMask; Key OneShot::prevKey; @@ -41,17 +41,17 @@ namespace KaleidoscopePlugins { #define isModifier(key) (key.raw >= Key_LCtrl.raw && key.raw <= Key_RGUI.raw) #define isLayerKey(key) (key.flags == (KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP) && key.keyCode >= MOMENTARY_OFFSET && key.keyCode <= MOMENTARY_OFFSET + 23) -#define isOneShot(idx) (bitRead (State, (idx))) -#define setOneShot(idx) (bitWrite (State, idx, 1)) -#define clearOneShot(idx) (bitWrite (State, idx, 0)) +#define isOneShot(idx) (bitRead (State.all, (idx))) +#define setOneShot(idx) (bitWrite (State.all, idx, 1)) +#define clearOneShot(idx) (bitWrite (State.all, idx, 0)) -#define isSticky(idx) (bitRead (stickyState, idx)) -#define setSticky(idx) (bitWrite (stickyState, idx, 1)) -#define clearSticky(idx) bitWrite (stickyState, idx, 0) +#define isSticky(idx) (bitRead (stickyState.all, idx)) +#define setSticky(idx) (bitWrite (stickyState.all, idx, 1)) +#define clearSticky(idx) bitWrite (stickyState.all, idx, 0) -#define setPressed(idx) bitWrite(pressedState, idx, 1) -#define clearPressed(idx) bitWrite(pressedState, idx, 0) -#define isPressed(idx) bitRead (pressedState, idx) +#define setPressed(idx) bitWrite(pressedState.all, idx, 1) +#define clearPressed(idx) bitWrite(pressedState.all, idx, 0) +#define isPressed(idx) bitRead (pressedState.all, idx) #define isSameAsPrevious(key) (key.raw == prevKey.raw) #define saveAsPrevious(key) prevKey.raw = key.raw @@ -128,7 +128,7 @@ namespace KaleidoscopePlugins { if (keyState & INJECTED) return mappedKey; - if (!State) { + if (!State.all) { if (!isOS (mappedKey)) { if (isMasked (row, col)) { if (key_toggled_off (keyState)) @@ -207,7 +207,7 @@ namespace KaleidoscopePlugins { void OneShot::loopHook (bool postClear) { - if (!State) + if (!State.all) return; if (postClear) { @@ -252,7 +252,7 @@ namespace KaleidoscopePlugins { bool OneShot::isActive (void) { - return (State && !hasTimedOut ()); + return (State.all && !hasTimedOut ()); } bool diff --git a/src/Kaleidoscope/OneShot.h b/src/Kaleidoscope/OneShot.h index 8a0e4495..54539a5a 100644 --- a/src/Kaleidoscope/OneShot.h +++ b/src/Kaleidoscope/OneShot.h @@ -42,10 +42,17 @@ namespace KaleidoscopePlugins { void inject (Key key, uint8_t keyState); private: + typedef union { + struct { + uint8_t mods; + uint8_t layers; + }; + uint16_t all; + } state_t; static uint32_t startTime; - static uint16_t State; - static uint16_t stickyState; - static uint16_t pressedState; + static state_t State; + static state_t stickyState; + static state_t pressedState; static uint32_t leftMask; static uint32_t rightMask; static Key prevKey;