From da2bc4d656240c4664ccb2318eb785f5a7dc8ee3 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 1 Feb 2017 14:22:31 +0100 Subject: [PATCH] Expose a way to set the timeOut Fixes #6. Signed-off-by: Gergely Nagy --- README.md | 9 +++++++++ src/Akela/OneShot.cpp | 6 +++--- src/Akela/OneShot.h | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6ff09727..bb9e7415 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,15 @@ modifiers and one-shot layer keys. It has the following methods: > momentary layer switchers. As `on()`, this method is idempotent, and can be > called at any time, from anywhere. +### `.timeOut` + +> The number of loop iterations to wait before timing out and cancelling the +> one-shot effect, unless interrupted or cancelled before by any other means. +> +> Not strictly a method, it is a variable one can assign a new value to. +> +> Defaults to 40. + ## Further reading Starting from the [example][plugin:example] is the recommended way of getting diff --git a/src/Akela/OneShot.cpp b/src/Akela/OneShot.cpp index 77c45e1c..98693683 100644 --- a/src/Akela/OneShot.cpp +++ b/src/Akela/OneShot.cpp @@ -24,7 +24,7 @@ namespace Akela { // ---- state --------- uint8_t OneShot::Timer = 0; - uint8_t OneShot::TimeOut = DEFAULT_TIMEOUT; + uint8_t OneShot::timeOut = 40; uint32_t OneShot::State = 0; uint32_t OneShot::stickyState = 0; uint32_t OneShot::pressedState = 0; @@ -57,7 +57,7 @@ namespace Akela { #define toNormalMod(key, idx) {key.flags = 0; key.keyCode = Key_LCtrl.keyCode + idx;} #define toNormalMT(key, idx) { key.raw = Key_NoKey.raw; Layer.on (idx - 8); } -#define hasTimedOut() (Timer >= TimeOut) +#define hasTimedOut() (Timer >= timeOut) // ----- passthrough ------ @@ -255,7 +255,7 @@ namespace Akela { return; if (postClear) { - if (Timer < TimeOut) + if (Timer < timeOut) Timer++; if (hasTimedOut ()) diff --git a/src/Akela/OneShot.h b/src/Akela/OneShot.h index 4902c0c0..77b7377e 100644 --- a/src/Akela/OneShot.h +++ b/src/Akela/OneShot.h @@ -36,6 +36,7 @@ namespace Akela { static bool isActive (void); static void cancel (bool withStickies); static void cancel (void) { cancel (false); }; + static uint8_t timeOut; static bool isModifierActive (Key key); @@ -43,7 +44,6 @@ namespace Akela { private: static uint8_t Timer; - static uint8_t TimeOut; static uint32_t State; static uint32_t stickyState; static uint32_t pressedState;