-
-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1288 from vincentpun/center-prominently
Add centerProminently command
- Loading branch information
Showing
5 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Rectangle/WindowCalculation/CenterProminentlyCalculation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// CenterProminentlyCalculation.swift | ||
// Rectangle | ||
// | ||
// Copyright © 2019 Ryan Hanson. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class CenterProminentlyCalculation: WindowCalculation { | ||
|
||
override func calculate(_ params: WindowCalculationParameters) -> WindowCalculationResult? { | ||
|
||
var screenFrame: CGRect? | ||
if !Defaults.alwaysAccountForStage.userEnabled { | ||
screenFrame = params.usableScreens.currentScreen.adjustedVisibleFrame(params.ignoreTodo, true) | ||
} | ||
|
||
let rectResult = calculateRect(params.asRectParams(visibleFrame: screenFrame)) | ||
|
||
let resultingAction: WindowAction = rectResult.resultingAction ?? params.action | ||
|
||
return WindowCalculationResult(rect: rectResult.rect, | ||
screen: params.usableScreens.currentScreen, | ||
resultingAction: resultingAction, | ||
resultingScreenFrame: screenFrame) | ||
} | ||
|
||
override func calculateRect(_ params: RectCalculationParameters) -> RectResult { | ||
|
||
let rectResult = WindowCalculationFactory.centerCalculation.calculateRect(params) | ||
var rect = rectResult.rect | ||
rect.origin.y += -0.25 * rect.height + 0.25 * params.visibleFrameOfScreen.height | ||
return RectResult(rect, resultingAction: rectResult.resultingAction) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters