Small un/register_code() cleanups (#18544)

This commit is contained in:
Ryan 2022-10-01 06:29:24 +10:00 committed by GitHub
parent 8bd73d4455
commit 2c96c75263
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 31 deletions

View file

@ -527,18 +527,10 @@ void process_action(keyrecord_t *record, action_t action) {
case ACT_USAGE:
switch (action.usage.page) {
case PAGE_SYSTEM:
if (event.pressed) {
host_system_send(action.usage.code);
} else {
host_system_send(0);
}
host_system_send(event.pressed ? action.usage.code : 0);
break;
case PAGE_CONSUMER:
if (event.pressed) {
host_consumer_send(action.usage.code);
} else {
host_consumer_send(0);
}
host_consumer_send(event.pressed ? action.usage.code : 0);
break;
}
break;
@ -852,9 +844,9 @@ void process_action(keyrecord_t *record, action_t action) {
__attribute__((weak)) void register_code(uint8_t code) {
if (code == KC_NO) {
return;
}
#ifdef LOCKING_SUPPORT_ENABLE
else if (KC_LOCKING_CAPS_LOCK == code) {
} else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is on
if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return;
@ -864,9 +856,8 @@ __attribute__((weak)) void register_code(uint8_t code) {
wait_ms(TAP_HOLD_CAPS_DELAY);
del_key(KC_CAPS_LOCK);
send_keyboard_report();
}
else if (KC_LOCKING_NUM_LOCK == code) {
} else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return;
# endif
@ -875,9 +866,8 @@ __attribute__((weak)) void register_code(uint8_t code) {
wait_ms(100);
del_key(KC_NUM_LOCK);
send_keyboard_report();
}
else if (KC_LOCKING_SCROLL_LOCK == code) {
} else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return;
# endif
@ -886,10 +876,9 @@ __attribute__((weak)) void register_code(uint8_t code) {
wait_ms(100);
del_key(KC_SCROLL_LOCK);
send_keyboard_report();
}
#endif
else if IS_KEY (code) {
} else if IS_KEY (code) {
// TODO: should push command_proc out of this block?
if (command_proc(code)) return;
@ -922,15 +911,15 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if IS_MOD (code) {
add_mods(MOD_BIT(code));
send_keyboard_report();
}
#ifdef EXTRAKEY_ENABLE
else if IS_SYSTEM (code) {
} else if IS_SYSTEM (code) {
host_system_send(KEYCODE2SYSTEM(code));
} else if IS_CONSUMER (code) {
host_consumer_send(KEYCODE2CONSUMER(code));
}
#endif
else if IS_MOUSEKEY (code) {
} else if IS_MOUSEKEY (code) {
register_mouse(code, true);
}
}
@ -942,9 +931,9 @@ __attribute__((weak)) void register_code(uint8_t code) {
__attribute__((weak)) void unregister_code(uint8_t code) {
if (code == KC_NO) {
return;
}
#ifdef LOCKING_SUPPORT_ENABLE
else if (KC_LOCKING_CAPS_LOCK == code) {
} else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is off
if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return;
@ -953,9 +942,8 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
send_keyboard_report();
del_key(KC_CAPS_LOCK);
send_keyboard_report();
}
else if (KC_LOCKING_NUM_LOCK == code) {
} else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return;
# endif
@ -963,9 +951,8 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
send_keyboard_report();
del_key(KC_NUM_LOCK);
send_keyboard_report();
}
else if (KC_LOCKING_SCROLL_LOCK == code) {
} else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return;
# endif
@ -973,19 +960,22 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
send_keyboard_report();
del_key(KC_SCROLL_LOCK);
send_keyboard_report();
}
#endif
else if IS_KEY (code) {
} else if IS_KEY (code) {
del_key(code);
send_keyboard_report();
} else if IS_MOD (code) {
del_mods(MOD_BIT(code));
send_keyboard_report();
#ifdef EXTRAKEY_ENABLE
} else if IS_SYSTEM (code) {
host_system_send(0);
} else if IS_CONSUMER (code) {
host_consumer_send(0);
#endif
} else if IS_MOUSEKEY (code) {
register_mouse(code, false);
}

View file

@ -192,7 +192,11 @@ enum mods_codes {
/** \brief Other Keys
*/
enum usage_pages { PAGE_SYSTEM, PAGE_CONSUMER };
enum usage_pages {
PAGE_SYSTEM,
PAGE_CONSUMER,
};
#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM << 10 | (id))
#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER << 10 | (id))
#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)