Skip to content

screenshots: keep an open menu or popup in area and full-screen shots - #3045

Open
opencodejr[bot] wants to merge 1 commit into
devfrom
agent/issue-3044
Open

opencodejr[bot] wants to merge 1 commit into
devfrom
agent/issue-3044

Conversation

@opencodejr

@opencodejr opencodejr Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Fixes #3044 (reported by @tmcfarlane, whose diagnosis pointed to the cause; this is a clean implementation).

Problem

Labs › Screenshots took the shot only after the pick: picked() hid the picker, then take() called capture_core::screenshot_with. The pick's click lands on the picker, outside an open menu, so macOS closes the menu before the shot is taken.

Change

  • New src/screenshots/frozen.rs. When the ⌘⇧4 picker opens for a shot (not for recording), menu_open reads the on-screen window list. If another app (pid ≠ Hex) has a visible window between kCGPopUpMenuWindowLevel (101) and kCGHelpWindowLevel (200) overlapping the display under the pointer, that display is shot once, before the picker shows. That level range covers menus, pop-up buttons, <select> lists and tooltips. The shot uses the same exclusions as before (Hex's overlays and the picker window) and no pointer.
  • The frame is tied to that picker opening's id: it is kept only if the opening is still current, dropped on cancel, and taken on pick. take() cuts an area or a full-screen click from it, converting points to the display's pixels and trimming to the display.
  • Without an open menu nothing is frozen. Picks are shot live, exactly as before, and opening the picker costs only one extra window-list read.
  • Window picks, other displays, hex screenshot, and a failed early capture always use a live shot. Recording (⌘⇧5) is unchanged. Nothing under ios/ is touched.
  • The doc comments in src/screenshots.rs and frozen.rs now say the freeze happens only while a menu or popup is open.

Trade-offs

  • While a menu is open, the picker shows the live screen, so the menu visibly closes on click even though the shot keeps it. Drawing the frozen frame behind the picker would change what the picker draws and needs new goldens; it is left for a follow-up.
  • The 101–200 range comes from macOS's documented window levels and has not been checked against real window lists. A utility that keeps an overlay window at level 102 would also trigger a freeze.

Testing

  • The Screenshots code is macOS-only (cfg(all(target_os = "macos", hex_capture))) and was written on Linux. The full app build and clippy have NOT run; they need a Mac before merging.
  • Unit tests in frozen.rs:
    • the freeze check (another app's menu or tooltip on this display → freeze; Hex's own windows, normal or status-level windows, layer 1000, another display, an alpha-0 window, or no windows → no freeze);
    • cropping at 2x;
    • trimming to the display and refusing empty or out-of-range areas;
    • cutting only from the matching display, never for a window.
  • On Linux these were run by copying the file into a scratch crate with stub capture_core, scrawl_capture and tracing: 4 tests pass and clippy -D warnings reports nothing.
  • rustfmt --edition 2024 --check passes on both files, and python3 scripts/code-shape.py --check reports no hard problems.
  • Still to check by hand on a Mac: open a <select> or a popup menu, press ⌘⇧4, drag over it, and confirm the saved shot includes the menu. With no menu open, confirm shots still show the live screen and the picker opens as fast as before.

Fixes #3044

@opencodejr opencodejr Bot added the agent-strict-review Issue pipeline: flagged patch approved by the strict reviewer label Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-strict-review Issue pipeline: flagged patch approved by the strict reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screenshots can't capture open dropdowns

0 participants