EscapeOneShot: Remove run-time toggleability

It turns out that being able to toggle the plugin at run-time is unnecessary: if
one wants to disable the functionality, they can just set the cancel key to
something that will never be pressed.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/1090/head
Gergely Nagy 3 years ago
parent efdae81b3a
commit 32c175d51e
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -70,23 +70,9 @@ configuration methods:
> Returns the `Key` value that will trigger deactivation of one-shot (including > Returns the `Key` value that will trigger deactivation of one-shot (including
> sticky) keys. > sticky) keys.
### `.enable()`, `.disable()`, `.toggle()`, and `.isEnabled()`
> Enables, disables, toggles, and returns the enabled state of the plugin,
> respectively.
>
> By default, the plugin starts enabled.
## Focus commands ## Focus commands
The plugin provides two Focus commands: `escape_oneshot.enabled`, and The plugin provides a single Focus command: `escape_oneshot.cancel_key`.
`escape_oneshot.cancel_key`.
### `escape_oneshot.enabled [0|1]`
> Without arguments, returns whether the plugin is enabled or not.
>
> With an argument, enables or disables it.
### `escape_oneshot.cancel_key [keycode]` ### `escape_oneshot.cancel_key [keycode]`

@ -29,15 +29,12 @@ uint16_t EscapeOneShotConfig::settings_base_;
EventHandlerResult EscapeOneShotConfig::onSetup() { EventHandlerResult EscapeOneShotConfig::onSetup() {
settings_base_ = ::EEPROMSettings.requestSlice(sizeof(EscapeOneShot::settings_)); settings_base_ = ::EEPROMSettings.requestSlice(sizeof(EscapeOneShot::settings_));
struct { uint16_t checker;
uint8_t b;
uint16_t w;
} checker;
Runtime.storage().get(settings_base_, checker); Runtime.storage().get(settings_base_, checker);
// Check if we have an empty eeprom... // Check if we have an empty eeprom...
if (checker.b == 0xff && checker.w == 0xffff) { if (checker == 0xffff) {
// ...if the eeprom was empty, store the default settings. // ...if the eeprom was empty, store the default settings.
Runtime.storage().put(settings_base_, EscapeOneShot::settings_); Runtime.storage().put(settings_base_, EscapeOneShot::settings_);
Runtime.storage().commit(); Runtime.storage().commit();
@ -52,40 +49,12 @@ EventHandlerResult EscapeOneShotConfig::onNameQuery() {
} }
EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) { EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) {
enum { if (::Focus.handleHelp(command, PSTR("escape_oneshot.cancel_key")))
ENABLED,
CANCEL_KEY
} subCommand;
if (::Focus.handleHelp(command, PSTR("escape_oneshot.enabled\n"
"escape_oneshot.cancel_key")))
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (strncmp_P(command, PSTR("escape_oneshot."), 15) != 0) if (strcmp_P(command, PSTR("escape_oneshot.cancel_key")) != 0)
return EventHandlerResult::OK;
if (strcmp_P(command + 15, PSTR("enabled")) == 0)
subCommand = ENABLED;
else if (strcmp_P(command + 15, PSTR("cancel_key")) == 0)
subCommand = CANCEL_KEY;
else
return EventHandlerResult::OK; return EventHandlerResult::OK;
switch (subCommand) {
case ENABLED:
if (::Focus.isEOL()) {
::Focus.send(::EscapeOneShot.isEnabled());
} else {
uint8_t v;
::Focus.read(v);
if (v != 0) {
::EscapeOneShot.enable();
} else {
::EscapeOneShot.disable();
}
}
break;
case CANCEL_KEY:
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
::Focus.send(::EscapeOneShot.getCancelKey()); ::Focus.send(::EscapeOneShot.getCancelKey());
} else { } else {
@ -93,8 +62,6 @@ EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) {
::Focus.read(k); ::Focus.read(k);
::EscapeOneShot.setCancelKey(k); ::EscapeOneShot.setCancelKey(k);
} }
break;
}
Runtime.storage().put(settings_base_, EscapeOneShot::settings_); Runtime.storage().put(settings_base_, EscapeOneShot::settings_);
Runtime.storage().commit(); Runtime.storage().commit();

@ -25,15 +25,10 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
EscapeOneShot::Settings EscapeOneShot::settings_ = { EscapeOneShot::Settings EscapeOneShot::settings_ = {
.disabled = false,
.cancel_oneshot_key = Key_Escape .cancel_oneshot_key = Key_Escape
}; };
EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) { EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) {
// If we're disabled, just pass through.
if (settings_.disabled)
return EventHandlerResult::OK;
// We only act on an escape key (or `cancel_oneshot_key_`, if that has been // We only act on an escape key (or `cancel_oneshot_key_`, if that has been
// set) that has just been pressed, and not generated by some other // set) that has just been pressed, and not generated by some other
// plugin. Also, only if at least one OneShot key is active and/or // plugin. Also, only if at least one OneShot key is active and/or

@ -40,24 +40,11 @@ class EscapeOneShot : public kaleidoscope::Plugin {
static Key getCancelKey() { static Key getCancelKey() {
return settings_.cancel_oneshot_key; return settings_.cancel_oneshot_key;
} }
static void enable() {
settings_.disabled = false;
}
static void disable() {
settings_.disabled = true;
}
static void toggle() {
settings_.disabled = !settings_.disabled;
}
static bool isEnabled() {
return !settings_.disabled;
}
friend class EscapeOneShotConfig; friend class EscapeOneShotConfig;
private: private:
struct Settings { struct Settings {
bool disabled;
Key cancel_oneshot_key; Key cancel_oneshot_key;
}; };
static Settings settings_; static Settings settings_;
@ -69,7 +56,6 @@ class EscapeOneShotConfig : public Plugin {
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
private: private:
static uint16_t settings_base_; static uint16_t settings_base_;
}; };

Loading…
Cancel
Save