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

@ -60,6 +60,8 @@ namespace KaleidoscopePlugins {
lockStartTime = 0; lockStartTime = 0;
leftHandKeys = rightHandKeys = 0; leftHandKeys = rightHandKeys = 0;
sessionStartTime = millis (); sessionStartTime = millis ();
TypingBreak (false);
} }
// Any other case, we are not locked yet! (or we just unlocked) // 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 we have a limit on the left hand, and we reached it, lock up!
if (settings.leftHandMaxKeys && leftHandKeys >= settings.leftHandMaxKeys) { if (settings.leftHandMaxKeys && leftHandKeys >= settings.leftHandMaxKeys) {
lockStartTime = millis (); lockStartTime = millis ();
TypingBreak (true);
return Key_NoKey; return Key_NoKey;
} }
// If we have a limit on the right hand, and we reached it, lock up! // If we have a limit on the right hand, and we reached it, lock up!
if (settings.rightHandMaxKeys && rightHandKeys >= settings.rightHandMaxKeys) { if (settings.rightHandMaxKeys && rightHandKeys >= settings.rightHandMaxKeys) {
lockStartTime = millis (); lockStartTime = millis ();
TypingBreak (true);
return Key_NoKey; return Key_NoKey;
} }
@ -89,6 +93,7 @@ namespace KaleidoscopePlugins {
if (millis () - sessionStartTime >= settings.lockTimeOut) { if (millis () - sessionStartTime >= settings.lockTimeOut) {
// Yeah, it is. // Yeah, it is.
lockStartTime = millis (); lockStartTime = millis ();
TypingBreak (true);
return Key_NoKey; return Key_NoKey;
} }
} }
@ -191,3 +196,8 @@ namespace KaleidoscopePlugins {
}; };
KaleidoscopePlugins::TypingBreaks TypingBreaks; KaleidoscopePlugins::TypingBreaks TypingBreaks;
__attribute__((weak))
void
TypingBreak (bool isLocked) {
}

@ -55,6 +55,8 @@ namespace KaleidoscopePlugins {
extern KaleidoscopePlugins::TypingBreaks TypingBreaks; extern KaleidoscopePlugins::TypingBreaks TypingBreaks;
void TypingBreak (bool isLocked);
#define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \ #define FOCUS_HOOK_TYPINGBREAKS FOCUS_HOOK(TypingBreaks.focusHook, \
"typingbreaks.idleTimeLimit\n" \ "typingbreaks.idleTimeLimit\n" \
"typingbreaks.lockTimeOut\n" \ "typingbreaks.lockTimeOut\n" \

Loading…
Cancel
Save