Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fdc2fca95 | ||
|
|
590be2356f |
@@ -117,19 +117,13 @@ final class ScreenCapture {
|
|||||||
private init() {}
|
private init() {}
|
||||||
|
|
||||||
@available(macOS 14.0, *)
|
@available(macOS 14.0, *)
|
||||||
private func crop(_ image: CGImage, to rect: NSRect, display: SCDisplay) -> CGImage? {
|
private func crop(_ image: CGImage, to cgRect: CGRect, display: SCDisplay) -> CGImage? {
|
||||||
// The captured image may be at any scale (retina 2x, secondary display
|
// cgRect is already in SCDisplay space (Y flipped relative to AppKit).
|
||||||
// 1x, or trimmed by ScreenCaptureKit). Derive the pixel scale from the
|
// Derive the pixel scale from the image we actually got, relative to
|
||||||
// image we actually got, relative to the display's point frame.
|
// the display's point frame.
|
||||||
let scaleX = CGFloat(image.width) / display.frame.width
|
let scaleX = CGFloat(image.width) / display.frame.width
|
||||||
let scaleY = CGFloat(image.height) / display.frame.height
|
let scaleY = CGFloat(image.height) / display.frame.height
|
||||||
guard scaleX > 0, scaleY > 0 else { return nil }
|
guard scaleX > 0, scaleY > 0 else { return nil }
|
||||||
let cgRect = CGRect(
|
|
||||||
x: rect.minX,
|
|
||||||
y: rect.minY,
|
|
||||||
width: rect.width,
|
|
||||||
height: rect.height
|
|
||||||
)
|
|
||||||
let pxRect = CGRect(
|
let pxRect = CGRect(
|
||||||
x: (cgRect.minX - display.frame.minX) * scaleX,
|
x: (cgRect.minX - display.frame.minX) * scaleX,
|
||||||
y: (cgRect.minY - display.frame.minY) * scaleY,
|
y: (cgRect.minY - display.frame.minY) * scaleY,
|
||||||
@@ -177,18 +171,30 @@ final class ScreenCapture {
|
|||||||
// width/height are output PIXELS. Multiply by the backing scale
|
// width/height are output PIXELS. Multiply by the backing scale
|
||||||
// of the screen containing the selection so retina displays are
|
// of the screen containing the selection so retina displays are
|
||||||
// captured at full resolution and 1x displays stay 1x.
|
// captured at full resolution and 1x displays stay 1x.
|
||||||
let backingScale = NSScreen.screens
|
guard let screen = NSScreen.screens.first(where: { $0.frame.contains(NSPoint(x: rect.midX, y: rect.midY)) }) else {
|
||||||
.first(where: { $0.frame.contains(NSPoint(x: rect.midX, y: rect.midY)) })?
|
completion(nil)
|
||||||
.backingScaleFactor ?? 1
|
return
|
||||||
|
}
|
||||||
|
let backingScale = screen.backingScaleFactor
|
||||||
config.width = Int(CGFloat(display.width) * backingScale)
|
config.width = Int(CGFloat(display.width) * backingScale)
|
||||||
config.height = Int(CGFloat(display.height) * backingScale)
|
config.height = Int(CGFloat(display.height) * backingScale)
|
||||||
config.showsCursor = true
|
config.showsCursor = true
|
||||||
|
|
||||||
|
// ScreenCaptureKit uses a different origin than AppKit for
|
||||||
|
// screens stacked around the main display: per-display,
|
||||||
|
// SCDisplay y = appKitY - NSScreen.maxY + SCDisplay.maxY.
|
||||||
|
let scRect = CGRect(
|
||||||
|
x: rect.minX,
|
||||||
|
y: rect.minY - screen.frame.maxY + display.frame.maxY,
|
||||||
|
width: rect.width,
|
||||||
|
height: rect.height
|
||||||
|
)
|
||||||
|
|
||||||
guard let image = try? await SCScreenshotManager.captureImage(contentFilter: filter, configuration: config) else {
|
guard let image = try? await SCScreenshotManager.captureImage(contentFilter: filter, configuration: config) else {
|
||||||
completion(nil)
|
completion(nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
completion(self.crop(image, to: rect, display: display))
|
completion(self.crop(image, to: scRect, display: display))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
guard let primary = NSScreen.screens.first(where: { $0.frame.origin == .zero }) ?? NSScreen.screens.first else {
|
guard let primary = NSScreen.screens.first(where: { $0.frame.origin == .zero }) ?? NSScreen.screens.first else {
|
||||||
|
|||||||
+2
-2
@@ -108,9 +108,9 @@ cat > "$APP/Contents/Info.plist" <<'PLIST'
|
|||||||
<key>CFBundleIconFile</key>
|
<key>CFBundleIconFile</key>
|
||||||
<string>Icon</string>
|
<string>Icon</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.1.6</string>
|
<string>1.1.8</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>16</string>
|
<string>18</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user