From 58d07f1e06c095c8265feadf7114efd7104bb087 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 9 Aug 2017 10:54:46 +0200 Subject: [PATCH] Lift out `isModifier` into its own function To make it easier to extend the plugin, to teach it to highlight keys other than the traditional modifiers, lift the code that checks for a modifier into its own function. No functional change, just refactoring. Signed-off-by: Gergely Nagy --- src/Kaleidoscope/LED-ActiveModColor.cpp | 21 ++++++++++++++------- src/Kaleidoscope/LED-ActiveModColor.h | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Kaleidoscope/LED-ActiveModColor.cpp b/src/Kaleidoscope/LED-ActiveModColor.cpp index f4f77f46..e0d328d7 100644 --- a/src/Kaleidoscope/LED-ActiveModColor.cpp +++ b/src/Kaleidoscope/LED-ActiveModColor.cpp @@ -33,6 +33,19 @@ void ActiveModColorEffect::begin(void) { loop_hook_use(loopHook); } +bool ActiveModColorEffect::isModifier(Key key) { + if (key.raw >= ranges::OSM_FIRST && key.raw <= ranges::OSM_LAST) { + uint8_t idx = key.raw - ranges::OSM_FIRST; + key.flags = 0; + key.keyCode = Key_LeftControl.keyCode + idx; + } + + if (key.raw < Key_LeftControl.raw || key.raw > Key_RightGui.raw) + return false; + + return true; +} + void ActiveModColorEffect::loopHook(bool is_post_clear) { if (is_post_clear) return; @@ -41,13 +54,7 @@ void ActiveModColorEffect::loopHook(bool is_post_clear) { for (byte c = 0; c < COLS; c++) { Key k = Layer.lookup(r, c); - if (k.raw >= ranges::OSM_FIRST && k.raw <= ranges::OSM_LAST) { - uint8_t idx = k.raw - ranges::OSM_FIRST; - k.flags = 0; - k.keyCode = Key_LeftControl.keyCode + idx; - } - - if (k.raw < Key_LeftControl.raw || k.raw > Key_RightGui.raw) + if (!isModifier(k)) continue; if (hid::isModifierKeyActive(k)) diff --git a/src/Kaleidoscope/LED-ActiveModColor.h b/src/Kaleidoscope/LED-ActiveModColor.h index ef75aa1a..6151e3a9 100644 --- a/src/Kaleidoscope/LED-ActiveModColor.h +++ b/src/Kaleidoscope/LED-ActiveModColor.h @@ -31,6 +31,7 @@ class ActiveModColorEffect : public KaleidoscopePlugin { static cRGB highlight_color; private: + static bool isModifier(Key key); static void loopHook(bool is_post_clear); }; }