Simplify trigger logic to port-only matching and improve Samsung detection

This commit is contained in:
Lago
2026-03-27 15:09:16 +01:00
parent 33e762c182
commit 37eb9e9fa0
8 changed files with 276 additions and 186 deletions
+35 -7
View File
@@ -36,15 +36,20 @@ class RealMonitorBackend:
return HardwareScan(samsung_present=samsung_present, errors=errors)
alienware_candidates: list[tuple[object, str]] = []
trigger_candidates: list[tuple[object, str]] = []
samsung_named_candidates: list[tuple[object, str]] = []
non_alienware_candidates: list[tuple[object, str]] = []
for monitor in monitors:
description = str(getattr(getattr(monitor, "vcp", None), "description", "") or "")
normalized = description.upper()
description = str(getattr(getattr(monitor, "vcp", None), "description", "") or str(monitor))
normalized = description.upper().strip()
if ALIENWARE_MODEL_TOKEN in normalized:
alienware_candidates.append((monitor, description))
else:
trigger_candidates.append((monitor, description or "Unknown DDC monitor"))
continue
candidate = (monitor, description or "Unknown DDC monitor")
non_alienware_candidates.append(candidate)
if _is_samsung_description(normalized):
samsung_named_candidates.append(candidate)
alienware_description: str | None = None
alienware_input_code: int | None = None
@@ -62,6 +67,11 @@ class RealMonitorBackend:
trigger_description: str | None = None
trigger_input_code: int | None = None
trigger_candidates = (
samsung_named_candidates
if samsung_named_candidates
else (non_alienware_candidates if samsung_present else [])
)
if len(trigger_candidates) == 1:
trigger_monitor, trigger_description = trigger_candidates[0]
trigger_input_code = self._read_input_code(
@@ -69,10 +79,19 @@ class RealMonitorBackend:
"Samsung trigger monitor",
errors,
)
if not samsung_named_candidates:
errors.append(
"Samsung trigger monitor did not expose a Samsung model in DDC/CI; using the only non-Alienware DDC monitor as trigger."
)
elif not trigger_candidates:
errors.append("A non-Alienware DDC monitor was not found for trigger-only logic.")
errors.append("Samsung trigger monitor could not be identified through DDC/CI.")
else:
errors.append("Multiple non-Alienware DDC monitors were detected; trigger monitor is ambiguous.")
if samsung_named_candidates:
errors.append("Multiple Samsung DDC monitors were detected; trigger monitor is ambiguous.")
else:
errors.append(
"Multiple non-Alienware DDC monitors were detected and Samsung did not expose model info; trigger monitor is ambiguous."
)
if not samsung_present:
errors.append("Samsung monitor could not be confirmed from Windows monitor metadata.")
@@ -144,3 +163,12 @@ def _decode_wmi_string(raw_values: object) -> str:
continue
chars.append(chr(number))
return "".join(chars).strip()
def _is_samsung_description(description: str) -> bool:
normalized = description.upper().strip()
if "SAMSUNG" in normalized:
return True
if normalized.startswith("SAM"):
return True
return " SAM " in f" {normalized} "