Skip to content

Latest commit

 

History

History
184 lines (138 loc) · 17 KB

styling.md

File metadata and controls

184 lines (138 loc) · 17 KB

Styles and states

Widget styles

Each widget can override any of these styles:

foreground, background, hoverBackground, borderColor, borderWidth, cornerRadius, fontName, fontSize, fontWeight, iconSize, paddingHorizontal, paddingVertical, spacing, width, accent, accentText, shadowRadius, shadowColor.

borderWidth is in points, rounded to whole pixels: on a screen that isn't Retina, a border 1.5 wide is drawn 2 pixels wide, and one 0.5 wide 1 pixel.

fontName is system or an installed font name. fontWeight is regular, medium, semibold or bold. Unset, text uses the system font at 13 points, regular, like the macOS menu bar. Set width on frequently changing widgets to keep their footprint stable. Without a width, the active app widget animates to fit each app's name, and the widgets beside it slide along. The workspace highlight uses accent and accentText; its motion respects Reduce Motion. Set bar.motion to none to remove animation.

Styles also accept hoverForeground, height, paddingLeading, paddingTrailing, paddingTop, paddingBottom, offsetX, offsetY, opacity, shadowOffsetX, shadowOffsetY, shadowFrom and appIcons. Side-specific padding overrides horizontal/vertical padding. ultralight, thin and light font weights are available too. Offsets move the drawing without moving its neighbours.

shadowOffsetX and shadowOffsetY move the shadowColor shadow right and down by that many points, or left and up when negative. Unset, a shadow drops 1 point. Widgets, groups, popups and tooltips draw it.

shadowFrom sets what casts a widget's shadow: content, the default, casts it from everything the widget draws, text and symbols included, and shape from its background alone, as groups, popups and tooltips do; a widget without a background then casts none. Use shape for a hard shadow, one with a shadowRadius of 0, which would otherwise double the widget's text:

"defaults": { "background": "#ffffff", "shadowColor": "#000000", "shadowRadius": 0, "shadowOffsetX": 2, "shadowOffsetY": 2, "shadowFrom": "shape" }

symbolVariant draws SF Symbols in one of their variants, so bell with fill draws as bell.fill: fill, slash, circle, square or rectangle, or several joined by dots in the order SF Symbols names them (slash, then one shape, then fill), such as circle.fill or slash.circle.fill. A symbol without that variant keeps its own look. none draws symbols as named, undoing a variant set in a lower layer. Like iconSize, it reaches a layout's blocks. Set it in a state to change a symbol while the state is active, such as a leaf that fills while the Apple menu is open:

{
  "id": "apple", "type": "appleMenu", "position": "left",
  "layout": { "type": "symbol", "name": "leaf", "style": { "states": { "open": { "symbolVariant": "fill" } } } }
}

appIcons sets how app icons draw: color, the default, keeps their own colors, and tinted draws them in the text color, keeping enough of their light and dark parts to recognize them on a light or a dark background. It covers the app icons of the workspaces, active app, App menus and Menu bar items widgets and the apps in the System and Sound popups. Like iconSize, it reaches a layout's blocks and the widget's popup. A theme sets it in defaults; a widget's style brings back the colors on that widget, and the workspace appStyle, with its states, sets it for workspace icons alone:

{
  "defaults": { "appIcons": "tinted" },
  "widgets": [
    { "id": "app", "type": "activeApp", "position": "left", "style": { "appIcons": "color" } }
  ]
}

States

Any style can have states: styles that apply over it while a state is active. A state needs only the properties that change:

{
  "defaults": {
    "background": "#25252c",
    "states": { "hover": { "background": "#383842" } }
  },
  "widgets": [
    {
      "id": "status", "type": "text", "text": "Ready", "position": "left",
      "style": { "states": { "hover": { "foreground": "#69d2b0", "borderColor": "#69d2b0" } } }
    }
  ]
}

hover is active while the pointer is over a bar widget, a workspace cell or a layout block, on that display only. The open state is active on a bar widget, its layout and its overlay while its popup shows, on the instance that opened it: not on its copies on other displays, and not when the popup opened from the More widgets popup. A block's own background, border, padding, size, offset and opacity change for open only through that block's own states. Workspace cells also have a workspace state; see Workspace appearance. Script and provider widgets can have a data state; see Data states. States apply in a fixed order, later ones winning: the data state, the workspace state, mode, mode.<alias>, hover, then open, so an open style stays visible while the pointer rests on its widget. A state's style can have its own states, which refine later states while both are active: states.focused.states.hover styles the focused workspace under the pointer. bar.style consumes mode states; group states remain inactive.

