From 754cbf3fdb9e4c4b12771eee2eab1d175e73cdee Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 12:55:47 +0100 Subject: [PATCH 1/8] feat: read a name for each widget group --- .../Configuration/LayoutConfiguration.swift | 11 ++++++++- Sources/StableBar/Themes/ThemeEdits.swift | 2 ++ .../StableBarTests/WidgetGroupingTests.swift | 24 +++++++++++++++++++ stablebar.schema.json | 4 ++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Sources/StableBar/Configuration/LayoutConfiguration.swift b/Sources/StableBar/Configuration/LayoutConfiguration.swift index fb46a9a9..9331722a 100644 --- a/Sources/StableBar/Configuration/LayoutConfiguration.swift +++ b/Sources/StableBar/Configuration/LayoutConfiguration.swift @@ -1,20 +1,29 @@ import Foundation struct WidgetGroupConfiguration: Decodable, Sendable { + /// The group's name in Settings; the bar doesn't draw it. + let name: String? var style: WidgetStyle let members: [WidgetGroupMember] - enum CodingKeys: String, CodingKey, CaseIterable { case style, members } + enum CodingKeys: String, CodingKey, CaseIterable { case name, style, members } init(from decoder: Decoder) throws { try decoder.rejectUnknownKeys(CodingKeys.self) let values = try decoder.container(keyedBy: CodingKeys.self) + name = try values.decodeIfPresent(String.self, forKey: .name) style = try values.decodeIfPresent(WidgetStyle.self, forKey: .style) ?? WidgetStyle() members = try values.decodeIfPresent([WidgetGroupMember].self, forKey: .members) ?? [] } var takesOthers: Bool { members.contains(where: \.others) } + /// What Settings calls `group`: its name, or its ID made readable when it has none. + static func title(of group: String, in groups: [String: WidgetGroupConfiguration]) -> String { + let name = groups[group]?.name?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" + return name.isEmpty ? friendly(group) : name + } + /// `widgets`, each enabled one without a `group` in the group whose `members` match it best, unless that group's /// widgets sit in another position and it doesn't take others. Widgets with their own `group` settle a group's /// position first. `ownGroup` can stand in for a widget's own `group`, to see where a widget would go without it. diff --git a/Sources/StableBar/Themes/ThemeEdits.swift b/Sources/StableBar/Themes/ThemeEdits.swift index 82c46a6f..41022313 100644 --- a/Sources/StableBar/Themes/ThemeEdits.swift +++ b/Sources/StableBar/Themes/ThemeEdits.swift @@ -245,6 +245,8 @@ private func lookValues(in document: [String: ConfigurationValue], tokens: (Stri case "defaults": add(path, leaf, section: "Widgets", title: styleTitle(Array(path.dropFirst()))) case "popupDefaults": add(path, leaf, section: "Popups", title: styleTitle(Array(path.dropFirst()))) case "groupDefaults": add(path, leaf, section: "Groups", title: "Every group: \(detailTitle(spacing(Array(path.dropFirst()))))") + // A group's name belongs to the bar under every theme, not to its look. + case "groups" where path == ["groups", name, "name"]: continue case "groups": add(path, leaf, section: "Groups", title: "\(friendly(name)) group: \(detailTitle(spacing(path.dropFirst(2).filter { $0 != "style" })))") case "roles": add(path, leaf, section: "Roles", title: "\(friendly(name)): \(detailTitle(Array(path.dropFirst(2))))") diff --git a/Tests/StableBarTests/WidgetGroupingTests.swift b/Tests/StableBarTests/WidgetGroupingTests.swift index 1b1fd498..d31e6f37 100644 --- a/Tests/StableBarTests/WidgetGroupingTests.swift +++ b/Tests/StableBarTests/WidgetGroupingTests.swift @@ -551,3 +551,27 @@ private let row = #""" #expect(grouping.ungroupBlocker("status") != nil) #expect(grouping.ungroupBlocker("other") == nil) } + +@MainActor @Test func aGroupsNameIsItsTitleAndItsIDIsTheFallback() throws { + let bar = try GroupingFixture(#""" + {"groups":{"group-2":{"name":"Status"},"group-3":{"name":" "},"group-4":{}},"widgets":[ + {"id":"a","type":"text","text":"A","position":"right","group":"group-2"}, + {"id":"b","type":"text","text":"B","position":"right","group":"group-3"}, + {"id":"c","type":"text","text":"C","position":"right","group":"group-4"} + ]} + """#) + defer { bar.close() } + let groups = bar.store.configuration!.groups + #expect(groups["group-2"]?.name == "Status") + #expect(WidgetGroupConfiguration.title(of: "group-2", in: groups) == "Status") + #expect(WidgetGroupConfiguration.title(of: "group-3", in: groups) == "Group 3") + #expect(WidgetGroupConfiguration.title(of: "group-4", in: groups) == "Group 4") + #expect(WidgetGroupConfiguration.title(of: "missing", in: groups) == "Missing") +} + +@Test func aGroupsNameIsNotALookValue() { + let main: [String: ConfigurationValue] = ["groups": .object(["status": .object([ + "name": .string("Status"), "style": .object(["cornerRadius": .number(8)])])])] + let edits = ThemeEdits(main: main, themeID: "clear") + #expect(edits.everyTheme.map(\.path) == [["groups", "status", "style", "cornerRadius"]]) +} diff --git a/stablebar.schema.json b/stablebar.schema.json index 5c113791..2c0927a0 100644 --- a/stablebar.schema.json +++ b/stablebar.schema.json @@ -2205,6 +2205,10 @@ "type": "object", "additionalProperties": false, "properties": { + "name": { + "$ref": "#/definitions/string", + "description": "The group's name in Settings. The bar doesn't show it." + }, "style": { "anyOf": [ { From 0a1baf0fb66755715a58fd0093ff2aca2217de58 Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 12:57:48 +0100 Subject: [PATCH 2/8] feat: rename a widget group from Settings' editor --- .../Settings/ConfigurationEditor.swift | 11 ++++ .../StableBarTests/WidgetGroupingTests.swift | 62 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/Sources/StableBar/Settings/ConfigurationEditor.swift b/Sources/StableBar/Settings/ConfigurationEditor.swift index 154a020a..57a84bf7 100644 --- a/Sources/StableBar/Settings/ConfigurationEditor.swift +++ b/Sources/StableBar/Settings/ConfigurationEditor.swift @@ -110,6 +110,17 @@ final class ConfigurationEditor { catch { self.error = errorMessage(error) } } + /// Names `group`, or removes its name when `name` is blank. The name isn't part of the look, so it's saved for every + /// theme rather than as an edit of the selected one. + func renameGroup(_ group: String, to name: String) { + let name = name.trimmingCharacters(in: .whitespacesAndNewlines) + if !name.isEmpty { + change([ConfigurationEdit(action: .groups, properties: [group: .object(["name": .string(name)])])]) + } else if store.configuration?.groups[group]?.name != nil { + change([ConfigurationEdit(action: .unset, properties: ["groups": .object([group: .object(["name": .null])])])]) + } + } + func showPackage(_ id: String) { finishEditing() searchTarget = nil diff --git a/Tests/StableBarTests/WidgetGroupingTests.swift b/Tests/StableBarTests/WidgetGroupingTests.swift index d31e6f37..be942bf4 100644 --- a/Tests/StableBarTests/WidgetGroupingTests.swift +++ b/Tests/StableBarTests/WidgetGroupingTests.swift @@ -575,3 +575,65 @@ private let row = #""" let edits = ThemeEdits(main: main, themeID: "clear") #expect(edits.everyTheme.map(\.path) == [["groups", "status", "style", "cornerRadius"]]) } + +@MainActor @Test func renamingAGroupSavesItsNameInOneUndoStepAndClearingRemovesIt() throws { + let bar = try GroupingFixture(row) + defer { bar.close() } + let editor = ConfigurationEditor(store: bar.store) + editor.group("a", .groupWith("b")) + editor.renameGroup("group", to: " Status ") + #expect(editor.error == nil) + #expect(bar.store.configuration?.groups["group"]?.name == "Status") + let saved = try bar.fixture.document()["groups"]?.decoded([String: [String: ConfigurationValue]].self) + #expect(saved?["group"]?["name"] == .string("Status")) + editor.undo() + #expect(bar.store.configuration?.groups["group"] != nil) + #expect(bar.store.configuration?.groups["group"]?.name == nil) + editor.renameGroup("group", to: "Status") + editor.renameGroup("group", to: " ") + #expect(bar.store.configuration?.groups["group"]?.name == nil) + editor.renameGroup("group", to: "") + #expect(editor.error == nil) + editor.renameGroup("group", to: "Status") + editor.ungroup("group") + #expect(try bar.fixture.document()["groups"] == nil) +} + +@MainActor @Test func renamingAThemesGroupKeepsTheNameOutOfTheThemesEdits() throws { + let bar = try GroupingFixture(#"{"widgets":[{"id":"clock","type":"clock","position":"right"}]}"#) + defer { bar.close() } + _ = try bar.fixture.theme(##"{"groups":{"time":{"style":{"background":"#000000"},"members":[{"type":"clock"}]}}}"##) + try bar.fixture.write(#"{"theme":{"id":"test-theme","version":"1"},"widgets":[{"id":"clock","type":"clock","position":"right"}]}"#, + to: bar.fixture.url) + bar.store.configurationStore.reloadConfiguration() + let editor = ConfigurationEditor(store: bar.store) + editor.renameGroup("time", to: "Time") + #expect(editor.error == nil) + #expect(bar.store.configuration?.groups["time"]?.name == "Time") + #expect(bar.store.configuration?.groups["time"]?.style.background != nil) + let document = try bar.fixture.document() + #expect(document["groups"] == .object(["time": .object(["name": .string("Time")])])) + #expect(document["profiles"] == nil) + #expect(ThemeEdits(main: document, themeID: "test-theme").everyTheme.isEmpty) +} + +@MainActor @Test func renamingAGroupWhileEditingAProfileKeepsTheNameInThatProfile() throws { + let bar = try GroupingFixture(#""" + {"profiles":[{"name":"work","when":{"app":"com.example.never"},"configuration":{}}],"widgets":[ + {"id":"a","type":"text","text":"A","position":"right"}, + {"id":"b","type":"text","text":"B","position":"right"} + ]} + """#) + defer { bar.close() } + let editor = ConfigurationEditor(store: bar.store) + editor.editBar(for: "work") + editor.group("a", .groupWith("b")) + editor.renameGroup("group", to: "Work") + #expect(editor.error == nil) + let document = try bar.fixture.document() + #expect(document["groups"] == nil) + let configuration = try document["profiles"]?.decoded([[String: ConfigurationValue]].self).first?["configuration"]? + .decoded([String: ConfigurationValue].self) + let groups = try configuration?["groups"]?.decoded([String: [String: ConfigurationValue]].self) + #expect(groups?["group"]?["name"] == .string("Work")) +} From a22508833217e5f6a1c570e66abe7f6cb3cd2722 Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:00:02 +0100 Subject: [PATCH 3/8] feat: rename a widget group in Settings --- Sources/StableBar/Editing/BarEditView.swift | 7 ++-- .../StableBar/Editing/WidgetGrouping.swift | 4 +-- Sources/StableBar/Settings/BarInspector.swift | 9 +++++- .../Settings/ConfigurationEditor.swift | 7 ++++ .../StableBar/Settings/GroupNameField.swift | 32 +++++++++++++++++++ Sources/StableBar/Settings/WidgetsView.swift | 8 +++-- .../StableBarTests/WidgetGroupingTests.swift | 26 +++++++++++++++ scenes/settings-group-name.json | 32 +++++++++++++++++++ 8 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 Sources/StableBar/Settings/GroupNameField.swift create mode 100644 scenes/settings-group-name.json diff --git a/Sources/StableBar/Editing/BarEditView.swift b/Sources/StableBar/Editing/BarEditView.swift index 3a071423..2ff81310 100644 --- a/Sources/StableBar/Editing/BarEditView.swift +++ b/Sources/StableBar/Editing/BarEditView.swift @@ -455,17 +455,18 @@ struct BarEditTile: View { @ViewBuilder private func groupCommands(on screen: BarDisplay) -> some View { let grouping = WidgetGrouping(store: store) + let groups = store.configuration?.onScreen(kind).groups ?? [:] if let group = entry.widget.group { Divider() - Button("Edit Group “\(friendly(group))”…") { editing.editGroup(group) } + Button("Edit Group “\(WidgetGroupConfiguration.title(of: group, in: groups))”…") { editing.editGroup(group) } .disabled(grouping.groups[group] == nil) Button("Leave Group") { editing.leaveGroup(entry.id, on: display) } .disabled(!grouping.canLeave(entry.id)) } else { - let choices = grouping.choices(for: entry.id, among: editing.widgets(on: screen), groups: store.configuration?.onScreen(kind).groups ?? [:]) + let choices = grouping.choices(for: entry.id, among: editing.widgets(on: screen), groups: groups) if !choices.isEmpty { Divider() } ForEach(choices, id: \.self) { choice in - Button(choice.title(names: editing.names)) { editing.group(entry.id, choice, on: display) } + Button(choice.title(names: editing.names, groups: groups)) { editing.group(entry.id, choice, on: display) } } } Divider() diff --git a/Sources/StableBar/Editing/WidgetGrouping.swift b/Sources/StableBar/Editing/WidgetGrouping.swift index c94c19c7..42b0de0c 100644 --- a/Sources/StableBar/Editing/WidgetGrouping.swift +++ b/Sources/StableBar/Editing/WidgetGrouping.swift @@ -15,9 +15,9 @@ struct WidgetGrouping { case join(String) case groupWith(String) - func title(names: [String: String]) -> String { + func title(names: [String: String], groups: [String: WidgetGroupConfiguration]) -> String { switch self { - case let .join(group): "Add to Group “\(friendly(group))”" + case let .join(group): "Add to Group “\(WidgetGroupConfiguration.title(of: group, in: groups))”" case let .groupWith(id): "Group With “\(names[id] ?? id)”" } } diff --git a/Sources/StableBar/Settings/BarInspector.swift b/Sources/StableBar/Settings/BarInspector.swift index 85c862cf..3e84b671 100644 --- a/Sources/StableBar/Settings/BarInspector.swift +++ b/Sources/StableBar/Settings/BarInspector.swift @@ -60,7 +60,8 @@ struct BarInspector: View { if let widget { widgetHeader(widget) } else if let group { - header(Image(systemName: WidgetGrouping.symbol).font(.system(size: 18)), title: friendly(group)) { + header(Image(systemName: WidgetGrouping.symbol).font(.system(size: 18)), + title: WidgetGroupConfiguration.title(of: group, in: store.configuration?.onScreen(screen).groups ?? [:])) { Text(groupMembers(group).isEmpty ? "Group" : "Group of \(groupMembers(group).map { names[$0.id] ?? $0.id }.formatted(.list(type: .and)))") } @@ -248,6 +249,12 @@ struct BarInspector: View { set: { editor.changeLook(ConfigurationEdit(action: .groups, properties: [group: .object(["style": .object($0)])])) }, unset: { unset(["groups": .object([group: .object(["style": .object($0)])])]) }) let grouping = WidgetGrouping(store: store) + SettingsGroup("Group") { + SettingRow(title: "Name", hint: "Shown in Settings only, under every theme.") { + GroupNameField(placeholder: friendly(group), name: store.configuration?.groups[group]?.name ?? "", + focusRequested: $editor.renameGroupRequested) { editor.renameGroup(group, to: $0) } + } + } GroupsLookSection(editor: editor, style: style, flared: store.configuration?.groups[group]?.style.flare != nil, spacing: store.configuration?.onScreen(screen).bar.spacing ?? 0, title: "Style") SettingsGroup("Widgets") { diff --git a/Sources/StableBar/Settings/ConfigurationEditor.swift b/Sources/StableBar/Settings/ConfigurationEditor.swift index 57a84bf7..52ef55e6 100644 --- a/Sources/StableBar/Settings/ConfigurationEditor.swift +++ b/Sources/StableBar/Settings/ConfigurationEditor.swift @@ -29,6 +29,8 @@ final class ConfigurationEditor { var barItem = BarItem.widget /// The group Settings shows while `barItem` is `group`. var selectedGroup: String? + /// Set by Rename…: the group's Name field takes focus once it shows, and clears it. + var renameGroupRequested = false var appearanceTab = AppearanceTab.themes var widgetTab = WidgetTab.content var barScreen = ScreenKind.laptop @@ -110,6 +112,11 @@ final class ConfigurationEditor { catch { self.error = errorMessage(error) } } + func startRenaming(_ group: String) { + showGroup(group) + renameGroupRequested = barItem == .group && selectedGroup == group + } + /// Names `group`, or removes its name when `name` is blank. The name isn't part of the look, so it's saved for every /// theme rather than as an edit of the selected one. func renameGroup(_ group: String, to name: String) { diff --git a/Sources/StableBar/Settings/GroupNameField.swift b/Sources/StableBar/Settings/GroupNameField.swift new file mode 100644 index 00000000..8c062ea5 --- /dev/null +++ b/Sources/StableBar/Settings/GroupNameField.swift @@ -0,0 +1,32 @@ +import SwiftUI + +/// A group's name, saved on Return or when the field loses focus. A blank name goes back to `placeholder`. +struct GroupNameField: View { + let placeholder: String + let name: String + @Binding var focusRequested: Bool + let save: (String) -> Void + @State private var text = "" + @FocusState private var focused: Bool + + var body: some View { + TextField("Name", text: $text, prompt: Text(placeholder)) + .labelsHidden() + .frame(width: 220) + .focused($focused) + .onSubmit(commit) + .onAppear { text = name } + .onChange(of: name) { if !focused { text = name } } + .onChange(of: focused) { if !focused { commit() } } + .onChange(of: focusRequested, initial: true) { + guard focusRequested else { return } + focusRequested = false + focused = true + } + } + + private func commit() { + guard text.trimmingCharacters(in: .whitespacesAndNewlines) != name else { return } + save(text) + } +} diff --git a/Sources/StableBar/Settings/WidgetsView.swift b/Sources/StableBar/Settings/WidgetsView.swift index 0773790d..76f7e22b 100644 --- a/Sources/StableBar/Settings/WidgetsView.swift +++ b/Sources/StableBar/Settings/WidgetsView.swift @@ -221,7 +221,7 @@ struct WidgetsView: View { grouping: WidgetGrouping) -> some View { let selected = selectedGroup == group let first = members[0] - let title = friendly(group) + let title = WidgetGroupConfiguration.title(of: group, in: groups) let subtitle = members.count == 1 ? "Group · 1 widget" : "Group · \(members.count) widgets" let collapsed = collapsedGroups.contains(group) return ListRow(selected: selected) { _ in @@ -264,6 +264,8 @@ struct WidgetsView: View { } } Divider() + Button("Rename…") { editor.startRenaming(group) } + .disabled(grouping.groups[group] == nil) Button("Ungroup") { editor.ungroup(group) } .disabled(grouping.ungroupBlocker(group) != nil) } @@ -310,7 +312,7 @@ struct WidgetsView: View { } Divider() if let group = widget.group { - Button("Edit Group “\(friendly(group))”") { editor.showGroup(group) } + Button("Edit Group “\(WidgetGroupConfiguration.title(of: group, in: groups))”") { editor.showGroup(group) } .disabled(grouping.groups[group] == nil) Button("Leave Group") { editor.leaveGroup(widget.id) } .disabled(!grouping.canLeave(widget.id)) @@ -318,7 +320,7 @@ struct WidgetsView: View { } else { let choices = grouping.choices(for: widget.id, among: listed, groups: groups) ForEach(choices, id: \.self) { choice in - Button(choice.title(names: names)) { editor.group(widget.id, choice) } + Button(choice.title(names: names, groups: groups)) { editor.group(widget.id, choice) } } if !choices.isEmpty { Divider() } } diff --git a/Tests/StableBarTests/WidgetGroupingTests.swift b/Tests/StableBarTests/WidgetGroupingTests.swift index be942bf4..3229f2ce 100644 --- a/Tests/StableBarTests/WidgetGroupingTests.swift +++ b/Tests/StableBarTests/WidgetGroupingTests.swift @@ -637,3 +637,29 @@ private let row = #""" let groups = try configuration?["groups"]?.decoded([String: [String: ConfigurationValue]].self) #expect(groups?["group"]?["name"] == .string("Work")) } + +@MainActor @Test func groupCommandsUseTheGroupsName() throws { + let bar = try GroupingFixture(#""" + {"groups":{"group-2":{"name":"Status"}},"widgets":[ + {"id":"a","type":"text","text":"A","position":"right","group":"group-2"}, + {"id":"b","type":"text","text":"B","position":"right"} + ]} + """#) + defer { bar.close() } + let groups = bar.store.configuration!.groups + #expect(WidgetGrouping.Choice.join("group-2").title(names: [:], groups: groups) == "Add to Group “Status”") + #expect(WidgetGrouping.Choice.groupWith("a").title(names: ["a": "Alpha"], groups: groups) == "Group With “Alpha”") +} + +@MainActor @Test func renameShowsTheGroupAndAsksForItsName() throws { + let bar = try GroupingFixture(row) + defer { bar.close() } + let editor = ConfigurationEditor(store: bar.store) + editor.group("a", .groupWith("b")) + editor.showWidget("c") + #expect(!editor.renameGroupRequested) + editor.startRenaming("group") + #expect(editor.barItem == .group) + #expect(editor.selectedGroup == "group") + #expect(editor.renameGroupRequested) +} diff --git a/scenes/settings-group-name.json b/scenes/settings-group-name.json new file mode 100644 index 00000000..5902ffb6 --- /dev/null +++ b/scenes/settings-group-name.json @@ -0,0 +1,32 @@ +{ + "$schema": "../scene.schema.json", + "configuration": { + "groups": { + "status": { "name": "Status", "style": { "background": "#8080802e", "cornerRadius": 14, "paddingHorizontal": 4 } } + }, + "widgets": [ + { "id": "apple", "type": "appleMenu", "position": "left" }, + { "id": "battery", "type": "battery", "position": "right", "group": "status" }, + { "id": "network", "type": "network", "position": "right", "group": "status" }, + { "id": "time", "type": "clock", "format": "EEE d MMM HH:mm", "position": "right" } + ] + }, + "outputs": { + "battery": { + "text": "82%", + "icon": "battery.75percent", + "values": { "percent": 0.82 }, + "fields": { "percent": "82", "state": "battery" } + }, + "network": { + "text": "↓1.2 MiB/s ↑240 KiB/s", + "icon": "network", + "fields": { "interface": "en0", "downloadRate": "1.2 MiB/s", "uploadRate": "240 KiB/s" }, + "values": { "download": 1258291, "upload": 245760 } + } + }, + "appearances": ["dark"], + "draw": "settings", + "group": "status", + "height": 900 +} From ef0edd0f260659e41acee51933ed74b021ac8ebb Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:00:22 +0100 Subject: [PATCH 4/8] docs: describe naming a widget group --- docs/layout.md | 2 +- docs/settings.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/layout.md b/docs/layout.md index 1a3ef454..81bde789 100644 --- a/docs/layout.md +++ b/docs/layout.md @@ -77,7 +77,7 @@ Use `"overflow": "never"` for essential widgets. If these alone exceed the avail } ``` -A named group has one shared background, padding, border and spacing. Members must use the same `position`; their first appearance places the group. To make one without editing the file, right-click a widget in [**Settings → Widgets**](settings.md) or while editing the bar in place and choose **Group With** the widget beside it. In Settings, the new group opens so you can choose its look; on the bar, choose **Edit Group…** for that. A group overflows as one unit, takes its highest member priority, and stays visible if any member sets `overflow` to `never`. +A named group has one shared background, padding, border and spacing. Members must use the same `position`; their first appearance places the group. To make one without editing the file, right-click a widget in [**Settings → Widgets**](settings.md) or while editing the bar in place and choose **Group With** the widget beside it. In Settings, the new group opens so you can choose its look; on the bar, choose **Edit Group…** for that. Such a group's ID is `group`, `group-2` and so on; give it a `name`, such as `"groups": {"group-2": {"name": "Status"}}`, or type one in the group's **Name** field in Settings, or choose **Rename…** in its context menu. Settings shows the name instead of the ID under every theme; the bar doesn't draw it. Clearing the field removes the name. A group overflows as one unit, takes its highest member priority, and stays visible if any member sets `overflow` to `never`. Every group starts from `groupDefaults`, then its own `style`, property by property. A theme drawn as pills sets its pill look there once, and the groups you make follow it too. Set it in **Settings → Appearance → Groups**. **Group With** gives a new group its faint backdrop only while `groupDefaults` has no background; otherwise the group takes the shared look. A `null` in a group's style inherits the shared value, as a widget's does from `defaults`; for no background on one group, give it a transparent color such as `#00000000`. diff --git a/docs/settings.md b/docs/settings.md index f481af91..7c5b36ed 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -19,7 +19,7 @@ Outside Applications, **Open at login** offers **Move to Applications**; **Comma **Widgets** holds what's on the bar and where. **Editing**, at its top, chooses the kind of screen whose bar shows, the [screen setup](layout.md#screen-setups) whose bar you edit, with **Give it its own bar** or **Use the shared bar again…**, and the profile. Below are screen-kind thumbnails and a preview; click a widget in the preview to select it. The list contains **Screens**, widgets grouped by position, and **Not on this screen**. **Screens** says whether these screens have their own bar, and opens Appearance, where the bar's look and position are. A [group](layout.md#adaptive-layout-and-groups) is a row of its own, with its widgets indented under it; its arrow hides or shows them, and hiding them while one is selected selects the group. Selecting a hidden widget, such as in the preview, shows them again. Each widget's line names the screens it shows on, such as **All screens**, **Laptop only** or **Hidden everywhere**. Selecting a group outlines it in the preview and shows its **Style**, the rows of **Groups** for that group alone, with the values it takes from **Groups** in Appearance, then its widgets, each with **Leave Group**, and **Ungroup**, which takes them all out. -Drag widgets in the bar preview or the list, within or between position groups, to move them; widgets that share a group move together, with one Undo step. The preview, the screen thumbnails and the theme cards show your wallpaper when it's one of Apple's or in your Pictures folder, outside a Photos library. StableBar doesn't read other pictures, since macOS could ask for access to them, and shows its own wallpaper instead. Position targets appear along the preview while dragging, including empty positions. The context menu offers **Move up**, **Move down**, **Move to**, **Shows on** and **Remove from bar**; ⌥⌘↑ and ⌥⌘↓ move the selected widget. A widget beside a group in the same position offers **Add to Group**, and one beside another widget offers **Group With** that widget, which starts a group and selects it so you can style it. The group takes the look of **Groups** in Appearance, or a faint background when that sets none. A widget in a group offers **Edit Group** and **Leave Group**; a group's own context menu offers **Ungroup**. A widget that a group's `members` take in, such as one in a theme's pill, can't leave it this way: change the group's `members` instead. Neither can one that a profile in an included file puts in the group, which also keeps **Ungroup** off; change that profile. On a screen with [its own theme](layout.md#screen-setups), a group that only that theme has can't be selected and offers no **Edit Group**, **Add to Group**, **Leave Group** or **Ungroup**. Empty positions remain drop targets, including both sides of the notch when a display or widget uses them. Eye controls show or hide widgets on the selected screen kind. +Drag widgets in the bar preview or the list, within or between position groups, to move them; widgets that share a group move together, with one Undo step. The preview, the screen thumbnails and the theme cards show your wallpaper when it's one of Apple's or in your Pictures folder, outside a Photos library. StableBar doesn't read other pictures, since macOS could ask for access to them, and shows its own wallpaper instead. Position targets appear along the preview while dragging, including empty positions. The context menu offers **Move up**, **Move down**, **Move to**, **Shows on** and **Remove from bar**; ⌥⌘↑ and ⌥⌘↓ move the selected widget. A widget beside a group in the same position offers **Add to Group**, and one beside another widget offers **Group With** that widget, which starts a group and selects it so you can style it. The group takes the look of **Groups** in Appearance, or a faint background when that sets none. A widget in a group offers **Edit Group** and **Leave Group**; a group's own context menu offers **Rename…** and **Ungroup**. A group's settings start with its **Name**, which Settings shows in place of its ID, such as `group-2`, under every theme; clear it to go back to the ID. A widget that a group's `members` take in, such as one in a theme's pill, can't leave it this way: change the group's `members` instead. Neither can one that a profile in an included file puts in the group, which also keeps **Ungroup** off; change that profile. On a screen with [its own theme](layout.md#screen-setups), a group that only that theme has can't be selected and offers no **Edit Group**, **Add to Group**, **Leave Group**, **Rename…** or **Ungroup**. Empty positions remain drop targets, including both sides of the notch when a display or widget uses them. Eye controls show or hide widgets on the selected screen kind. **Add widget** opens a searchable grid of built-in, Store and script choices. With more than one kind of screen connected, **Add to** has a checkbox for each; newly added widgets show on the checked ones, all by default, and one must stay checked. Built-in choices stay available offline. Click a choice or select it with the arrow keys and press Return. Adding a package already on the bar selects its widget and keeps its position and compatible settings. Packages with commands, permissions, hosts, required tools or secret settings show their review before you add them. New widgets go to the end of the selected widget's position, or Right if none is selected, and become selected. The **+** beside a position's name, or a click in an empty position, adds to that position instead. From c07853fc47b50381022c6b2a596eb01f20c6e4d8 Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:06:57 +0100 Subject: [PATCH 5/8] fix: clear a group name that another layer sets, and skip a group that is gone --- .../Settings/ConfigurationEditor.swift | 13 +++++- .../StableBarTests/WidgetGroupingTests.swift | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Sources/StableBar/Settings/ConfigurationEditor.swift b/Sources/StableBar/Settings/ConfigurationEditor.swift index 52ef55e6..203ab36d 100644 --- a/Sources/StableBar/Settings/ConfigurationEditor.swift +++ b/Sources/StableBar/Settings/ConfigurationEditor.swift @@ -120,12 +120,21 @@ final class ConfigurationEditor { /// Names `group`, or removes its name when `name` is blank. The name isn't part of the look, so it's saved for every /// theme rather than as an edit of the selected one. func renameGroup(_ group: String, to name: String) { + // The field saves when it loses focus, which can come after Ungroup or Undo took the group away. + guard let current = store.configuration?.groups[group] else { return } let name = name.trimmingCharacters(in: .whitespacesAndNewlines) if !name.isEmpty { change([ConfigurationEdit(action: .groups, properties: [group: .object(["name": .string(name)])])]) - } else if store.configuration?.groups[group]?.name != nil { - change([ConfigurationEdit(action: .unset, properties: ["groups": .object([group: .object(["name": .null])])])]) + return } + guard current.name != nil else { return } + // A name another layer gives the group, such as an included file or the bar under a profile, needs a `null` here. + let mainFile = store.configurationStore.configurationURL.standardizedFileURL.path + let elsewhere = store.contributions["groups.\(group).name"]?.contains { + $0.value != .null && ($0.origin.file != mainFile || $0.origin.profile != editingProfile) + } == true + change([elsewhere ? ConfigurationEdit(action: .groups, properties: [group: .object(["name": .null])]) + : ConfigurationEdit(action: .unset, properties: ["groups": .object([group: .object(["name": .null])])])]) } func showPackage(_ id: String) { diff --git a/Tests/StableBarTests/WidgetGroupingTests.swift b/Tests/StableBarTests/WidgetGroupingTests.swift index 3229f2ce..0c14e6b2 100644 --- a/Tests/StableBarTests/WidgetGroupingTests.swift +++ b/Tests/StableBarTests/WidgetGroupingTests.swift @@ -663,3 +663,43 @@ private let row = #""" #expect(editor.selectedGroup == "group") #expect(editor.renameGroupRequested) } + +@MainActor @Test func clearingANameAnIncludedFileSetsHidesItInTheMainFile() throws { + let bar = try GroupingFixture(#""" + {"includes":["included.json"],"widgets":[{"id":"a","type":"text","text":"A","position":"right","group":"status"}]} + """#, includes: #"{"groups":{"status":{"name":"Status"}}}"#) + defer { bar.close() } + let editor = ConfigurationEditor(store: bar.store) + #expect(bar.store.configuration?.groups["status"]?.name == "Status") + editor.renameGroup("status", to: "") + #expect(editor.error == nil) + #expect(bar.store.configuration?.groups["status"]?.name == nil) + #expect(try bar.fixture.document()["groups"] == .object(["status": .object(["name": .null])])) +} + +@MainActor @Test func clearingTheBarsNameWhileEditingAProfileHidesItInThatProfile() throws { + let bar = try GroupingFixture(#""" + {"profiles":[{"name":"work","when":{"app":"com.example.never"},"configuration":{}}], + "groups":{"status":{"name":"Status"}}, + "widgets":[{"id":"a","type":"text","text":"A","position":"right","group":"status"}]} + """#) + defer { bar.close() } + let editor = ConfigurationEditor(store: bar.store) + editor.editBar(for: "work") + editor.renameGroup("status", to: " ") + #expect(editor.error == nil) + #expect(bar.store.configuration?.groups["status"]?.name == nil) + let document = try bar.fixture.document() + #expect(document["groups"] == .object(["status": .object(["name": .string("Status")])])) + let configuration = try document["profiles"]?.decoded([[String: ConfigurationValue]].self).first?["configuration"] + #expect(configuration == .object(["groups": .object(["status": .object(["name": .null])])])) +} + +@MainActor @Test func renamingAGroupThatIsGoneChangesNothing() throws { + let bar = try GroupingFixture(row) + defer { bar.close() } + let editor = ConfigurationEditor(store: bar.store) + editor.renameGroup("group", to: "Status") + #expect(editor.undoSteps.isEmpty) + #expect(try bar.fixture.document()["groups"] == nil) +} From 50a48568c2ef50a6ac687048f83473e672623d0d Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:11:22 +0100 Subject: [PATCH 6/8] test: draw a generated group ID with its name in the settings scene --- scenes/settings-group-name.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scenes/settings-group-name.json b/scenes/settings-group-name.json index 5902ffb6..be783193 100644 --- a/scenes/settings-group-name.json +++ b/scenes/settings-group-name.json @@ -2,12 +2,12 @@ "$schema": "../scene.schema.json", "configuration": { "groups": { - "status": { "name": "Status", "style": { "background": "#8080802e", "cornerRadius": 14, "paddingHorizontal": 4 } } + "group-2": { "name": "Status", "style": { "background": "#8080802e", "cornerRadius": 14, "paddingHorizontal": 4 } } }, "widgets": [ { "id": "apple", "type": "appleMenu", "position": "left" }, - { "id": "battery", "type": "battery", "position": "right", "group": "status" }, - { "id": "network", "type": "network", "position": "right", "group": "status" }, + { "id": "battery", "type": "battery", "position": "right", "group": "group-2" }, + { "id": "network", "type": "network", "position": "right", "group": "group-2" }, { "id": "time", "type": "clock", "format": "EEE d MMM HH:mm", "position": "right" } ] }, @@ -27,6 +27,6 @@ }, "appearances": ["dark"], "draw": "settings", - "group": "status", + "group": "group-2", "height": 900 } From 454e148d158ddc7d74aca8e8d088ce3dd181deea Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:18:49 +0100 Subject: [PATCH 7/8] fix: leave a group without widgets unnamed when the name field saves late --- .../StableBar/Settings/ConfigurationEditor.swift | 3 ++- Tests/StableBarTests/WidgetGroupingTests.swift | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/StableBar/Settings/ConfigurationEditor.swift b/Sources/StableBar/Settings/ConfigurationEditor.swift index 203ab36d..e70b10e1 100644 --- a/Sources/StableBar/Settings/ConfigurationEditor.swift +++ b/Sources/StableBar/Settings/ConfigurationEditor.swift @@ -121,7 +121,8 @@ final class ConfigurationEditor { /// theme rather than as an edit of the selected one. func renameGroup(_ group: String, to name: String) { // The field saves when it loses focus, which can come after Ungroup or Undo took the group away. - guard let current = store.configuration?.groups[group] else { return } + guard let current = store.configuration?.groups[group], + store.configuration?.widgets.contains(where: { $0.group == group }) == true else { return } let name = name.trimmingCharacters(in: .whitespacesAndNewlines) if !name.isEmpty { change([ConfigurationEdit(action: .groups, properties: [group: .object(["name": .string(name)])])]) diff --git a/Tests/StableBarTests/WidgetGroupingTests.swift b/Tests/StableBarTests/WidgetGroupingTests.swift index 0c14e6b2..870beda7 100644 --- a/Tests/StableBarTests/WidgetGroupingTests.swift +++ b/Tests/StableBarTests/WidgetGroupingTests.swift @@ -703,3 +703,17 @@ private let row = #""" #expect(editor.undoSteps.isEmpty) #expect(try bar.fixture.document()["groups"] == nil) } + +@MainActor @Test func renamingAGroupNoWidgetIsInChangesNothing() throws { + let bar = try GroupingFixture(#""" + {"includes":["included.json"],"groups":{"status":{}},"widgetOverrides":{"imported":{"group":"status"}},"widgets":[]} + """#, includes: #"{"widgets":[{"id":"imported","type":"text","text":"B","position":"right","group":"status"}]}"#) + defer { bar.close() } + let editor = ConfigurationEditor(store: bar.store) + editor.ungroup("status") + #expect(bar.store.configuration?.groups["status"] != nil) + let steps = editor.undoSteps.count + editor.renameGroup("status", to: "Status") + #expect(editor.undoSteps.count == steps) + #expect(try bar.fixture.document()["groups"] == .object(["status": .object([:])])) +} From 8a62184f83659a849ab8f3fb40cb15c792be2878 Mon Sep 17 00:00:00 2001 From: Steve Mendes Reis <6802086+M4n0x@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:30:54 +0100 Subject: [PATCH 8/8] fix: keep a rename made elsewhere while the group name field has focus --- Sources/StableBar/Settings/GroupNameField.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/StableBar/Settings/GroupNameField.swift b/Sources/StableBar/Settings/GroupNameField.swift index 8c062ea5..a8c1908b 100644 --- a/Sources/StableBar/Settings/GroupNameField.swift +++ b/Sources/StableBar/Settings/GroupNameField.swift @@ -16,7 +16,10 @@ struct GroupNameField: View { .focused($focused) .onSubmit(commit) .onAppear { text = name } - .onChange(of: name) { if !focused { text = name } } + // A draft the user hasn't touched follows a rename made elsewhere, so leaving the field can't undo it. + .onChange(of: name) { oldName, newName in + if !focused || text == oldName { text = newName } + } .onChange(of: focused) { if !focused { commit() } } .onChange(of: focusRequested, initial: true) { guard focusRequested else { return }