Merge pull request #1090 from keyboardio/plugin/escape-oneshot/config

EscapeOneShot: Remove run-time toggleability
pull/1094/head
Gergely Nagy 3 years ago committed by GitHub
commit 4b1e122317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -70,23 +70,9 @@ configuration methods:
> Returns the `Key` value that will trigger deactivation of one-shot (including
> 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
The plugin provides two Focus commands: `escape_oneshot.enabled`, and
`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.
The plugin provides a single Focus command: `escape_oneshot.cancel_key`.
### `escape_oneshot.cancel_key [keycode]`

@ -29,15 +29,12 @@ uint16_t EscapeOneShotConfig::settings_base_;
EventHandlerResult EscapeOneShotConfig::onSetup() {
settings_base_ = ::EEPROMSettings.requestSlice(sizeof(EscapeOneShot::settings_));
struct {
uint8_t b;
uint16_t w;
} checker;
uint16_t checker;
Runtime.storage().get(settings_base_, checker);
// 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.
Runtime.storage().put(settings_base_, EscapeOneShot::settings_);
Runtime.storage().commit();
@ -52,40 +49,12 @@ EventHandlerResult EscapeOneShotConfig::onNameQuery() {
}
EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) {
enum {
ENABLED,
CANCEL_KEY
} subCommand;
if (::Focus.handleHelp(command, PSTR("escape_oneshot.enabled\n"
"escape_oneshot.cancel_key")))
if (::Focus.handleHelp(command, PSTR("escape_oneshot.cancel_key")))
return EventHandlerResult::OK;
if (strncmp_P(command, PSTR("escape_oneshot."), 15) != 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
if (strcmp_P(command, PSTR("escape_oneshot.cancel_key")) != 0)
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()) {
::Focus.send(::EscapeOneShot.getCancelKey());
} else {
@ -93,8 +62,6 @@ EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) {
::Focus.read(k);
::EscapeOneShot.setCancelKey(k);
}
break;
}
Runtime.storage().put(settings_base_, EscapeOneShot::settings_);
Runtime.storage().commit();

@ -25,15 +25,10 @@ namespace kaleidoscope {
namespace plugin {
EscapeOneShot::Settings EscapeOneShot::settings_ = {
.disabled = false,
.cancel_oneshot_key = Key_Escape
};
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
// 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

@ -40,24 +40,11 @@ class EscapeOneShot : public kaleidoscope::Plugin {
static Key getCancelKey() {
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;
private:
struct Settings {
bool disabled;
Key cancel_oneshot_key;
};
static Settings settings_;
@ -69,7 +56,6 @@ class EscapeOneShotConfig : public Plugin {
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onNameQuery();
private:
static uint16_t settings_base_;
};

Loading…
Cancel
Save