Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Add an entry when a pull request sets a rule, a policy or a choice not to do som

## Code

- **Sliders may take a role implicitly** (2026-11-17). Sliders with neither `filled` nor another role follow a nonempty `slider` role, so themes can style controls without owning widget layouts. Explicit `filled` choices retain their behavior, and an empty role retains the native control. Other blocks still require explicit roles.
- **Window managers own their gaps** (2026-11-13). StableBar does not turn macOS menu-bar auto-hide off to reserve space: that changes the usable screen area underneath existing window-manager gaps, and the reserved height does not follow StableBar’s height. Keep windows clear remains a correction for ordinary windows after a drag.
- **Architecture rules are tests** (2026-11-08, [#484]). `ArchitectureRulesTests` caps `BarStore`'s stored state, a number that only goes down, allows no `unowned` reference ([#493]) and keeps private macOS API in `PrivateAPI.swift` ([#490]).
- **Private macOS API is a maintainer's call** (2026-11-08, [#484], [#490]). Every call lives in `PrivateAPI.swift` and is looked up at runtime, never with `@_silgen_name`, so a macOS without one turns off only its feature.
Expand Down
5 changes: 4 additions & 1 deletion Sources/StableBar/AppearanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,12 @@ struct ThemeAdvancedSheet: View {
role.color("Accent", "accent")
role.number("Border width", "borderWidth", default: 0)
role.number("Corner radius", "cornerRadius", default: 0)
if selectedRole == .slider { role.number("Height", "height", default: 28) }
role.number("Horizontal padding", "paddingHorizontal", default: 0)
role.number("Vertical padding", "paddingVertical", default: 0)
Text("Only widgets and layout blocks explicitly assigned this role use it. A bar widget’s role does not style its popup.")
Text(selectedRole == .slider
? "Sliders follow this role unless they set filled or another role. An empty role keeps the native slider."
: "Only widgets and layout blocks explicitly assigned this role use it. A bar widget’s role does not style its popup.")
.font(.callout).foregroundStyle(.secondary)
}
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/StableBar/BarInspector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ struct BarInspector: View {
if $0 != (widget.role?.rawValue ?? "") { editor.set(["role": $0.isEmpty ? .null : .string($0)], for: widget.id) }
})) {
Text("None").tag("")
ForEach(PresentationRole.allCases, id: \.rawValue) { Text($0.rawValue.capitalized).tag($0.rawValue) }
// The slider role styles slider blocks, not a whole widget.
ForEach(PresentationRole.allCases.filter { $0 != .slider || widget.role == .slider }, id: \.rawValue) {
Text($0.rawValue.capitalized).tag($0.rawValue)
}
}
if widget.drawsTransitions {
Picker("Transition", selection: string("transition", for: widget,
Expand Down
8 changes: 6 additions & 2 deletions Sources/StableBar/BarStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ final class BarStore: NSObject {
let script = scripts[widget.id]
let base = resolveStyle(widgetStyleLayers(widget, defaults: configuration.defaults, overrides: overrides, own: script?.output,
role: configuration.roleStyle(widget.role)))
let usesMode = base.usesModeStates || widget.layout?.usesModeStates(roles: configuration.roles) == true
let usesMode = base.usesModeStates || configuration.usesSliderModeStates(widget) || widget.layout?.usesModeStates(roles: configuration.roles) == true
|| widget.hoverLayout?.usesModeStates(roles: configuration.roles) == true
|| widget.overlay?.usesModeStates(roles: configuration.roles) == true
|| script?.output.styles?.values.contains(where: \.usesModeStates) == true
Expand All @@ -871,8 +871,12 @@ final class BarStore: NSObject {
let base = resolveStyle(widgetStyleLayers(own, defaults: look.defaults, overrides: screenOverrides[kind]!, own: script?.output,
role: look.roleStyle(own.role)))
let screenStates = widgetDataStates(script?.output, widget: own, providers: configuration.providers)
let screenUsesMode = usesMode || base.usesModeStates || look.usesSliderModeStates(own)
Comment thread
M4n0x marked this conversation as resolved.
Resolved
|| own.layout?.usesModeStates(roles: look.roles) == true
|| own.hoverLayout?.usesModeStates(roles: look.roles) == true
|| own.overlay?.usesModeStates(roles: look.roles) == true
screenStyles[kind] = ResolvedWidgetStyle(base: base, state: screenStates.widget, parts: screenStates.parts,
mode: usesMode ? modePresentation(on: ScreenKind(rawValue: kind)!) : ModePresentation())
mode: screenUsesMode ? modePresentation(on: ScreenKind(rawValue: kind)!) : ModePresentation())
}
presentations[widget.id]?.update(style: ResolvedWidgetStyle(base: base, state: states.widget, parts: states.parts,
mode: usesMode ? mode : ModePresentation()),
Expand Down
8 changes: 6 additions & 2 deletions Sources/StableBar/BarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ struct WidgetView: View {
case .provider where isSound && inlineHoverControls:
SoundWidgetView(widget: widget, store: store, monitor: monitor,
style: resolution.layoutStyle(configured: false, hovered: hovered, open: open),
sliderStates: resolution.blockStates(open: open),
hovered: hovered, motion: motion, runAction: blockAction)
case .spacer where widget.layout == nil:
Spacer(minLength: resolution.base.minWidth ?? 0)
Expand Down Expand Up @@ -900,9 +901,10 @@ struct WidgetView: View {
if let layout = widget.hoverLayout {
WidgetBlocks(widget: widget, store: store,
style: LayoutStyle(inherited: style, states: resolution.blockStates(open: false), tracksHover: true),
block: layout, motion: motion, runAction: blockAction)
block: layout, inline: false, motion: motion, runAction: blockAction)
} else {
VolumeSlider(widget: widget, store: store, appearance: WidgetAppearance(style, defaults: WidgetStyle()), width: 120)
VolumeSlider(widget: widget, store: store,
style: LayoutStyle(inherited: style, states: resolution.blockStates(open: false), tracksHover: true), width: 120)
}
}
.controlSize(.small)
Expand Down Expand Up @@ -935,6 +937,7 @@ struct WidgetBlocks: View {
let store: BarStore
let style: LayoutStyle
var block: PopupBlock?
var inline = true
var date = Date.now
var fillsWidth = false
var motion = BlockMotion()
Expand All @@ -952,6 +955,7 @@ struct WidgetBlocks: View {
menu: script?.output.menu ?? widget.menu ?? [], values: script?.output.values ?? [:],
targets: script?.output.targets ?? [:], styles: script?.output.styles ?? [:],
series: script?.output.series ?? [:], roles: store.configuration?.look(on: screenKind).roles ?? [:],
inlineControlHeight: inline ? style.inherited.inlineControlHeight : nil,
fillsWidth: fillsWidth, open: { if store.barEditing.allowsWidgetActions { $0.open() } },
quit: { if store.barEditing.allowsWidgetActions { confirmQuit($0) } },
pressMenuBarItem: { if store.barEditing.allowsWidgetActions { store.appMenu.press($0) } },
Expand Down
6 changes: 4 additions & 2 deletions Sources/StableBar/FilledSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct FilledSliderTrack: Equatable {
/// A slider drawn as a bar in the block's style rather than macOS's control: its background is the track, the
/// accent fills it from the leading edge, and an optional symbol sits on the fill in the accent's text color. An end
/// stop follows a notch at its trailing end and fills the whole bar. Clicking or dragging anywhere sets the value. It
/// sends its value when the drag ends, as the native slider does.
/// sends its value when the drag ends, or continuously for the built-in volume control.
struct FilledSlider: View {
let title: String
let value: Double
Expand All @@ -79,6 +79,7 @@ struct FilledSlider: View {
/// Whether the block draws no track of its own, so the slider draws a faint one.
let drawsTrack: Bool
let appearance: WidgetAppearance
var continuous = false
let onChange: (Double) -> Void
@State private var dragged: FilledSliderTrack.Stop?
@State private var editing = false
Expand Down Expand Up @@ -186,11 +187,12 @@ struct FilledSlider: View {
} else {
dragged = stop
}
if continuous { onChange(sent(stop)) }
}

private func finish() {
editing = false
if let dragged { onChange(sent(dragged)) }
if !continuous, let dragged { onChange(sent(dragged)) }
}

/// A keyboard or VoiceOver step, which applies at once.
Expand Down
13 changes: 9 additions & 4 deletions Sources/StableBar/PopupConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ indirect enum PopupContent: Sendable {

struct PopupBlock: Decodable, Sendable {
let content: PopupContent
/// An omitted choice lets the slider role decide; explicit false keeps the native control.
private(set) var sliderFilled: Bool?
private(set) var sliderIcon: String?
let role: PresentationRole?
let style: WidgetStyle
let alignment: PopupAlignment
Expand Down Expand Up @@ -332,15 +335,17 @@ struct PopupBlock: Decodable, Sendable {
if let endStop, (minimum...maximum).contains(endStop.value) {
throw DecodingError.dataCorruptedError(forKey: .endStop, in: values, debugDescription: "An end stop's value must be outside min…max, so the slider can tell it from a step.")
}
let filled = try values.decodeIfPresent(Bool.self, forKey: .filled) ?? false
let filled = try values.decodeIfPresent(Bool.self, forKey: .filled)
let icon = try values.decodeIfPresent(String.self, forKey: .icon)
if icon != nil, !filled {
throw DecodingError.dataCorruptedError(forKey: .icon, in: values, debugDescription: "Only a filled slider shows an icon; add \"filled\": true.")
if icon != nil, filled == false {
throw DecodingError.dataCorruptedError(forKey: .icon, in: values, debugDescription: "Only a filled slider shows an icon; remove \"filled\": false to follow the slider role, or set it to true.")
}
sliderFilled = filled
sliderIcon = icon
let title = try values.decode(String.self, forKey: .title)
let source = try values.decode(String.self, forKey: .source)
let action = try controlAction([.volume])
content = filled
content = filled == true
? .filledSlider(title: title, source: source, minimum: minimum, maximum: maximum, step: step, endStop: endStop,
icon: icon, action: action)
: .slider(title: title, source: source, minimum: minimum, maximum: maximum, step: step, endStop: endStop, action: action)
Expand Down
48 changes: 38 additions & 10 deletions Sources/StableBar/PopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ struct BlockContext {
var styles: [String: WidgetStyle] = [:]
var series: [String: [Double]] = [:]
var roles: [String: WidgetStyle] = [:]
/// Nil in popups and tooltips; bar controls must fit the widget's content area.
var inlineControlHeight: Double?
var continuousSliders = false
/// Popup layouts fill their width; bar layouts take their content's width.
var fillsWidth = true
/// Opens an `open` or `openField` block's target; a popup's also closes the popup when its actions dismiss it.
Expand Down Expand Up @@ -332,10 +335,10 @@ struct PopupBlockView: View {
}

private var styledContent: some View {
let resting = block.resolvedStyle(inherited: inheritedStyle, styles: context.styles, fields: fields, states: context.states, roles: context.roles)
let resting = resolvedStyle(states: context.states)
var hovering = context.states
hovering.hover = true
let current = hovered ? block.resolvedStyle(inherited: inheritedStyle, styles: context.styles, fields: fields, states: hovering, roles: context.roles) : resting
let current = hovered ? resolvedStyle(states: hovering) : resting
let stacksBlocks = if topLevel, case .column = block.content { true } else { false }
var box = current.box
var drawn = resting
Expand All @@ -344,6 +347,7 @@ struct PopupBlockView: View {
box.background = nil
drawn = current
}
if block.automaticallyFillsSlider(roles: context.roles) { drawn = current }
let appearance = WidgetAppearance(drawn.text, defaults: WidgetStyle(spacing: stacksBlocks ? PopupConfiguration.blockSpacing : nil))
let alignment: Alignment = switch block.alignment {
case .leading: .leading
Expand Down Expand Up @@ -421,6 +425,12 @@ struct PopupBlockView: View {
.frame(maxWidth: block.fitsWidth && context.fillsWidth ? .infinity : nil, alignment: alignment)
}

private func resolvedStyle(states: StyleStates) -> BlockStyle {
let style = block.resolvedStyle(inherited: inheritedStyle, styles: context.styles, fields: fields, states: states, roles: context.roles)
return block.automaticallyFillsSlider(roles: context.roles)
? style.limitingSliderHeight(to: context.inlineControlHeight) : style
}

private func fieldText(_ text: String) -> Text {
block.markdown ? MarkdownBlocks.inline(text) : Text(text)
}
Expand Down Expand Up @@ -460,7 +470,13 @@ struct PopupBlockView: View {

/// A child block, built as a concrete view so SwiftUI diffs it without type erasure.
private func child(_ block: PopupBlock, of style: BlockStyle, fields: [String: String]) -> PopupBlockView {
PopupBlockView(block: block, inheritedStyle: style.inherited, fields: fields, context: context)
var context = context
if let limit = context.inlineControlHeight {
// Negative padding lets a child overflow its box, but an inline control still stays within the widget.
let inset = max(style.box.paddingTop ?? style.box.paddingVertical ?? 0, 0) + max(style.box.paddingBottom ?? style.box.paddingVertical ?? 0, 0)
context.inlineControlHeight = max(min(limit, style.box.height ?? limit) - inset, 1)
}
return PopupBlockView(block: block, inheritedStyle: style.inherited, fields: fields, context: context)
}

@ViewBuilder
Expand Down Expand Up @@ -559,7 +575,10 @@ struct PopupBlockView: View {
.modifier(FocusRing(cornerRadius: appearance.cornerRadius))
case let .slider(title, source, minimum, maximum, step, endStop, action):
let value = context.values[source] ?? Double(fields[source] ?? "") ?? minimum
if let endStop {
if block.automaticallyFillsSlider(roles: context.roles) {
filledSlider(title: title, value: value, minimum: minimum, maximum: maximum, step: step,
endStop: endStop, icon: block.sliderIcon, action: action, style: style, appearance: appearance)
} else if let endStop {
EndStopSlider(title: title, value: value, minimum: minimum, maximum: maximum, step: step, endStop: endStop) {
context.runAction(action, ["VALUE": String($0)])
}
Expand All @@ -570,12 +589,8 @@ struct PopupBlockView: View {
}
case let .filledSlider(title, source, minimum, maximum, step, endStop, icon, action):
let value = context.values[source] ?? Double(fields[source] ?? "") ?? minimum
let inset = (style.box.paddingTop ?? style.box.paddingVertical ?? 0) + (style.box.paddingBottom ?? style.box.paddingVertical ?? 0)
FilledSlider(title: title, value: value, minimum: minimum, maximum: maximum, step: step, endStop: endStop, icon: icon,
height: max((style.box.height ?? 28) - inset, 1), drawsTrack: style.box.background == nil,
appearance: appearance) {
context.runAction(action, ["VALUE": String($0)])
}
filledSlider(title: title, value: value, minimum: minimum, maximum: maximum, step: step,
endStop: endStop, icon: icon, action: action, style: style, appearance: appearance)
case let .toggle(title, source, action):
PopupToggle(title: title, value: fields[source] == "true" || fields[source] == "1" || context.values[source] == 1) {
context.runAction(action, ["VALUE": $0 ? "true" : "false"])
Expand Down Expand Up @@ -685,6 +700,19 @@ struct PopupBlockView: View {
}
}

extension PopupBlockView {
private func filledSlider(title: String, value: Double, minimum: Double, maximum: Double, step: Double,
endStop: SliderEndStop?, icon: String?, action: BlockAction, style: BlockStyle,
appearance: WidgetAppearance) -> some View {
let inset = (style.box.paddingTop ?? style.box.paddingVertical ?? 0) + (style.box.paddingBottom ?? style.box.paddingVertical ?? 0)
return FilledSlider(title: title, value: value, minimum: minimum, maximum: maximum, step: step, endStop: endStop, icon: icon,
height: max((style.box.height ?? 28) - inset, 1), drawsTrack: style.box.background == nil,
appearance: appearance, continuous: context.continuousSliders) {
context.runAction(action, ["VALUE": String($0)])
}
}
}

struct ControlEditingPreference: PreferenceKey {
static let defaultValue = false

Expand Down
2 changes: 1 addition & 1 deletion Sources/StableBar/PresentationConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

enum PresentationRole: String, Decodable, CaseIterable, Sendable {
case time, primary, secondary, key, value, heading, button, meter, separator
case time, primary, secondary, key, value, heading, button, meter, separator, slider
}

/// Only presentation belongs in workspace defaults. Workspace visibility and local app-glyph
Expand Down
Loading
Loading