Skip to content

macOS: 用 screencapture 实现真实截屏 - #2

Merged
KuaaMU merged 2 commits into
mainfrom
fix/macos-screencapture
Oct 22, 2026
Merged

KuaaMU merged 2 commits into
mainfrom
fix/macos-screencapture

Conversation

@KuaaMU

@KuaaMU KuaaMU commented Oct 22, 2026

Copy link
Copy Markdown
Owner

概述

macOS 的截屏此前返回 generate_fallback_capture,也就是一张生成的网格图,截屏流程实际拿不到屏幕内容。

改动

  • screen::capture_via_screencapture 调用 /usr/sbin/screencapture -x -t png,读回文件并编码为 data URL。需要「屏幕录制」权限,权限被拒时返回错误,不会静默给出一张空图。
  • macOS 的 capture_screen 返回主显示器截图,原点为 (0,0)。多显示器机器只截主屏,代码注释写明了这一点。
  • 非 Linux 的截屏分支现在发出与 Linux 相同的 capture / monitor 载荷,并在 show 之后回传窗口真实矩形。这样当合成器缩小叠加层时(macOS 会避开菜单栏),前端的 1:1 裁剪仍然对齐。

同时补上 scripts/*.sh 的可执行位。这个 checkout 的 core.fileMode 是 false,之前从未提交过该位,新克隆的仓库无法直接运行 ./scripts/check.sh。

验证

  • ./scripts/check.sh 通过,包含 cargo clippy -p glint-core --target aarch64-apple-darwin。
  • macOS 的实际运行行为只经过编译验证,没有在 Mac 上运行过。合并前需要有人在 Mac 上确认:权限弹窗、多显示器只截主屏、叠加层与截图是否对齐。

🤖 Generated with Claude Code

macOS returned `generate_fallback_capture`, a generated grid, so the snip
flow captured nothing on that platform.

- `screen::capture_via_screencapture` runs `/usr/sbin/screencapture -x -t png`
  and reads the result back as a data URL. It needs the Screen Recording
  permission; a denied permission surfaces as an error, not a silent empty
  image.
- `capture_screen` on macOS reports the image as the main display at (0,0).
  Multi-display Macs capture the main display only, and the doc comment says
  so.
- The non-Linux snip branch now emits the same `capture`/`monitor` payload as
  Linux and reports the mapped window rect after `show`, so the frontend's
  1:1 crop works when the compositor shrinks the overlay (macOS keeps the
  menu bar strip free).

Also record the executable bit on `scripts/*.sh`. `core.fileMode` is false in
this checkout, so the bits were never committed and a fresh clone could not
run `./scripts/check.sh`.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b302ca3-d162-4f7a-b744-b1800000d4f1
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T06:13:54.075752Z 41724ca PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41724caddd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/glint-core/src/screen.rs Resolved
Comment thread crates/glint-core/src/capture.rs Resolved
`screencapture` exits 0 without Screen Recording permission and returns an
image of the desktop wallpaper. The PNG header check cannot tell that apart
from a real capture, so the snip UI could submit the wallpaper with no error.

Call `CGPreflightScreenCaptureAccess` first and return a distinct
`PermissionDenied` error naming the System Settings pane. The framework call
is the only FFI here: one function, no pointers.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@KuaaMU
KuaaMU merged commit e43baa9 into main Oct 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant