From 924a692f2bfc7658884eb447a10296ffc89285e1 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Wed, 9 Sep 2026 15:15:21 +0800 Subject: [PATCH] Round window-capture corners with a clip instead of masking() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The masking() call could silently fail against ScreenCaptureKit's pixel format, leaving sharp corners. Clip to a rounded path and redraw instead, verified headlessly for corner clipping and orientation. 💘 Generated with Crush Assisted-by: Crush:deepseek-v4-flash-0731 --- Sources/Kapture/CaptureController.swift | 18 +++++++----------- build-app.sh | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Sources/Kapture/CaptureController.swift b/Sources/Kapture/CaptureController.swift index 82f5306..1f7cccb 100644 --- a/Sources/Kapture/CaptureController.swift +++ b/Sources/Kapture/CaptureController.swift @@ -402,23 +402,19 @@ final class ScreenCapture { // Apply a rounded-corner alpha mask for window captures, matching // macOS window chrome (≈10pt radius, scaled to image pixels). if roundedCorners { + // Clip to a rounded rect and redraw — deterministic corner alpha + // (masking() can fail depending on the source pixel format). let radius = 10 * scaleX - let maskRect = CGRect(x: 0, y: 0, width: result.width, height: result.height) - guard let maskCtx = CGContext( + guard let ctx = CGContext( data: nil, width: result.width, height: result.height, bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue ) else { return result } - maskCtx.setFillColor(CGColor(gray: 1, alpha: 1)) - maskCtx.fill(maskRect) - maskCtx.setBlendMode(.clear) - maskCtx.setFillColor(CGColor(gray: 0, alpha: 1)) - maskCtx.addPath(CGPath(roundedRect: maskRect, cornerWidth: radius, cornerHeight: radius, transform: nil)) - maskCtx.fillPath() - maskCtx.setBlendMode(.normal) - if let mask = maskCtx.makeImage(), - let masked = result.masking(mask) { + ctx.addPath(CGPath(roundedRect: CGRect(x: 0, y: 0, width: result.width, height: result.height), cornerWidth: radius, cornerHeight: radius, transform: nil)) + ctx.clip() + ctx.draw(result, in: CGRect(x: 0, y: 0, width: result.width, height: result.height)) + if let masked = ctx.makeImage() { result = masked } } diff --git a/build-app.sh b/build-app.sh index 0062a73..e895133 100755 --- a/build-app.sh +++ b/build-app.sh @@ -108,9 +108,9 @@ cat > "$APP/Contents/Info.plist" <<'PLIST' CFBundleIconFile Icon CFBundleShortVersionString - 1.8.3 + 1.8.4 CFBundleVersion - 83 + 84 LSUIElement NSHighResolutionCapable