Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
590be2356f | ||
|
|
af32a36a91 |
@@ -48,6 +48,13 @@ struct MenuView: View {
|
|||||||
|
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
|
Button("Copy Diagnostics") {
|
||||||
|
let diag = CaptureController.shared.diagnostics()
|
||||||
|
let pasteboard = NSPasteboard.general
|
||||||
|
pasteboard.clearContents()
|
||||||
|
pasteboard.setString(diag, forType: .string)
|
||||||
|
}
|
||||||
|
|
||||||
Button(LoginItem.isEnabled ? "Disable Launch at Login" : "Launch at Login") {
|
Button(LoginItem.isEnabled ? "Disable Launch at Login" : "Launch at Login") {
|
||||||
if !LoginItem.toggle() {
|
if !LoginItem.toggle() {
|
||||||
let alert = NSAlert()
|
let alert = NSAlert()
|
||||||
|
|||||||
@@ -10,6 +10,38 @@ final class CaptureController: NSObject {
|
|||||||
private var previousApp: NSRunningApplication?
|
private var previousApp: NSRunningApplication?
|
||||||
private var overlayIDs: [Int] = []
|
private var overlayIDs: [Int] = []
|
||||||
|
|
||||||
|
/// Diagnostic snapshot for "Copy Diagnostics" menu item.
|
||||||
|
func diagnostics() -> String {
|
||||||
|
var lines: [String] = []
|
||||||
|
lines.append("Kapture diagnostics")
|
||||||
|
for (i, s) in NSScreen.screens.enumerated() {
|
||||||
|
let scale = s.backingScaleFactor
|
||||||
|
let cgID = (s.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? NSNumber)?.uint32Value ?? 0
|
||||||
|
lines.append("screen[\(i)]: frame=\(s.frame) scale=\(scale) backingSize=\(s.frame.width*scale)x\(s.frame.height*scale) cgID=\(cgID)")
|
||||||
|
}
|
||||||
|
if #available(macOS 14.0, *) {
|
||||||
|
Task {
|
||||||
|
if let content = try? await SCShareableContent.current {
|
||||||
|
for (i, d) in content.displays.enumerated() {
|
||||||
|
lines.append("SCDisplay[\(i)]: frame=\(d.frame) width=\(d.width)x\(d.height) id=\(d.displayID)")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lines.append("SCShareableContent: unavailable (no Screen Recording permission?)")
|
||||||
|
}
|
||||||
|
let text = lines.joined(separator: "\n")
|
||||||
|
let pb = NSPasteboard.general
|
||||||
|
pb.clearContents()
|
||||||
|
pb.setString(text, forType: .string)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let text = lines.joined(separator: "\n")
|
||||||
|
let pb = NSPasteboard.general
|
||||||
|
pb.clearContents()
|
||||||
|
pb.setString(text, forType: .string)
|
||||||
|
}
|
||||||
|
return lines.joined(separator: "\n")
|
||||||
|
}
|
||||||
|
|
||||||
func begin() {
|
func begin() {
|
||||||
guard !isSelecting else { return }
|
guard !isSelecting else { return }
|
||||||
guard PermissionManager.isGranted else {
|
guard PermissionManager.isGranted else {
|
||||||
@@ -85,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,
|
||||||
@@ -145,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's Y axis is flipped relative to AppKit
|
||||||
|
// NSScreen frames. Convert the selection into SCDisplay space
|
||||||
|
// using the matching NSScreen's top edge, then crop there.
|
||||||
|
let scRect = CGRect(
|
||||||
|
x: rect.minX,
|
||||||
|
y: screen.frame.maxY - rect.maxY + display.frame.minY,
|
||||||
|
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.5</string>
|
<string>1.1.7</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>15</string>
|
<string>17</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user