Skip to content

Commit

Permalink
#128 Adjust window frame in real-time when preview is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Dec 24, 2023
1 parent b4d10cc commit 9764b85
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
17 changes: 16 additions & 1 deletion Loop/Managers/LoopManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ class LoopManager: ObservableObject {

DispatchQueue.main.async {
Notification.Name.directionChanged.post(userInfo: ["direction": self.currentResizeDirection])

if !Defaults[.previewVisibility] {
WindowEngine.resize(
self.targetWindow!,
to: self.currentResizeDirection,
self.screenWithMouse!,
supressAnimations: true
)
}
}

NSHapticFeedbackManager.defaultPerformer.perform(
Expand Down Expand Up @@ -257,7 +266,13 @@ class LoopManager: ObservableObject {
self.currentResizeDirection != .noAction &&
self.isLoopActive {

WindowEngine.resize(self.targetWindow!, to: self.currentResizeDirection, self.screenWithMouse!)
if Defaults[.previewVisibility] {
WindowEngine.resize(
self.targetWindow!,
to: self.currentResizeDirection,
self.screenWithMouse!
)
}

// This rotates the menubar icon
Notification.Name.didLoop.post()
Expand Down
20 changes: 19 additions & 1 deletion Loop/Settings/PreviewSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,28 @@ struct PreviewSettingsView: View {
@Default(.previewCornerRadius) var previewCornerRadius
@Default(.previewBorderThickness) var previewBorderThickness

@Default(.animateWindowResizes) var animateWindowResizes

var body: some View {
Form {
Section("Behavior") {
Toggle("Show Preview when looping", isOn: $previewVisibility)
Toggle(isOn: $previewVisibility) {
VStack(alignment: .leading) {
Text("Show Preview when looping")

if !previewVisibility {
VStack(alignment: .leading) {
Text("Adjusts window frame in real-time as you choose a direction.")

if self.animateWindowResizes {
Text("Windows will not animate their resizes.")
}
}
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
}

Section {
Expand Down
4 changes: 2 additions & 2 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct WindowEngine {
/// - window: Window to be resized
/// - direction: WindowDirection
/// - screen: Screen the window should be resized on
static func resize(_ window: Window, to direction: WindowDirection, _ screen: NSScreen) {
static func resize(_ window: Window, to direction: WindowDirection, _ screen: NSScreen, supressAnimations: Bool = false) {
guard direction != .noAction else { return }
window.activate()

Expand Down Expand Up @@ -47,7 +47,7 @@ struct WindowEngine {
}
var targetWindowFrame = WindowEngine.applyPadding(currentWindowFrame, direction)

var animate = Defaults[.animateWindowResizes]
var animate = (!supressAnimations && Defaults[.animateWindowResizes])
if animate {
if PermissionsManager.ScreenRecording.getStatus() == false {
PermissionsManager.ScreenRecording.requestAccess()
Expand Down

0 comments on commit 9764b85

Please sign in to comment.