Skip to content

Commit

Permalink
focus command: add --ignore-floating flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Jul 21, 2024
1 parent 2c1cebd commit 879cb61
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Sources/AppBundle/command/FocusCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ struct FocusCommand: Command {
let window = state.subject.windowOrNil
let workspace = state.subject.workspace
// todo bug: floating windows break mru
let floatingWindows = makeFloatingWindowsSeenAsTiling(workspace: workspace)
let floatingWindows = args.floatingAsTiling ? makeFloatingWindowsSeenAsTiling(workspace: workspace) : []
defer {
restoreFloatingWindows(floatingWindows: floatingWindows, workspace: workspace)
if args.floatingAsTiling {
restoreFloatingWindows(floatingWindows: floatingWindows, workspace: workspace)
}
}

var result: Bool = true
Expand Down Expand Up @@ -94,7 +96,7 @@ private func makeFloatingWindowsSeenAsTiling(workspace: Workspace) -> [FloatingW
}
let floatingWindows: [FloatingWindowData] = workspace.floatingWindows
.map { (window: Window) -> FloatingWindowData? in
let center = window.getCenter()
let center = window.getCenter() // todo bug: we shouldn't access ax api here. What if the window was moved but it wasn't committed to ax yet?
guard let center else { return nil }
// todo bug: what if there are no tiling windows on the workspace?
guard let target = center.coerceIn(rect: workspace.workspaceMonitor.visibleRectPaddedByOuterGaps).findIn(tree: workspace.rootTilingContainer, virtual: true) else { return nil }
Expand Down
4 changes: 4 additions & 0 deletions Sources/AppBundleTests/command/FocusCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ final class FocusCommandTest: XCTestCase {
parseCommand("focus --boundaries workspace --boundaries workspace left").errorOrNil,
"ERROR: Duplicated option '--boundaries'"
)
assertEquals(
parseCommand("focus --window-id 42 --ignore-floating").errorOrNil,
"--window-id is incompatible with other options"
)
}

func testFocus() {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Common/cmdArgs/FocusCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public struct FocusCmdArgs: CmdArgs, RawCmdArgs, Equatable, AeroAny {
--boundaries-action \(actio) Defines the behavior when requested to cross the \(boundar).
\(actio) possible values: \(FocusCmdArgs.WhenBoundariesCrossed.unionLiteral)
The default is: \(FocusCmdArgs.WhenBoundariesCrossed.wrapAroundTheWorkspace.rawValue)
--ignore-floating Don't perceive floating windows as part of the tree
ARGUMENTS:
(left|down|up|right) Focus direction
""",
options: [
"--ignore-floating": falseBoolFlag(\.floatingAsTiling),
"--boundaries": ArgParser(\.rawBoundaries, upcastArgParserFun(parseBoundaries)),
"--boundaries-action": ArgParser(\.rawBoundariesAction, upcastArgParserFun(parseBoundariesAction)),
"--window-id": ArgParser(\.windowId, upcastArgParserFun(parseArgWithUInt32))
Expand All @@ -34,6 +36,7 @@ public struct FocusCmdArgs: CmdArgs, RawCmdArgs, Equatable, AeroAny {
public var rawBoundariesAction: WhenBoundariesCrossed? = nil
public var windowId: UInt32? = nil
public var direction: CardinalDirection? = nil
public var floatingAsTiling: Bool = true

public let rawArgs: EquatableNoop<[String]>
fileprivate init(rawArgs: [String]) { self.rawArgs = .init(rawArgs) }
Expand Down
4 changes: 4 additions & 0 deletions Sources/Common/cmdArgs/other/parseCmdArgsUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ public func trueBoolFlag<T: Copyable>(_ keyPath: WritableKeyPath<T, Bool>) -> Ar
ArgParser(keyPath) { _, _ in .success(true) }
}

public func falseBoolFlag<T: Copyable>(_ keyPath: WritableKeyPath<T, Bool>) -> ArgParser<T, Bool> {
ArgParser(keyPath) { _, _ in .success(false) }
}

public func boolFlag<T: Copyable>(_ keyPath: WritableKeyPath<T, Bool?>) -> ArgParser<T, Bool?> {
ArgParser(keyPath) { _, nextArgs in
let value: Bool
Expand Down
10 changes: 7 additions & 3 deletions docs/aerospace-focus.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include::util/man-attributes.adoc[]
[verse]
// tag::synopsis[]
aerospace focus [-h|--help] [--boundaries <boundary>]
[--boundaries-action <action>] (left|down|up|right)
[--boundaries-action <action>] [--ignore-floating] (left|down|up|right)
aerospace focus [-h|--help] --window-id <window-id>

// end::synopsis[]
Expand All @@ -24,8 +24,8 @@ aerospace focus [-h|--help] --window-id <window-id>
Contrary to i3, `focus` command doesn't have a separate argument to focus floating windows.
From `focus` command perspective, floating windows are part of xref:guide.adoc#tree[the tree].
The floating window parent container is determined as the smallest tiling container that contains the center of the floating window.

This technique eliminates the need for an additional binding for floating windows.
The technique eliminates the need for an additional binding for floating windows.
This behavior can be disabled with `--ignore-floating` flag.

`focus child|parent` isn't supported because the necessity of this operation is under the question.
https:/nikitabobko/AeroSpace/issues/5
Expand All @@ -48,6 +48,10 @@ The default is: `wrap-around-the-workspace`
--window-id <window-id>::
Focus the window with specified `<window-id>`

--ignore-floating::
Don't perceive floating windows as part of the tree.
It may be useful for more reliable scripting.

// end::body[]

// =========================================================== Footer
Expand Down
2 changes: 1 addition & 1 deletion grammar/commands-bnf-grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ aerospace -h;

<list_workspaces1_flag> ::= --visible [no] | --empty [no] | --format <output_format>;

<focus_flag> ::= --boundaries <boundary>|--boundaries-actions <boundaries_action>;
<focus_flag> ::= --boundaries <boundary>|--boundaries-actions <boundaries_action>|--ignore-floating;
<boundaries_action> ::= stop|wrap-around-the-workspace|wrap-around-all-monitors;
<boundary> ::= workspace|all-monitors-outer-frame;

Expand Down

0 comments on commit 879cb61

Please sign in to comment.