diff options
author | WeirdTreeThing <bradyn127@protonmail.com> | 2024-02-24 21:47:27 -0500 |
---|---|---|
committer | WeirdTreeThing <bradyn127@protonmail.com> | 2024-02-24 21:47:27 -0500 |
commit | 8b4375bec2901b789b0e040ed591d1e64e542390 (patch) | |
tree | d95d34f3310027fdd1df545dc9ae6b76b0fb0583 | |
parent | e9aaf3b74cbf5a7e913ae9c4a18a11e6ca8ce4b1 (diff) |
Add arm vivaldi support
-rwxr-xr-x | cros-keyboard-map.py | 117 |
1 files changed, 89 insertions, 28 deletions
diff --git a/cros-keyboard-map.py b/cros-keyboard-map.py index 8b522ff..be44b7e 100755 --- a/cros-keyboard-map.py +++ b/cros-keyboard-map.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import argparse +import platform device_ids = { "k:0000:0000", # cros_ec keyboard @@ -19,52 +20,106 @@ device_ids = { } vivaldi_keys = { - "90": "previoussong", - "91": "zoom", - "92": "scale", - "93": "print", - "94": "brightnessdown", - "95": "brightnessup", - "97": "kbdillumdown", - "98": "kbdillumup", - "99": "nextsong", - "9A": "playpause", - "9B": "micmute", - "9E": "kbdillumtoggle", - "A0": "mute", - "AE": "volumedown", - "B0": "volumeup", - "E9": "forward", - "EA": "back", - "E7": "refresh", + "x86_64": { + "90": "previoussong", + "91": "zoom", + "92": "scale", + "93": "print", + "94": "brightnessdown", + "95": "brightnessup", + "97": "kbdillumdown", + "98": "kbdillumup", + "99": "nextsong", + "9A": "playpause", + "9B": "micmute", + "9E": "kbdillumtoggle", + "A0": "mute", + "AE": "volumedown", + "B0": "volumeup", + "E9": "forward", + "EA": "back", + "E7": "refresh", + }, + "arm": { + "158": "back", + "159": "forward", + "173": "refresh", + "372": "zoom", + "120": "scale", + "224": "brightnessdown", + "225": "brightnessup", + "113": "mute", + "114": "volumedown", + "115": "volumeup", + "99" : "print", + "142": "coffee", + } } +def get_arch(): + return platform.uname().machine + def get_ids_string(device_ids): return "\n".join(device_ids) -def get_physmap_data(): +def get_dt_layout(): + keys = [] + keycodes = [] + try: - with open("/sys/bus/platform/devices/i8042/serio0/function_row_physmap", "r") as file: - return file.read().strip().split() - except FileNotFoundError: + fdt = libfdt.Fdt(open("/sys/firmware/fdt", "rb").read()) + except: return "" + currentnode = fdt.first_subnode(0) + + while True: + try: + if fdt.get_name(currentnode) == "keyboard-controller": + prop = fdt.getprop(currentnode, "linux,keymap") + keys = prop.as_uint32_list() + currentnode = fdt.next_node(currentnode, 10)[0] + except: + break + + if not keys: + return "" + + for key in keys: + keycode = str(key & 0xFFFF) + if keycode in vivaldi_keys["arm"]: + keycodes.append(keycode) + return keycodes + +def get_physmap_data(): + if get_arch() == "x86_64": + try: + with open("/sys/bus/platform/devices/i8042/serio0/function_row_physmap", "r") as file: + return file.read().strip().split() + except FileNotFoundError: + return "" + else: + return get_dt_layout() def get_functional_row(physmap, use_vivaldi, super_is_held, super_inverted): + arch = get_arch() + if arch != "x86_64": + arch = "arm" + i = 0 result = "" - for scancode in physmap: + for code in physmap: i += 1 # Map zoom to f11 since most applications wont listen to zoom - mapping = "f11" if vivaldi_keys[scancode] == "zoom" \ - else vivaldi_keys[scancode] + mapping = "f11" if vivaldi_keys[arch][code] == "zoom" \ + else vivaldi_keys[arch][code] match [super_is_held, use_vivaldi, super_inverted]: case [True, True, False] | [False, True, True]: - result += f"{vivaldi_keys[scancode]} = f{i}\n" + result += f"{vivaldi_keys[arch][code]} = f{i}\n" case [True, False, False] | [False, False, True]: result += f"f{i} = f{i}\n" case [False, True, False] | [True, True, True]: - result += f"{vivaldi_keys[scancode]} = {mapping}\n" + result += f"{vivaldi_keys[arch][code]} = {mapping}\n" case [False, False, False] | [True, False, True]: result += f"f{i} = {mapping}\n" @@ -108,10 +163,16 @@ def main(): help="use functional keys by default and media keys when super is held") args = vars(parser.parse_args()) + if get_arch() != "x86_64": + import libfdt + physmap = get_physmap_data() if not physmap: print("no function row mapping found, using default mapping") - physmap = ['EA', 'E9', 'E7', '91', '92', '94', '95', 'A0', 'AE', 'B0'] + if is_x86: + physmap = ['EA', 'E9', 'E7', '91', '92', '94', '95', 'A0', 'AE', 'B0'] + else: + physmap = ['158', '159', '173', '372', '120', '224', '225', '113', '114', '115'] config = get_keyd_config(physmap, args["inverted"]) with open(args["file"], "w") as conf: |