Skip to content

Commit 0444d0a

Browse files
committed
Cleanup
1 parent a2ec5ea commit 0444d0a

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

src/axWrappers/MacWindow.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class MacWindow: TreeNode, Hashable {
5353
?? workspace.rootTilingContainer
5454
parent = tilingParent
5555
weight = parent.children.sumOf { $0.getWeight(tilingParent.orientation) }
56-
.div(parent.children.count, orIfZero: 1)
56+
.div(parent.children.count) ?? 1
5757
}
5858
let window = MacWindow(id, app, axWindow, parent: parent, adaptiveWeight: weight)
5959

src/model/TilingContainer.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,24 @@ extension TilingContainer {
3030
}
3131

3232
func normalizeContainersRecursive() {
33-
if children.isEmpty && !(parent is Workspace) {
33+
if children.isEmpty && !isRootContainer {
3434
unbindFromParent()
3535
}
3636
// todo make it configurable
3737
if let child = children.singleOrNil() as? TilingContainer { // flatten containers
3838
let previousBinding = unbindFromParent()
3939
child.bindTo(parent: parent, adaptiveWeight: previousBinding.adaptiveWeight, index: previousBinding.index)
4040
child.normalizeContainersRecursive()
41-
}
42-
for child in children {
43-
if let tilingChild = child as? TilingContainer {
44-
tilingChild.normalizeContainersRecursive()
41+
} else {
42+
for child in children {
43+
if let tilingChild = child as? TilingContainer {
44+
tilingChild.normalizeContainersRecursive()
45+
}
4546
}
4647
}
4748
}
49+
50+
var isRootContainer: Bool { parent is Workspace }
4851
}
4952

5053
enum Orientation {

src/model/TreeNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TreeNode: Equatable {
3535
return tilingParent.orientation == targetOrientation ? adaptiveWeight : parent.getWeight(targetOrientation)
3636
} else {
3737
precondition(parent is Workspace)
38-
if self is MacWindow { // self is floating window
38+
if self is MacWindow { // self is a floating window
3939
error("Weight doesn't make sense for floating windows")
4040
} else { // root tiling container
4141
precondition(self is TilingContainer)

src/util/utils.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ extension CGPoint {
8181
}
8282

8383
extension CGFloat {
84-
func div(_ denominator: Int, orIfZero: CGFloat) -> CGFloat {
85-
denominator == 0 ? orIfZero : self / CGFloat(denominator)
86-
}
87-
8884
func div(_ denominator: Int) -> CGFloat? {
8985
denominator == 0 ? nil : self / CGFloat(denominator)
9086
}

0 commit comments

Comments
 (0)