Files
arek d20f4d5481 fix(input): honor pointer entry position and make clear work
Pointer enter ignored the surface position, so the pattern preview
rendered at a stale cell until the first motion event. The clear
action only printed a message and toggle_grid had no default key
binding, leaving both unreachable without a hand-written config.

Set the cursor position from the enter event, implement clear via
grid_clear plus a dirty flag, and add g/c default bindings in both
the built-in table and the generated config template. Also defer
wl_buffer destruction on resize until the compositor releases it,
route pointer motion through a handler hook instead of reading
pointer_data directly, and clean up dead code (show_lines, unused
ternary, unchecked ftruncate, unfreed grid buffers). Fixes a
wl_callback proxy leak from frame-callback overwrite. Syncs the
keyboard-bindings and display-scaling specs and archives the
fix-review-findings change.
2026-11-11 18:04:50 +01:00

50 lines
3.6 KiB
Markdown

# Design
## Context
Review findings span three modules: `tpointer.c` (enter handler ignores surface position), `wlgol.c` (ACTION_CLEAR no-op, buffer destroyed during resize while the compositor may hold it, minor cleanups) and `config.c` (default keymap lacks toggle_grid and clear). The renderer is now dirty-driven; a cleared grid propagates through the existing per-cell diff, so no special render path is needed for clear.
## Goals / Non-Goals
**Goals:**
- Preview appears at the true entry cell when the pointer enters the surface.
- Clear works with the default bindings; every supported action is reachable without a config file.
- No buffer destruction while the compositor may still be reading it.
**Non-Goals:**
- New input features (drag with tool, middle button), cursor theme changes.
- Double buffering or a general buffer-age pipeline.
## Decisions
### 1. Pointer enter sets `pd->x`/`pd->y` from `sx`/`sy`
Two lines: convert with `wl_fixed_to_double`. Alternative — query position elsewhere or force a synthetic motion: both more code for the same result. Wayland guarantees `enter` carries the entry position, so motion events are not needed to know where the pointer is.
### 2. Clear = `grid_clear()` + `screen_dirty = 1`
The on-demand renderer diffs against `grid_rendered`, so a wholesale clear repaints exactly the cells that were alive. No `full_redraw` needed. The incremental path is already exercised for large cell counts; nothing new to build.
### 3. Default keys: `"g" = toggle_grid`, `"c" = clear`
Both are free in the default keymap and mnemonic. Recorded as an assumption — if these keys are wanted for something else later, they are remappable like any other binding.
### 4. Resize defers buffer/pool destruction to the release event
`canvas_resize` stops destroying `canvas.buffer`/`canvas.pool` immediately; it parks them in `canvas.old_buffer`/`canvas.old_pool` and munmaps the old data right away (the compositor keeps its own mapping, so unmapping ours is safe). The existing `wl_buffer_release_handler` destroys parked buffer and pool when the compositor lets go. Rationale: destroying a `wl_buffer` still referenced by a pending frame is tolerated by compositors today but is protocol-untidy and can glitch; deferring costs one pointer pair. Alternative — double-buffering to avoid reuse conflicts entirely: out of scope per proposal.
### 5. Pointer position reaches the loop via a motion handler hook
Add `pointer_set_motion_handler()` mirroring the existing `pointer_set_button_handler()` pattern; `wlgol.c` registers a callback that stores logical `x`/`y` into module-local cursor variables. `loop_update()` stops reading `pointer_data.x` directly. Keeps input state owned by `tpointer.c`.
### 6. Cleanup items ride along
Remove `grid.show_lines` (single `show_grid_lines` flag remains), free the three grid buffers after the event loop exits, replace the dead `ok ? 220 : 220` ternary, and check `ftruncate`'s return. All behavior-neutral; tested by build + existing tests.
## Risks / Trade-offs
- [Deferring buffer destruction keeps an old SHM mapping alive one extra frame on rapid resizes] → Bounded: each release event drains the queue; worst case is one parked buffer per resize.
- [New default keys g/c could clash with a user's existing `keys.conf`] → No: user config merges over defaults, and existing files simply keep working; only fresh default files gain the keys.
## Migration Plan
Single commit; no data migration. Users with an existing `~/.config/wlgol/keys.conf` keep their bindings (merge semantics) and can gain g/c by deleting the file or adding the entries. Rollback is `git revert`.
## Open Questions
None.