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
3 changes: 3 additions & 0 deletions Sources/StableBar/Bar/WidgetAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct WorkspaceConfiguration: Decodable, Sendable {
var layoutGlyphs: [String: String]?
var hideApps: [String]?
var hideWorkspaces: [String]?
var order: [String]?
var showEmpty: Bool?
var showApps: Bool?
var windows: Bool?
Expand All @@ -197,6 +198,7 @@ struct WorkspaceConfiguration: Decodable, Sendable {
case indicator, indicatorStyle, style, focusedStyle, visibleStyle, emptyStyle, appStyle, focusedAppStyle, visibleAppStyle
case focusedWindowStyle
case appGlyphs, layoutGlyphs, hideApps, hideWorkspaces, showEmpty, showApps, windows, titleLength, magnification, badges
case order
}

init(from decoder: Decoder) throws {
Expand All @@ -207,6 +209,7 @@ struct WorkspaceConfiguration: Decodable, Sendable {
layoutGlyphs = try values.decodeIfPresent([String: String].self, forKey: .layoutGlyphs)
hideApps = try values.decodeIfPresent([String].self, forKey: .hideApps)
hideWorkspaces = try values.decodeIfPresent([String].self, forKey: .hideWorkspaces)
order = try values.decodeIfPresent([String].self, forKey: .order)
showEmpty = try values.decodeIfPresent(Bool.self, forKey: .showEmpty)
showApps = try values.decodeIfPresent(Bool.self, forKey: .showApps)
windows = try values.decodeIfPresent(Bool.self, forKey: .windows)
Expand Down
6 changes: 6 additions & 0 deletions Sources/StableBar/Settings/BarInspector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ struct BarInspector: View {
for: widget.id)
}
}
SettingRow(title: "Workspace order", hint: "Names in the order to show, separated by commas. Others follow in the source's order.") {
NameListField(title: "Workspace order", prompt: "Z, X, C, V, B, N, M", names: widget.workspace?.order ?? []) {
editor.set(["workspace": .object(["order": $0.isEmpty ? .null : .array($0.map(ConfigurationValue.string))])],
for: widget.id)
}
}
if widget.workspace?.windows == true {
let length = Binding(get: { Double(widget.workspace?.titleLength ?? 0) }, set: {
editor.set(["workspace": .object(["titleLength": .number($0)])], for: widget.id)
Expand Down
10 changes: 9 additions & 1 deletion Sources/StableBar/Workspaces/WorkspaceLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ struct WorkspaceFilter: Hashable {
let showEmpty: Bool
var hideApps: [String] = []
var hideWorkspaces: [String] = []
var order: [String] = []

func apply(to workspaces: [Workspace]) -> [Workspace] {
workspaces.compactMap { workspace in
let shown: [Workspace] = workspaces.compactMap { workspace -> Workspace? in
guard shows(workspace) else { return nil }
var workspace = workspace
workspace.apps.removeAll(where: hides)
workspace.windows.removeAll { hides($0.app) }
return workspace
}
guard !order.isEmpty else { return shown }
var seen = Set<String>()
let listed = order.compactMap { name -> Workspace? in
guard seen.insert(name).inserted else { return nil }
return shown.first { $0.name == name }
}
return listed + shown.filter { !seen.contains($0.name) }
}

/// Whether no workspace is shown, without filtering their apps and windows.
Expand Down
3 changes: 2 additions & 1 deletion Sources/StableBar/Workspaces/WorkspaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct WorkspaceView: View {
let workspaces = workspaceStore.workspaces(on: monitor,
showEmpty: configuration?.showEmpty == true
|| (workspaceStore.source.supportsWindowMoves && workspaceStore.windowDrag.active != nil),
hideApps: configuration?.hideApps ?? [], hideWorkspaces: configuration?.hideWorkspaces ?? [])
hideApps: configuration?.hideApps ?? [], hideWorkspaces: configuration?.hideWorkspaces ?? [],
order: configuration?.order ?? [])
let indicator = configuration?.indicator ?? .background
HStack(spacing: appearance.spacing) {
ForEach(workspaces) { workspace in
Expand Down
4 changes: 2 additions & 2 deletions Sources/StableBar/Workspaces/Workspaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ final class WorkspaceStore {
self.workspaceNotificationCenter = workspaceNotificationCenter
}

func workspaces(on monitor: Int, showEmpty: Bool, hideApps: [String] = [], hideWorkspaces: [String] = []) -> [Workspace] {
WorkspaceFilter(monitor: monitor, showEmpty: showEmpty, hideApps: hideApps, hideWorkspaces: hideWorkspaces).apply(to: workspaces)
func workspaces(on monitor: Int, showEmpty: Bool, hideApps: [String] = [], hideWorkspaces: [String] = [], order: [String] = []) -> [Workspace] {
WorkspaceFilter(monitor: monitor, showEmpty: showEmpty, hideApps: hideApps, hideWorkspaces: hideWorkspaces, order: order).apply(to: workspaces)
}

/// Retain the same subscription while either workspaces or presentation needs it.
Expand Down
11 changes: 11 additions & 0 deletions Tests/StableBarTests/WidgetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,17 @@ private func calls(_ log: URL) -> [Substring] {
#expect(workspaceStore.workspaces(on: 1, showEmpty: true, hideApps: hidden).map(\.name) == ["1", "2", "S", "T"])
}

@Test @MainActor func workspaceOrderPutsNamedWorkspacesFirst() {
let workspaceStore = WorkspaceStore()
workspaceStore.workspaces = ["Z", "X", "C", "V", "B", "N", "M"].map {
Workspace(name: $0, isFocused: false, isVisible: false, monitor: 1)
}
let keyboard = ["Z", "X", "C", "V", "B", "N", "M"]
#expect(workspaceStore.workspaces(on: 1, showEmpty: true, order: keyboard).map(\.name) == keyboard)
#expect(workspaceStore.workspaces(on: 1, showEmpty: true, order: ["M", "C", "Q"]).map(\.name)
== ["M", "C", "Z", "X", "V", "B", "N"])
}

@Test @MainActor func workspaceRowGrowsWhenAnEmptyWorkspaceAppears() throws {
let workspaceStore = WorkspaceStore()
workspaceStore.workspaces = [
Expand Down
1 change: 1 addition & 0 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ A `workspaces` widget (also accepted as `aerospace`) accepts `workspace` with:
- `showEmpty` and `showApps`: control empty workspaces and app icons.
- `hideApps`: app bundle IDs or app names the widget leaves out, matched like `appGlyphs` keys, so `Adobe Photoshop*` hides every Photoshop version. Hidden apps leave the per-app and `windows` views, and a workspace whose only apps are hidden counts as empty, so `showEmpty: false` hides it unless it's visible on a display. For example, `"workspace": { "hideApps": ["com.1password.1password", "Raycast"] }`.
- `hideWorkspaces`: workspace names the widget leaves out, unless that workspace is focused, such as `["S", "scratch"]`. In **Settings → Widgets**, select the workspace widget and list both in **Hide apps** and **Hide workspaces**, separated by commas.
- `order`: workspace names in the order the cells show them, such as `["Z", "X", "C", "V", "B", "N", "M"]`. Workspaces the list doesn't name follow in the source's order, and names that aren't present are skipped, like [`widgetOrder`](configuration.md#theme-tokens-and-automatic-profiles). It matches a workspace's name, as `hideWorkspaces` does, which with OmniWM or Rift can differ from the label the cell shows. In **Settings → Widgets**, select the workspace widget and list them in **Workspace order**, separated by commas. Without it, workspaces keep the source's order (alphabetical with AeroSpace).
- `windows`: when `true`, shows one item per window instead of one per app. Each item keeps its app icon or `appGlyphs` glyph. Clicking it focuses that window; clicking the workspace number or cell padding switches workspace. An item can outlive its window: AeroSpace, for one, doesn't announce a window leaving every workspace. When OmniWM can't find the window of an app that is running, clicking its item opens that app instead, as described in [OmniWM workspaces](#omniwm-workspaces). Otherwise, when clicking an item, or dropping it on another workspace, fails with AeroSpace, yabai, OmniWM, Rift or KiwiDesk, the widget reads the workspaces again and drops the item without an error if its window is gone. The error shows while the window is still listed, or when the workspaces can't be read. `showApps: false` hides these items too.
- `focusedWindowStyle`: the icon of the focused window, or in per-app mode of the app it belongs to. Off unless set: `{}` turns it on with the default look, a background reaching 3 pt past the icon on each side and 2 pt above and below, in the cell's text color at low opacity and with the cell's corner radius. With `magnification`, it hugs the icon while the pointer is over the widget. In **Settings → Widgets**, select the workspace widget and turn on **Mark the focused window**. AeroSpace, OmniWM, Rift, KiwiDesk and yabai report which window has focus; with yabai, register `window_focused` so the highlight follows focus. `background`, `cornerRadius`, `borderColor` and `borderWidth` change it, `paddingHorizontal` and `paddingVertical` set how far it reaches past the icon, `foreground`, `fontSize`, `appIcons` and the icon `width` and `height` apply to its icon or glyph over `appStyle`, and its `states` follow the cell: `focused`, `visible`, `empty`, mode and `hover`. `workspaceDefaults` accepts it too, so a theme can set it. For example, `"workspace": { "windows": true, "focusedWindowStyle": { "background": "#ffffff33", "cornerRadius": 6 } }`.
- `titleLength`: maximum characters of each window title when `windows` is enabled. Omit it or use `0` for icons only. For example, `"workspace": { "windows": true, "titleLength": 24 }`. The full title is available on hover. Titles refresh with workspace and window events; yabai users can also register `window_title_changed`.
Expand Down
21 changes: 21 additions & 0 deletions scenes/workspace-order-bar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "../scene.schema.json",
"configuration": {
"workspaceSource": "aerospace",
"widgets": [
{ "id": "order", "type": "workspaces", "position": "left",
"workspace": { "order": ["Z", "X", "C", "V", "B", "N"], "showEmpty": true } }
]
},
"workspaces": [
{ "workspace": "C", "workspace-is-focused": false, "workspace-is-visible": false, "monitor-appkit-nsscreen-screens-id": 1 },
{ "workspace": "V", "workspace-is-focused": false, "workspace-is-visible": false, "monitor-appkit-nsscreen-screens-id": 1 },
{ "workspace": "X", "workspace-is-focused": true, "workspace-is-visible": true, "monitor-appkit-nsscreen-screens-id": 1 },
{ "workspace": "N", "workspace-is-focused": false, "workspace-is-visible": false, "monitor-appkit-nsscreen-screens-id": 1 },
{ "workspace": "B", "workspace-is-focused": false, "workspace-is-visible": false, "monitor-appkit-nsscreen-screens-id": 1 },
{ "workspace": "Z", "workspace-is-focused": false, "workspace-is-visible": false, "monitor-appkit-nsscreen-screens-id": 1 }
],
"appearances": ["dark"],
"draw": "bar",
"width": 700
}
4 changes: 4 additions & 0 deletions stablebar.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,10 @@
"$ref": "#/definitions/strings",
"description": "Workspace names to leave out unless focused."
},
"order": {
"$ref": "#/definitions/strings",
"description": "Workspace names in the order the cells show them. Workspaces it doesn't name follow in the source's order."
},
"showEmpty": {
"$ref": "#/definitions/boolean"
},
Expand Down
Loading