core: Clean up code of Locking key support

This commit is contained in:
tmk 2020-11-07 16:39:15 +09:00
parent df164fecc9
commit ab083c7ecf

View file

@ -375,37 +375,28 @@ void register_code(uint8_t code)
} }
#ifdef LOCKING_SUPPORT_ENABLE #ifdef LOCKING_SUPPORT_ENABLE
else if (KC_LOCKING_CAPS == code) { else if (code == KC_LOCKING_CAPS ||
#ifdef LOCKING_RESYNC_ENABLE code == KC_LOCKING_NUM ||
// Resync: ignore if caps lock already is on code == KC_LOCKING_SCROLL) {
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return; uint8_t c, l;
#endif if (code == KC_LOCKING_CAPS) {
add_key(KC_CAPSLOCK); c = KC_CAPSLOCK;
send_keyboard_report(); l = 1<<USB_LED_CAPS_LOCK;
wait_ms(100); } else if (code == KC_LOCKING_NUM) {
del_key(KC_CAPSLOCK); c = KC_NUMLOCK;
send_keyboard_report(); l = 1<<USB_LED_NUM_LOCK;
} else if (code == KC_LOCKING_SCROLL) {
c = KC_SCROLLLOCK;
l = 1<<USB_LED_SCROLL_LOCK;
} }
else if (KC_LOCKING_NUM == code) {
#ifdef LOCKING_RESYNC_ENABLE #ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return; // Resync: ignore if lock indicator is already on
if (host_keyboard_leds() & l) return;
#endif #endif
add_key(KC_NUMLOCK); add_key(c);
send_keyboard_report(); send_keyboard_report();
wait_ms(100); wait_ms(100); // Delay for MacOS #390
del_key(KC_NUMLOCK); del_key(c);
send_keyboard_report();
}
else if (KC_LOCKING_SCROLL == code) {
#ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return;
#endif
add_key(KC_SCROLLLOCK);
send_keyboard_report();
wait_ms(100);
del_key(KC_SCROLLLOCK);
send_keyboard_report(); send_keyboard_report();
} }
#endif #endif
@ -453,37 +444,28 @@ void unregister_code(uint8_t code)
} }
#ifdef LOCKING_SUPPORT_ENABLE #ifdef LOCKING_SUPPORT_ENABLE
else if (KC_LOCKING_CAPS == code) { else if (code == KC_LOCKING_CAPS ||
#ifdef LOCKING_RESYNC_ENABLE code == KC_LOCKING_NUM ||
// Resync: ignore if caps lock already is off code == KC_LOCKING_SCROLL) {
if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return; uint8_t c, l;
#endif if (code == KC_LOCKING_CAPS) {
add_key(KC_CAPSLOCK); c = KC_CAPSLOCK;
send_keyboard_report(); l = 1<<USB_LED_CAPS_LOCK;
wait_ms(100); } else if (code == KC_LOCKING_NUM) {
del_key(KC_CAPSLOCK); c = KC_NUMLOCK;
send_keyboard_report(); l = 1<<USB_LED_NUM_LOCK;
} else if (code == KC_LOCKING_SCROLL) {
c = KC_SCROLLLOCK;
l = 1<<USB_LED_SCROLL_LOCK;
} }
else if (KC_LOCKING_NUM == code) {
#ifdef LOCKING_RESYNC_ENABLE #ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return; // Resync: ignore if lock indicator is already off
if (!(host_keyboard_leds() & l)) return;
#endif #endif
add_key(KC_NUMLOCK); add_key(c);
send_keyboard_report(); send_keyboard_report();
wait_ms(100); wait_ms(100); // Delay for MacOS #390
del_key(KC_NUMLOCK); del_key(c);
send_keyboard_report();
}
else if (KC_LOCKING_SCROLL == code) {
#ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return;
#endif
add_key(KC_SCROLLLOCK);
send_keyboard_report();
wait_ms(100);
del_key(KC_SCROLLLOCK);
send_keyboard_report(); send_keyboard_report();
} }
#endif #endif