Skip to content

feat(platform): add bitty-platform crate skeleton with owned winit event adapter - #20

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-0014/feat-bitty-platform
Aug 26, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-0014/feat-bitty-platform

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Implements CarryCtx task CTX-0014. Closes #17.

Contract outcome

  • Lands the bitty-platform row of the accepted ADR-0003 crate graph (window/event-loop adapter + DPI; depends on no other workspace crate) and the ADR-0004 decision row: ADOPT winit (~0.30.x) inside bitty-platform; crossterm stays rejected as a runtime input path. Locked to winit 0.30.13 via Cargo.lock (single-pin rule).

Public API (strictly owned; no winit type escapes)

  • App::run(AppHandler) — drives the OS event loop; returns owned PlatformError::DisplayUnavailable headlessly instead of panicking.
  • AppHandler::handle_event(&mut EventContext, PlatformEvent) — single delivery point; EventContext exposes create_window(WindowConfig) -> WindowHandle, exit, set_poll, set_wait.
  • PlatformEvent: Window { window_id, kind } plus Resumed/Suspended/AboutToWait/Exiting.
  • WindowEventKind (owned translation of winit window events): Resized(PhysicalSize), ScaleFactorChanged(ScaleFactor), RedrawRequested, Focused(bool), KeyboardInput(KeyEvent), MouseInput(MouseEvent), MouseWheel(ScrollDelta), CursorMoved(CursorPosition), CursorLeft, CloseRequested, Closed.
  • DPI types: ScaleFactor (validated finite > 0, sanitized fallback), LogicalPixel, LogicalSize, PhysicalSize; deterministic round-half-away-from-zero conversions, saturating at u32::MAX.
  • Keyboard model: logical keys only — LogicalKey::{Character, Named(NamedKey), Dead, Unidentified}; terminal-relevant NamedKey subset with documented collapse-to-Other for the rest; positional KeyCodes deliberately deferred to the open input-domain placement question in ADR-0003. Synthetic focus-change key events are dropped during translation.
  • Window ids are crate-assigned sequential WindowId(u64) values; winit's opaque ids stay internal.

Headless-friendly test seam (CI has no display)

  • Field-level translation functions (translate_key_parts, map_*) are unit-tested without a display because several upstream payloads (DeviceId, InnerSizeWriter, KeyEvent.platform_specific) are not constructible off-platform.
  • Dedicated tests/headless_run.rs target with harness = false runs as a real process entry point (winit requires main-thread loop creation): asserts owned-error degradation headlessly and clean exit with a display. Not verifiable in CI: actual GPU/compositor present-path behavior.
  • Display-dependent window integration tests live in tests/display.rs behind the default-off gui-tests feature; never run in CI, documented in-file.

Safety / security

  • \#![forbid(unsafe_code)] — no exception claimed; consuming winit 0.30 requires none.
  • No render/grid/business coupling; no business semantics; no I/O beyond window-system interaction.

Manifest note

Workspace root change is exactly one members-list line (+ lockfile) so CTX-0015's parallel edits union-merge cleanly.

Validation

  • Local: just check green — fmt-check, clippy --workspace --all-targets --locked -D warnings, test --workspace --all-targets --locked (24 unit tests + headless_run entry point), actionlint, markdownlint.
  • Cargo.lock diff vs base contains only the bitty-platform member entry and the winit 0.30.13 dependency tree (plus resolver reorder noise).

Refs: CTX-0014

…ent adapter

Implements CarryCtx task CTX-0014 (GitHub issue #17) per the ADR-0003
crate graph row (bitty-platform: window/event-loop adapter, DPI; no
workspace deps) and the ADR-0004 decision row adopting winit ~0.30.x
inside bitty-platform with crossterm rejected as a runtime input path.

- Strictly owned public API: no winit type escapes the crate; internal
  ApplicationHandler adapter translates WindowEvent streams into the
  owned PlatformEvent/WindowEventKind vocabulary (resized, DPI scale
  factor, redraw, focus, keyboard, mouse button/wheel, cursor motion,
  close-requested/closed) plus loop resumed/suspended/about-to-wait/
  exiting phases.
- DPI-aware owned types: ScaleFactor (validated finite > 0), LogicalPixel,
  LogicalSize, PhysicalSize with deterministic round-half-away-from-zero
  conversions and saturating physical rounding.
- Owned keyboard model over logical keys (terminal-relevant NamedKey
  subset with documented Other collapse; positional KeyCodes deferred to
  the open input-domain placement question in ADR-0003), text/location/
  state/repeat/synthetic flags; synthetic focus events are dropped.
- Headless-friendly test seam: field-level translation functions unit-
  tested without a display; winit event-loop main-thread constraint
  handled by a dedicated harness=false integration target verifying
  graceful PlatformError::DisplayUnavailable degradation headlessly and
  clean exit with a display; display-dependent window tests gated behind
  the default-off gui-tests feature and documented as not run in CI.
- #![forbid(unsafe_code)]; no render/grid/business coupling; workspace
  manifest change limited to one members-list line for CTX-0015 union
  merge; Cargo.lock gains the winit 0.30.13 tree.

just check green locally (fmt-check, clippy -D warnings --locked,
test --locked incl. headless_run entry point, actionlint, markdownlint).

Closes #17

Refs: CTX-0014
@Xuepoo
Xuepoo merged commit 10136a9 into main Aug 26, 2026
4 checks passed
@Xuepoo
Xuepoo deleted the ctx-0014/feat-bitty-platform branch August 26, 2026 10:29
@Xuepoo Xuepoo added this to the v0.0.1 milestone Aug 29, 2026
@Xuepoo Xuepoo added feat Feature area:package Area: package lifecycle area:platform Area: platform / windowing P0 Priority: highest labels Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:package Area: package lifecycle area:platform Area: platform / windowing feat Feature P0 Priority: highest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(platform): implement bitty-platform crate skeleton: owned winit event adapter

1 participant