Fix bug in do_code16() (#6935)

* Fix bug in `do_code16()`

* Remove qk_ mods functions
This commit is contained in:
fauxpark 2019-10-16 10:02:09 +11:00 committed by Joel Challis
parent 4522519079
commit 63f4806d7a
3 changed files with 45 additions and 37 deletions

View file

@ -85,44 +85,28 @@ static void do_code16(uint16_t code, void (*f)(uint8_t)) {
return; return;
} }
if (code & QK_LCTL) f(KC_LCTL); uint8_t mods_to_send = 0;
if (code & QK_LSFT) f(KC_LSFT);
if (code & QK_LALT) f(KC_LALT);
if (code & QK_LGUI) f(KC_LGUI);
if (code < QK_RMODS_MIN) return; if (code & QK_RMODS_MIN) { // Right mod flag is set
if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL);
if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT);
if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT);
if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI);
} else {
if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL);
if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT);
if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT);
if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
}
if (code & QK_RCTL) f(KC_RCTL); f(mods_to_send);
if (code & QK_RSFT) f(KC_RSFT);
if (code & QK_RALT) f(KC_RALT);
if (code & QK_RGUI) f(KC_RGUI);
}
static inline void qk_register_weak_mods(uint8_t kc) {
add_weak_mods(MOD_BIT(kc));
send_keyboard_report();
}
static inline void qk_unregister_weak_mods(uint8_t kc) {
del_weak_mods(MOD_BIT(kc));
send_keyboard_report();
}
static inline void qk_register_mods(uint8_t kc) {
add_weak_mods(MOD_BIT(kc));
send_keyboard_report();
}
static inline void qk_unregister_mods(uint8_t kc) {
del_weak_mods(MOD_BIT(kc));
send_keyboard_report();
} }
void register_code16(uint16_t code) { void register_code16(uint16_t code) {
if (IS_MOD(code) || code == KC_NO) { if (IS_MOD(code) || code == KC_NO) {
do_code16(code, qk_register_mods); do_code16(code, register_mods);
} else { } else {
do_code16(code, qk_register_weak_mods); do_code16(code, register_weak_mods);
} }
register_code(code); register_code(code);
} }
@ -130,9 +114,9 @@ void register_code16(uint16_t code) {
void unregister_code16(uint16_t code) { void unregister_code16(uint16_t code) {
unregister_code(code); unregister_code(code);
if (IS_MOD(code) || code == KC_NO) { if (IS_MOD(code) || code == KC_NO) {
do_code16(code, qk_unregister_mods); do_code16(code, unregister_mods);
} else { } else {
do_code16(code, qk_unregister_weak_mods); do_code16(code, unregister_weak_mods);
} }
} }

View file

@ -868,9 +868,9 @@ void tap_code(uint8_t code) {
unregister_code(code); unregister_code(code);
} }
/** \brief Utilities for actions. (FIXME: Needs better description) /** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately.
* *
* FIXME: Needs documentation. * \param mods A bitfield of modifiers to unregister.
*/ */
void register_mods(uint8_t mods) { void register_mods(uint8_t mods) {
if (mods) { if (mods) {
@ -879,9 +879,9 @@ void register_mods(uint8_t mods) {
} }
} }
/** \brief Utilities for actions. (FIXME: Needs better description) /** \brief Removes the given physically pressed modifiers and sends a keyboard report immediately.
* *
* FIXME: Needs documentation. * \param mods A bitfield of modifiers to unregister.
*/ */
void unregister_mods(uint8_t mods) { void unregister_mods(uint8_t mods) {
if (mods) { if (mods) {
@ -890,6 +890,28 @@ void unregister_mods(uint8_t mods) {
} }
} }
/** \brief Adds the given weak modifiers and sends a keyboard report immediately.
*
* \param mods A bitfield of modifiers to register.
*/
void register_weak_mods(uint8_t mods) {
if (mods) {
add_weak_mods(mods);
send_keyboard_report();
}
}
/** \brief Removes the given weak modifiers and sends a keyboard report immediately.
*
* \param mods A bitfield of modifiers to unregister.
*/
void unregister_weak_mods(uint8_t mods) {
if (mods) {
del_weak_mods(mods);
send_keyboard_report();
}
}
/** \brief Utilities for actions. (FIXME: Needs better description) /** \brief Utilities for actions. (FIXME: Needs better description)
* *
* FIXME: Needs documentation. * FIXME: Needs documentation.

View file

@ -90,6 +90,8 @@ void unregister_code(uint8_t code);
void tap_code(uint8_t code); void tap_code(uint8_t code);
void register_mods(uint8_t mods); void register_mods(uint8_t mods);
void unregister_mods(uint8_t mods); void unregister_mods(uint8_t mods);
void register_weak_mods(uint8_t mods);
void unregister_weak_mods(uint8_t mods);
// void set_mods(uint8_t mods); // void set_mods(uint8_t mods);
void clear_keyboard(void); void clear_keyboard(void);
void clear_keyboard_but_mods(void); void clear_keyboard_but_mods(void);