@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
/* -*- mode: c++ -*-
* Kaleidoscope - Escape - OneShot - - Turn ESC into a key that cancels OneShots , if active .
* Kaleidoscope - Escape - OneShot - - Turn ESC into a key that cancels OneShots , if active .
* Copyright ( C ) 2016 - 202 0 Keyboard . io , Inc
* Copyright ( C ) 2016 - 202 1 Keyboard . io , Inc
*
*
* This program is free software : you can redistribute it and / or modify it under
* 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
* the terms of the GNU General Public License as published by the Free Software
@ -24,14 +24,21 @@
namespace kaleidoscope {
namespace kaleidoscope {
namespace plugin {
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 ) {
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
// sticky. Last, only if there are no OneShot keys currently being held.
// 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 ) & &
keyToggledOn ( event . state ) & &
! keyIsInjected ( event . state ) & &
! keyIsInjected ( event . state ) & &
: : OneShot . isActive ( ) ) {
: : OneShot . isActive ( ) ) {