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 <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 7 years ago
parent f2d73d4d71
commit 58d07f1e06

@ -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))

@ -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);
};
}

Loading…
Cancel
Save