Skip to content

Commit

Permalink
Add commands for larger width & smaller width (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilweee authored Nov 3, 2024
1 parent 5cd1db5 commit 8e8a16d
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 25 deletions.
17 changes: 12 additions & 5 deletions Rectangle/WindowAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ enum WindowAction: Int, Codable {
halveHeightUp = 76,
halveHeightDown = 77,
halveWidthLeft = 78,
halveWidthRight = 79
halveWidthRight = 79,
largerWidth = 80,
smallerWidth = 81

// Order matters here - it's used in the menu
static let active = [leftHalf, rightHalf, centerHalf, topHalf, bottomHalf,
topLeft, topRight, bottomLeft, bottomRight,
firstThird, centerThird, lastThird, firstTwoThirds, lastTwoThirds,
maximize, almostMaximize, maximizeHeight, smaller, larger, center, centerProminently, restore,
maximize, almostMaximize, maximizeHeight, larger, smaller, largerWidth, smallerWidth,
center, centerProminently, restore,
nextDisplay, previousDisplay,
moveLeft, moveRight, moveUp, moveDown,
firstFourth, secondFourth, thirdFourth, lastFourth, firstThreeFourths, lastThreeFourths,
Expand Down Expand Up @@ -225,6 +228,8 @@ enum WindowAction: Int, Codable {
case .rightTodo: return "rightTodo"
case .cascadeActiveApp: return "cascadeActiveApp"
case .centerProminently: return "centerProminently"
case .largerWidth: return "largerWidth"
case .smallerWidth: return "smallerWidth"
}
}

Expand Down Expand Up @@ -361,7 +366,7 @@ enum WindowAction: Int, Codable {
return nil
case .specified, .reverseAll, .tileAll, .cascadeAll, .leftTodo, .rightTodo, .cascadeActiveApp:
return nil
case .centerProminently:
case .centerProminently, .largerWidth, .smallerWidth:
return nil
}

Expand Down Expand Up @@ -398,7 +403,7 @@ enum WindowAction: Int, Codable {

var isDragSnappable: Bool {
switch self {
case .restore, .previousDisplay, .nextDisplay, .moveUp, .moveDown, .moveLeft, .moveRight, .specified, .reverseAll, .tileAll, .cascadeAll, .smaller, .larger, .cascadeActiveApp,
case .restore, .previousDisplay, .nextDisplay, .moveUp, .moveDown, .moveLeft, .moveRight, .specified, .reverseAll, .tileAll, .cascadeAll, .larger, .smaller, .largerWidth, .smallerWidth, .cascadeActiveApp,
// Ninths
.topLeftNinth, .topCenterNinth, .topRightNinth, .middleLeftNinth, .middleCenterNinth, .middleRightNinth, .bottomLeftNinth, .bottomCenterNinth, .bottomRightNinth,
// Corner thirds
Expand Down Expand Up @@ -537,6 +542,8 @@ enum WindowAction: Int, Codable {
case .rightTodo: return NSImage()
case .cascadeActiveApp: return NSImage()
case .centerProminently: return NSImage()
case .largerWidth: return NSImage()
case .smallerWidth: return NSImage()
}
}

Expand Down Expand Up @@ -579,7 +586,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, .center, .centerProminently, .restore, .specified, .reverseAll, .tileAll, .cascadeAll, .cascadeActiveApp:
case .almostMaximize, .previousDisplay, .nextDisplay, .larger, .smaller, .largerWidth, .smallerWidth, .center, .centerProminently, .restore, .specified, .reverseAll, .tileAll, .cascadeAll, .cascadeActiveApp:
return .none
}
}
Expand Down
70 changes: 50 additions & 20 deletions Rectangle/WindowCalculation/ChangeSizeCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,73 @@ class ChangeSizeCalculation: WindowCalculation, ChangeWindowDimensionCalculation
}

override func calculateRect(_ params: RectCalculationParameters) -> RectResult {
let sizeOffset: CGFloat = params.action == .smaller ? -sizeOffsetAbs : sizeOffsetAbs

let sizeOffset: CGFloat
switch params.action {
case .larger, .largerWidth:
sizeOffset = sizeOffsetAbs
case .smaller, .smallerWidth:
sizeOffset = -sizeOffsetAbs
default:
sizeOffset = 0
}

let visibleFrameOfScreen = params.visibleFrameOfScreen
let window = params.window

// Calculate Width

var resizedWindowRect = window.rect
resizedWindowRect.size.width = resizedWindowRect.width + sizeOffset
resizedWindowRect.origin.x = resizedWindowRect.minX - floor(sizeOffset / 2.0)

if curtainChangeSize {
resizedWindowRect = againstLeftAndRightScreenEdges(originalWindowRect: window.rect, resizedWindowRect: resizedWindowRect, visibleFrameOfScreen: visibleFrameOfScreen)
}

if resizedWindowRect.width >= visibleFrameOfScreen.width {
resizedWindowRect.size.width = visibleFrameOfScreen.width
}
resizedWindowRect.size.height = resizedWindowRect.height + sizeOffset
resizedWindowRect.origin.y = resizedWindowRect.minY - floor(sizeOffset / 2.0)

if curtainChangeSize {
resizedWindowRect = againstTopAndBottomScreenEdges(originalWindowRect: window.rect, resizedWindowRect: resizedWindowRect, visibleFrameOfScreen: visibleFrameOfScreen)
if [.larger, .smaller, .largerWidth, .smallerWidth].contains(params.action) {
resizedWindowRect.size.width = resizedWindowRect.width + sizeOffset
resizedWindowRect.origin.x = resizedWindowRect.minX - floor(sizeOffset / 2.0)

if curtainChangeSize {
resizedWindowRect = againstLeftAndRightScreenEdges(
originalWindowRect: window.rect,
resizedWindowRect: resizedWindowRect,
visibleFrameOfScreen: visibleFrameOfScreen
)
}

if resizedWindowRect.width >= visibleFrameOfScreen.width {
resizedWindowRect.size.width = visibleFrameOfScreen.width
}
}

if resizedWindowRect.height >= visibleFrameOfScreen.height {
resizedWindowRect.size.height = visibleFrameOfScreen.height
resizedWindowRect.origin.y = params.window.rect.minY

// Calculate Height

if [.larger, .smaller].contains(params.action) {
resizedWindowRect.size.height = resizedWindowRect.height + sizeOffset
resizedWindowRect.origin.y = resizedWindowRect.minY - floor(sizeOffset / 2.0)

if curtainChangeSize {
resizedWindowRect = againstTopAndBottomScreenEdges(
originalWindowRect: window.rect,
resizedWindowRect: resizedWindowRect,
visibleFrameOfScreen: visibleFrameOfScreen
)
}

if resizedWindowRect.height >= visibleFrameOfScreen.height {
resizedWindowRect.size.height = visibleFrameOfScreen.height
resizedWindowRect.origin.y = params.window.rect.minY
}
}


if againstAllScreenEdges(windowRect: window.rect, visibleFrameOfScreen: visibleFrameOfScreen) && (sizeOffset < 0) {
resizedWindowRect.size.width = params.window.rect.width + sizeOffset
resizedWindowRect.origin.x = params.window.rect.origin.x - floor(sizeOffset / 2.0)
resizedWindowRect.size.height = params.window.rect.height + sizeOffset
resizedWindowRect.origin.y = params.window.rect.origin.y - floor(sizeOffset / 2.0)
}

if params.action == .smaller, resizedWindowRectIsTooSmall(windowRect: resizedWindowRect, visibleFrameOfScreen: visibleFrameOfScreen) {
if [.smaller, .smallerWidth].contains(params.action), resizedWindowRectIsTooSmall(windowRect: resizedWindowRect, visibleFrameOfScreen: visibleFrameOfScreen) {
resizedWindowRect = window.rect
}

return RectResult(resizedWindowRect)
}

Expand Down
2 changes: 2 additions & 0 deletions Rectangle/WindowCalculation/WindowCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class WindowCalculationFactory {
.nextDisplay: nextPrevDisplayCalculation,
.larger: changeSizeCalculation,
.smaller: changeSizeCalculation,
.largerWidth: changeSizeCalculation,
.smallerWidth: changeSizeCalculation,
.bottomHalf: bottomHalfCalculation,
.topHalf: topHalfCalculation,
.center: centerCalculation,
Expand Down
12 changes: 12 additions & 0 deletions TerminalCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The preferences window is purposefully slim, but there's a lot that can be modif
- [Make Smaller limits](#make-smaller-limits)
- [Make Smaller/Make Larger size increments](#make-smallermake-larger-size-increments)
- [Make Smaller/Make Larger "curtain resize" with gaps](#make-smallermake-larger-curtain-resize-with-gaps)
- [Make Smaller/Make Larger width only](#make-smallermake-larger-width-only)
- [Disabling window restore when moving windows](#disabling-window-restore-when-moving-windows)
- [Changing the margin for the snap areas](#changing-the-margin-for-the-snap-areas)
- [Setting gaps at the screen edges](#setting-gaps-at-the-screen-edges)
Expand Down Expand Up @@ -333,6 +334,17 @@ By default, windows touching the edge of the screen will keep those shared edges
defaults write com.knollsoft.Rectangle curtainChangeSize -int 2
```

## Make Smaller/Make Larger width only

By default, "Make Smaller" and "Make Larger" change both, the window height and the window width. If you only want to change the window width without changing window height, configure shortcuts for the _largerWidth_ and _smallerWidth_ commands.

For example, if you want to assign `ctrl option ]` to _largerWidth_ and `ctrl option [` to _smallerWidth_, the commands would be:

```bash
defaults write com.knollsoft.Rectangle largerWidth -dict-add keyCode -float 30 modifierFlags -float 786432
defaults write com.knollsoft.Rectangle smallerWidth -dict-add keyCode -float 33 modifierFlags -float 786432
```

## Disabling window restore when moving windows

```bash
Expand Down

0 comments on commit 8e8a16d

Please sign in to comment.