From a880eea367965aa75f5f0a328b372386e9dbf712 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 31 Mar 2017 12:55:40 +0200 Subject: [PATCH] Add a way to hook into the lock/unlock mechanism The callback can't prevent the action, but it can have side effects, such as lighting up the LEDs, when the keyboard becomes locked (or unlocked). Signed-off-by: Gergely Nagy --- src/Kaleidoscope/TypingBreaks.cpp | 10 ++++++++++ src/Kaleidoscope/TypingBreaks.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/Kaleidoscope/TypingBreaks.cpp b/src/Kaleidoscope/TypingBreaks.cpp index 24168232..356caf9f 100644 --- a/src/Kaleidoscope/TypingBreaks.cpp +++ b/src/Kaleidoscope/TypingBreaks.cpp @@ -60,6 +60,8 @@ namespace KaleidoscopePlugins { lockStartTime = 0; leftHandKeys = rightHandKeys = 0; sessionStartTime = millis (); + + TypingBreak (false); } // Any other case, we are not locked yet! (or we just unlocked) @@ -75,12 +77,14 @@ namespace KaleidoscopePlugins { // If we have a limit on the left hand, and we reached it, lock up! if (settings.leftHandMaxKeys && leftHandKeys >= settings.leftHandMaxKeys) { lockStartTime = millis (); + TypingBreak (true); return Key_NoKey; } // If we have a limit on the right hand, and we reached it, lock up! if (settings.rightHandMaxKeys && rightHandKeys >= settings.rightHandMaxKeys) { lockStartTime = millis (); + TypingBreak (true); return Key_NoKey; } @@ -89,6 +93,7 @@ namespace KaleidoscopePlugins { if (millis () - sessionStartTime >= settings.lockTimeOut) { // Yeah, it is. lockStartTime = millis (); + TypingBreak (true); return Key_NoKey; } } @@ -191,3 +196,8 @@ namespace KaleidoscopePlugins { }; KaleidoscopePlugins::TypingBreaks TypingBreaks; + +__attribute__((weak)) +void +TypingBreak (bool isLocked) { +} diff --git a/src/Kaleidoscope/TypingBreaks.h b/src/Kaleidoscope/TypingBreaks.h index 9ef8a858..cea9133c 100644 --- a/src/Kaleidoscope/TypingBreaks.h +++ b/src/Kaleidoscope/TypingBreaks.h @@ -55,6 +55,8 @@ namespace KaleidoscopePlugins { extern KaleidoscopePlugins::TypingBreaks TypingBreaks; +void TypingBreak (bool isLocked); + #define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \ "typingbreaks.idleTimeLimit\n" \ "typingbreaks.lockTimeOut\n" \