Skip to content

feat(screenshot): support 4-corner resizing while holding Ctrl - #3259

Merged
bbedward merged 6 commits into
duxlabs-dev:masterfrom
hthienloc:feat/screenshot-corner-resize
Sep 2, 2026
Merged

bbedward merged 6 commits into
duxlabs-dev:masterfrom
hthienloc:feat/screenshot-corner-resize

Conversation

@hthienloc

@hthienloc hthienloc commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Adds 4-corner resizing support while holding Ctrl in the screenshot region selector (core/internal/screenshot).

recording_20260902_143444.mp4

- Hit-test selection corners when Ctrl is held to allow resizing.
- Set opposite corner as fixed anchor and update dynamic cursor shape
  (NwseResize/NeswResize).
- Draw corner handle indicators when Ctrl is held or during active resize.
- Add 'Ctrl resize/move' to overlay HUD and provide complete glyph
  coverage for HUD labels.
- Add comprehensive unit tests covering hit testing, inverted dragging,
  incremental handle damage, and glyph coverage.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

@claude

claude Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Claude review

One rendering issue; resize geometry, hit-testing, cursor shapes and the incremental-damage math all check out.

  • Modifier toggle repaints the overlay incrementally over a HUD-bearing cached background, punching a hole in the HUD — core/internal/screenshot/region_input.go:419

Checked: handle hit-test/anchor-swap math, corner-handle draw + damage/dim-delta invariants, cursor-shape values against the vendored cursor-shape-v1 enum, HUD glyph coverage, resizingHandle reset paths, and the new tests. Model: claude-opus-5.

…fier changes

- Track backgroundHandles and backgroundShift in RenderSlot.cacheValid.
- Rebuild background slot and HUD when handle or shift modifier states
  change with an existing selection, preventing incremental re-dimming
  from punching holes in the HUD.
- Fix trailing newline in region_resize_test.go for golangci-lint.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

