Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Rectangle/MultiWindow/MultiWindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class MultiWindowManager {
case .cascadeActiveApp:
cascadeActiveAppWindowsOnScreen(windowElement: parameters.windowElement)
return true
case .tileActiveApp:
tileActiveAppWindowsOnScreen(windowElement: parameters.windowElement)
return true
default:
return false
}
Expand Down Expand Up @@ -186,4 +189,29 @@ class MultiWindowManager {
w.setFrame(rect)
w.bringToFront()
}

static func tileActiveAppWindowsOnScreen(windowElement: AccessibilityElement? = nil) {
guard let (screens, windows) = allWindowsOnScreen(windowElement: windowElement, sortByPID: true),
let frontWindowElement = AccessibilityElement.getFrontWindowElement()
else {
return
}

let screenFrame = screens.currentScreen.adjustedVisibleFrame().screenFlipped

// keep windows with a pid equal to the front window's pid
let filtered = windows.filter { $0.pid == frontWindowElement.pid }

let count = filtered.count

let columns = Int(ceil(sqrt(CGFloat(count))))
let rows = Int(ceil(CGFloat(count) / CGFloat(columns)))
let size = CGSize(width: (screenFrame.maxX - screenFrame.minX) / CGFloat(columns), height: (screenFrame.maxY - screenFrame.minY) / CGFloat(rows))

for (ind, w) in filtered.enumerated() {
let column = ind % Int(columns)
let row = ind / Int(columns)
tileWindow(w, screenFrame: screenFrame, size: size, column: column, row: row)
}
}
}
13 changes: 8 additions & 5 deletions Rectangle/WindowAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ enum WindowAction: Int, Codable {
largerHeight = 82,
smallerHeight = 83,
centerTwoThirds = 84,
centerThreeFourths = 85
centerThreeFourths = 85,
tileActiveApp = 86

// Order matters here - it's used in the menu
static let active = [leftHalf, rightHalf, centerHalf, topHalf, bottomHalf,
Expand All @@ -121,7 +122,7 @@ enum WindowAction: Int, Codable {
halveHeightUp, halveHeightDown, halveWidthLeft, halveWidthRight,
tileAll, cascadeAll,
leftTodo, rightTodo,
cascadeActiveApp
cascadeActiveApp, tileActiveApp
]

func post() {
Expand Down Expand Up @@ -233,6 +234,7 @@ enum WindowAction: Int, Codable {
case .leftTodo: return "leftTodo"
case .rightTodo: return "rightTodo"
case .cascadeActiveApp: return "cascadeActiveApp"
case .tileActiveApp: return "tileActiveApp"
case .centerProminently: return "centerProminently"
case .largerWidth: return "largerWidth"
case .smallerWidth: return "smallerWidth"
Expand Down Expand Up @@ -378,7 +380,7 @@ enum WindowAction: Int, Codable {
return nil
case .doubleHeightUp, .doubleHeightDown, .doubleWidthLeft, .doubleWidthRight, .halveHeightUp, .halveHeightDown, .halveWidthLeft, .halveWidthRight:
return nil
case .specified, .reverseAll, .tileAll, .cascadeAll, .leftTodo, .rightTodo, .cascadeActiveApp:
case .specified, .reverseAll, .tileAll, .cascadeAll, .leftTodo, .rightTodo, .cascadeActiveApp, .tileActiveApp:
return nil
case .centerProminently, .largerWidth, .smallerWidth, .largerHeight, .smallerHeight:
return nil
Expand Down Expand Up @@ -410,7 +412,7 @@ enum WindowAction: Int, Codable {

var isDragSnappable: Bool {
switch self {
case .restore, .previousDisplay, .nextDisplay, .moveUp, .moveDown, .moveLeft, .moveRight, .specified, .reverseAll, .tileAll, .cascadeAll, .larger, .smaller, .largerWidth, .smallerWidth, .cascadeActiveApp,
case .restore, .previousDisplay, .nextDisplay, .moveUp, .moveDown, .moveLeft, .moveRight, .specified, .reverseAll, .tileAll, .cascadeAll, .larger, .smaller, .largerWidth, .smallerWidth, .cascadeActiveApp, .tileActiveApp,
// Ninths
.topLeftNinth, .topCenterNinth, .topRightNinth, .middleLeftNinth, .middleCenterNinth, .middleRightNinth, .bottomLeftNinth, .bottomCenterNinth, .bottomRightNinth,
// Corner thirds
Expand Down Expand Up @@ -557,6 +559,7 @@ enum WindowAction: Int, Codable {
case .leftTodo: return NSImage()
case .rightTodo: return NSImage()
case .cascadeActiveApp: return NSImage()
case .tileActiveApp: return NSImage()
case .centerProminently: return NSImage()
case .largerWidth: return NSImage(imageLiteralResourceName: "largerWidthTemplate")
case .smallerWidth: return NSImage(imageLiteralResourceName: "smallerWidthTemplate")
Expand Down Expand Up @@ -604,7 +607,7 @@ enum WindowAction: Int, Codable {
return Defaults.applyGapsToMaximize.userDisabled ? .none : .both;
case .maximizeHeight:
return Defaults.applyGapsToMaximizeHeight.userDisabled ? .none : .vertical;
case .almostMaximize, .previousDisplay, .nextDisplay, .larger, .smaller, .largerWidth, .smallerWidth, .largerHeight, .smallerHeight, .center, .centerProminently, .restore, .specified, .reverseAll, .tileAll, .cascadeAll, .cascadeActiveApp:
case .almostMaximize, .previousDisplay, .nextDisplay, .larger, .smaller, .largerWidth, .smallerWidth, .largerHeight, .smallerHeight, .center, .centerProminently, .restore, .specified, .reverseAll, .tileAll, .cascadeAll, .cascadeActiveApp, .tileActiveApp:
return .none
}
}
Expand Down
3 changes: 3 additions & 0 deletions TerminalCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,14 @@ The key codes are:
* tileAll
* cascadeAll
* cascadeActiveApp
* tileActiveApp

_tileAll_ and _cascadeAll_ act on all visible windows.

_cascadeActiveApp_ cascades and brings to the front only windows belonging to the currently active (foremost) app, leaving all other windows alone.

_tileActiveApp_ tiles only windows belonging to the currently active (foremost) app into a grid, leaving all other windows alone.

For example, the command for setting the cascadeActiveApp shortcut to `ctrl shift 2` would be:

```bash
Expand Down