Skip to content

Commit

Permalink
Support MoveInCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Oct 15, 2023
1 parent b0cfc80 commit acc507e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 6 deletions.
8 changes: 8 additions & 0 deletions AeroSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
2E06134604F2510189F1FA85 /* ExecAndWaitCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9EDB8770FBA8B2E6FE91BBB /* ExecAndWaitCommand.swift */; };
374CE35B85B941B8F584C113 /* FlattenWorkspaceTreeCommandTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53FDECECC773EBA30661EB8A /* FlattenWorkspaceTreeCommandTest.swift */; };
3BD6FF4CC51532977DA0C05A /* AeroAny.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82476B9BEBAC00EB9E32256F /* AeroAny.swift */; };
3BE358D5C209F279BB71AC95 /* MoveInCommandTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13E5ED8E885494CAEEC70A90 /* MoveInCommandTest.swift */; };
42197B9C71A0CDDE65804A6A /* accessibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D31BF26EAFA96F675D2C14B /* accessibility.swift */; };
45AA5FD4A023AF751922BC22 /* BundleEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B7A2DF0D1F72B80B1F04240 /* BundleEx.swift */; };
45EA2D1C90430C432E123B51 /* keysMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C0D40CBD65704BA9595C2FA /* keysMap.swift */; };
4D62EC19C6A1E3BBF54306BA /* Copyable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54B4C778D2594EB23C295741 /* Copyable.swift */; };
56E72B24303F5F337B31B776 /* TrayMenuModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F5F52E346D024960EAF5938 /* TrayMenuModel.swift */; };
5A3B1D50474AFBE7C05D2E6F /* MoveInCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E330182A6FACBABABB6FC51 /* MoveInCommand.swift */; };
5DA2DA21600E8B5BCA3DCFC0 /* LayoutCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2B673C67B00DBFCC27FFE7 /* LayoutCommand.swift */; };
5FB1B80967DF269BA45F84A4 /* resizeWithMouse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A90E205F7C4A569840262EB8 /* resizeWithMouse.swift */; };
6317AB471F4C4F5D66A25784 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EEDBFFCA7A77D96B18FB0732 /* Assets.xcassets */; };
Expand Down Expand Up @@ -90,6 +92,7 @@
00ECDFE176777828D560A737 /* TilingContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TilingContainer.swift; sourceTree = "<group>"; };
09685297933511208058F7CF /* AeroSpace.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AeroSpace.app; sourceTree = BUILT_PRODUCTS_DIR; };
0FF221FD5C0CB4163E322D6D /* MoveWorkspaceToDisplayCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveWorkspaceToDisplayCommand.swift; sourceTree = "<group>"; };
13E5ED8E885494CAEEC70A90 /* MoveInCommandTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveInCommandTest.swift; sourceTree = "<group>"; };
1A2B673C67B00DBFCC27FFE7 /* LayoutCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutCommand.swift; sourceTree = "<group>"; };
1C0D40CBD65704BA9595C2FA /* keysMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = keysMap.swift; sourceTree = "<group>"; };
1E81623E8954701269A22322 /* AeroSpaceApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AeroSpaceApp.swift; sourceTree = "<group>"; };
Expand All @@ -112,6 +115,7 @@
6352ADEE6625D9703CFCA99A /* Window.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Window.swift; sourceTree = "<group>"; };
67B9FFF81EB0327ABD51A7FE /* MoveThroughCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveThroughCommand.swift; sourceTree = "<group>"; };
67DBAF4ECF8A0B931FC34EAD /* parseConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = parseConfig.swift; sourceTree = "<group>"; };
6E330182A6FACBABABB6FC51 /* MoveInCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveInCommand.swift; sourceTree = "<group>"; };
6F1905935B0C61590A96EFEF /* TestWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestWindow.swift; sourceTree = "<group>"; };
7A247B616D1951777C565D02 /* MoveThroughCommandTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveThroughCommandTest.swift; sourceTree = "<group>"; };
7DBD002C4A68AED07BB63EFA /* MoveContainerToWorkspaceCommandTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveContainerToWorkspaceCommandTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -186,6 +190,7 @@
53FDECECC773EBA30661EB8A /* FlattenWorkspaceTreeCommandTest.swift */,
D0EAADE8D2FB5D05FA5456B0 /* FocusCommandTest.swift */,
7DBD002C4A68AED07BB63EFA /* MoveContainerToWorkspaceCommandTest.swift */,
13E5ED8E885494CAEEC70A90 /* MoveInCommandTest.swift */,
7A247B616D1951777C565D02 /* MoveThroughCommandTest.swift */,
);
path = command;
Expand Down Expand Up @@ -291,6 +296,7 @@
1A2B673C67B00DBFCC27FFE7 /* LayoutCommand.swift */,
4B0CD3C2A0E86CDB9DF312AB /* ModeCommand.swift */,
CD62043D7F5113A8BA635FDF /* MoveContainerToWorkspaceCommand.swift */,
6E330182A6FACBABABB6FC51 /* MoveInCommand.swift */,
67B9FFF81EB0327ABD51A7FE /* MoveThroughCommand.swift */,
0FF221FD5C0CB4163E322D6D /* MoveWorkspaceToDisplayCommand.swift */,
CB03A4736BC3F6D19E4E69F3 /* parseCommand.swift */,
Expand Down Expand Up @@ -432,6 +438,7 @@
374CE35B85B941B8F584C113 /* FlattenWorkspaceTreeCommandTest.swift in Sources */,
1311398A83B998908773C54D /* FocusCommandTest.swift in Sources */,
A55F31B0CC357B37108B8F54 /* MoveContainerToWorkspaceCommandTest.swift in Sources */,
3BE358D5C209F279BB71AC95 /* MoveInCommandTest.swift in Sources */,
B1E527CF4941A4E9B8D9C3D0 /* MoveThroughCommandTest.swift in Sources */,
E22ACB36C90695FBAC78226E /* TestWindow.swift in Sources */,
70A82A4A9DFC89286C4F7696 /* TilingContainer.swift in Sources */,
Expand Down Expand Up @@ -467,6 +474,7 @@
6E4E235FDA41307B19F16182 /* ModeCommand.swift in Sources */,
920FDF8498DCCB62149D1719 /* Monitor.swift in Sources */,
89064BDDB5E9D17BEDE52E8C /* MoveContainerToWorkspaceCommand.swift in Sources */,
5A3B1D50474AFBE7C05D2E6F /* MoveInCommand.swift in Sources */,
EDFDE707B4DC5E500B1709B1 /* MoveThroughCommand.swift in Sources */,
05407EA2B9AC3F9371B56E6B /* MoveWorkspaceToDisplayCommand.swift in Sources */,
635733FDDF37E44364372B74 /* MruStack.swift in Sources */,
Expand Down
16 changes: 10 additions & 6 deletions config-examples/default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ alt-y = 'workspace Y'
alt-z = 'workspace Z'

