Compare commits

...

10 Commits

Author SHA1 Message Date
Andrew M
9b193cc85c
Merge 79c2afa39e into 9bea332a21 2024-11-20 22:22:14 -08:00
Ryan
9bea332a21
qmk via2json: Improve macro parsing (#24345) 2024-11-21 17:20:05 +11:00
Ryan
8cbcdcac62
qmk new-keymap: validate keymap name (#23420) 2024-11-21 17:18:51 +11:00
Andrew M
79c2afa39e
Update tests/auto_shift/test_auto_shift.cpp
Co-authored-by: Drashna Jaelre <drashna@live.com>
2024-10-20 13:16:31 -04:00
Andrew M
f6b3c3ba07
Update tests/auto_shift/test_auto_shift.cpp
Co-authored-by: Drashna Jaelre <drashna@live.com>
2024-10-16 09:22:08 -04:00
Andrew M
28dc7dc812
Update tests/auto_shift/test_auto_shift.cpp
Co-authored-by: Drashna Jaelre <drashna@live.com>
2024-10-12 22:25:50 -04:00
Andrew M
f56ff19d91
Update tests/auto_shift/test_auto_shift.cpp
Co-authored-by: Drashna Jaelre <drashna@live.com>
2024-10-12 22:25:44 -04:00
Andrew M
925f7be986
Update tests/auto_shift/test_auto_shift.cpp
Co-authored-by: Drashna Jaelre <drashna@live.com>
2024-10-12 22:25:40 -04:00
Andrew M
397df6f874
Update test_auto_shift.cpp 2024-09-27 21:20:48 -04:00
Andrew M
2348892402
Fix space cadet and auto shift interaction
https://github.com/qmk/qmk_firmware/issues/20978
2024-09-26 11:44:36 -04:00
4 changed files with 66 additions and 12 deletions

View File

@ -1,5 +1,6 @@
"""This script automates the copying of the default keymap into your own keymap.
"""
import re
import shutil
from milc import cli
@ -13,6 +14,13 @@ from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.userspace import UserspaceDefs
def validate_keymap_name(name):
"""Returns True if the given keymap name contains only a-z, 0-9 and underscore characters.
"""
regex = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_]+$')
return bool(regex.match(name))
def prompt_keyboard():
prompt = """{fg_yellow}Select Keyboard{style_reset_all}
If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}.
@ -60,6 +68,10 @@ def new_keymap(cli):
cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
return False
if not validate_keymap_name(user_name):
cli.log.error('Keymap names must contain only {fg_cyan}a-z{fg_reset}, {fg_cyan}0-9{fg_reset} and {fg_cyan}_{fg_reset}! Please choose a different name.')
return False
if keymap_path_new.exists():
cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
return False

View File

@ -29,6 +29,7 @@ def _convert_macros(via_macros):
if len(via_macros) == 0:
return list()
split_regex = re.compile(r'(}\,)|(\,{)')
macro_group_regex = re.compile(r'({.+?})')
macros = list()
for via_macro in via_macros:
# Split VIA macro to its elements
@ -38,13 +39,28 @@ def _convert_macros(via_macros):
macro_data = list()
for m in macro:
if '{' in m or '}' in m:
# Found keycode(s)
keycodes = m.split(',')
# Remove whitespaces and curly braces from around keycodes
keycodes = list(map(lambda s: s.strip(' {}'), keycodes))
# Remove the KC prefix
keycodes = list(map(lambda s: s.replace('KC_', ''), keycodes))
macro_data.append({"action": "tap", "keycodes": keycodes})
# Split macro groups
macro_groups = macro_group_regex.findall(m)
for macro_group in macro_groups:
# Remove whitespaces and curly braces from around group
macro_group = macro_group.strip(' {}')
macro_action = 'tap'
macro_keycodes = []
if macro_group[0] == '+':
macro_action = 'down'
macro_keycodes.append(macro_group[1:])
elif macro_group[0] == '-':
macro_action = 'up'
macro_keycodes.append(macro_group[1:])
else:
macro_keycodes.extend(macro_group.split(',') if ',' in macro_group else [macro_group])
# Remove the KC prefixes
macro_keycodes = list(map(lambda s: s.replace('KC_', ''), macro_keycodes))
macro_data.append({"action": macro_action, "keycodes": macro_keycodes})
else:
# Found text
macro_data.append(m)
@ -54,13 +70,13 @@ def _convert_macros(via_macros):
def _fix_macro_keys(keymap_data):
macro_no = re.compile(r'MACRO0?([0-9]{1,2})')
macro_no = re.compile(r'MACRO0?\(([0-9]{1,2})\)')
for i in range(0, len(keymap_data)):
for j in range(0, len(keymap_data[i])):
kc = keymap_data[i][j]
m = macro_no.match(kc)
if m:
keymap_data[i][j] = f'MACRO_{m.group(1)}'
keymap_data[i][j] = f'MC_{m.group(1)}'
return keymap_data

View File

@ -364,15 +364,15 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef LEADER_ENABLE
process_leader(keycode, record) &&
#endif
#ifdef SPACE_CADET_ENABLE
process_space_cadet(keycode, record) &&
#endif
#ifdef AUTO_SHIFT_ENABLE
process_auto_shift(keycode, record) &&
#endif
#ifdef DYNAMIC_TAPPING_TERM_ENABLE
process_dynamic_tapping_term(keycode, record) &&
#endif
#ifdef SPACE_CADET_ENABLE
process_space_cadet(keycode, record) &&
#endif
#ifdef MAGIC_ENABLE
process_magic(keycode, record) &&
#endif

View File

@ -68,3 +68,29 @@ TEST_F(AutoShift, key_release_after_timeout) {
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}
// test auto shift and space cadet interaction
// press shift, press key, release shift, release key
// the right interaction is we only get the shifted key
// the wrong interaction is we get a bracket and a shifted key
TEST_F(AutoShift, auto_shift_with_space_cadet) {
TestDriver driver;
InSequence s;
auto left_shift = KeymapKey(0, 0, 0, SC_LSPO);
auto key_a = KeymapKey(0, 1, 0, KC_A);
set_keymap({left_shift, key_a});
/* Press regular key */
EXPECT_NO_REPORT(driver);
left_shift.press();
key_a.press();
left_shift.release();
key_a.release();
VERIFY_AND_CLEAR(driver);
/* Release regular key */
EXPECT_REPORT(driver, (KC_LSFT, KC_A));
EXPECT_EMPTY_REPORT(driver);
run_one_scan_loop();
VERIFY_AND_CLEAR(driver);
}