Add a "no-delay" mode to SpaceCadet

SpaceCadet now has three "modes": on, off, and on with no delay. In "no-delay"
mode, when a SpaceCadet key is pressed, its primary (modifier) key value is sent
immediately to the host, and if it is released before timing out, that value is
then replaced by the configured "tap" value of the key.

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1037/head
Michael Richters 4 years ago
parent 768c95ae46
commit 2faa7c00a9
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -117,7 +117,7 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(KeyEvent &event) {
}
// Do nothing if disabled, but keep the event tracker current.
if (mode_ != Mode::ON)
if (mode_ == Mode::OFF)
return EventHandlerResult::OK;
if (!event_queue_.isEmpty()) {
@ -145,7 +145,13 @@ EventHandlerResult SpaceCadet::onKeyswitchEvent(KeyEvent &event) {
// Check for a SpaceCadet key
pending_map_index_ = getSpaceCadetKeyIndex(event.key);
if (pending_map_index_ >= 0) {
// A SpaceCadet key was pressed
// A SpaceCadet key has just toggled on. First, if we're in no-delay mode,
// we need to send the event unchanged (with the primary `Key` value),
// bypassing other `onKeyswitchEvent()` handlers.
if (mode_ == Mode::NO_DELAY)
Runtime.handleKeyEvent(event);
// Queue the press event and abort; this press event will be resolved
// later.
event_queue_.append(event);
return EventHandlerResult::ABORT;
}
@ -194,6 +200,11 @@ void SpaceCadet::flushQueue() {
void SpaceCadet::flushEvent(bool is_tap) {
KeyEvent event = event_queue_.event(0);
if (is_tap && pending_map_index_ >= 0) {
// If we're in no-delay mode, we should first send the release of the
// modifier key as a courtesy before sending the tap event.
if (mode_ == Mode::NO_DELAY) {
Runtime.handleKeyEvent(KeyEvent(event.addr, WAS_PRESSED));
}
event.key = map[pending_map_index_].output;
}
event_queue_.shift();

@ -66,8 +66,11 @@ class SpaceCadet : public kaleidoscope::Plugin {
static void disable() {
mode_ = Mode::OFF;
}
static void enableWithoutDelay() {
mode_ = Mode::NO_DELAY;
}
static bool active() {
return (mode_ == Mode::ON);
return (mode_ == Mode::ON || mode_ == Mode::NO_DELAY);
}
// Publically accessible variables

Loading…
Cancel
Save