Skip to content

Commit

Permalink
WIP support resize command
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Oct 5, 2023
1 parent 8527402 commit 95dec4f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions AeroSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
BD6301B2CFC16FDE4223ACB8 /* MacApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = B7DB782C527ABE0CF31740EB /* MacApp.swift */; };
BF16873111EEDE60A8AACD6B /* Workspace.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F068BCC50ED846DCBFDE57 /* Workspace.swift */; };
C0A88261ECF505FC5648FC0A /* OptionalEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9EDFD4A9F45182CA6E0BD7B /* OptionalEx.swift */; };
D24D02B1FD87424B908986AF /* ResizeCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB371951459F8CB0137788C2 /* ResizeCommand.swift */; };
E1E35DC5D9D74D54E92AB5F3 /* ExecCommandTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A6EF465EF4129BCB10FE247 /* ExecCommandTest.swift */; };
E22ACB36C90695FBAC78226E /* TestWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F1905935B0C61590A96EFEF /* TestWindow.swift */; };
E5682579AEC6B84CF6FCE90D /* TilingContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C848D6E57FDF22AAF0FB45E6 /* TilingContainer.swift */; };
Expand Down Expand Up @@ -132,6 +133,7 @@
C3F068BCC50ED846DCBFDE57 /* Workspace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Workspace.swift; sourceTree = "<group>"; };
C848D6E57FDF22AAF0FB45E6 /* TilingContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TilingContainer.swift; sourceTree = "<group>"; };
CB03A4736BC3F6D19E4E69F3 /* parseCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = parseCommand.swift; sourceTree = "<group>"; };
CB371951459F8CB0137788C2 /* ResizeCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResizeCommand.swift; sourceTree = "<group>"; };
CD62043D7F5113A8BA635FDF /* MoveContainerToWorkspaceCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveContainerToWorkspaceCommand.swift; sourceTree = "<group>"; };
CD90FB41FD41602120F67FF5 /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = "<group>"; };
CF3C9038C846369FDD71D1D2 /* ReloadConfigCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReloadConfigCommand.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -281,6 +283,7 @@
67B9FFF81EB0327ABD51A7FE /* MoveThroughCommand.swift */,
CB03A4736BC3F6D19E4E69F3 /* parseCommand.swift */,
CF3C9038C846369FDD71D1D2 /* ReloadConfigCommand.swift */,
CB371951459F8CB0137788C2 /* ResizeCommand.swift */,
EED7EE20910D7BE4D0150CED /* WorkspaceBackAndForthCommand.swift */,
43DD32B1711B8EFCC834B68E /* WorkspaceCommand.swift */,
);
Expand Down Expand Up @@ -458,6 +461,7 @@
C0A88261ECF505FC5648FC0A /* OptionalEx.swift in Sources */,
78EE0CEF814ABDBA67941B84 /* Rect.swift in Sources */,
FC35D6D0A678CC802972C6FE /* ReloadConfigCommand.swift in Sources */,
D24D02B1FD87424B908986AF /* ResizeCommand.swift in Sources */,
AE76A183D0454E4C8ADCE380 /* SequenceEx.swift in Sources */,
E5682579AEC6B84CF6FCE90D /* TilingContainer.swift in Sources */,
56E72B24303F5F337B31B776 /* TrayMenuModel.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions config-examples/default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ alt-shift-j = 'move-through down'
alt-shift-l = 'move-through right'

# Resize window
# alt-shift-minus = 'resize shrink height 2 px'
# alt-shift-equal = 'resize grow height 2 px'
# alt-shift-comma = 'resize shrink width 2 px'
# alt-shift-period = 'resize grow width 2 px'
# alt-shift-minus = 'resize height -10'
# alt-shift-equal = 'resize height +10'
# alt-shift-comma = 'resize width -10'
# alt-shift-period = 'resize width +10'

alt-0 = 'workspace 000'
alt-1 = 'workspace 111'
Expand Down
23 changes: 23 additions & 0 deletions src/command/ResizeCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
struct ResizeCommand: Command { // todo cover with tests
enum Dimension {
case width, height
}

let dimension: Dimension
let units: CGFloat

func runWithoutRefresh() {
precondition(Thread.current.isMainThread)
guard let window = focusedWindowOrEffectivelyFocused else { return }

let orientation: Orientation
switch dimension {
case .width:
orientation = .H
case .height:
orientation = .V
}

window.setWeight(orientation, window.getWeight(orientation) + units)
}
}
2 changes: 2 additions & 0 deletions src/command/parseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private func parseSingleCommand(_ raw: String) -> ParsedCommand<Command> {
return parseSingleArg(args, firstWord).map { MoveContainerToWorkspaceCommand(targetWorkspaceName: $0) }
} else if firstWord == "mode" {
return parseSingleArg(args, firstWord).map { ModeCommand(idToActivate: $0) }
} else if firstWord == "resize" {
TODO()
} else if firstWord == "exec-and-wait" {
return .success(ExecAndWaitCommand(bashCommand: raw.removePrefix(firstWord)))
} else if firstWord == "exec-and-forget" {
Expand Down
4 changes: 2 additions & 2 deletions src/tree/TreeNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class TreeNode: Equatable {
if parent.orientation == targetOrientation {
adaptiveWeight = newValue
} else {
error("You can't change \(targetOrientation) weight of nodes located in \(parent.orientation) container")
parent.setWeight(targetOrientation, newValue)
}
case .workspace:
error("Can't change weight for floating windows and workspace root containers")
break
case .window:
error("Windows can't be parent containers")
case nil:
Expand Down

0 comments on commit 95dec4f

Please sign in to comment.