Round window-capture corners with a clip instead of masking()

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
This commit is contained in:
2026-09-09 15:15:21 +08:00
parent ae054d70b9
commit 924a692f2b
2 changed files with 9 additions and 13 deletions
+7 -11
View File
@@ -402,23 +402,19 @@ final class ScreenCapture {
// Apply a rounded-corner alpha mask for window captures, matching // Apply a rounded-corner alpha mask for window captures, matching
// macOS window chrome (≈10pt radius, scaled to image pixels). // macOS window chrome (≈10pt radius, scaled to image pixels).
if roundedCorners { 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 radius = 10 * scaleX
let maskRect = CGRect(x: 0, y: 0, width: result.width, height: result.height) guard let ctx = CGContext(
guard let maskCtx = CGContext(
data: nil, width: result.width, height: result.height, data: nil, width: result.width, height: result.height,
bitsPerComponent: 8, bytesPerRow: 0, bitsPerComponent: 8, bytesPerRow: 0,
space: CGColorSpaceCreateDeviceRGB(), space: CGColorSpaceCreateDeviceRGB(),
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
) else { return result } ) else { return result }
maskCtx.setFillColor(CGColor(gray: 1, alpha: 1)) ctx.addPath(CGPath(roundedRect: CGRect(x: 0, y: 0, width: result.width, height: result.height), cornerWidth: radius, cornerHeight: radius, transform: nil))
maskCtx.fill(maskRect) ctx.clip()
maskCtx.setBlendMode(.clear) ctx.draw(result, in: CGRect(x: 0, y: 0, width: result.width, height: result.height))
maskCtx.setFillColor(CGColor(gray: 0, alpha: 1)) if let masked = ctx.makeImage() {
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) {
result = masked result = masked
} }
} }
+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.8.3</string> <string>1.8.4</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>83</string> <string>84</string>
<key>LSUIElement</key> <key>LSUIElement</key>
<true/> <true/>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>