Skip to content

Commit

Permalink
🐛 Fix #46
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Sep 30, 2023
1 parent d95c17f commit 756a49b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Loop/Managers/LoopManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class LoopManager {
self.screenWithMouse = NSScreen.screenWithMouse

if Defaults[.previewVisibility] == true && frontmostWindow != nil {
previewController.open(screen: self.screenWithMouse!)
previewController.open(screen: self.screenWithMouse!, window: frontmostWindow)
}
radialMenuController.open(frontmostWindow: frontmostWindow)
keybindMonitor.start()
Expand Down
2 changes: 1 addition & 1 deletion Loop/Managers/SnappingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SnappingManager {
ignoredFrame: ignoredFrame
)

self.previewController.open(screen: screen)
self.previewController.open(screen: screen, window: nil)
DispatchQueue.main.async {
NotificationCenter.default.post(
name: Notification.Name.directionChanged,
Expand Down
4 changes: 2 additions & 2 deletions Loop/Preview Window/PreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PreviewController {

var loopPreviewWindowController: NSWindowController?

func open(screen: NSScreen) {
func open(screen: NSScreen, window: Window?) {
if let windowController = loopPreviewWindowController {
windowController.window?.orderFrontRegardless()
return
Expand All @@ -25,7 +25,7 @@ class PreviewController {
panel.hasShadow = false
panel.backgroundColor = NSColor.white.withAlphaComponent(0.00001)
panel.level = .screenSaver
panel.contentView = NSHostingView(rootView: PreviewView())
panel.contentView = NSHostingView(rootView: PreviewView(window: window))
panel.collectionBehavior = .canJoinAllSpaces
panel.alphaValue = 0
panel.orderFrontRegardless()
Expand Down
25 changes: 19 additions & 6 deletions Loop/Preview Window/PreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ struct PreviewView: View {
@State var previewMode = false

@State var currentResizeDirection: WindowDirection = .noAction
private let window: Window?
private var sidePadding: CGFloat = 0

init(previewMode: Bool = false, window: Window?) {
self.window = window
self.sidePadding = previewPadding + previewBorderThickness / 2
}

@Default(.useSystemAccentColor) var useSystemAccentColor
@Default(.customAccentColor) var customAccentColor
Expand All @@ -29,7 +36,8 @@ struct PreviewView: View {
GeometryReader { geo in
VStack {
switch currentResizeDirection {
case .bottomHalf,
case .center,
.bottomHalf,
.bottomRightQuarter,
.bottomLeftQuarter,
.verticalCenterThird,
Expand All @@ -45,7 +53,8 @@ struct PreviewView: View {

HStack {
switch currentResizeDirection {
case .rightHalf,
case .center,
.rightHalf,
.topRightQuarter,
.bottomRightQuarter,
.horizontalCenterThird,
Expand Down Expand Up @@ -78,9 +87,12 @@ struct PreviewView: View {
lineWidth: previewBorderThickness
)
}
.padding(previewPadding + previewBorderThickness/2)
.padding(sidePadding)
.frame(width: currentResizeDirection == .noAction ? 0 : nil,
height: currentResizeDirection == .noAction ? 0 : nil)
.frame(width: currentResizeDirection == .center ? (window?.size.width ?? 10) - sidePadding : nil,
height: currentResizeDirection == .center ? (window?.size.height ?? 10) - sidePadding : nil)

.frame(width: currentResizeDirection == .lastDirection ? 0 : nil,
height: currentResizeDirection == .lastDirection ? 0 : nil)
.frame(width: currentResizeDirection == .topTwoThirds ? geo.size.height / 3 * 2 : nil)
Expand All @@ -89,7 +101,8 @@ struct PreviewView: View {
.frame(width: currentResizeDirection == .leftTwoThirds ? geo.size.width / 3 * 2 : nil)

switch currentResizeDirection {
case .leftHalf,
case .center,
.leftHalf,
.topLeftQuarter,
.bottomLeftQuarter,
.horizontalCenterThird,
Expand All @@ -105,7 +118,8 @@ struct PreviewView: View {
}

switch currentResizeDirection {
case .topHalf,
case .center,
.topHalf,
.topRightQuarter,
.topLeftQuarter,
.verticalCenterThird,
Expand All @@ -122,7 +136,6 @@ struct PreviewView: View {
}
.foregroundColor(.clear)
.opacity(currentResizeDirection == .noAction ? 0 : 1)
.scaleEffect(currentResizeDirection == .center ? 0.8 : 1)
.animation(.interpolatingSpring(stiffness: 250, damping: 25), value: currentResizeDirection)
.onReceive(.directionChanged) { obj in
if !previewMode {
Expand Down
2 changes: 1 addition & 1 deletion Loop/Settings/PreviewSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct PreviewSettingsView: View {
}

Section {
PreviewView(previewMode: true)
PreviewView(previewMode: true, window: nil)
}
.frame(height: 150)
.opacity(previewVisibility ? 1 : 0.5)
Expand Down

0 comments on commit 756a49b

Please sign in to comment.