diff options
| author | Joel Challis <git@zvecr.com> | 2025-11-23 11:21:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-23 22:21:55 +1100 |
| commit | 53de903fb89d4138fdc38f98d266db0fec9548b1 (patch) | |
| tree | 0314a7c90999515b9e66af0667ee0823760a8fc5 /lib/python/qmk | |
| parent | fd65390496cb47b3164c507656798664b8c2fcd1 (diff) | |
Better defaulting of `{RGB,LED}_MATRIX_DEFAULT_FLAGS` (#25785)
Diffstat (limited to 'lib/python/qmk')
| -rw-r--r-- | lib/python/qmk/info.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index e6d51e1239..a0b8fe72b6 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
| @@ -5,6 +5,7 @@ import os | |||
| 5 | from pathlib import Path | 5 | from pathlib import Path |
| 6 | import jsonschema | 6 | import jsonschema |
| 7 | from dotty_dict import dotty | 7 | from dotty_dict import dotty |
| 8 | from enum import IntFlag | ||
| 8 | 9 | ||
| 9 | from milc import cli | 10 | from milc import cli |
| 10 | 11 | ||
| @@ -21,6 +22,15 @@ true_values = ['1', 'on', 'yes'] | |||
| 21 | false_values = ['0', 'off', 'no'] | 22 | false_values = ['0', 'off', 'no'] |
| 22 | 23 | ||
| 23 | 24 | ||
| 25 | class LedFlags(IntFlag): | ||
| 26 | ALL = 0xFF | ||
| 27 | NONE = 0x00 | ||
| 28 | MODIFIER = 0x01 | ||
| 29 | UNDERGLOW = 0x02 | ||
| 30 | KEYLIGHT = 0x04 | ||
| 31 | INDICATOR = 0x08 | ||
| 32 | |||
| 33 | |||
| 24 | def _keyboard_in_layout_name(keyboard, layout): | 34 | def _keyboard_in_layout_name(keyboard, layout): |
| 25 | """Validate that a layout macro does not contain name of keyboard | 35 | """Validate that a layout macro does not contain name of keyboard |
| 26 | """ | 36 | """ |
| @@ -813,12 +823,23 @@ def _extract_led_config(info_data, keyboard): | |||
| 813 | info_data[feature]['led_count'] = len(info_data[feature]['layout']) | 823 | info_data[feature]['led_count'] = len(info_data[feature]['layout']) |
| 814 | 824 | ||
| 815 | if info_data[feature].get('layout', None) and not info_data[feature].get('flag_steps', None): | 825 | if info_data[feature].get('layout', None) and not info_data[feature].get('flag_steps', None): |
| 816 | flags = {0xFF, 0} | 826 | flags = {LedFlags.ALL, LedFlags.NONE} |
| 827 | default_flags = {LedFlags.MODIFIER | LedFlags.KEYLIGHT, LedFlags.UNDERGLOW} | ||
| 828 | |||
| 817 | # if only a single flag is used, assume only all+none flags | 829 | # if only a single flag is used, assume only all+none flags |
| 818 | unique_flags = set(x.get('flags', 0) for x in info_data[feature]['layout']) | 830 | kb_flags = set(x.get('flags', LedFlags.NONE) for x in info_data[feature]['layout']) |
| 819 | if len(unique_flags) > 1: | 831 | if len(kb_flags) > 1: |
| 820 | flags.update(unique_flags) | 832 | # check if any part of LED flag is with the defaults |
| 821 | info_data[feature]['flag_steps'] = sorted(list(flags), reverse=True) | 833 | unique_flags = set() |
| 834 | for candidate in default_flags: | ||
| 835 | if any(candidate & flag for flag in kb_flags): | ||
| 836 | unique_flags.add(candidate) | ||
| 837 | |||
| 838 | # if we still have a single flag, assume only all+none | ||
| 839 | if len(unique_flags) > 1: | ||
| 840 | flags.update(unique_flags) | ||
| 841 | |||
| 842 | info_data[feature]['flag_steps'] = sorted([int(flag) for flag in flags], reverse=True) | ||
| 822 | 843 | ||
| 823 | return info_data | 844 | return info_data |
| 824 | 845 | ||