alt-shift-semicolon = 'mode service'
alt-shift-slash = 'mode move-in'

alt-shift-0 = 'move-container-to-workspace 0'
alt-shift-1 = 'move-container-to-workspace 1'
Expand Down Expand Up @@ -112,16 +113,19 @@ alt-shift-z = 'move-container-to-workspace Z'
alt-tab = 'workspace-back-and-forth'
alt-shift-tab = 'move-workspace-to-display next'

# alt-shift-slash.alt-shift-k = 'move-in up'
# alt-shift-slash.alt-shift-h = 'move-in left'
# alt-shift-slash.alt-shift-j = 'move-in down'
# alt-shift-slash.alt-shift-l = 'move-in right'

[mode.service.binding]
r = ['flatten-workspace-tree', 'mode main']
o = ['reload-config', 'mode main']
s = ['layout sticky', 'mode main']
f = ['layout floating', 'mode main']
backslash = 'close-all-windows-but-current'
backslash = ['close-all-windows-but-current', 'mode main']
esc = 'mode main'
enter = 'mode main'

[mode.move-in.binding]
alt-shift-h = ['move-in left', 'mode main']
alt-shift-j = ['move-in down', 'mode main']
alt-shift-k = ['move-in up', 'mode main']
alt-shift-l = ['move-in right', 'mode main']
esc = 'mode main'
enter = 'mode main'
22 changes: 22 additions & 0 deletions src/command/MoveInCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
struct MoveInCommand: Command {
let direction: CardinalDirection

func runWithoutRefresh() {
precondition(Thread.current.isMainThread)
guard let currentWindow = focusedWindowOrEffectivelyFocused else { return }
guard let (parent, ownIndex) = currentWindow.closestParent(hasChildrenInDirection: direction, withLayout: nil) else { return }
let moveInTarget = parent.children[ownIndex + direction.focusOffset]
let prevBinding = moveInTarget.unbindFromParent()
let newParent = TilingContainer(
parent: parent,
adaptiveWeight: prevBinding.adaptiveWeight,
parent.orientation.opposite,
.List,
index: prevBinding.index
)
currentWindow.unbindFromParent()

moveInTarget.bindTo(parent: newParent, adaptiveWeight: WEIGHT_AUTO, index: 0)
currentWindow.bindTo(parent: newParent, adaptiveWeight: WEIGHT_AUTO, index: direction.isPositive ? 0 : INDEX_BIND_LAST)
}
}
4 changes: 4 additions & 0 deletions src/command/parseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ 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 == "move-in" {
return parseSingleArg(args, firstWord)
.flatMap { CardinalDirection(rawValue: $0).orFailure("Can't parse '\(firstWord)' direction") }
.map { MoveInCommand(direction: $0) }
} else if firstWord == "move-workspace-to-display" {
return parseSingleArg(args, firstWord)
.flatMap { MoveWorkspaceToDisplayCommand.DisplayTarget(rawValue: $0).orFailure("Can't parse '\(firstWord)' display target") }
Expand Down
1 change: 1 addition & 0 deletions src/config/parseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ private func parseBindings(_ raw: TOMLValueConvertible, _ backtrace: TomlBacktra
let keyBacktrace = backtrace + .key(binding)
let (binding, error): (HotkeyBinding?, TomlParseError?) = parseBinding(binding, keyBacktrace)
.flatMap { (modifiers, key) -> ParsedTomlResult<HotkeyBinding> in
// todo support parsing of implicit modes?
parseCommand(rawCommand).toParsedTomlResult(keyBacktrace).map { HotkeyBinding(modifiers, key, $0) }
}
.getOrNils()
Expand Down
4 changes: 4 additions & 0 deletions src/tree/TilingContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ enum Orientation {
case V
}

extension Orientation {
var opposite: Orientation { self == .H ? .V : .H }
}

enum Layout {
case List
case Accordion
Expand Down
23 changes: 23 additions & 0 deletions test/command/MoveInCommandTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import XCTest
@testable import AeroSpace_Debug

final class MoveInCommandTest: XCTestCase {
override func setUpWithError() throws { setUpWorkspacesForTests() }

func testMoveIn() async {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 0, parent: $0)
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

await MoveInCommand(direction: .right).runWithoutRefresh()
XCTAssertEqual(root.layoutDescription, .h_list([
.window(0),
.v_list([
.window(1),
.window(2)
])
]))
}
}

0 comments on commit acc507e

Please sign in to comment.