Merge pull request #7 from MartyGentillon/master

Numpad now properly restores the former numlock state on deactivation.
pull/365/head
Jesse Vincent 6 years ago committed by GitHub
commit 386787f1ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,8 +15,12 @@ kaleidoscope::EventHandlerResult NumPad_::onSetup(void) {
return kaleidoscope::EventHandlerResult::OK; return kaleidoscope::EventHandlerResult::OK;
} }
static bool getNumlockState() {
return !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
}
static void syncNumlock(bool state) { static void syncNumlock(bool state) {
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); bool numState = getNumlockState();
if (numState != state) { if (numState != state) {
kaleidoscope::hid::pressKey(Key_KeypadNumLock); kaleidoscope::hid::pressKey(Key_KeypadNumLock);
} }
@ -24,16 +28,15 @@ static void syncNumlock(bool state) {
kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() { kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() {
if (!Layer.isOn(numPadLayer)) { if (!Layer.isOn(numPadLayer)) {
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); bool numState = getNumlockState();
if (!cleanupDone) { if (!cleanupDone) {
LEDControl.set_mode(LEDControl.get_mode_index()); LEDControl.set_mode(LEDControl.get_mode_index());
syncNumlock(false);
cleanupDone = true;
if (numState && !originalNumLockState) { if (!originalNumLockState) {
kaleidoscope::hid::pressKey(Key_KeypadNumLock); syncNumlock(false);
numState = false; numState = false;
} }
cleanupDone = true;
} }
originalNumLockState = numState; originalNumLockState = numState;

Loading…
Cancel
Save