Skip to content

Commit

Permalink
fullscreen command: support [on|off] argument
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Mar 9, 2024
1 parent a53074e commit 68df46c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
20 changes: 20 additions & 0 deletions LocalPackage/Sources/Common/cmdArgs/FullscreenCmdArgs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public struct FullscreenCmdArgs: CmdArgs, RawCmdArgs {
public init() {}
public static let parser: CmdParser<Self> = cmdParser(
kind: .fullscreen,
allowInConfig: true,
help: """
USAGE: fullscreen [-h|--help] [on|off]
OPTIONS:
-h, --help Print help
ARGUMENTS:
[on|off] 'on' means enter fullscreen mode. 'off' means exit fullscreen mode.
Toggle between the two if not specified
""",
options: [:],
arguments: [ArgParser(\.toggle, parseToggleEnum)]
)
public var toggle: ToggleEnum = .toggle
}
4 changes: 0 additions & 4 deletions LocalPackage/Sources/Common/cmdArgs/noCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ public struct FlattenWorkspaceTreeCmdArgs: RawCmdArgs, CmdArgs {
public init() {}
public static let parser: CmdParser<Self> = noArgsParser(.flattenWorkspaceTree, allowInConfig: true)
}
public struct FullscreenCmdArgs: RawCmdArgs, CmdArgs {
public init() {}
public static let parser: CmdParser<Self> = noArgsParser(.fullscreen, allowInConfig: true)
}
public struct ReloadConfigCmdArgs: RawCmdArgs, CmdArgs {
public init() {}
public static let parser: CmdParser<Self> = noArgsParser(.reloadConfig, allowInConfig: true)
Expand Down
11 changes: 9 additions & 2 deletions docs/aerospace-fullscreen.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include::util/man-attributes.adoc[]

== Synopsis
// tag::synopsis[]
aerospace fullscreen [-h|--help]
aerospace fullscreen [-h|--help] [on|off]
// end::synopsis[]

== Description
Expand All @@ -16,10 +16,17 @@ aerospace fullscreen [-h|--help]
{manpurpose}

Switching to a different tiling window within the same workspace while the current focused window is in fullscreen mode results in the fullscreen window exiting fullscreen mode.
// end::body[]

include::util/conditional-options-header.adoc[]

-h, --help:: Print help

include::util/conditional-arguments-header.adoc[]

[on|off]::
'on' means enter fullscreen mode. 'off' means exit fullscreen mode.
Toggle between the two if not specified

// end::body[]

include::util/man-footer.adoc[]
21 changes: 19 additions & 2 deletions src/command/FullscreenCommand.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import Common

struct FullscreenCommand: Command {
let args = FullscreenCmdArgs()
let args: FullscreenCmdArgs

func _run(_ state: CommandMutableState, stdin: String) -> Bool {
check(Thread.current.isMainThread)
guard let window = state.subject.windowOrNil else {
state.stderr.append(noWindowIsFocused)
return false
}
window.isFullscreen = !window.isFullscreen
let newState: Bool
switch args.toggle {
case .on:
newState = true
case .off:
newState = false
case .toggle:
newState = !window.isFullscreen
}
if newState == window.isFullscreen {
if newState {
state.stderr.append("Already fullscreen")
} else {
state.stderr.append("Already not fullscreen")
}
return false
}
window.isFullscreen = newState

// Focus on its own workspace
window.markAsMostRecentChild()
Expand Down
2 changes: 1 addition & 1 deletion src/command/other/parseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension CmdArgs {
case .focus:
command = FocusCommand(args: self as! FocusCmdArgs)
case .fullscreen:
command = FullscreenCommand()
command = FullscreenCommand(args: self as! FullscreenCmdArgs)
case .joinWith:
command = JoinWithCommand(args: self as! JoinWithCmdArgs)
case .layout:
Expand Down

0 comments on commit 68df46c

Please sign in to comment.