Skip to content

Resolve widget styles in one place, with named states #15

Closed

Description

@M4n0x

Problem

Each surface works out its style separately, with different rules:

  • Bar widgets (Sources/StableBar/BarView.swift:238): configured style, defaults, other scripts' widgetStyles, output style, output color. Hover is applied afterwards in view modifiers, and an unset hoverBackground falls back to the system hover colour (Sources/StableBar/Configuration.swift:176).
  • Workspace cells (BarView.swift:433): their own focused/visible/empty chain and hover fallback. The underline has one indicatorStyle for every state (BarView.swift:476).
  • Layout and popup blocks (Sources/StableBar/PopupView.swift:79): styleSource and styleField. An unset hoverBackground keeps the block's background (PopupView.swift:106), unlike bar widgets.
  • The bar (BarView.swift:14): folds in barStyle from every script.

Because this lives in views, none of it is tested. Each new kind of state would add a layer to all four places:

  • a style for the widget whose popup is open, to show which widget owns it;
  • workspace indicator styles per state: the focused display, the other display, a window-manager mode;
  • data states such as warning and critical for built-in providers (battery at 20 % or below, memory at 90 % or above). Native providers can't return a style, so today this means wrapping them in a script.

Proposal

  1. Move resolution into one pure function used by bar widgets, workspace cells, blocks and the bar, with unit tests. No behaviour change in this step.
  2. Add a states map beside any style: { "style": {…}, "states": { "hover": {…}, "open": {…}, "warning": {…} } }. Active states apply in a fixed order over the base style.
    • Interaction: hover, and open while the widget's popup shows.
    • Workspace: focused, visible, empty. workspace.indicatorStyle gets the same map.
    • Data: set by script or provider output ("state": "warning"), or by rules comparing values or fields for built-in providers, for example { "when": { "value": "percent", "below": 0.2 }, "state": "warning" }.
  3. defaults.states lets a theme define each state once. Document a small set of shared names (warning, critical, active, muted) so widget packages can use them without hard-coded colours.
  4. Keep today's keys as aliases: hoverForeground and hoverBackground map to states.hover; focusedStyle, visibleStyle and emptyStyle map to the workspace states.

This would unlock:

  • An open state for a popup's widget
  • Workspace indicator styles per state
  • state output and rules for built-in providers
  • Shared state names and defaults.states for themes

Possible today

Partly. Scripts can return style, styles and widgetStyles, so a script widget can colour itself by threshold or restyle another widget. Built-in providers (battery, system, audio) can't. There is no style for an open popup's widget, and the workspace underline has one style for all states. Popups already close on app and workspace switches (Sources/StableBar/BarStore.swift:50, :79).

Related

None tracked. #16 (one way to draw widgets) lets states reach the parts of built-in widgets too.

Triaged by Claude Code (Claude Opus 5.5).

Activity

  1. added
    enhancement
    on Oct 15, 2026
  2. M4n0x commented on Oct 15, 2026

    @M4n0x
    CollaboratorAuthor

    Performance

    Today any script update re-evaluates the whole bar on every display. Each widget's style reads every script's output to apply widgetStyles (Sources/StableBar/BarView.swift:241), and the bar reads every output for barStyle and hidden (BarView.swift:14, :31).

    Requirements for this change:

    • Resolve styles once per output or state change, in the store, rather than in view bodies. Each widget view reads only its own resolved style, so one script's update redraws only the widgets it affects.
    • Evaluate rules when output arrives, not on every render.
    • Check with Instruments' SwiftUI template or Self._printChanges() that an update touching one widget doesn't re-evaluate the others, and note the result in the pull request.

    Triaged by Claude Code (Claude Opus 5.5).

  3. stablebar-releases commented on Oct 21, 2026

    @stablebar-releases

    🎉 This issue has been resolved in version 0.5.0 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions