1
0
Fork 0
forked from forks/qmk_firmware

Tidy up use of keycode range helpers (#19756)

This commit is contained in:
Joel Challis 2023-02-10 21:10:14 +00:00 committed by GitHub
parent 2ffdec5dc2
commit 1d0b4c8d38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 39 additions and 33 deletions

View file

@ -189,7 +189,7 @@ extern "C" {
bool matrix_is_on(uint8_t row, uint8_t col) {
uint8_t code = CODE(row, col);
if (IS_MOD(code)) {
if (IS_MODIFIER_KEYCODE(code)) {
if (local_keyboard_report.mods & ROW_BITS(code)) {
return true;
}
@ -205,7 +205,7 @@ extern "C" {
matrix_row_t matrix_get_row(uint8_t row) {
uint16_t row_bits = 0;
if (IS_MOD(CODE(row, 0)) && local_keyboard_report.mods) {
if (IS_MODIFIER_KEYCODE(CODE(row, 0)) && local_keyboard_report.mods) {
row_bits |= local_keyboard_report.mods;
}

View file

@ -47,7 +47,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
}
if (!IS_MOD(keycode) && record->event.pressed) {
if (!IS_MODIFIER_KEYCODE(keycode) && record->event.pressed) {
if(keycode == KC_E || keycode == KC_A || keycode == KC_O || keycode == KC_I || keycode == KC_U) {
predecessor_key = KC_O;
vowel_proximity = timer_read();

View file

@ -175,7 +175,7 @@ extern "C"
bool matrix_is_on(uint8_t row, uint8_t col) {
uint8_t code = CODE(row, col);
if (IS_MOD(code)) {
if (IS_MODIFIER_KEYCODE(code)) {
if (local_keyboard_report.mods & ROW_BITS(code)) {
return true;
}
@ -191,7 +191,7 @@ extern "C"
matrix_row_t matrix_get_row(uint8_t row) {
uint16_t row_bits = 0;
if (IS_MOD(CODE(row, 0)) && local_keyboard_report.mods) {
if (IS_MODIFIER_KEYCODE(CODE(row, 0)) && local_keyboard_report.mods) {
row_bits |= local_keyboard_report.mods;
}

View file

@ -45,7 +45,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
backlight_level(6);
}
if (IS_MOD(keycode)) {
if (IS_MODIFIER_KEYCODE(keycode)) {
if (record->event.pressed) {
rgblight_setrgb(RGB_RED);
} else {

View file

@ -8,6 +8,14 @@ from qmk.path import normpath
from qmk.keycodes import load_spec
def _translate_group(group):
"""Fix up any issues with badly chosen values
"""
if group == 'modifiers':
return 'modifier'
return group
def _render_key(key):
width = 7
if 'S(' in key:
@ -82,7 +90,7 @@ def _generate_helpers(lines, keycodes):
for group, codes in temp.items():
lo = keycodes["keycodes"][f'0x{codes[0]:04X}']['key']
hi = keycodes["keycodes"][f'0x{codes[1]:04X}']['key']
lines.append(f'#define IS_{ group.upper() }_KEYCODE(code) ((code) >= {lo} && (code) <= {hi})')
lines.append(f'#define IS_{ _translate_group(group).upper() }_KEYCODE(code) ((code) >= {lo} && (code) <= {hi})')
def _generate_aliases(lines, keycodes):

View file

@ -351,7 +351,7 @@ void process_action(keyrecord_t *record, action_t action) {
bool do_release_oneshot = false;
// notice we only clear the one shot layer if the pressed key is not a modifier.
if (is_oneshot_layer_active() && event.pressed &&
(action.kind.id == ACT_USAGE || !(IS_MOD(action.key.code)
(action.kind.id == ACT_USAGE || !(IS_MODIFIER_KEYCODE(action.key.code)
# ifndef NO_ACTION_TAPPING
|| (tap_count == 0 && (action.kind.id == ACT_LMODS_TAP || action.kind.id == ACT_RMODS_TAP))
# endif
@ -372,7 +372,7 @@ void process_action(keyrecord_t *record, action_t action) {
uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : action.key.mods << 4;
if (event.pressed) {
if (mods) {
if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
// e.g. LSFT(KC_LEFT_GUI): we don't want the LSFT to be weak as it would make it useless.
// This also makes LSFT(KC_LEFT_GUI) behave exactly the same as LGUI(KC_LEFT_SHIFT).
// Same applies for some keys like KC_MEH which are declared as MEH(KC_NO).
@ -386,7 +386,7 @@ void process_action(keyrecord_t *record, action_t action) {
} else {
unregister_code(action.key.code);
if (mods) {
if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
del_mods(mods);
} else {
del_weak_mods(mods);
@ -406,7 +406,7 @@ void process_action(keyrecord_t *record, action_t action) {
if (!keymap_config.oneshot_enable) {
if (event.pressed) {
if (mods) {
if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
// e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless.
// This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT).
// Same applies for some keys like KC_MEH which are declared as MEH(KC_NO).
@ -420,7 +420,7 @@ void process_action(keyrecord_t *record, action_t action) {
} else {
unregister_code(action.key.code);
if (mods) {
if (IS_MOD(action.key.code) || action.key.code == KC_NO) {
if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
del_mods(mods);
} else {
del_weak_mods(mods);
@ -877,7 +877,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
send_keyboard_report();
#endif
} else if IS_KEY (code) {
} else if IS_BASIC_KEYCODE (code) {
// TODO: should push command_proc out of this block?
if (command_proc(code)) return;
@ -890,7 +890,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
}
add_key(code);
send_keyboard_report();
} else if IS_MOD (code) {
} else if IS_MODIFIER_KEYCODE (code) {
add_mods(MOD_BIT(code));
send_keyboard_report();
@ -944,10 +944,10 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
send_keyboard_report();
#endif
} else if IS_KEY (code) {
} else if IS_BASIC_KEYCODE (code) {
del_key(code);
send_keyboard_report();
} else if IS_MOD (code) {
} else if IS_MODIFIER_KEYCODE (code) {
del_mods(MOD_BIT(code));
send_keyboard_report();

View file

@ -247,12 +247,12 @@ bool process_tapping(keyrecord_t *keyp) {
case ACT_LMODS:
case ACT_RMODS:
if (action.key.mods && !action.key.code) return false;
if (IS_MOD(action.key.code)) return false;
if (IS_MODIFIER_KEYCODE(action.key.code)) return false;
break;
case ACT_LMODS_TAP:
case ACT_RMODS_TAP:
if (action.key.mods && keyp->tap.count == 0) return false;
if (IS_MOD(action.key.code)) return false;
if (IS_MODIFIER_KEYCODE(action.key.code)) return false;
break;
case ACT_LAYER_TAP:
case ACT_LAYER_TAP_EXT:

View file

@ -27,8 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* FIXME: Add doxygen comments here */
#define IS_ANY(code) (KC_A <= (code) && (code) <= 0xFF)
#define IS_KEY(code) IS_BASIC_KEYCODE(code)
#define IS_MOD(code) IS_MODIFIERS_KEYCODE(code)
#define IS_SYSTEM(code) IS_SYSTEM_KEYCODE(code)
#define IS_CONSUMER(code) IS_MEDIA_KEYCODE(code)

View file

@ -1321,7 +1321,7 @@ enum qk_keycode_defines {
#define IS_SYSTEM_KEYCODE(code) ((code) >= KC_SYSTEM_POWER && (code) <= KC_SYSTEM_WAKE)
#define IS_MEDIA_KEYCODE(code) ((code) >= KC_AUDIO_MUTE && (code) <= KC_ASSISTANT)
#define IS_MOUSE_KEYCODE(code) ((code) >= KC_MS_UP && (code) <= KC_MS_ACCEL2)
#define IS_MODIFIERS_KEYCODE(code) ((code) >= KC_LEFT_CTRL && (code) <= KC_RIGHT_GUI)
#define IS_MODIFIER_KEYCODE(code) ((code) >= KC_LEFT_CTRL && (code) <= KC_RIGHT_GUI)
#define IS_SWAP_HANDS_KEYCODE(code) ((code) >= QK_SWAP_HANDS_TOGGLE && (code) <= QK_SWAP_HANDS_ONE_SHOT)
#define IS_MAGIC_KEYCODE(code) ((code) >= MAGIC_SWAP_CONTROL_CAPSLOCK && (code) <= MAGIC_TOGGLE_ESCAPE_CAPSLOCK)
#define IS_MIDI_KEYCODE(code) ((code) >= QK_MIDI_ON && (code) <= QK_MIDI_PITCH_BEND_UP)

View file

@ -69,7 +69,7 @@ typedef struct {
#endif
/* check if keycode is only modifiers */
#define KEYCODE_IS_MOD(code) (IS_MOD(code) || (code >= QK_MODS && code <= QK_MODS_MAX && !(code & QK_BASIC_MAX)))
#define KEYCODE_IS_MOD(code) (IS_MODIFIER_KEYCODE(code) || (IS_QK_MODS(code) && !QK_MODS_GET_BASIC_KEYCODE(code)))
bool process_combo(uint16_t keycode, keyrecord_t *record);
void combo_task(void);

View file

@ -402,7 +402,7 @@ bool process_key_override(const uint16_t keycode, const keyrecord_t *const recor
#endif
const bool key_down = record->event.pressed;
const bool is_mod = IS_MOD(keycode);
const bool is_mod = IS_MODIFIER_KEYCODE(keycode);
if (key_down) {
switch (keycode) {

View file

@ -89,16 +89,16 @@ void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdM
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
sc_mods = get_mods();
#endif
if (IS_MOD(holdMod)) {
if (IS_MODIFIER_KEYCODE(holdMod)) {
register_mods(MOD_BIT(holdMod));
}
} else {
if (sc_last == holdMod && timer_elapsed(sc_timer) < GET_TAPPING_TERM(sc_keycode, record)) {
if (holdMod != tapMod) {
if (IS_MOD(holdMod)) {
if (IS_MODIFIER_KEYCODE(holdMod)) {
unregister_mods(MOD_BIT(holdMod));
}
if (IS_MOD(tapMod)) {
if (IS_MODIFIER_KEYCODE(tapMod)) {
register_mods(MOD_BIT(tapMod));
}
}
@ -109,11 +109,11 @@ void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdM
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
clear_weak_mods();
#endif
if (IS_MOD(tapMod)) {
if (IS_MODIFIER_KEYCODE(tapMod)) {
unregister_mods(MOD_BIT(tapMod));
}
} else {
if (IS_MOD(holdMod)) {
if (IS_MODIFIER_KEYCODE(holdMod)) {
unregister_mods(MOD_BIT(holdMod));
}
}

View file

@ -76,7 +76,7 @@ void do_code16(uint16_t code, void (*f)(uint8_t)) {
}
__attribute__((weak)) void register_code16(uint16_t code) {
if (IS_MOD(code) || code == KC_NO) {
if (IS_MODIFIER_KEYCODE(code) || code == KC_NO) {
do_code16(code, register_mods);
} else {
do_code16(code, register_weak_mods);
@ -86,7 +86,7 @@ __attribute__((weak)) void register_code16(uint16_t code) {
__attribute__((weak)) void unregister_code16(uint16_t code) {
unregister_code(code);
if (IS_MOD(code) || code == KC_NO) {
if (IS_MODIFIER_KEYCODE(code) || code == KC_NO) {
do_code16(code, unregister_mods);
} else {
do_code16(code, unregister_weak_mods);

View file

@ -97,7 +97,7 @@ std::ostream& operator<<(std::ostream& os, const report_keyboard_t& report) {
KeyboardReportMatcher::KeyboardReportMatcher(const std::vector<uint8_t>& keys) {
memset(m_report.raw, 0, sizeof(m_report.raw));
for (auto k : keys) {
if (IS_MOD(k)) {
if (IS_MODIFIER_KEYCODE(k)) {
m_report.mods |= MOD_BIT(k);
} else {
add_key_to_report(&m_report, k);

View file

@ -89,7 +89,7 @@ static void comma_period(uint16_t keycode) {
bool process_record_vimlayer(uint16_t keycode, keyrecord_t *record) {
/****** mod passthru *****/
if(record->event.pressed && layer_state_is(vim_cmd_layer()) && (IS_MOD(keycode) || keycode == LSFT(KC_LALT))) {
if(record->event.pressed && layer_state_is(vim_cmd_layer()) && (IS_MODIFIER_KEYCODE(keycode) || keycode == LSFT(KC_LALT))) {
mod_override_layer_state = layer_state;
mod_override_triggering_key = keycode;
// TODO: change this to track key location instead

View file

@ -139,7 +139,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
/****** mod passthru *****/
if(record->event.pressed && layer_state_is(vim_cmd_layer()) && (IS_MOD(keycode) || keycode == LSFT(KC_LALT))) {
if(record->event.pressed && layer_state_is(vim_cmd_layer()) && (IS_MODIFIER_KEYCODE(keycode) || keycode == LSFT(KC_LALT))) {
mod_override_layer_state = layer_state;
mod_override_triggering_key = keycode;
// TODO: change this to track key location instead