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

@ -28,22 +28,8 @@ active if another one-shot of the same type is tapped, so `Ctrl, Alt, b` becomes
## Using the plugin ## Using the plugin
There are two major ways in which the plugin can be used: one is to turn After adding one-shot keys to the keymap, all one needs to do, is enable the
existing modifiers or momentary layer toggles into one-shot keys: plugin:
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-OneShot.h>
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:
```c++ ```c++
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
@ -53,8 +39,8 @@ The other is to explicitly mark keys as one-shot in the keymap:
OSM(LCtrl), OSL(_FN) OSM(LCtrl), OSL(_FN)
void setup () { void setup () {
Kaleidoscope.setup (KEYMAP_SIZE); Kaleidoscope.setup ();
Kaleidoscope.use (&OneShot, NULL); 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 The plugin provides one object, `OneShot`, which implements both one-shot
modifiers and one-shot layer keys. It has the following methods: 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()` ### `.isActive()`
> Returns if any one-shot key is in flight. This makes it possible to > 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 > sticky one-shot effects. If omitted, it defaults to `false`, and not canceling
> stickies. > 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` ### `.timeOut`
> The number of milliseconds to wait before timing out and cancelling the > The number of milliseconds to wait before timing out and cancelling the

@ -56,54 +56,9 @@ namespace KaleidoscopePlugins {
#define isSameAsPrevious(key) (key.raw == prevKey.raw) #define isSameAsPrevious(key) (key.raw == prevKey.raw)
#define saveAsPrevious(key) prevKey.raw = key.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) #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 ---- // ---- 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 void
OneShot::injectNormalKey (uint8_t idx, uint8_t keyState) { OneShot::injectNormalKey (uint8_t idx, uint8_t keyState) {
Key key; Key key;
@ -314,23 +269,6 @@ namespace KaleidoscopePlugins {
shouldCancelStickies = withStickies; 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 void
OneShot::inject (Key key, uint8_t keyState) { OneShot::inject (Key key, uint8_t keyState) {
eventHandlerHook (key, 255, 255, keyState); eventHandlerHook (key, 255, 255, keyState);

@ -31,9 +31,6 @@ namespace KaleidoscopePlugins {
virtual void begin (void) final; virtual void begin (void) final;
static void on (void);
static void off (void);
static void enableAuto (void);
static bool isActive (void); static bool isActive (void);
static void cancel (bool withStickies); static void cancel (bool withStickies);
static void cancel (void) { cancel (false); }; static void cancel (void) { cancel (false); };
@ -63,10 +60,6 @@ namespace KaleidoscopePlugins {
static void unmask (byte row, byte col); static void unmask (byte row, byte col);
static bool isMasked (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 Key eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState);
static void loopHook (bool postClear); static void loopHook (bool postClear);
}; };

Loading…
Cancel
Save