Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69e1a7fccb | ||
|
|
e22bcb99c4 | ||
|
|
457e303152 | ||
|
|
345f306edf | ||
|
|
45e4962ec3 | ||
|
|
5f137f89bf | ||
|
|
b998ea210e | ||
|
|
86826f7ecc |
@@ -25,11 +25,14 @@ No network calls, no API keys — everything runs locally.
|
||||
## Install with Homebrew
|
||||
|
||||
```bash
|
||||
brew tap TZGyn/tap
|
||||
brew trust TZGyn/tap # Homebrew 6+ requires trusting third-party taps
|
||||
brew tap TZGyn/tap https://gitea.tzgyn.dev/TZGyn/homebrew-tap.git
|
||||
brew trust TZGyn/tap
|
||||
brew install --cask kapture
|
||||
```
|
||||
|
||||
The tap is hosted on Gitea, so the full URL is required. Homebrew may print
|
||||
an "Unsupported tap" warning — it's harmless.
|
||||
|
||||
Releases are published as zips on GitHub Releases; `release.sh` packages a
|
||||
new one (`./release.sh 1.0.1 && git tag v1.0.1 && git push origin v1.0.1`).
|
||||
The cask lives in the [TZGyn/homebrew-tap](https://github.com/TZGyn/homebrew-tap)
|
||||
|
||||
@@ -10,10 +10,21 @@ final class CaptureController: NSObject {
|
||||
private var previousApp: NSRunningApplication?
|
||||
private var overlayIDs: [Int] = []
|
||||
|
||||
/// Session event log for debugging (dumped via Copy Diagnostics).
|
||||
static var sessionLog: [String] = []
|
||||
static func log(_ line: String) {
|
||||
sessionLog.append(line)
|
||||
if sessionLog.count > 100 { sessionLog.removeFirst() }
|
||||
NSLog("[Kapture] \(line)")
|
||||
}
|
||||
|
||||
/// Diagnostic snapshot for "Copy Diagnostics" menu item.
|
||||
func diagnostics() -> String {
|
||||
var lines: [String] = []
|
||||
lines.append("Kapture diagnostics")
|
||||
lines.append("Kapture diagnostics — version \(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "?")")
|
||||
lines.append("--- session log (newest last) ---")
|
||||
lines.append(contentsOf: Self.sessionLog)
|
||||
lines.append("--- screens ---")
|
||||
for (i, s) in NSScreen.screens.enumerated() {
|
||||
let scale = s.backingScaleFactor
|
||||
let cgID = (s.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? NSNumber)?.uint32Value ?? 0
|
||||
@@ -50,12 +61,15 @@ final class CaptureController: NSObject {
|
||||
}
|
||||
isSelecting = true
|
||||
previousApp = NSWorkspace.shared.frontmostApplication
|
||||
if #available(macOS 14.0, *) {
|
||||
NSApp.activate()
|
||||
} else {
|
||||
// Activation is ASYNC: isActive only flips on a later runloop tick
|
||||
// (verified on macOS 26). Show overlays only once active, otherwise
|
||||
// the first click can pass through to the windows below.
|
||||
NSApp.activate(ignoringOtherApps: true)
|
||||
}
|
||||
overlays = NSScreen.screens.map { screen in
|
||||
CaptureController.log("begin: activate issued, active=\(NSApp.isActive)")
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { [weak self] in
|
||||
guard let self, self.isSelecting else { return }
|
||||
CaptureController.log("begin: active=\(NSApp.isActive) — showing overlays")
|
||||
self.overlays = NSScreen.screens.map { screen in
|
||||
OverlayWindow(
|
||||
screen: screen,
|
||||
onComplete: { [weak self] rect in self?.finishSelection(rect) },
|
||||
@@ -63,8 +77,10 @@ final class CaptureController: NSObject {
|
||||
onWindowPick: { [weak self] rect in self?.finishWindowPick(rect) }
|
||||
)
|
||||
}
|
||||
overlays.forEach { $0.makeKeyAndOrderFront(nil) }
|
||||
overlayIDs = overlays.map { $0.windowNumber }
|
||||
self.overlays.forEach { $0.makeKeyAndOrderFront(nil) }
|
||||
self.overlayIDs = self.overlays.map { $0.windowNumber }
|
||||
CaptureController.log("begin: \(self.overlays.count) overlays, ids=\(self.overlayIDs), active=\(NSApp.isActive)")
|
||||
}
|
||||
}
|
||||
|
||||
/// A window was picked from hover — capture it with rounded corners.
|
||||
|
||||
@@ -30,11 +30,11 @@ final class OverlayView: NSView {
|
||||
private var startPoint: NSPoint?
|
||||
private(set) var selection: NSRect?
|
||||
private var isDragging = false
|
||||
private var dragDistance: CGFloat = 0
|
||||
|
||||
// Window detection
|
||||
// Window detection (frames stored in AppKit global space)
|
||||
private var trackedWindows: [(id: CGWindowID, frame: NSRect)] = []
|
||||
private var hoveredWindowFrame: NSRect?
|
||||
private var excludedIDs: [Int] = []
|
||||
|
||||
init(onComplete: @escaping (NSRect) -> Void, onCancel: @escaping () -> Void, onWindowPick: @escaping (NSRect) -> Void) {
|
||||
self.onComplete = onComplete
|
||||
@@ -79,14 +79,17 @@ final class OverlayView: NSView {
|
||||
else { continue }
|
||||
// Skip our own overlays
|
||||
if Int(cid) == ownID { continue }
|
||||
let rect = NSRect(
|
||||
let cgRect = NSRect(
|
||||
x: bounds["X"] ?? 0,
|
||||
y: bounds["Y"] ?? 0,
|
||||
width: bounds["Width"] ?? 0,
|
||||
height: bounds["Height"] ?? 0
|
||||
)
|
||||
guard rect.width >= 80, rect.height >= 60 else { continue }
|
||||
// Skip tiny/utility windows
|
||||
guard cgRect.width >= 80, cgRect.height >= 60 else { continue }
|
||||
// Convert to AppKit space FIRST — CG and AppKit Y axes disagree on
|
||||
// multi-desktop layouts, so intersect tests must use one space.
|
||||
let rect = Self.cgToAppKit(rect: cgRect)
|
||||
// Skip windows filling the whole screen (fullscreen apps)
|
||||
guard rect.width < screenFrame.width || rect.height < screenFrame.height else { continue }
|
||||
// Only windows intersecting this screen
|
||||
guard rect.intersects(screenFrame) else { continue }
|
||||
@@ -97,24 +100,19 @@ final class OverlayView: NSView {
|
||||
|
||||
private func windowFrame(at point: NSPoint) -> NSRect? {
|
||||
guard let window = window else { return nil }
|
||||
let screenPoint = window.convertToScreen(NSRect(origin: point, size: .zero))
|
||||
// CGWindowList bounds use a TOP-LEFT origin; convert the cursor point.
|
||||
guard let mainScreen = NSScreen.screens.first else { return nil }
|
||||
let topLeftPoint = NSPoint(
|
||||
x: screenPoint.origin.x,
|
||||
y: mainScreen.frame.height - screenPoint.origin.y
|
||||
)
|
||||
// Pick the frontmost (list order) window containing the point
|
||||
// convertToScreen gives AppKit-global coordinates; tracked frames are
|
||||
// already in that space.
|
||||
let screenPoint = window.convertToScreen(NSRect(origin: point, size: .zero)).origin
|
||||
for (_, frame) in trackedWindows {
|
||||
if frame.contains(topLeftPoint) {
|
||||
if frame.contains(screenPoint) {
|
||||
return frame
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/// Convert a CGWindowList (top-left origin) frame into AppKit screen
|
||||
/// coordinates (bottom-left origin) for capture.
|
||||
/// Convert a CGWindowList (top-left origin, CG global space) frame into
|
||||
/// AppKit screen coordinates (bottom-left origin) for capture.
|
||||
private static func cgToAppKit(rect: NSRect) -> NSRect {
|
||||
guard let mainScreen = NSScreen.screens.first else { return rect }
|
||||
let y = mainScreen.frame.height - rect.origin.y - rect.height
|
||||
@@ -137,15 +135,20 @@ final class OverlayView: NSView {
|
||||
override func mouseDown(with event: NSEvent) {
|
||||
let p = convert(event.locationInWindow, from: nil)
|
||||
startPoint = p
|
||||
dragDistance = 0
|
||||
selection = NSRect(origin: p, size: .zero)
|
||||
needsDisplay = true
|
||||
}
|
||||
|
||||
override func mouseDragged(with event: NSEvent) {
|
||||
guard let start = startPoint else { return }
|
||||
let p = convert(event.locationInWindow, from: nil)
|
||||
dragDistance = hypot(p.x - start.x, p.y - start.y)
|
||||
// Only become a marquee after real movement; micro-jitter from a
|
||||
// click must not cancel window-pick mode.
|
||||
guard dragDistance >= 4 else { return }
|
||||
isDragging = true
|
||||
hoveredWindowFrame = nil
|
||||
let p = convert(event.locationInWindow, from: nil)
|
||||
selection = NSRect(
|
||||
x: min(start.x, p.x),
|
||||
y: min(start.y, p.y),
|
||||
@@ -156,6 +159,10 @@ final class OverlayView: NSView {
|
||||
}
|
||||
|
||||
override func mouseUp(with event: NSEvent) {
|
||||
defer {
|
||||
isDragging = false
|
||||
dragDistance = 0
|
||||
}
|
||||
if isDragging {
|
||||
guard let sel = selection else { return }
|
||||
if sel.width >= 2, sel.height >= 2 {
|
||||
@@ -166,10 +173,10 @@ final class OverlayView: NSView {
|
||||
return
|
||||
}
|
||||
|
||||
// No drag: it was a click. If a window is hovered, capture it with
|
||||
// rounded corners; otherwise treat as an empty marquee (cancel).
|
||||
// It was a click. If a window is hovered, capture it with rounded
|
||||
// corners; otherwise treat as an empty marquee (cancel).
|
||||
if let frame = hoveredWindowFrame {
|
||||
onWindowPick(Self.cgToAppKit(rect: frame))
|
||||
onWindowPick(frame)
|
||||
} else {
|
||||
onCancel()
|
||||
}
|
||||
@@ -189,12 +196,12 @@ final class OverlayView: NSView {
|
||||
|
||||
// Highlight the hovered window (rounded, like the real window corners)
|
||||
if let frame = hoveredWindowFrame {
|
||||
// Convert CGWindowList (top-left) frame to view (bottom-left) space
|
||||
guard let window = window, let mainScreen = NSScreen.screens.first else { return }
|
||||
// Tracked frames are AppKit-global; view space = global - window origin.
|
||||
guard let window = window else { return }
|
||||
let screenFrame = window.convertToScreen(NSRect(origin: .zero, size: bounds.size))
|
||||
let viewFrame = NSRect(
|
||||
x: frame.origin.x - screenFrame.origin.x,
|
||||
y: mainScreen.frame.height - frame.origin.y - frame.height - screenFrame.origin.y,
|
||||
y: frame.origin.y - screenFrame.origin.y,
|
||||
width: frame.width,
|
||||
height: frame.height
|
||||
)
|
||||
|
||||
@@ -95,16 +95,23 @@ final class CaptureModel: ObservableObject {
|
||||
/// Redo stack of removed strokes
|
||||
@Published var redoStack: [Stroke] = []
|
||||
/// Whether the pen is active (drag draws instead of selecting)
|
||||
@Published var isDrawing = false
|
||||
@Published var tool: Tool = .select
|
||||
/// Current drawing color
|
||||
@Published var drawColor: NSColor = .systemRed
|
||||
/// Stroke thickness in points (image space)
|
||||
@Published var strokeWidth: CGFloat = 3.0
|
||||
|
||||
enum Tool {
|
||||
case select
|
||||
case draw
|
||||
case redact
|
||||
}
|
||||
|
||||
struct Stroke {
|
||||
let points: [CGPoint]
|
||||
let width: CGFloat
|
||||
let color: NSColor
|
||||
var isRedaction: Bool = false
|
||||
}
|
||||
|
||||
enum CaptureMode {
|
||||
@@ -159,6 +166,20 @@ final class CaptureModel: ObservableObject {
|
||||
ctx.setLineJoin(.round)
|
||||
for stroke in strokes {
|
||||
guard stroke.points.count > 1 else { continue }
|
||||
if stroke.isRedaction {
|
||||
// Redaction bar: filled black rect covering the stroke bounds,
|
||||
// padded so it fully covers text.
|
||||
let xs = stroke.points.map { $0.x }
|
||||
let ys = stroke.points.map { $0.y }
|
||||
let bar = NSRect(
|
||||
x: xs.min()! - 2,
|
||||
y: ys.min()! - 2,
|
||||
width: (xs.max()! - xs.min()!) + 4,
|
||||
height: max(stroke.width, ys.max()! - ys.min()!) + 4
|
||||
)
|
||||
NSColor.black.setFill()
|
||||
NSBezierPath(rect: bar).fill()
|
||||
} else {
|
||||
stroke.color.setStroke()
|
||||
ctx.setLineWidth(stroke.width)
|
||||
ctx.beginPath()
|
||||
@@ -168,6 +189,7 @@ final class CaptureModel: ObservableObject {
|
||||
}
|
||||
ctx.strokePath()
|
||||
}
|
||||
}
|
||||
ctx.restoreGState()
|
||||
NSGraphicsContext.restoreGraphicsState()
|
||||
return rep.cgImage ?? image
|
||||
@@ -175,7 +197,13 @@ final class CaptureModel: ObservableObject {
|
||||
|
||||
func addStroke(_ points: [CGPoint]) {
|
||||
guard points.count > 1 else { return }
|
||||
if tool == .redact {
|
||||
// Redaction: a filled black bar from start to end, as thick as the
|
||||
// current stroke width (drawn as a rect for clean edges).
|
||||
strokes.append(Stroke(points: points, width: max(strokeWidth, 12), color: .black, isRedaction: true))
|
||||
} else {
|
||||
strokes.append(Stroke(points: points, width: strokeWidth, color: drawColor))
|
||||
}
|
||||
redoStack = []
|
||||
}
|
||||
|
||||
@@ -309,14 +337,24 @@ struct ResultView: View {
|
||||
Divider().frame(height: 18)
|
||||
|
||||
Button {
|
||||
model.isDrawing.toggle()
|
||||
if model.isDrawing { model.selection = nil }
|
||||
model.tool = model.tool == .draw ? .select : .draw
|
||||
if model.tool != .select { model.selection = nil }
|
||||
} label: {
|
||||
Label("Draw", systemImage: model.isDrawing ? "pencil.tip.crop.circle.fill" : "pencil.tip.crop.circle")
|
||||
Label("Draw", systemImage: model.tool == .draw ? "pencil.tip.crop.circle.fill" : "pencil.tip.crop.circle")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.foregroundStyle(model.isDrawing ? .primary : .secondary)
|
||||
.help("Toggle drawing on the screenshot")
|
||||
.foregroundStyle(model.tool == .draw ? .primary : .secondary)
|
||||
.help("Draw on the screenshot")
|
||||
|
||||
Button {
|
||||
model.tool = model.tool == .redact ? .select : .redact
|
||||
if model.tool != .select { model.selection = nil }
|
||||
} label: {
|
||||
Label("Redact", systemImage: model.tool == .redact ? "rectangle.fill.on.rectangle.fill" : "rectangle.dashed")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.foregroundStyle(model.tool == .redact ? .primary : .secondary)
|
||||
.help("Cover sensitive areas with black bars")
|
||||
|
||||
Button {
|
||||
model.copyImage()
|
||||
@@ -348,15 +386,16 @@ struct ResultView: View {
|
||||
|
||||
Divider()
|
||||
|
||||
// Draw toolbar (only when drawing)
|
||||
if model.isDrawing {
|
||||
// Tool toolbar (only when a draw tool is active)
|
||||
if model.tool != .select {
|
||||
HStack(spacing: 14) {
|
||||
Label("Draw", systemImage: "pencil.tip")
|
||||
Label(model.tool == .redact ? "Redact" : "Draw", systemImage: model.tool == .redact ? "rectangle.fill" : "pencil.tip")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Divider().frame(height: 18)
|
||||
|
||||
if model.tool == .draw {
|
||||
HStack(spacing: 6) {
|
||||
Image(systemName: "circle.fill").font(.system(size: 4))
|
||||
Image(systemName: "circle.fill").font(.system(size: 7))
|
||||
@@ -376,6 +415,11 @@ struct ResultView: View {
|
||||
.labelsHidden()
|
||||
.frame(width: 28)
|
||||
.help("Drawing color")
|
||||
} else {
|
||||
Label("Drag to cover sensitive text", systemImage: "eye.slash")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
@@ -515,6 +559,17 @@ struct ScreenshotPane: View {
|
||||
Canvas { context, _ in
|
||||
for stroke in model.strokes {
|
||||
guard stroke.points.count > 1 else { continue }
|
||||
if stroke.isRedaction {
|
||||
let xs = stroke.points.map { $0.x }
|
||||
let ys = stroke.points.map { $0.y }
|
||||
let bar = CGRect(
|
||||
x: origin.x + (xs.min()! - 2) * scale,
|
||||
y: origin.y + (ys.min()! - 2) * scale,
|
||||
width: ((xs.max()! - xs.min()!) + 4) * scale,
|
||||
height: (max(stroke.width, ys.max()! - ys.min()!) + 4) * scale
|
||||
)
|
||||
context.fill(Path(bar), with: .color(.black))
|
||||
} else {
|
||||
var path = Path()
|
||||
path.move(to: CGPoint(x: origin.x + stroke.points[0].x * scale, y: origin.y + stroke.points[0].y * scale))
|
||||
for point in stroke.points.dropFirst() {
|
||||
@@ -523,6 +578,7 @@ struct ScreenshotPane: View {
|
||||
context.stroke(path, with: .color(Color(nsColor: stroke.color)), lineWidth: stroke.width)
|
||||
}
|
||||
}
|
||||
}
|
||||
.allowsHitTesting(false)
|
||||
|
||||
// In-progress stroke
|
||||
@@ -540,7 +596,7 @@ struct ScreenshotPane: View {
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
|
||||
if !model.isDrawing, let sel = model.selection {
|
||||
if model.tool == .select, let sel = model.selection {
|
||||
let viewRect = CGRect(
|
||||
x: origin.x + sel.minX * scale,
|
||||
y: origin.y + sel.minY * scale,
|
||||
@@ -559,7 +615,7 @@ struct ScreenshotPane: View {
|
||||
.gesture(
|
||||
DragGesture(minimumDistance: 0)
|
||||
.onChanged { value in
|
||||
if model.isDrawing {
|
||||
if model.tool != .select {
|
||||
let p = toImagePoint(value.location, scale: scale, origin: origin)
|
||||
let imgRect = CGRect(origin: .zero, size: imageSize)
|
||||
if imgRect.contains(p) {
|
||||
@@ -578,7 +634,7 @@ struct ScreenshotPane: View {
|
||||
}
|
||||
}
|
||||
.onEnded { _ in
|
||||
if model.isDrawing {
|
||||
if model.tool != .select {
|
||||
if currentStroke.count > 1 {
|
||||
model.addStroke(currentStroke)
|
||||
}
|
||||
|
||||
+2
-2
@@ -108,9 +108,9 @@ cat > "$APP/Contents/Info.plist" <<'PLIST'
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>Icon</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.5.0</string>
|
||||
<string>1.6.4</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>50</string>
|
||||
<string>64</string>
|
||||
<key>LSUIElement</key>
|
||||
<true/>
|
||||
<key>NSHighResolutionCapable</key>
|
||||
|
||||
Reference in New Issue
Block a user