Skip to content

Commit

Permalink
🐛 Windows now resize while considering the dock
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 authored Aug 31, 2023
2 parents 80b8353 + 77e73ee commit 55e3868
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Loop/Helpers/LoopManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class LoopManager {
self.screenWithMouse = NSScreen.screenWithMouse

if Defaults[.previewVisibility] == true && frontmostWindow != nil {
previewController.show()
previewController.show(screen: self.screenWithMouse!)
}
radialMenuController.show(frontmostWindow: frontmostWindow)
keybindMonitor.start()
Expand Down
16 changes: 12 additions & 4 deletions Loop/Helpers/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,21 @@ struct WindowEngine {

private func getScreenFrame(screen: NSScreen) -> CGRect? {
guard let displayID = screen.displayID else { return nil }
let menubarHeight = screen.frame.size.height - screen.visibleFrame.size.height
var screenFrame = CGDisplayBounds(displayID)
screenFrame.size.height -= menubarHeight
screenFrame.origin.y += menubarHeight
let screenFrameOrigin = CGDisplayBounds(displayID).origin
var screenFrame: CGRect = screen.visibleFrame

// Set position of the screenFrame (useful for multiple displays)
screenFrame.origin = screenFrameOrigin

// Move screenFrame's y origin to compensate for menubar & dock, if it's on the bottom
screenFrame.origin.y += (screen.frame.size.height - screen.visibleFrame.size.height)

// Move screenFrame's x origin when dock is shown on left/right
screenFrame.origin.x += (screen.frame.size.width - screen.visibleFrame.size.width)

return screenFrame
}

private func generateWindowFrame(_ windowFrame: CGRect, _ screenFrame: CGRect, _ direction: WindowDirection) -> CGRect? {
let screenWidth = screenFrame.size.width
let screenHeight = screenFrame.size.height
Expand Down
15 changes: 2 additions & 13 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 show() {
func show(screen: NSScreen) {
if let windowController = loopPreviewWindowController {
windowController.window?.orderFrontRegardless()
return
Expand All @@ -30,18 +30,7 @@ class PreviewController {
panel.alphaValue = 0
panel.orderFrontRegardless()

guard let screen = NSScreen.screenWithMouse else { return }
let menubarHeight = screen.frame.size.height - screen.visibleFrame.size.height

let screenWidth = screen.frame.size.width
let screenHeight = screen.frame.size.height - menubarHeight
let screenOriginX = screen.frame.origin.x
let screenOriginY = screen.frame.origin.y

panel.setFrame(NSRect(x: screenOriginX,
y: screenOriginY,
width: screenWidth,
height: screenHeight), display: false)
panel.setFrame(screen.visibleFrame, display: false)

loopPreviewWindowController = .init(window: panel)

Expand Down

0 comments on commit 55e3868

Please sign in to comment.