pulsar-mouse: make the per-state widget colors configurable (#336)
* pulsar-mouse: make the per-state widget colors configurable Both widgets hardcoded their state colors: error for a fault, secondary while charging, error at the mouse's low-power threshold. The desktop widget's one `color` setting only covered the normal state, and the bar widget had no color setting at all. Expose all four states (normal/charging/low/error) as `type = "color"` settings on each widget, in the same shape battery-widget uses. Defaults reproduce exactly what was hardcoded, so an existing install renders identically until someone changes one. The new settings are `advanced`; the desktop widget's pre-existing `color` stays where it was so it does not disappear behind the toggle for anyone already using it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * pulsar-mouse: rename the bar's normal-state key to normal_color A bar widget's plugin settings share one TOML table with Noctalia's own per-widget presentation settings, where `color` already exists ("Color role for this widget's icon and label"). A plugin declaring `color` there does not shadow it, it aliases it - one `color = "primary"` under [widget.<id>] drove both pickers at once, so setting either silently moved the other. Renamed to `normal_color`, which also makes the retest unambiguous: the glyph follows the plugin setting while Presentation's own Color picker stays on Default. The desktop widget keeps plain `color` - no clash there, and renaming it would break existing configs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a7581e8a1c
commit
13bde174ad
+23
-9
@@ -17,9 +17,10 @@
|
||||
--
|
||||
-- Icon-only (no percentage label): battery level and charging state are
|
||||
-- already in the hover tooltip, so a bar-row number would just be the same
|
||||
-- fact twice. Just the Tabler "mouse-filled" glyph, tinted red by
|
||||
-- statusColor() same as before, swapping to "mouse-off" for a genuine
|
||||
-- error/no-mouse state.
|
||||
-- fact twice. Just the Tabler "mouse-filled" glyph, tinted per state by
|
||||
-- statusColor(), swapping to "mouse-off" for a genuine error/no-mouse state.
|
||||
-- Each of those state colors is a setting (normal/charging/low/error),
|
||||
-- defaulting to what they were previously hardcoded to.
|
||||
--
|
||||
-- Signal quality has no synchronous getter (see gui.py's own comment on
|
||||
-- this) - it only arrives via an async hidraw event the GUI listens for, so
|
||||
@@ -57,6 +58,17 @@ local checkingCli = false
|
||||
local isVertical = false
|
||||
local glyphSize = noctalia.getConfig("glyph_size")
|
||||
|
||||
-- Per-state colors, defaulted in plugin.toml to the values these used to be
|
||||
-- hardcoded to. Read once here rather than per-render, same as glyph_size -
|
||||
-- a settings change reloads the widget anyway.
|
||||
--
|
||||
-- `normal_color`, not `color` - see plugin.toml for why that name is
|
||||
-- unusable on a bar widget.
|
||||
local normalColor = noctalia.getConfig("normal_color")
|
||||
local chargingColor = noctalia.getConfig("charging_color")
|
||||
local warningColor = noctalia.getConfig("warning_color")
|
||||
local errorColor = noctalia.getConfig("error_color")
|
||||
|
||||
local function statusGlyph(color)
|
||||
local name = (errorText ~= nil or percent == nil) and "mouse-off" or "mouse-filled"
|
||||
return ui.glyph({ name = name, size = glyphSize, color = color })
|
||||
@@ -64,15 +76,15 @@ end
|
||||
|
||||
local function statusColor()
|
||||
if errorText ~= nil then
|
||||
return "error"
|
||||
return errorColor
|
||||
end
|
||||
if charging then
|
||||
return "secondary"
|
||||
return chargingColor
|
||||
end
|
||||
if percent ~= nil and percent <= (lowPowerThreshold or LOW_POWER_DEFAULT) then
|
||||
return "error"
|
||||
return warningColor
|
||||
end
|
||||
return "on_surface"
|
||||
return normalColor
|
||||
end
|
||||
|
||||
local function tooltipText()
|
||||
@@ -98,8 +110,10 @@ local function render()
|
||||
local glyph
|
||||
if not wireless then
|
||||
-- No battery to show, but still clickable - a wired mouse still has
|
||||
-- DPI/lighting controls in the panel, just not the Power tab.
|
||||
glyph = ui.glyph({ name = "mouse-filled", size = glyphSize, color = "on_surface" })
|
||||
-- DPI/lighting controls in the panel, just not the Power tab. Takes the
|
||||
-- normal-state color: there's nothing wrong here, it's just permanently
|
||||
-- the only state this mouse has.
|
||||
glyph = ui.glyph({ name = "mouse-filled", size = glyphSize, color = normalColor })
|
||||
barWidget.setTooltip(noctalia.tr("ui.wired"))
|
||||
else
|
||||
glyph = statusGlyph(statusColor())
|
||||
|
||||
Reference in New Issue
Block a user