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
4 changes: 4 additions & 0 deletions Rectangle/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class Defaults {
static let notifiedOfProblemApps = BoolDefault(key: "notifiedOfProblemApps")
static let specifiedHeight = FloatDefault(key: "specifiedHeight", defaultValue: 1050)
static let specifiedWidth = FloatDefault(key: "specifiedWidth", defaultValue: 1680)
static let horizontalSplitRatio = FloatDefault(key: "horizontalSplitRatio", defaultValue: 50)
static let verticalSplitRatio = FloatDefault(key: "verticalSplitRatio", defaultValue: 50)
static let moveCursorAcrossDisplays = OptionalBoolDefault(key: "moveCursorAcrossDisplays")
static let moveCursor = OptionalBoolDefault(key: "moveCursor")
static let autoMaximize = OptionalBoolDefault(key: "autoMaximize")
Expand Down Expand Up @@ -151,6 +153,8 @@ class Defaults {
notifiedOfProblemApps,
specifiedHeight,
specifiedWidth,
horizontalSplitRatio,
verticalSplitRatio,
moveCursorAcrossDisplays,
moveCursor,
autoMaximize,
Expand Down
72 changes: 69 additions & 3 deletions Rectangle/PrefsWindow/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,44 @@ class SettingsViewController: NSViewController {
integerFormatter.minimum = 1
widthStepField.formatter = integerFormatter

let splitRatioHeaderLabel = NSTextField(labelWithString: NSLocalizedString("Half Split Ratios", tableName: "Main", value: "", comment: ""))
splitRatioHeaderLabel.font = NSFont.boldSystemFont(ofSize: NSFont.systemFontSize)
splitRatioHeaderLabel.alignment = .center
splitRatioHeaderLabel.translatesAutoresizingMaskIntoConstraints = false

let hSplitLabel = NSTextField(labelWithString: NSLocalizedString("Horizontal (L/R, %)", tableName: "Main", value: "", comment: ""))
hSplitLabel.alignment = .right
hSplitLabel.translatesAutoresizingMaskIntoConstraints = false

let vSplitLabel = NSTextField(labelWithString: NSLocalizedString("Vertical (T/B, %)", tableName: "Main", value: "", comment: ""))
vSplitLabel.alignment = .right
vSplitLabel.translatesAutoresizingMaskIntoConstraints = false

let percentFormatter = NumberFormatter()
percentFormatter.allowsFloats = false
percentFormatter.minimum = 1
percentFormatter.maximum = 99

let hSplitField = AutoSaveFloatField(frame: NSRect(x: 0, y: 0, width: 160, height: 19))
hSplitField.stringValue = String(Int(Defaults.horizontalSplitRatio.value))
hSplitField.delegate = self
hSplitField.defaults = Defaults.horizontalSplitRatio
hSplitField.fallbackValue = 50
hSplitField.translatesAutoresizingMaskIntoConstraints = false
hSplitField.refusesFirstResponder = true
hSplitField.alignment = .right
hSplitField.formatter = percentFormatter

let vSplitField = AutoSaveFloatField(frame: NSRect(x: 0, y: 0, width: 160, height: 19))
vSplitField.stringValue = String(Int(Defaults.verticalSplitRatio.value))
vSplitField.delegate = self
vSplitField.defaults = Defaults.verticalSplitRatio
vSplitField.fallbackValue = 50
vSplitField.translatesAutoresizingMaskIntoConstraints = false
vSplitField.refusesFirstResponder = true
vSplitField.alignment = .right
vSplitField.formatter = percentFormatter

largerWidthShortcutView.setAssociatedUserDefaultsKey(WindowAction.largerWidth.name, withTransformerName: MASDictionaryTransformerName)
smallerWidthShortcutView.setAssociatedUserDefaultsKey(WindowAction.smallerWidth.name, withTransformerName: MASDictionaryTransformerName)

Expand Down Expand Up @@ -572,6 +610,20 @@ class SettingsViewController: NSViewController {
widthStepRow.spacing = 18
widthStepRow.addArrangedSubview(widthStepLabel)
widthStepRow.addArrangedSubview(widthStepField)

let hSplitRow = NSStackView()
hSplitRow.orientation = .horizontal
hSplitRow.alignment = .centerY
hSplitRow.spacing = 18
hSplitRow.addArrangedSubview(hSplitLabel)
hSplitRow.addArrangedSubview(hSplitField)

let vSplitRow = NSStackView()
vSplitRow.orientation = .horizontal
vSplitRow.alignment = .centerY
vSplitRow.spacing = 18
vSplitRow.addArrangedSubview(vSplitLabel)
vSplitRow.addArrangedSubview(vSplitField)

let topVerticalThirdRow = NSStackView()
topVerticalThirdRow.orientation = .horizontal
Expand Down Expand Up @@ -682,9 +734,14 @@ class SettingsViewController: NSViewController {
mainStackView.addArrangedSubview(bottomCenterLeftEighthRow)
mainStackView.addArrangedSubview(bottomCenterRightEighthRow)
mainStackView.addArrangedSubview(bottomRightEighthRow)
mainStackView.addArrangedSubview(splitRatioHeaderLabel)
mainStackView.setCustomSpacing(10, after: splitRatioHeaderLabel)
mainStackView.addArrangedSubview(hSplitRow)
mainStackView.addArrangedSubview(vSplitRow)

NSLayoutConstraint.activate([
headerLabel.widthAnchor.constraint(equalTo: mainStackView.widthAnchor),
splitRatioHeaderLabel.widthAnchor.constraint(equalTo: mainStackView.widthAnchor),
largerWidthLabel.widthAnchor.constraint(equalTo: smallerWidthLabel.widthAnchor),
smallerWidthLabel.widthAnchor.constraint(equalTo: widthStepLabel.widthAnchor),
widthStepLabel.widthAnchor.constraint(equalTo: topVerticalThirdLabel.widthAnchor),
Expand All @@ -700,6 +757,8 @@ class SettingsViewController: NSViewController {
bottomLeftEighthLabel.widthAnchor.constraint(equalTo: bottomCenterLeftEighthLabel.widthAnchor),
bottomCenterLeftEighthLabel.widthAnchor.constraint(equalTo: bottomCenterRightEighthLabel.widthAnchor),
bottomCenterRightEighthLabel.widthAnchor.constraint(equalTo: bottomRightEighthLabel.widthAnchor),
bottomVerticalTwoThirdsLabel.widthAnchor.constraint(equalTo: hSplitLabel.widthAnchor),
hSplitLabel.widthAnchor.constraint(equalTo: vSplitLabel.widthAnchor),
largerWidthLabelStack.widthAnchor.constraint(equalTo: smallerWidthLabelStack.widthAnchor),
largerWidthShortcutView.widthAnchor.constraint(equalToConstant: 160),
smallerWidthShortcutView.widthAnchor.constraint(equalToConstant: 160),
Expand All @@ -717,7 +776,12 @@ class SettingsViewController: NSViewController {
bottomCenterLeftEighthShortcutView.widthAnchor.constraint(equalToConstant: 160),
bottomCenterRightEighthShortcutView.widthAnchor.constraint(equalToConstant: 160),
bottomRightEighthShortcutView.widthAnchor.constraint(equalToConstant: 160),
widthStepField.trailingAnchor.constraint(equalTo: largerWidthShortcutView.trailingAnchor)
widthStepField.trailingAnchor.constraint(equalTo: largerWidthShortcutView.trailingAnchor),
hSplitField.widthAnchor.constraint(equalToConstant: 160),
vSplitField.widthAnchor.constraint(equalToConstant: 160),
widthStepField.trailingAnchor.constraint(equalTo: largerWidthShortcutView.trailingAnchor),
hSplitField.trailingAnchor.constraint(equalTo: largerWidthShortcutView.trailingAnchor),
vSplitField.trailingAnchor.constraint(equalTo: largerWidthShortcutView.trailingAnchor)
])

let containerView = NSView()
Expand Down Expand Up @@ -966,8 +1030,9 @@ extension SettingsViewController: NSTextFieldDelegate {
let defaults: FloatDefault = sender.defaults else { return }

if sender.stringValue.isEmpty {
sender.stringValue = "30"
defaults.value = 30
let fallback = sender.fallbackValue
sender.stringValue = "\(Int(fallback))"
defaults.value = fallback
sender.defaultsSetAction?()
}
}
Expand All @@ -976,4 +1041,5 @@ extension SettingsViewController: NSTextFieldDelegate {
class AutoSaveFloatField: NSTextField {
var defaults: FloatDefault?
var defaultsSetAction: (() -> Void)?
var fallbackValue: Float = 30
}
4 changes: 4 additions & 0 deletions Rectangle/WindowCalculation/BottomHalfCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class BottomHalfCalculation: WindowCalculation, RepeatedExecutionsInThirdsCalcul
return calculateRepeatedRect(params)
}

func calculateFirstRect(_ params: RectCalculationParameters) -> RectResult {
return calculateFractionalRect(params, fraction: 1.0 - Defaults.verticalSplitRatio.value / 100.0)
}

func calculateFractionalRect(_ params: RectCalculationParameters, fraction: Float) -> RectResult {
let visibleFrameOfScreen = params.visibleFrameOfScreen

Expand Down
24 changes: 15 additions & 9 deletions Rectangle/WindowCalculation/LeftRightHalfCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,22 @@ class LeftRightHalfCalculation: WindowCalculation, RepeatedExecutionsInThirdsCal

}

func calculateFirstRect(_ params: RectCalculationParameters) -> RectResult {
let ratio = Defaults.horizontalSplitRatio.value / 100.0
let fraction = params.action == .rightHalf ? 1.0 - ratio : ratio
return calculateFractionalRect(params, fraction: fraction)
}

func calculateFractionalRect(_ params: RectCalculationParameters, fraction: Float) -> RectResult {
let visibleFrameOfScreen = params.visibleFrameOfScreen

var rect = visibleFrameOfScreen

rect.size.width = floor(visibleFrameOfScreen.width * CGFloat(fraction))
if params.action == .rightHalf {
rect.origin.x = visibleFrameOfScreen.maxX - rect.width
}

return RectResult(rect)
}

Expand Down Expand Up @@ -96,15 +102,15 @@ class LeftRightHalfCalculation: WindowCalculation, RepeatedExecutionsInThirdsCal

// Used to draw box for snapping
override func calculateRect(_ params: RectCalculationParameters) -> RectResult {
let ratio = CGFloat(Defaults.horizontalSplitRatio.value / 100.0)
var rect = params.visibleFrameOfScreen
let leftWidth = floor(rect.width * ratio)
if params.action == .leftHalf {
var oneHalfRect = params.visibleFrameOfScreen
oneHalfRect.size.width = floor(oneHalfRect.width / 2.0)
return RectResult(oneHalfRect)
rect.size.width = leftWidth
} else {
var oneHalfRect = params.visibleFrameOfScreen
oneHalfRect.size.width = floor(oneHalfRect.width / 2.0)
oneHalfRect.origin.x += oneHalfRect.size.width
return RectResult(oneHalfRect)
rect.size.width = rect.width - leftWidth
rect.origin.x += leftWidth
}
return RectResult(rect)
}
}
4 changes: 4 additions & 0 deletions Rectangle/WindowCalculation/TopHalfCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class TopHalfCalculation: WindowCalculation, RepeatedExecutionsInThirdsCalculati
return calculateRepeatedRect(params)
}

func calculateFirstRect(_ params: RectCalculationParameters) -> RectResult {
return calculateFractionalRect(params, fraction: Defaults.verticalSplitRatio.value / 100.0)
}

func calculateFractionalRect(_ params: RectCalculationParameters, fraction: Float) -> RectResult {
let visibleFrameOfScreen = params.visibleFrameOfScreen

Expand Down
2 changes: 1 addition & 1 deletion TerminalCommands.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,4 @@ By default, display order is left-to-right, line-by-line. You can change this to

```bash
defaults write com.knollsoft.Rectangle screensOrderedByX -int 1
```
```