Skip to content

Commit 31e6b9a

Browse files
stefanpricopieuser
authored andcommitted
feat(keyboard): dynamically generate TTY switching mappings
- Add get_tty_switching() function to generate mappings based on physmap - Remove hardcoded key mappings (brightnessdown, brightnessup, mute) - Support all top row keys dynamically (10-12 keys vs previous 8) - Ensure compatibility with all Chromebook vivaldi keyboard layouts - Works for both inverted and non-inverted keyboard modes
1 parent 8aeeed0 commit 31e6b9a

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

cros-keyboard-map.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,33 @@ def get_functional_row(physmap, use_vivaldi, super_is_held, super_inverted):
122122

123123
return result
124124

125+
def get_tty_switching(physmap):
126+
"""Generate TTY switching mappings for all top row keys.
127+
128+
Dynamically generates Ctrl+Alt+F{n} mappings based on the actual physmap,
129+
ensuring compatibility with all Chromebook keyboard layouts.
130+
"""
131+
arch = get_arch()
132+
if arch != "x86_64":
133+
arch = "arm"
134+
135+
i = 0
136+
result = ""
137+
138+
# Generate F-key mappings for inverted mode (F-keys by default)
139+
for code in physmap:
140+
i += 1
141+
result += f"f{i} = C-A-f{i}\n"
142+
143+
# Generate Chrome key mappings for non-inverted mode (Chrome keys by default)
144+
i = 0
145+
for code in physmap:
146+
i += 1
147+
chrome_key = vivaldi_keys[arch][code]
148+
result += f"{chrome_key} = C-A-f{i}\n"
149+
150+
return result
151+
125152
def get_keyd_config(physmap, inverted):
126153
config = f"""\
127154
[ids]
@@ -157,24 +184,7 @@ def get_keyd_config(physmap, inverted):
157184
158185
[control+alt]
159186
backspace = C-A-delete
160-
# TTY switching for inverted mode (F-keys by default)
161-
f1 = C-A-f1
162-
f2 = C-A-f2
163-
f3 = C-A-f3
164-
f4 = C-A-f4
165-
f5 = C-A-f5
166-
f6 = C-A-f6
167-
f7 = C-A-f7
168-
f8 = C-A-f8
169-
# TTY switching for non-inverted mode (Chrome keys by default)
170-
back = C-A-f1
171-
forward = C-A-f2
172-
refresh = C-A-f3
173-
zoom = C-A-f4
174-
scale = C-A-f5
175-
brightnessdown = C-A-f6
176-
brightnessup = C-A-f7
177-
mute = C-A-f8
187+
{get_tty_switching(physmap)}
178188
"""
179189
return config
180190

0 commit comments

Comments
 (0)