Skip to content

Commit

Permalink
3/n Implement macos-native-minimize command
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Mar 8, 2024
1 parent 1041a96 commit 1273c6b
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 2 deletions.
4 changes: 4 additions & 0 deletions AeroSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
77FA83225024151CD556E1ED /* CloseAllWindowsButCurrentCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99853C505D93E41F6531C324 /* CloseAllWindowsButCurrentCommand.swift */; };
78622D72C0CCE8D69B080D29 /* moveWithMouse.swift in Sources */ = {isa = PBXBuildFile; fileRef = AD0938DE74E687A8959E3F9C /* moveWithMouse.swift */; };
78C38FAF21E574DBE3B88806 /* CloseCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FDC079C530D7B3C568E35F /* CloseCommand.swift */; };
7C0ACF53062631B667424927 /* MacosNativeMinimizeCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7862747CF7F654B8BF8C9CF9 /* MacosNativeMinimizeCommand.swift */; };
7ED8C2A66DD6F903796F090C /* TestApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2431BEAFFF1AC12D3001317A /* TestApp.swift */; };
8086A22EDCDC4C906C337D0B /* resizeWithMouse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9745E5FC11701AE35712EC18 /* resizeWithMouse.swift */; };
852F88894A3B9FC385563665 /* HotKey in Frameworks */ = {isa = PBXBuildFile; productRef = 42BC1E757EF69233C2262FF4 /* HotKey */; };
Expand Down Expand Up @@ -157,6 +158,7 @@
6F1905935B0C61590A96EFEF /* TestWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestWindow.swift; sourceTree = "<group>"; };
71908440CD1ADBE13AD58E26 /* DebugWindowsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugWindowsCommand.swift; sourceTree = "<group>"; };
739F4FE1DB101DF4E508F3FE /* Monitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Monitor.swift; sourceTree = "<group>"; };
7862747CF7F654B8BF8C9CF9 /* MacosNativeMinimizeCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacosNativeMinimizeCommand.swift; sourceTree = "<group>"; };
796713A1B3AEEBF4D0D180C7 /* server.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = server.swift; sourceTree = "<group>"; };
7ACD4E9C6C0C08F1B0622C57 /* ResizeCommandTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResizeCommandTest.swift; sourceTree = "<group>"; };
7DAEA4B9015FBF8711E532D0 /* MonitorEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonitorEx.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -419,6 +421,7 @@
D27A7AF7E9A049700BDE276B /* JoinWithCommand.swift */,
1A2B673C67B00DBFCC27FFE7 /* LayoutCommand.swift */,
BF3D87FF4D8238F07870F2F6 /* MacosNativeFullscreenCommand.swift */,
7862747CF7F654B8BF8C9CF9 /* MacosNativeMinimizeCommand.swift */,
4B0CD3C2A0E86CDB9DF312AB /* ModeCommand.swift */,
1376845BAB666880919B9AA2 /* MoveCommand.swift */,
25AC44D0E9450867215FCBEC /* MoveNodeToWorkspaceCommand.swift */,
Expand Down Expand Up @@ -621,6 +624,7 @@
BD6301B2CFC16FDE4223ACB8 /* MacApp.swift in Sources */,
EECC59858691B99A95542D72 /* MacWindow.swift in Sources */,
DEE74487CFB70CEC10D9D3D7 /* MacosNativeFullscreenCommand.swift in Sources */,
7C0ACF53062631B667424927 /* MacosNativeMinimizeCommand.swift in Sources */,
6E4E235FDA41307B19F16182 /* ModeCommand.swift in Sources */,
C76E421FB0D0F0EB1C93A06C /* Monitor.swift in Sources */,
B04363E8C28CEC76F39977F2 /* MonitorDescription.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let subcommandDescriptions = [
[" list-windows", "Prints windows that satisfy conditions"],
[" list-workspaces", "Prints workspaces that satisfy conditions"],
[" macos-native-fullscreen", "Toggle macOS fullscreen for the currently focused window"],
[" macos-native-minimize", "Toggle macOS minimize for the currently focused window"],
[" mode", "Activates the specified binding modes"],
[" move-node-to-workspace", "Moves currently focused window to the specified workspace"],
[" move-workspace-to-monitor", "Moves currently focused workspace to the next or previous monitor"],
Expand Down
4 changes: 4 additions & 0 deletions LocalPackage/Sources/Common/cmdArgs/MacosNativeMinimize.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public struct MacosNativeMinimizeCmdArgs: RawCmdArgs, CmdArgs {
public init() {}
public static let parser: CmdParser<Self> = noArgsParser(.macosNativeMinimize, allowInConfig: true)
}
1 change: 1 addition & 0 deletions LocalPackage/Sources/Common/cmdArgs/other/CmdKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum CmdKind: String, CaseIterable, Equatable {
case listWindows = "list-windows"
case listWorkspaces = "list-workspaces"
case macosNativeFullscreen = "macos-native-fullscreen"
case macosNativeMinimize = "macos-native-minimize"
case mode
case move = "move"
case moveNodeToWorkspace = "move-node-to-workspace"
Expand Down
2 changes: 2 additions & 0 deletions LocalPackage/Sources/Common/cmdArgs/other/parseCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ private func initSubcommands() -> [String: any SubCommandParserProtocol] {
result[kind.rawValue] = SubCommandParser(parseListWorkspacesCmdArgs)
case .macosNativeFullscreen:
result[kind.rawValue] = defaultSubCommandParser(MacosNativeFullscreenCmdArgs())
case .macosNativeMinimize:
result[kind.rawValue] = defaultSubCommandParser(MacosNativeMinimizeCmdArgs())
case .mode:
result[kind.rawValue] = defaultSubCommandParser(ModeCmdArgs())
case .moveNodeToWorkspace:
Expand Down
24 changes: 24 additions & 0 deletions docs/aerospace-macos-native-minimize.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
= aerospace-macos-native-minimize(1)
include::util/man-attributes.adoc[]
:manname: aerospace-macos-native-minimize
// tag::purpose[]
:manpurpose: Toggle macOS minimize for the currently focused window
// end::purpose[]

== Synopsis
// tag::synopsis[]
macos-native-minimize [-h|--help]
// end::synopsis[]

== Description

// tag::body[]
{manpurpose}

// end::body[]

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

-h, --help:: Print help

include::util/man-footer.adoc[]
7 changes: 7 additions & 0 deletions docs/commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ include::aerospace-macos-native-fullscreen.adoc[tags=synopsis]
include::aerospace-macos-native-fullscreen.adoc[tags=purpose]
include::aerospace-macos-native-fullscreen.adoc[tags=body]

== macos-native-minimize
----
include::aerospace-macos-native-minimize.adoc[tags=synopsis]
----
include::aerospace-macos-native-minimize.adoc[tags=purpose]
include::aerospace-macos-native-minimize.adoc[tags=body]

== mode
----
include::aerospace-mode.adoc[tags=synopsis]
Expand Down
17 changes: 17 additions & 0 deletions src/command/MacosNativeMinimizeCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Common

struct MacosNativeMinimizeCommand: Command {
let args: MacosNativeMinimizeCmdArgs

func _run(_ state: CommandMutableState, stdin: String) -> Bool {
check(Thread.current.isMainThread)
guard let window = state.subject.windowOrNil else {
state.stderr.append("No window in focus")
return false
}
let axWindow = window.asMacWindow().axWindow
let success = axWindow.set(Ax.minimizedAttr, !window.isMacosMinimized)
if !success { state.stderr.append("Failed") }
return success
}
}
2 changes: 2 additions & 0 deletions src/command/other/parseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ extension CmdArgs {
command = ListWorkspacesCommand(args: self as! ListWorkspacesCmdArgs)
case .macosNativeFullscreen:
command = MacosNativeFullscreenCommand(args: self as! MacosNativeFullscreenCmdArgs)
case .macosNativeMinimize:
command = MacosNativeMinimizeCommand(args: self as! MacosNativeMinimizeCmdArgs)
case .mode:
command = ModeCommand(args: self as! ModeCmdArgs)
case .moveNodeToWorkspace:
Expand Down
1 change: 1 addition & 0 deletions src/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ final class MacWindow: Window, CustomStringConvertible {

override var title: String? { axWindow.get(Ax.titleAttr) }
override var isMacosFullscreen: Bool { axWindow.get(Ax.isFullscreenAttr) == true }
override var isMacosMinimized: Bool { axWindow.get(Ax.minimizedAttr) == true }

@discardableResult
override func nativeFocus() -> Bool { // todo make focus reliable: make async + active waiting
Expand Down
1 change: 1 addition & 0 deletions src/tree/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Window: TreeNode, Hashable {
func getSize() -> CGSize? { error("Not implemented") }
var title: String? { error("Not implemented") }
var isMacosFullscreen: Bool { false }
var isMacosMinimized: Bool { false }
var isHiddenViaEmulation: Bool { error("Not implemented") }
func setSize(_ size: CGSize) { error("Not implemented") }

Expand Down
5 changes: 3 additions & 2 deletions src/util/accessibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,10 @@ enum Ax {
getter: { $0 as? Bool },
setter: { $0 as CFTypeRef }
)
static let minimizedAttr = ReadableAttrImpl<Bool>(
static let minimizedAttr = WritableAttrImpl<Bool>(
key: kAXMinimizedAttribute,
getter: { $0 as? Bool }
getter: { $0 as? Bool },
setter: { $0 as CFTypeRef }
)
//static let minimizedAttr = ReadableAttrImpl<Bool>(
// key: kAXMinimizedAttribute,
Expand Down

0 comments on commit 1273c6b

Please sign in to comment.