From bde30b0831fc884e24f9966f65c6ea7f00a7f370 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Wed, 28 Apr 2021 14:45:32 -0500 Subject: [PATCH] Use `Key.isKeyboardModifier()` & `Key.isLayerShift()` in OneShot Instead of using a separate version defined in the plugin itself. Signed-off-by: Michael Richters --- .../src/kaleidoscope/plugin/OneShot.cpp | 25 +++---------------- .../src/kaleidoscope/plugin/OneShot.h | 2 -- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp index a8de1935..9b5c7c5f 100644 --- a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp +++ b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.cpp @@ -119,29 +119,12 @@ bool OneShot::isSticky() { // could potentially use three different color values for the three // states (sticky | active && !sticky | pressed && !active). -bool OneShot::isModifier(Key key) { - // Returns `true` if `key` is a modifier key, including modifiers - // with extra mod flags applied (e.g. `Key_Meh`). - if ((key.getFlags() & (SYNTHETIC | RESERVED)) != 0) { - return false; - } - return (key.getKeyCode() >= Key_LeftControl.getKeyCode() && - key.getKeyCode() <= Key_RightGui.getKeyCode()); -} - -bool OneShot::isLayerShift(Key key) { - // Returns `true` if `key` is a layer-shift key. - return (key.getFlags() == (SYNTHETIC | SWITCH_TO_KEYMAP) && - key.getKeyCode() >= LAYER_SHIFT_OFFSET && - key.getKeyCode() < LAYER_MOVE_OFFSET); -} - bool OneShot::isStickable(Key key) { int8_t n; - if (isModifier(key)) { + if (key.isKeyboardModifier()) { n = key.getKeyCode() - Key_LeftControl.getKeyCode(); return bitRead(stickable_keys_, n); - } else if (isLayerShift(key)) { + } else if (key.isLayerShift()) { n = oneshot_mod_count + key.getKeyCode() - LAYER_SHIFT_OFFSET; if (n < oneshot_key_count) { return bitRead(stickable_keys_, n); @@ -434,9 +417,9 @@ uint8_t OneShot::getKeyIndex(Key key) { if (isOneShotKey(key)) { n = getOneShotKeyIndex(key); - } else if (isModifier(key)) { + } else if (key.isKeyboardModifier()) { n = key.getKeyCode() - Key_LeftControl.getKeyCode(); - } else if (isLayerShift(key)) { + } else if (key.isLayerShift()) { n = oneshot_mod_count + key.getKeyCode() - LAYER_SHIFT_OFFSET; } return n; diff --git a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h index 633f8d22..afad5c3a 100644 --- a/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h +++ b/plugins/Kaleidoscope-OneShot/src/kaleidoscope/plugin/OneShot.h @@ -144,8 +144,6 @@ class OneShot : public kaleidoscope::Plugin { return (key.getRaw() >= kaleidoscope::ranges::OS_FIRST && key.getRaw() <= kaleidoscope::ranges::OS_LAST); } - static bool isModifier(Key key); - static bool isLayerShift(Key key); static bool isStickable(Key key); // inline?