aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Challis2025-11-23 12:21:55 +0100
committerGitHub2025-11-23 12:21:55 +0100
commit53de903fb89d4138fdc38f98d266db0fec9548b1 (patch)
tree0314a7c90999515b9e66af0667ee0823760a8fc5
parentfd65390496cb47b3164c507656798664b8c2fcd1 (diff)
Better defaulting of `{RGB,LED}_MATRIX_DEFAULT_FLAGS` (#25785)
-rw-r--r--lib/python/qmk/info.py31
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
from pathlib import Path
import jsonschema
from dotty_dict import dotty
+from enum import IntFlag
from milc import cli
@@ -21,6 +22,15 @@ true_values = ['1', 'on', 'yes']
false_values = ['0', 'off', 'no']
+class LedFlags(IntFlag):
+ ALL = 0xFF
+ NONE = 0x00
+ MODIFIER = 0x01
+ UNDERGLOW = 0x02
+ KEYLIGHT = 0x04
+ INDICATOR = 0x08
+
+
def _keyboard_in_layout_name(keyboard, layout):
"""Validate that a layout macro does not contain name of keyboard
"""
@@ -813,12 +823,23 @@ def _extract_led_config(info_data, keyboard):
info_data[feature]['led_count'] = len(info_data[feature]['layout'])
if info_data[feature].get('layout', None) and not info_data[feature].get('flag_steps', None):
- flags = {0xFF, 0}
+ flags = {LedFlags.ALL, LedFlags.NONE}
+ default_flags = {LedFlags.MODIFIER | LedFlags.KEYLIGHT, LedFlags.UNDERGLOW}
+
# if only a single flag is used, assume only all+none flags
- unique_flags = set(x.get('flags', 0) for x in info_data[feature]['layout'])
- if len(unique_flags) > 1:
- flags.update(unique_flags)
- info_data[feature]['flag_steps'] = sorted(list(flags), reverse=True)
+ kb_flags = set(x.get('flags', LedFlags.NONE) for x in info_data[feature]['layout'])
+ if len(kb_flags) > 1:
+ # check if any part of LED flag is with the defaults
+ unique_flags = set()
+ for candidate in default_flags:
+ if any(candidate & flag for flag in kb_flags):
+ unique_flags.add(candidate)
+
+ # if we still have a single flag, assume only all+none
+ if len(unique_flags) > 1:
+ flags.update(unique_flags)
+
+ info_data[feature]['flag_steps'] = sorted([int(flag) for flag in flags], reverse=True)
return info_data