From 188b4bc02c458fb282dc7d10b2f96765ddda09eb Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 7 Mar 2017 12:44:15 +0100 Subject: [PATCH] Drop on, off, and enableAuto There are - or will be - better ways to experiment, drop these, lest anyone starts depending on them. Fixes #7. Signed-off-by: Gergely Nagy --- README.md | 44 +++---------------------- src/Kaleidoscope/OneShot.cpp | 62 ------------------------------------ src/Kaleidoscope/OneShot.h | 7 ---- 3 files changed, 4 insertions(+), 109 deletions(-) diff --git a/README.md b/README.md index a28e8901..ab9919f0 100644 --- a/README.md +++ b/README.md @@ -28,22 +28,8 @@ active if another one-shot of the same type is tapped, so `Ctrl, Alt, b` becomes ## Using the plugin -There are two major ways in which the plugin can be used: one is to turn -existing modifiers or momentary layer toggles into one-shot keys: - -```c++ -#include -#include - -void setup () { - OneShot.enableAuto (); - - Kaleidoscope.setup (KEYMAP_SIZE); - Kaleidoscope.use (&OneShot, NULL); -} -``` - -The other is to explicitly mark keys as one-shot in the keymap: +After adding one-shot keys to the keymap, all one needs to do, is enable the +plugin: ```c++ #include @@ -53,8 +39,8 @@ The other is to explicitly mark keys as one-shot in the keymap: OSM(LCtrl), OSL(_FN) void setup () { - Kaleidoscope.setup (KEYMAP_SIZE); - Kaleidoscope.use (&OneShot, NULL); + Kaleidoscope.setup (); + USE_PLUGINS (&OneShot); } ``` @@ -81,16 +67,6 @@ There are two macros the plugin provides: The plugin provides one object, `OneShot`, which implements both one-shot modifiers and one-shot layer keys. It has the following methods: -### `.enableAuto()` - -> Automatically turns modifiers and momentary layer switches into their one-shot -> variant. It will only turn keys on the keymap into one-shots: if any macro -> injects a modifier or a momentary layer switch key, those will be left alone, -> as-is. -> -> This **must** be called before any `Kaleidoscope.use()` call in the `setup()` -> method of your Sketch. - ### `.isActive()` > Returns if any one-shot key is in flight. This makes it possible to @@ -115,18 +91,6 @@ modifiers and one-shot layer keys. It has the following methods: > sticky one-shot effects. If omitted, it defaults to `false`, and not canceling > stickies. -### `.on()` - -> Turns the one-shot behaviour on. This method is idempotent, you can call it -> any number of times, at any time. - -### `.off()` - -> The counterpart of the `on()` method, this turns off one-shot behaviour. -> Modifiers will act as normal modifiers, and one-shot layer keys will act as -> momentary layer switchers. As `on()`, this method is idempotent, and can be -> called at any time, from anywhere. - ### `.timeOut` > The number of milliseconds to wait before timing out and cancelling the diff --git a/src/Kaleidoscope/OneShot.cpp b/src/Kaleidoscope/OneShot.cpp index d07ad0e0..324d4bf5 100644 --- a/src/Kaleidoscope/OneShot.cpp +++ b/src/Kaleidoscope/OneShot.cpp @@ -56,54 +56,9 @@ namespace KaleidoscopePlugins { #define isSameAsPrevious(key) (key.raw == prevKey.raw) #define saveAsPrevious(key) prevKey.raw = key.raw -#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() (millis () - startTime >= timeOut) - // ----- passthrough ------ - - Key - OneShot::eventHandlerPassthroughHook (Key mappedKey, byte row, byte col, uint8_t keyState) { - if (!isOS (mappedKey)) - return mappedKey; - - uint8_t idx = mappedKey.raw - OS_FIRST; - - if (idx >= 8) { - toNormalMT (mappedKey, idx); - } else { - toNormalMod (mappedKey, idx); - } - - return mappedKey; - } - - void - OneShot::loopNoOpHook (bool postClear) { - } - // ---- OneShot stuff ---- - - Key - OneShot::eventHandlerAutoHook (Key mappedKey, byte row, byte col, uint8_t keyState) { - // If mappedKey is an injected key, we don't fiddle with those. - if (keyState & INJECTED) - return mappedKey; - - if (!isModifier (mappedKey) && !isLayerKey (mappedKey)) - return mappedKey; - - if (isModifier (mappedKey)) { - uint8_t idx = mappedKey.keyCode - Key_LCtrl.keyCode; - - return (Key){.raw = OSM_FIRST + idx}; - } else { - uint8_t idx = mappedKey.keyCode - MOMENTARY_OFFSET; - - return (Key){.raw = OSL_FIRST + idx}; - } - } - void OneShot::injectNormalKey (uint8_t idx, uint8_t keyState) { Key key; @@ -314,23 +269,6 @@ namespace KaleidoscopePlugins { shouldCancelStickies = withStickies; } - void - OneShot::on (void) { - event_handler_hook_replace (eventHandlerPassthroughHook, eventHandlerHook); - loop_hook_replace (loopNoOpHook, loopHook); - } - - void - OneShot::off (void) { - event_handler_hook_replace (eventHandlerHook, eventHandlerPassthroughHook); - loop_hook_replace (loopHook, loopNoOpHook); - } - - void - OneShot::enableAuto (void) { - event_handler_hook_use (eventHandlerAutoHook); - } - void OneShot::inject (Key key, uint8_t keyState) { eventHandlerHook (key, 255, 255, keyState); diff --git a/src/Kaleidoscope/OneShot.h b/src/Kaleidoscope/OneShot.h index abae498d..9f9e8ddb 100644 --- a/src/Kaleidoscope/OneShot.h +++ b/src/Kaleidoscope/OneShot.h @@ -31,9 +31,6 @@ namespace KaleidoscopePlugins { virtual void begin (void) final; - static void on (void); - static void off (void); - static void enableAuto (void); static bool isActive (void); static void cancel (bool withStickies); static void cancel (void) { cancel (false); }; @@ -63,10 +60,6 @@ namespace KaleidoscopePlugins { static void unmask (byte row, byte col); static bool isMasked (byte row, byte col); - static Key eventHandlerPassthroughHook (Key mappedKey, byte row, byte col, uint8_t keyState); - static void loopNoOpHook (bool postClear); - - static Key eventHandlerAutoHook (Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState); static void loopHook (bool postClear); };