Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.2.1
6.2.1
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't touch unrelated files for no reasons

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird thing my editor did. you're right. sorry!

also, my PR wasnt ready for review when you left these comments, I would've caught some of these (and have fixed the CI already) as not to waste your time. I will mark the PR as draft in the future

9 changes: 8 additions & 1 deletion Sources/AppBundle/command/impl/ListWindowsCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ struct ListWindowsCommand: Command {
_list.append((window, try await window.title))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link the appropriate issue in the commit message: #491

Copy link
Copy Markdown
Author

@prawwtocol prawwtocol Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for creating an issue for me! will do

upd: didn't see this issue when I created my PR. just needed this functionality myself lol!

}
_list = _list.filter { $0.window.isBound }
_list = _list.sortedBy([{ $0.window.app.name ?? "" }, \.title])

// Sort based on --sort flag (default: tree-order)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comment

switch args.sortOrder {
case .appName:
_list = _list.sortedBy([{ $0.window.app.name ?? "" }, \.title])
case .treeOrder:
break // Already in tree order from allLeafWindowsRecursive
}

let list = _list.map { AeroObj.window(window: $0.window, title: $0.title) }
if args.json {
Expand Down
10 changes: 10 additions & 0 deletions Sources/Common/cmdArgs/impl/ListWindowsCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public struct ListWindowsCmdArgs: CmdArgs {
"--pid": singleValueSubArgParser(\.filteringOptions.pidFilter, "<pid>", Int32.init),
"--app-bundle-id": singleValueSubArgParser(\.filteringOptions.appIdFilter, "<app-bundle-id>") { $0 },

// Sorting flag
"--sort": singleValueSubArgParser(\._sortOrder, "<sort-order>") { SortOrder(rawValue: $0) },
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--sort flag should conflict with --count flag

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to call the flag --sort-by

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use parseEnum util function as it produces nicer error message in case of parsing error

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to --workspace and --monitor, <sort-order> should be not a scalar value but a space-separated array. Otherwise, the current .sortedBy([{ $0.window.app.name ?? "" }, \.title]) sorting is not representable

Right now, you call it app-name, but it's just wrong. The flag that represents the current default sorting should be --sort-by app-name window-title


// Formatting flags
"--format": formatParser(\._format, for: .window),
"--count": trueBoolFlag(\.outputOnlyCount),
Expand All @@ -36,6 +39,8 @@ public struct ListWindowsCmdArgs: CmdArgs {
fileprivate var all: Bool = false // ALIAS

public var filteringOptions = FilteringOptions()
public var _sortOrder: SortOrder? = nil
public var sortOrder: SortOrder { _sortOrder ?? .treeOrder }
Comment on lines +42 to +43
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public var _sortOrder: SortOrder? = nil
public var sortOrder: SortOrder { _sortOrder ?? .treeOrder }
public var sortOrder: SortOrder = .treeOrder

The second variable seems redundant

public var _format: [StringInterToken] = []
public var outputOnlyCount: Bool = false
public var json: Bool = false
Expand All @@ -47,6 +52,11 @@ public struct ListWindowsCmdArgs: CmdArgs {
public var pidFilter: Int32?
public var appIdFilter: String?
}

public enum SortOrder: String, Sendable {
case treeOrder = "tree-order"
case appName = "app-name"
}
}

extension ListWindowsCmdArgs {
Expand Down
5 changes: 3 additions & 2 deletions Sources/Common/cmdHelpGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ let list_monitors_help_generated = """
let list_windows_help_generated = """
USAGE: list-windows [-h|--help] (--workspace <workspace>...|--monitor <monitor>...)
[--monitor <monitor>...] [--workspace <workspace>...]
[--pid <pid>] [--app-bundle-id <app-bundle-id>] [--format <output-format>]
[--pid <pid>] [--app-bundle-id <app-bundle-id>]
[--sort <sort-order>] [--format <output-format>]
[--count] [--json]
OR: list-windows [-h|--help] --all [--format <output-format>] [--count] [--json]
OR: list-windows [-h|--help] --all [--sort <sort-order>] [--format <output-format>] [--count] [--json]
OR: list-windows [-h|--help] --focused [--format <output-format>] [--count] [--json]
"""
let list_workspaces_help_generated = """
Expand Down
13 changes: 11 additions & 2 deletions docs/aerospace-list-windows.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ include::util/man-attributes.adoc[]
// tag::synopsis[]
aerospace list-windows [-h|--help] (--workspace <workspace>...|--monitor <monitor>...)
[--monitor <monitor>...] [--workspace <workspace>...]
[--pid <pid>] [--app-bundle-id <app-bundle-id>] [--format <output-format>]
[--pid <pid>] [--app-bundle-id <app-bundle-id>]
[--sort <sort-order>] [--format <output-format>]
[--count] [--json]
aerospace list-windows [-h|--help] --all [--format <output-format>] [--count] [--json]
aerospace list-windows [-h|--help] --all [--sort <sort-order>] [--format <output-format>] [--count] [--json]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update grammar/commands-bnf-grammar.txt

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your insightful comments! You know much more about this project than me, of course 🤗

aerospace list-windows [-h|--help] --focused [--format <output-format>] [--count] [--json]

// end::synopsis[]
Expand Down Expand Up @@ -55,6 +56,14 @@ Filter results to only print windows that belong to the Application with specifi
+
Deprecated (but still supported) flag name: `--app-id`

--sort <sort-order>::
Specify the order in which windows are listed.
+
Possible values: +
+
. `tree-order` - (default) Windows are listed in tree traversal order (DFS). This matches the visual order in accordion/tiles layout.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think that tree-order is a better default? (It's a genuine question)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I failed to address this in my comment notes but one of the usecases is better integration with window bar applications like

https://github.com/Jean-Tinland/simple-bar
https://github.com/cmacrae/spacebar?tab=readme-ov-file
https://github.com/FelixKratz/SketchyBar

They benefit from displaying open windows in tree-order instead of id-sorted order

Copy link
Copy Markdown
Author

@prawwtocol prawwtocol Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will include that info in further commit descriptions

. `app-name` - Windows are sorted alphabetically by application name, then by window title.

--format <output-format>:: Specify output format. See "Output Format" section for more details.
Incompatible with `--count`

Expand Down
Loading