Comment on lines +419 to +423
if r.selection.hasSelection {
for _, os := range r.surfaces {
r.redrawSurface(os)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding handles/shift to cacheValid fixes the Ctrl and Shift cases, but this handler redraws on every modifier change — Alt, Super, Caps Lock included — and those change neither handles nor shift, so the cache stays valid and the frame takes the incremental path over a background that still holds the HUD.

overlayDelta then re-dims prev's ring, label and (when Ctrl is held) the four handleRects() via paintRect, which repaints straight from the screencopy buffer. Only the circle quadrants of each handle get redrawn, so HUD pixels under the rest of each (2r+1)² handle box are erased. Repro: selection near the bottom-center HUD, hold Ctrl (handles drawn), tap Alt — chunks of the HUD disappear.

Fix: only redraw when a modifier that affects rendering actually changed, e.g. read shift/ctrl into locals first, compare against r.shiftHeld/r.ctrlHeld before assigning, and gate this loop on changed && r.selection.hasSelection.

@claude

claude Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Claude review

The Ctrl/Shift cache-invalidation fix works; one residual HUD-corruption path remains.

  • Redraw fires on any modifier change (Alt/Super/Caps), which keeps the cache valid and repaints handle boxes over the HUD — core/internal/screenshot/region_input.go:419

Checked: new cacheValid keys against every render-affecting state, handleRects vs drawCornerHandle pixel coverage, overlayDelta/overlayDamage supersets for prev+cur handles, resize anchor swap and inverted drags, cursor-shape selection, HUD glyph coverage and width math, resizingHandle reset paths. Model: claude-opus-5.

…anges

- Only trigger redrawSurface when Shift or Ctrl modifier states actually
  change, preventing redundant redraws when tapping Alt, Super, or Locks.
- Only re-dim and damage corner handle bounding boxes in overlayDelta and
  overlayDamage when handles move or their visibility changes, preventing
  unnecessary re-dimming of stationary handles over the HUD.
- Add TestOverlayDeltaIdenticalOverlayNoHandleDimming test.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

{captureKey, "capture"},
{"Ctrl", "resize/move"},
{"P", cursorLabel + " cursor"},
{"Esc", "cancel"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding a fourth HUD item pushes the text past the right edge of the HUD pill.

totalW charges +4 for the space between key and desc, but the draw loop advances (1 + len(desc)) * (charW+1) — a full 9px glyph cell. That's 5px of under-measurement per item, and the trailing padding is only 12px, so the error goes visible once there are 4 items.

Walking the draw loop with charW+1 = 9 (default Space/Enter variant): totalW = 574, hudW = 598, so the pill covers columns hudX+0 .. hudX+597. tx reaches 543 at "Esc", " cancel" is drawn there, and the final 'l' cell starts at 543 + 6*9 = 597 with lit columns at 599–601 — entirely outside the pill. Same result for the Drag+Release variant (cell at 606, pill ends at 606). With the old 3 items the 'l' landed at 431–433 inside a pill ending at 434, which is why this only shows up now.

Fix is to measure with the same advance the draw loop uses:

Suggested change
{"Esc", "cancel"},
{"Ctrl", "resize/move"},

(no change needed on this line — the fix belongs in the totalW loop below:)

totalW += len(item.key)*(charW+1) + (1+len(item.desc))*(charW+1)

@claude

claude Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Claude review

The Ctrl/Alt cache-invalidation fixes hold up; one cosmetic rendering regression left.

  • Fourth HUD item pushes the last glyph outside the HUD pill (totalW under-measures the key/desc gap by 5px per item) — core/internal/screenshot/region_render.go:542

Checked: cacheValid keys vs every render-affecting state (incl. the cross-slot slot.overlay / os.shown divergence), modifier-handler dedup between the key and modifiers events in both orderings, handle pixels vs interior/dim/bright partitioning in overlayDelta, handleRects bounds against drawCornerHandle coverage, resize anchor swap + inverted drag + alt/shift interaction, resizingHandle reset paths, cursor-shape selection, new glyph tables, HUD width arithmetic. Model: claude-opus-5.

…overflow

- Use (1+len(item.desc))*(charW+1) when calculating totalW in drawHUD,
  matching the full 9px advance used when drawing space and description.
- Add TestHUDDimensionsContainText to verify HUD pill dimensions enclose
  all text items with correct padding across all variant combinations.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

@claude

claude Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Claude review

Previous HUD-corruption and pill-width issues are fixed; one incremental-damage gap remains.

  • Handle re-dim/damage guards compare only interior, missing corner-flag flips that leave stale handle pixels — core/internal/screenshot/region_render.go:189 (same at :433, :440)

Checked: cursor-shape enum values against the v1-bound wp_cursor_shape interface, cacheValid keys vs every render-affecting state, modifier-handler dedup between key and modifiers events, handleRects bounds vs drawCornerHandle pixel coverage and quadrant masking, overlayDelta/overlayDamage supersets, resize anchor swap + inverted drag, resizingHandle reset paths, HUD width arithmetic and glyph coverage, new tests. Model: claude-opus-5.

- Use slices.Equal to compare prev and cur handleRects in overlayDelta
  and overlayDamage instead of interior equality.
- Properly re-dim and damage handles when selection corners cross monitor
  boundaries where clamped interior is unchanged but top/bottom/left/right
  flags change.
- Add TestOverlayDeltaHandlesClampedMonitorEdge test.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

}
}

if hudW-tx != padding {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This assertion can never fail, so it doesn't guard the pill-width fix it was added for.

The test re-declares items, the constants, the totalW formula and the tx advance locally — it never touches drawHUD. tx is built from exactly the same terms as totalW, so tx == padding + totalW and hudW - tx == (totalW + 2*padding) - (padding + totalW) == padding for any input. Change drawHUD back to the old + 4 gap and this test still passes.

To actually cover the regression, drive drawHUD into a buffer and assert no lit pixel falls outside the pill (or export the width/advance calculation and have both drawHUD and the test call it).

@claude

claude Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Claude review

Rendering correctness looks sound now; only a test-quality issue left.

  • TestHUDDimensionsContainText is tautological — it re-implements both sides of the formula and never calls drawHUD, so it cannot catch the pill-overflow regression — core/internal/screenshot/region_resize_test.go:259

Checked: handle-rect sets vs drawCornerHandle pixel coverage and quadrant masking (all handle pixels fall outside interior, so bright/dim fully repaint them), overlayDelta/overlayDamage supersets across every prev/cur showHandles combination, the slot.backgroundHandles == slot.overlay.showHandles invariant that keeps the incremental path from re-dimming over the HUD, cacheValid keys vs every render-affecting state, modifier-handler dedup between key and modifiers events in both orderings, resize anchor swap + inverted drag + resizingHandle reset paths, cursor-shape selection incl. the hover path, new glyph tables, HUD width arithmetic. Model: claude-opus-5.

…l bounds

- Extract hudDimensions helper on RegionSelector used by drawHUD.
- Update TestHUDDimensionsContainText to drive drawHUD directly into a
  zeroed buffer and assert no lit pixel falls outside the computed
  HUD pill boundary across all configuration variants.
@hthienloc

Copy link
Copy Markdown
Member Author

/claude review

@claude

claude Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Claude review

No issues found.

Re-verified the two fixes from the last round: hudDimensions/drawHUD now agree with drawText's 9px-per-rune advance (last glyph lands padding+1 inside the pill right edge), and TestHUDDimensionsContainText now actually drives drawHUD into a buffer and scans for lit pixels outside the pill, so it would catch a regression in that arithmetic.

Checked: cacheValid keys (handles, shift) vs every render-affecting state and the handles == overlay.showHandles invariant; handleRects bounds vs drawCornerHandle quadrant masking (all handle pixels fall outside interior, so bright never erases them); overlayDelta/overlayDamage handle-set comparison across every prev/cur showHandles and corner-flag combination, including the clamped monitor-edge case; modifier-handler dedup between the key and modifiers events in both orderings, and that alt is correctly excluded from the redraw gate; resize anchor swap, inverted drags, shift/alt interaction, and resizingHandle reset on press/release; cursor-shape selection incl. the ctrl-hover path and the nil activeSurface fallback; new glyph table covers every HUD string; test helpers/symbols resolve.

Model: claude-opus-5.

@bbedward
bbedward merged commit 95ee917 into duxlabs-dev:master Sep 2, 2026
3 checks passed
@hthienloc
hthienloc deleted the feat/screenshot-corner-resize branch November 15, 2026 15:38
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.

2 participants