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