Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small un/register_code() cleanups #18544

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 20 additions & 30 deletions quantum/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
Expand All @@ -953,39 +942,40 @@ __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
add_key(KC_NUM_LOCK);
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
add_key(KC_SCROLL_LOCK);
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);
}
Expand Down
6 changes: 5 additions & 1 deletion quantum/action_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down