From 80e9330b1484951c5e2eac8234ab39ff990f9ea0 Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 10 Jun 2025 13:30:36 +0800 Subject: [PATCH] Add Commands for smaller/larger height only (#1607) --- Rectangle/WindowAction.swift | 14 ++++++++++---- .../WindowCalculation/ChangeSizeCalculation.swift | 8 ++++---- .../WindowCalculation/WindowCalculation.swift | 2 ++ TerminalCommands.md | 12 ++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Rectangle/WindowAction.swift b/Rectangle/WindowAction.swift index 0600926..0bd05a9 100644 --- a/Rectangle/WindowAction.swift +++ b/Rectangle/WindowAction.swift @@ -94,13 +94,15 @@ enum WindowAction: Int, Codable { halveWidthLeft = 78, halveWidthRight = 79, largerWidth = 80, - smallerWidth = 81 + smallerWidth = 81, + largerHeight = 82, + smallerHeight = 83 // 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, larger, smaller, largerWidth, smallerWidth, + maximize, almostMaximize, maximizeHeight, larger, smaller, largerWidth, smallerWidth, largerHeight, smallerHeight, center, centerProminently, restore, nextDisplay, previousDisplay, moveLeft, moveRight, moveUp, moveDown, @@ -230,6 +232,8 @@ enum WindowAction: Int, Codable { case .centerProminently: return "centerProminently" case .largerWidth: return "largerWidth" case .smallerWidth: return "smallerWidth" + case .largerHeight: return "largerHeight" + case .smallerHeight: return "smallerHeight" } } @@ -366,7 +370,7 @@ enum WindowAction: Int, Codable { return nil case .specified, .reverseAll, .tileAll, .cascadeAll, .leftTodo, .rightTodo, .cascadeActiveApp: return nil - case .centerProminently, .largerWidth, .smallerWidth: + case .centerProminently, .largerWidth, .smallerWidth, .largerHeight, .smallerHeight: return nil } @@ -544,6 +548,8 @@ enum WindowAction: Int, Codable { case .centerProminently: return NSImage() case .largerWidth: return NSImage() case .smallerWidth: return NSImage() + case .largerHeight: return NSImage() + case .smallerHeight: return NSImage() } } @@ -586,7 +592,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, .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: return .none } } diff --git a/Rectangle/WindowCalculation/ChangeSizeCalculation.swift b/Rectangle/WindowCalculation/ChangeSizeCalculation.swift index 3df9389..23edcd9 100644 --- a/Rectangle/WindowCalculation/ChangeSizeCalculation.swift +++ b/Rectangle/WindowCalculation/ChangeSizeCalculation.swift @@ -28,9 +28,9 @@ class ChangeSizeCalculation: WindowCalculation, ChangeWindowDimensionCalculation let sizeOffset: CGFloat switch params.action { - case .larger, .largerWidth: + case .larger, .largerWidth, .largerHeight: sizeOffset = sizeOffsetAbs - case .smaller, .smallerWidth: + case .smaller, .smallerWidth, .smallerHeight: sizeOffset = -sizeOffsetAbs default: sizeOffset = 0 @@ -62,7 +62,7 @@ class ChangeSizeCalculation: WindowCalculation, ChangeWindowDimensionCalculation // Calculate Height - if [.larger, .smaller].contains(params.action) { + if [.larger, .smaller, .largerHeight, .smallerHeight].contains(params.action) { resizedWindowRect.size.height = resizedWindowRect.height + sizeOffset resizedWindowRect.origin.y = resizedWindowRect.minY - floor(sizeOffset / 2.0) @@ -88,7 +88,7 @@ class ChangeSizeCalculation: WindowCalculation, ChangeWindowDimensionCalculation resizedWindowRect.origin.y = params.window.rect.origin.y - floor(sizeOffset / 2.0) } - if [.smaller, .smallerWidth].contains(params.action), resizedWindowRectIsTooSmall(windowRect: resizedWindowRect, visibleFrameOfScreen: visibleFrameOfScreen) { + if [.smaller, .smallerWidth, .smallerHeight].contains(params.action), resizedWindowRectIsTooSmall(windowRect: resizedWindowRect, visibleFrameOfScreen: visibleFrameOfScreen) { resizedWindowRect = window.rect } diff --git a/Rectangle/WindowCalculation/WindowCalculation.swift b/Rectangle/WindowCalculation/WindowCalculation.swift index fcfbc3a..66bd010 100644 --- a/Rectangle/WindowCalculation/WindowCalculation.swift +++ b/Rectangle/WindowCalculation/WindowCalculation.swift @@ -195,6 +195,8 @@ class WindowCalculationFactory { .smaller: changeSizeCalculation, .largerWidth: changeSizeCalculation, .smallerWidth: changeSizeCalculation, + .largerHeight: changeSizeCalculation, + .smallerHeight: changeSizeCalculation, .bottomHalf: bottomHalfCalculation, .topHalf: topHalfCalculation, .center: centerCalculation, diff --git a/TerminalCommands.md b/TerminalCommands.md index 42b127d..0763525 100644 --- a/TerminalCommands.md +++ b/TerminalCommands.md @@ -24,6 +24,7 @@ The preferences window is purposefully slim, but there's a lot that can be modif - [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) +- [Make Smaller/Make Larger height only](#make-smallermake-larger-height-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) @@ -345,6 +346,17 @@ defaults write com.knollsoft.Rectangle largerWidth -dict-add keyCode -float 30 m defaults write com.knollsoft.Rectangle smallerWidth -dict-add keyCode -float 33 modifierFlags -float 786432 ``` +## Make Smaller/Make Larger height only + +Similarly, if you only want to change the window height without changing window width, configure shortcuts for the _largerHeight_ and _smallerHeight_ commands. + +For example, if you want to assign `ctrl option shift ]` to _largerHeight_ and `ctrl option shift [` to _smallerHeight_, the commands would be: + +```bash +defaults write com.knollsoft.Rectangle largerHeight -dict-add keyCode -float 30 modifierFlags -float 917504 +defaults write com.knollsoft.Rectangle smallerHeight -dict-add keyCode -float 33 modifierFlags -float 917504 +``` + ## Disabling window restore when moving windows ```bash