hoverBackground and hoverForeground are shorthand for states.hover.background and states.hover.foreground. In each style, such as defaults or a widget's style, the two are compared after includes, packages, themes, templates, widget overrides and profiles merge, so a states.hover.background from any layer wins over hoverBackground from any layer, and likewise for the foreground; to override a lower layer's hover state, set states.hover.background. The Hover background rows in Settings handle this for you: they set hoverBackground and set states.hover.background to null beside it, so the color you pick wins over a lower layer's hover state but not over an active profile's hoverBackground. A hover without a background keeps the background. In a widget's layout and overlay and in popups, hover changes a block's text color, its symbol variant and its own background, border, padding, size, offset and opacity. A widget without layout draws its default layout with all of its hover and open styles.

A widget's states merge with those in defaults, and every style's states merge through includes, templates, profiles and widget overrides one state and property at a time: a widget's states.hover.foreground keeps the theme's states.hover.background. Set a state to null in a later layer to remove it at the same place: in defaults through includes, profiles and packages, and in a widget's style through its templates, widget overrides and package widgets. A hover set with hoverBackground or hoverForeground comes back from the shorthand, so set those to null too. Nothing set on a widget (its style, a template, a widget override or script output) can remove a state set in defaults. A state wins over the base style, so a theme's states also show on widgets that set their own colors.

The bar measures widths without hover and open, so use them for colors, borders, opacity, offsets and symbol variants rather than sizes.

With workspaceSource: "aerospace", mode is active while connected in any binding mode other than main. Map your local mode names to semantic aliases in your configuration; themes own the matching appearance:

{
  "modeAliases": { "tailing": "command" },
  "bar": { "style": { "states": {
    "mode.command": { "borderEdges": "all", "borderColor": "@token.warning" }
  } } }
}

An unmapped non-main mode activates only mode. Aliases start with a letter and contain letters, digits, _ or -; a null mapping clears an inherited mapping. Themes and widget packages cannot define modeAliases. The initial mode is read on connect and reconnect, even without a workspace widget; disconnect, stop or switching to yabai clears it. Mode changes update presentation and send aerospaceMode to subscribers without reloading configuration or closing popups. Theme/configuration changes still close popups; reopening uses the new theme. A mode state beats a script's plain barStyle, and leaving the mode restores the remaining layers, border edges included.

Migration: mode and every mode.* name are reserved. Rename custom output/rule data states that used these names. Previously ignored bar.style.states.mode and mode.<alias> rules now apply. Script colors still use literal colors; put token-based mode colors in configuration or a theme. Use --batch '[{"action":"modeAliases","properties":{"tailing":"command"}}]' to edit mappings through the shared CLI editor. --query and Status include the connected mode, active mode states and configuration origins.

Presentation roles and workspace defaults

role is an explicit annotation on a widget or any layout/popup block. The allowed names are time, primary, secondary, key, value, heading, button, meter, separator and slider; unknown names are errors. Sliders have the default role described below; other blocks and widgets are not selected by type or ID. In particular, two clock widgets can use time and secondary independently. The fallback under every theme defines each role, empty.

{
  "roles": { "time": { "fontName": "Helvetica Neue", "fontSize": 16, "fontWeight": "light" } },
  "workspaceDefaults": {
    "indicator": "underline",
    "indicatorStyle": { "placement": "belowBar", "height": 2 },
    "style": { "fontSize": 13 },
    "appStyle": { "fontSize": 14 }
  },
  "widgets": [
    { "id": "time", "type": "clock", "format": "HH:mm", "position": "right", "role": "time" },
    { "id": "date", "type": "clock", "format": "EEE d MMM", "position": "right", "role": "secondary" }
  ]
}

A selected theme can style any subset of roles. Configuration files, includes and profiles can override those styles. Widget packages (including command-capable packages) may annotate widgets and blocks, but cannot define global groupDefaults, roles, workspaceDefaults or modeAliases. Role styles accept only style properties: they cannot change actions, providers, visibility, display filters or the row/column structure of a layout.

A slider without filled or an explicit role follows roles.slider when that role sets a style property. It then draws as a filled bar, with background as its track and accent as its fill. An empty or missing role keeps macOS's slider; "roles": { "slider": null } clears a theme's slider style. "filled": false always keeps the native control. "filled": true always draws filled in the block's own style and takes a role only when explicitly assigned. An explicit role other than slider also keeps the native control when filled is omitted.

This applies to popup sliders, hover layouts and Sound's built-in hover control. Automatically styled sliders fit the widget's content height inline, or a line of text when it has no fixed height. Popups use the role's height, 28 points by default, and hover tooltips keep to a line of their text, like macOS's slider there. Existing explicit filled sliders keep their configured sizing.

