@@ -5,7 +5,7 @@ struct MoveCommand: Command {
55 let args : MoveCmdArgs
66 /*conforms*/ var shouldResetClosedWindowsCache = true
77
8- func run( _ env: CmdEnv , _ io: CmdIo ) -> Bool {
8+ func run( _ env: CmdEnv , _ io: CmdIo ) async throws -> Bool {
99 let direction = args. direction. val
1010 guard let target = args. resolveTargetOrReportError ( env, io) else { return false }
1111 guard let currentWindow = target. windowOrNil else {
@@ -29,7 +29,8 @@ struct MoveCommand: Command {
2929 return moveOut ( window: currentWindow, direction: direction, io, args, env)
3030 }
3131 case . workspace: // floating window
32- return io. err ( " moving floating windows isn't yet supported " ) // todo
32+ let pixels = args. floatingPixels ?? calculateDefaultPixels ( direction: direction, window: currentWindow)
33+ return await moveFloatingWindow ( window: currentWindow, direction: direction, pixels: pixels)
3334 case . macosMinimizedWindowsContainer, . macosFullscreenWindowsContainer, . macosHiddenAppsWindowsContainer:
3435 return io. err ( moveOutMacosUnconventionalWindow)
3536 case . macosPopupWindowsContainer:
@@ -154,6 +155,23 @@ private let moveOutMacosUnconventionalWindow = "moving macOS fullscreen, minimiz
154155 return true
155156}
156157
158+ @MainActor private func calculateDefaultPixels( direction: CardinalDirection , window: Window ) -> Int {
159+ guard let monitor = window. nodeMonitor else { return 50 }
160+ return direction. orientation == . h
161+ ? Int ( Double ( monitor. width) * 0.1 )
162+ : Int ( Double ( monitor. height) * 0.1 )
163+ }
164+
165+ @MainActor private func moveFloatingWindow( window: Window , direction: CardinalDirection , pixels: Int ) async -> Bool {
166+ guard let currentRect = try ? await window. getAxRect ( ) else { return false }
167+ let newTopLeft = CGPoint (
168+ x: currentRect. topLeftX + Double( direction. xOffset * pixels) ,
169+ y: currentRect. topLeftY + Double( direction. yOffset * pixels)
170+ )
171+ window. setAxFrame ( newTopLeft, nil )
172+ return true
173+ }
174+
157175extension TilingTreeNodeCases {
158176 @MainActor fileprivate func findDeepMoveInTargetRecursive( _ orientation: Orientation ) -> TilingTreeNodeCases {
159177 return switch self {
0 commit comments