Skip to content

Commit

Permalink
Numpad now properly restores the former numlock state on deactivation.
Browse files Browse the repository at this point in the history
Test procedure:
  1. Make sure numlock is off on host machine.
  2. Activate num layer. Confirm, numlock is now on.
  3. Deactivate num layer. Confirm, numlock is now off.
  4. Using another keyboard, activate numlock on host machine.
  5. Activate num layer. Confirm, numlock is still on.
  6. Deactivate num layer. Confirm, numlock is still on.

Prior to this commit, step 6 resulted in numlock being off.

see keyboardio#2
see keyboardio#3
see keyboardio#1
see keyboardio#6
  • Loading branch information
MartyGentillon committed Mar 15, 2018
1 parent 78710d0 commit 105fc14
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Kaleidoscope-NumPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ void NumPad_::begin(void) {
originalNumLockState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
}

static bool getNumlockState() {
return !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
}

static void syncNumlock(bool state) {
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
bool numState = getNumlockState();
if (numState != state) {
kaleidoscope::hid::pressKey(Key_KeypadNumLock);
}
Expand All @@ -26,16 +30,15 @@ void NumPad_::loopHook(bool postClear) {
return;

if (!Layer.isOn(numPadLayer)) {
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
bool numState = getNumlockState();
if (!cleanupDone) {
LEDControl.set_mode(LEDControl.get_mode_index());
syncNumlock(false);
cleanupDone = true;

if (numState && !originalNumLockState) {
kaleidoscope::hid::pressKey(Key_KeypadNumLock);
if (!originalNumLockState) {
syncNumlock(false);
numState = false;
}
cleanupDone = true;
}
originalNumLockState = numState;
return;
Expand Down

0 comments on commit 105fc14

Please sign in to comment.