diff --git a/src/command/LayoutCommand.swift b/src/command/LayoutCommand.swift index d54d5e4b..302b4dff 100644 --- a/src/command/LayoutCommand.swift +++ b/src/command/LayoutCommand.swift @@ -42,6 +42,12 @@ struct LayoutCommand: Command { case .vertical: changeTilingLayout(targetLayout: nil, targetOrientation: .v, window: window) case .tiling: + switch window.parent.kind { + case .workspace: + window.lastFloatingSize = window.getSize() ?? window.lastFloatingSize + case .tilingContainer: + error("Impossible") + } let data = getBindingDataForNewTilingWindow(window.unbindFromParent().parent.workspace) window.bind(to: data.parent, adaptiveWeight: data.adaptiveWeight, index: data.index) case .floating: @@ -51,7 +57,7 @@ struct LayoutCommand: Command { guard let size = window.getSize() else { break } guard let topLeftCorner = window.getTopLeftCorner() else { break } window.setTopLeftCorner(topLeftCorner.addingXOffset(padding).addingYOffset(padding)) - window.setSize(window.appearedWithSize + window.setSize(window.lastFloatingSize ?? CGSize(width: size.width - 2 * padding, height: size.height - 2 * padding)) } } diff --git a/src/tree/MacWindow.swift b/src/tree/MacWindow.swift index 56ad5d73..26756148 100644 --- a/src/tree/MacWindow.swift +++ b/src/tree/MacWindow.swift @@ -9,7 +9,7 @@ final class MacWindow: Window, CustomStringConvertible { private init(_ id: CGWindowID, _ app: MacApp, _ axWindow: AXUIElement, parent: NonLeafTreeNode, adaptiveWeight: CGFloat, index: Int) { self.axWindow = axWindow self.macApp = app - super.init(id: id, app, appearedWithSize: axWindow.get(Ax.sizeAttr), parent: parent, adaptiveWeight: adaptiveWeight, index: index) + super.init(id: id, app, lastFloatingSize: axWindow.get(Ax.sizeAttr), parent: parent, adaptiveWeight: adaptiveWeight, index: index) } private static var allWindowsMap: [CGWindowID: MacWindow] = [:] diff --git a/src/tree/Window.swift b/src/tree/Window.swift index 7f437440..083c0762 100644 --- a/src/tree/Window.swift +++ b/src/tree/Window.swift @@ -3,12 +3,12 @@ class Window: TreeNode, Hashable { let app: AeroApp override var parent: NonLeafTreeNode { super.parent ?? errorT("Windows always have parent") } var parentOrNilForTests: NonLeafTreeNode? { super.parent } - let appearedWithSize: CGSize? + var lastFloatingSize: CGSize? - init(id: UInt32, _ app: AeroApp, appearedWithSize: CGSize?, parent: NonLeafTreeNode, adaptiveWeight: CGFloat, index: Int) { + init(id: UInt32, _ app: AeroApp, lastFloatingSize: CGSize?, parent: NonLeafTreeNode, adaptiveWeight: CGFloat, index: Int) { self.windowId = id self.app = app - self.appearedWithSize = appearedWithSize + self.lastFloatingSize = lastFloatingSize super.init(parent: parent, adaptiveWeight: adaptiveWeight, index: index) } diff --git a/src/util/util.swift b/src/util/util.swift index 841d378b..ccfa21aa 100644 --- a/src/util/util.swift +++ b/src/util/util.swift @@ -70,7 +70,7 @@ public func makeAllWindowsVisibleAndRestoreSize() { } else { let monitor = window.workspace.monitor window.setTopLeftCorner(monitor.rect.topLeftCorner) - window.setSize(window.appearedWithSize + window.setSize(window.lastFloatingSize ?? CGSize(width: monitor.visibleRect.width, height: monitor.visibleRect.height)) } } diff --git a/test/tree/TestWindow.swift b/test/tree/TestWindow.swift index 7efa0013..097a51a2 100644 --- a/test/tree/TestWindow.swift +++ b/test/tree/TestWindow.swift @@ -6,7 +6,7 @@ final class TestWindow: Window, CustomStringConvertible { @discardableResult init(id: UInt32, parent: NonLeafTreeNode, adaptiveWeight: CGFloat = 1, rect: Rect? = nil) { _rect = rect - super.init(id: id, TestApp.shared, appearedWithSize: nil, parent: parent, adaptiveWeight: adaptiveWeight, index: INDEX_BIND_LAST) + super.init(id: id, TestApp.shared, lastFloatingSize: nil, parent: parent, adaptiveWeight: adaptiveWeight, index: INDEX_BIND_LAST) TestApp.shared.windows.append(self) }