Skip to content

Commit

Permalink
Merge branch 'dagronf:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cool8jay authored Sep 1, 2023
2 parents 56337cf + 4b16ad0 commit f0a0a2d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions Sources/DSFColorSampler/DSFColorSampler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,25 @@ private class DSFColorSamplerWindow: NSWindow {
override open func mouseMoved(with event: NSEvent) {
let point = NSEvent.mouseLocation
let captureSize: CGFloat = self.frame.size.width / self.pixelZoom
let screenWithMouse = NSScreen.screens.first { NSMouseInRect(point, $0.frame, false) } // screen where mouse resides
let screenWithOrigin = NSScreen.screens.first { $0.frame.origin.x == 0 } // screen where menu bar resides, can be changed in System Settings->Displays->Arrange...
guard
// screen where mouse resides
let screenWithMouse = NSScreen.screens.first(where: { NSMouseInRect(point, $0.frame, false) }),
// screen where menu bar resides, can be changed in System Settings->Displays->Arrange...
let screenWithOrigin = NSScreen.screens.first(where: { $0.frame.origin.x == 0 })
else {
// Odd? Mouse not on any screen?
return
}

let isInOrigin = screenWithMouse == screenWithOrigin
let x = floor(point.x)
let y = isInOrigin ? screenWithMouse!.frame.height - floor(point.y) : screenWithOrigin!.frame.size.height - floor(point.y)
let captureRect = NSRect(x: x - floor(captureSize / 2),
y: y - floor(captureSize / 2),
width: captureSize,
height: captureSize)
let y = isInOrigin ? screenWithMouse.frame.height - floor(point.y) : screenWithOrigin.frame.size.height - floor(point.y)
let captureRect = NSRect(
x: x - floor(captureSize / 2),
y: y - floor(captureSize / 2),
width: captureSize,
height: captureSize
)
let windowID = CGWindowID(self.windowNumber)

guard let image = CGWindowListCreateImage(
Expand Down

0 comments on commit f0a0a2d

Please sign in to comment.