Skip to content

Commit

Permalink
appearedWithSize -> lastFloatingSize
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Oct 28, 2023
1 parent 2db32b4 commit 4bcb664
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/command/LayoutCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [:]
Expand Down
6 changes: 3 additions & 3 deletions src/tree/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/tree/TestWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 4bcb664

Please sign in to comment.