diff --git a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp index c9708cbf..b1a53fb6 100644 --- a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp +++ b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Escape-OneShot -- Turn ESC into a key that cancels OneShots, if active. - * Copyright (C) 2016-2020 Keyboard.io, Inc + * Copyright (C) 2016-2021 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -24,14 +24,21 @@ namespace kaleidoscope { namespace plugin { -Key EscapeOneShot::cancel_oneshot_key_{Key_Escape}; +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 // sticky. Last, only if there are no OneShot keys currently being held. - if (event.key == cancel_oneshot_key_ && + if (event.key == settings_.cancel_oneshot_key && keyToggledOn(event.state) && !keyIsInjected(event.state) && ::OneShot.isActive()) { diff --git a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h index 90e8511b..d94111db 100644 --- a/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h +++ b/plugins/Kaleidoscope-Escape-OneShot/src/kaleidoscope/plugin/Escape-OneShot.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Escape-OneShot -- Turn ESC into a key that cancels OneShots, if active. - * Copyright (C) 2016-2020 Keyboard.io, Inc + * Copyright (C) 2016-2021 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -24,19 +24,41 @@ constexpr Key OneShotCancelKey {kaleidoscope::ranges::OS_CANCEL}; namespace kaleidoscope { namespace plugin { + class EscapeOneShot : public kaleidoscope::Plugin { public: EscapeOneShot(void) {} EventHandlerResult onKeyEvent(KeyEvent &event); - void setCancelKey(Key cancel_key) { - cancel_oneshot_key_ = cancel_key; + static void setCancelKey(Key cancel_key) { + settings_.cancel_oneshot_key = cancel_key; + } + 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; } private: - static Key cancel_oneshot_key_; + struct Settings { + bool disabled; + Key cancel_oneshot_key; + }; + static Settings settings_; }; +}; + } }