Themed sliders styles Sound's popup and built-in hover control without adding filled or an explicit role to either slider.

Layers apply from lowest to highest:

Element Base layers
Bar widget defaults → roles[role] → its group's foreground → widget style → output widgetStyles in configuration order → own output style/color
Layout/popup block inherited text style → roles[role] → block style → named output style selected by styleSource/styleField
Popup panel defaults → popupDefaults → widget's explicit style → popup style; the bar widget's role is excluded. Padding and spacing skip defaults and the widget's style, starting from 16 points of padding, 12 between the blocks of the popup's top-level column and 6 in any other row, column or list
Group groupDefaults → group style
Workspace workspaceDefaults → widget workspace
Bar strip bar.style → script barStyle in configuration order

Active states apply after the base layers in the order documented above. An explicit widget font beats its role's base font; an active state still beats base values. Role box properties (background, border, padding, dimensions and offsets) apply only to that block. Only the role’s typography, foreground, accent and spacing pass to its children, including their nested states; other inheritance is unchanged. Popups keep ignoring widget data states; they can use mode states in their own base layers and annotated blocks. Put bar-only mode styling in a role or bar.style rather than defaults.

workspaceDefaults permits only indicator, indicatorStyle, cell style, appStyle and focusedWindowStyle. Widget-level values merge over them, including legacy focusedStyle/visibleStyle/focusedAppStyle aliases; explicit states in the same widget still beat its shorthand. Local app-glyph mappings and workspace visibility choices remain widget-owned. Existing include/template/profile/package merge rules apply. Null clears a property within a composed map; a missing/cleared role style falls back to the inherited style. Widget styles retain their existing inheritance semantics.

Migration: opt in by adding roles to the time clock, a separate date clock, and popup blocks you want themed. Remove explicit fonts/colors when you want the role to control them. An explicit widget font still reaches its popup; a time role font does not. Keep music-popup rows/columns in the widget definition so every theme can style that same structure. Existing widgetStyles overrides, including a legacy self-targeted override, remain supported below the widget's own output style.

In Settings → Widgets, a widget’s More menu sets its presentation role, and Style → Workspaces edits workspace indicators. Appearance → Widgets → Workspaces edits the workspace look, and Appearance → Advanced shared role styles and AeroSpace mode names; theme cards show sample widgets and the workspace indicator. Profiles can override these maps through its JSON editor or by editing the profile in Widgets and Appearance. The shared CLI uses roles, workspaceDefaults and modeAliases batch actions; set assigns a widget's role or layout/block roles. Status/--query report the role, resolved style, ordered layers and source/token origins.

Data states

A data state says what a widget's data means, such as a battery running low, so its look can come from the theme. A script, or a command or stream provider, sets it with state in its output, for example {"text":"12%","state":"warning"}; the next output without state clears it. Use these shared names so themes and widget packages agree without hard-coded colors:

State Meaning
warning Needs attention soon, such as a battery at 20 %
critical Needs attention now, such as memory at 95 %
active On or in progress, such as charging or recording
muted Off or quiet, such as muted audio

Other names work too. hover, open, focused, visible, empty, mode and every mode.* name are StableBar's own, so output state with one of those names, or an empty one, is ignored. Define each state once in defaults.states:

"defaults": {
  "states": {
    "warning": { "foreground": "#f5b041" },
    "critical": {
      "foreground": "#ffffff", "background": "#c0392b",
      "states": { "hover": { "background": "#a93226" } }
    },
    "active": { "foreground": "#69d2b0" },
    "muted": { "opacity": 0.5 }
  }
}

A widget's own states override the theme's property by property. The data state applies first, so hover and open still show over it. Hover applies over the data state, so a state that sets a background should also set its hover background in its own states. A data state also reaches the widget's layout and overlay blocks, which apply their own states for it. Popups keep their own styles.

Apart from disk, native providers can't return state, so a widget can set it with rules. The first rule that matches the latest output sets the state; a state in the output takes precedence:

{
  "id": "power", "type": "battery", "position": "right",
  "rules": [
    { "when": { "value": "percent", "below": 0.1 }, "state": "critical" },
    { "when": { "value": "percent", "below": 0.2 }, "state": "warning" },
    { "when": { "field": "state", "equals": "charging" }, "state": "active" }
  ]
}

when compares one entry of the output: value names a number in values, which matches below when it is at or below that number and above when it is at or above it (give both for a range); field names a string in fields, which matches equals exactly. A missing value or field doesn't match. Rules are checked when output arrives and belong to the widget, so widgets that share a provider can use different thresholds. Only script and provider widgets accept rules.