Compare commits

...
4 Commits
Author SHA1 Message Date
TZGyn af32a36a91 Add Copy Diagnostics menu item for multi-display debugging
Prints each NSScreen's frame/backing scale/CG display ID and each
SCDisplay's frame/point size, and copies it to the clipboard, so
secondary-display capture failures can be debugged from the menu bar.

💘 Generated with Crush

Assisted-by: Crush:deepseek-v4-flash-0731
2026-08-12 16:44:56 +08:00
TZGyn 1327b61e2b Request capture pixels from the selection screen's backing scale
SCDisplay.width is in points, not pixels: the previous fix sent point
counts to SCStreamConfiguration, producing blurry main-screen captures and
failed secondary-screen captures. Multiply by the backing scale factor of
the screen containing the selection (defaulting to 1x, never forcing 2x).

💘 Generated with Crush

Assisted-by: Crush:deepseek-v4-flash-0731
2026-08-12 16:37:53 +08:00
TZGyn c9a807e8a0 Fix secondary display captures after retina scaling change
The 1.1.2 retina fix overrode the stream width from the display's pixel
dimensions, which made captures on secondary monitors come out at the
wrong scale or offset. Restore requesting the display's native pixel
resolution and keep the crop scale derived from the actual returned image,
plus guard against out-of-bounds crop rects.

💘 Generated with Crush

Assisted-by: Crush:deepseek-v4-flash-0731
2026-08-12 16:34:18 +08:00
TZGyn 7bc93c2014 Anti-alias downscaled screenshots in the result window
Full-res retina captures are downscaled to fit the window; nearest-neighbor
made them look chunky. Use high-quality interpolation when shrinking, keep
pixel-crisp rendering only when upscaling small selections.

💘 Generated with Crush

Assisted-by: Crush:deepseek-v4-flash-0731
2026-08-12 16:25:23 +08:00
4 changed files with 70 additions and 19 deletions
+7
View File
@@ -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()
+51 -11
View File
@@ -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 {
@@ -86,10 +118,12 @@ final class ScreenCapture {
@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 rect: NSRect, display: SCDisplay) -> CGImage? {
// Scale from the actual captured image dimensions, which reflect the // The captured image may be at any scale (retina 2x, secondary display
// stream's pixel output (retina => 2x, non-retina => 1x). // 1x, or trimmed by ScreenCaptureKit). Derive the pixel scale from the
// image we actually got, relative to 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 }
let cgRect = CGRect( let cgRect = CGRect(
x: rect.minX, x: rect.minX,
y: rect.minY, y: rect.minY,
@@ -102,14 +136,18 @@ final class ScreenCapture {
width: cgRect.width * scaleX, width: cgRect.width * scaleX,
height: cgRect.height * scaleY height: cgRect.height * scaleY
) )
// Guard against negative offsets when the selection reaches beyond the
// display's frame (e.g. secondary monitor coordinate quirks).
let safeRect = pxRect.intersection(CGRect(x: 0, y: 0, width: CGFloat(image.width), height: CGFloat(image.height)))
guard safeRect.width >= 1, safeRect.height >= 1 else { return nil }
guard let cropCtx = CGContext( guard let cropCtx = CGContext(
data: nil, width: Int(pxRect.width), height: Int(pxRect.height), data: nil, width: Int(safeRect.width), height: Int(safeRect.height),
bitsPerComponent: 8, bytesPerRow: 0, bitsPerComponent: 8, bytesPerRow: 0,
space: CGColorSpaceCreateDeviceRGB(), space: CGColorSpaceCreateDeviceRGB(),
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
) else { return nil } ) else { return nil }
cropCtx.interpolationQuality = .high cropCtx.interpolationQuality = .high
cropCtx.draw(image, in: CGRect(x: -pxRect.minX, y: -pxRect.minY, width: CGFloat(image.width), height: CGFloat(image.height))) cropCtx.draw(image, in: CGRect(x: -safeRect.minX, y: -safeRect.minY, width: CGFloat(image.width), height: CGFloat(image.height)))
return cropCtx.makeImage() return cropCtx.makeImage()
} }
@@ -135,13 +173,15 @@ final class ScreenCapture {
let excluded = content.windows.filter { excludedSet.contains($0.windowID) } let excluded = content.windows.filter { excludedSet.contains($0.windowID) }
let filter = SCContentFilter(display: display, excludingWindows: excluded) let filter = SCContentFilter(display: display, excludingWindows: excluded)
let config = SCStreamConfiguration() let config = SCStreamConfiguration()
// width/height are in points. Use the display's backing scale so // SCDisplay.width/height are in POINTS; SCStreamConfiguration
// retina captures come out at full pixel resolution. // width/height are output PIXELS. Multiply by the backing scale
let backingScale = NSScreen.screens.first(where: { $0.frame.contains( // of the screen containing the selection so retina displays are
NSPoint(x: rect.midX, y: rect.midY) // captured at full resolution and 1x displays stay 1x.
) })?.backingScaleFactor ?? 2 let backingScale = NSScreen.screens
config.width = Int(display.frame.width * backingScale) .first(where: { $0.frame.contains(NSPoint(x: rect.midX, y: rect.midY)) })?
config.height = Int(display.frame.height * backingScale) .backingScaleFactor ?? 1
config.width = Int(CGFloat(display.width) * backingScale)
config.height = Int(CGFloat(display.height) * backingScale)
config.showsCursor = true config.showsCursor = true
guard let image = try? await SCScreenshotManager.captureImage(contentFilter: filter, configuration: config) else { guard let image = try? await SCScreenshotManager.captureImage(contentFilter: filter, configuration: config) else {
+10 -6
View File
@@ -193,12 +193,16 @@ struct ResultView: View {
.padding(.top, 10) .padding(.top, 10)
if model.mode == .screenshot { if model.mode == .screenshot {
Image(nsImage: NSImage(cgImage: model.image, size: .zero)) GeometryReader { geo in
.resizable() let imageWidth = CGFloat(model.image.width)
.interpolation(.none) Image(nsImage: NSImage(cgImage: model.image, size: .zero))
.aspectRatio(contentMode: .fit) .resizable()
.border(Color.secondary.opacity(0.4)) // Downscale with smoothing (AA); upscale keeps pixels crisp.
.padding(.horizontal, 12) .interpolation(imageWidth >= geo.size.width ? .high : .none)
.aspectRatio(contentMode: .fit)
}
.border(Color.secondary.opacity(0.4))
.padding(.horizontal, 12)
} else { } else {
ZStack(alignment: .bottomTrailing) { ZStack(alignment: .bottomTrailing) {
ScrollView { ScrollView {
+2 -2
View File
@@ -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.2</string> <string>1.1.6</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>12</string> <string>16</string>
<key>LSUIElement</key> <key>LSUIElement</key>
<true/> <true/>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>