From a511d29e1fa2f0cb2101c87969eece9a0607c4a1 Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 15 Oct 2026 22:26:56 +0200 Subject: [PATCH] Fix mouse widget's active DPI stage display getting stuck openrazer's own dpi_stages active-index only updates when a stage is cycled via the mouse's physical button, not when set-dpi-stage sets d.dpi directly - so it went stale and no longer matched the real current DPI, highlighting the wrong stage regardless of what was actually applied. Derive the active stage from the current DPI value instead of trusting that index. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Dujsk9jYfxUVLtb5B8eC94 --- quickshell/default/scripts/mouse.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/quickshell/default/scripts/mouse.py b/quickshell/default/scripts/mouse.py index b9d7b25..04b724f 100644 --- a/quickshell/default/scripts/mouse.py +++ b/quickshell/default/scripts/mouse.py @@ -43,15 +43,22 @@ def get_device(): def status_json(d): - stage_index, stages = d.dpi_stages + _, stages = d.dpi_stages + current_dpi = d.dpi[0] + stage_values = [s[0] for s in stages] + # d.dpi_stages' own active-stage index only updates when a stage is cycled via the + # mouse's physical button, not when set-dpi-stage below sets d.dpi directly - so it + # goes stale and no longer matches the actual current DPI. Derive it from the real + # current DPI instead of trusting that index. + stage_index = stage_values.index(current_dpi) if current_dpi in stage_values else -1 return { "available": True, "name": d.name, "pct": d.battery_level, "charging": d.is_charging, - "dpi": d.dpi[0], + "dpi": current_dpi, "dpi_stage": stage_index, - "dpi_stages": [s[0] for s in stages], + "dpi_stages": stage_values, "poll_rate": d.poll_rate, "supported_poll_rates": d.supported_poll_rates, "idle_time": d.get_idle_time(),