<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Egui on Tiziano Basile | Software Engineer</title><link>https://bstz.it/tags/egui/</link><description>Recent content in Egui on Tiziano Basile | Software Engineer</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Tiziano Basile</copyright><lastBuildDate>Sat, 28 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://bstz.it/tags/egui/index.xml" rel="self" type="application/rss+xml"/><item><title>Bonooru Devlog #4: A window, three lights and a gamepad</title><link>https://bstz.it/p/bonooru-devlog-4/</link><pubDate>Sat, 28 Nov 2026 00:00:00 +0000</pubDate><guid>https://bstz.it/p/bonooru-devlog-4/</guid><description>&lt;img src="https://bstz.it/p/bonooru-devlog-4/bonooru-main-window.png" alt="Featured image of post Bonooru Devlog #4: A window, three lights and a gamepad" /&gt;&lt;p&gt;Until now, everything in Bonooru happened in a terminal. Now it has a window: it finds the bridge by itself, shows the state of all three links as it changes, and has a gamepad on the screen that I clicked to walk Link to a quiet spot and play five notes on the ocarina. The hard part wasn&amp;rsquo;t drawing the window. It was making sure a button can&amp;rsquo;t stay held on my console when the window disappears.&lt;/p&gt;
&lt;p&gt;&lt;a class="link" href="https://github.com/basteez/bonooru" target="_blank" rel="noopener"
&gt;Bonooru&lt;/a&gt; is my side project to play arbitrary melodies on the ocarina in &lt;em&gt;The Legend of Zelda: Ocarina of Time&lt;/em&gt; on Switch 2. It does that by pretending to be a wired controller. The chain is a desktop app on the PC, a &amp;ldquo;bridge&amp;rdquo; RP2040 board on USB, a UART link, and a &amp;ldquo;controller&amp;rdquo; RP2040 board that the Switch 2 sees as a Pro Controller. &lt;a class="link" href="https://bstz.it/p/bonooru-devlog-0/" target="_blank" rel="noopener"
&gt;Devlog #0&lt;/a&gt; explains the idea, &lt;a class="link" href="https://bstz.it/p/bonooru-devlog-1/" target="_blank" rel="noopener"
&gt;Devlog #1&lt;/a&gt; measures the ocarina, &lt;a class="link" href="https://bstz.it/p/bonooru-devlog-2/" target="_blank" rel="noopener"
&gt;Devlog #2&lt;/a&gt; is the controller firmware, &lt;a class="link" href="https://bstz.it/p/bonooru-devlog-3/" target="_blank" rel="noopener"
&gt;Devlog #3&lt;/a&gt; is the bridge and the PC streaming a melody end to end.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://bstz.it/p/bonooru-devlog-4/bonooru-main-window.png"
width="1600"
height="1018"
srcset="https://bstz.it/p/bonooru-devlog-4/bonooru-main-window_hu_d273e8da55d4f646.png 480w, https://bstz.it/p/bonooru-devlog-4/bonooru-main-window_hu_7d58dfd963595d4d.png 1024w"
loading="lazy"
alt="The Bonooru main window: three green status LEDs at the top (Bridge v0.0.0, Controller v0.0.0, Switch ready), an empty parchment note view in the middle, the on-screen gamepad with its key legend on the right, and the STOP button at the bottom"
class="gallery-image"
data-flex-grow="157"
data-flex-basis="377px"
&gt;
&lt;em&gt;The Bonooru main window after Epic 4: the status strip on top, the gamepad on the right, the STOP button at the bottom. The song panel and the note view are still empty: they arrive with Epic 5.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id="where-we-were"&gt;Where we were
&lt;/h2&gt;&lt;p&gt;At the end of Epic 3 the PC could stream &lt;em&gt;Ode to Joy&lt;/em&gt; to the Switch 2 through two boards running my firmware. But the PC side was &lt;code&gt;ocb-dev&lt;/code&gt;, a command-line tool that takes a serial port and a timeline file, and the person using it was me, reading log lines.&lt;/p&gt;
&lt;p&gt;The goal of Epic 4 was milestone M5: &lt;strong&gt;the app shows the link state and drives the Switch with the virtual gamepad.&lt;/strong&gt; In practice:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a real desktop window, with the look from the UX spec;&lt;/li&gt;
&lt;li&gt;a background worker that finds the bridge without asking me for a port, and keeps the link alive;&lt;/li&gt;
&lt;li&gt;three status lights, one per link: PC ↔ bridge, bridge ↔ controller, controller ↔ Switch;&lt;/li&gt;
&lt;li&gt;a firmware version check that refuses to drive mismatched boards;&lt;/li&gt;
&lt;li&gt;a STOP button, and Esc, that always work;&lt;/li&gt;
&lt;li&gt;an on-screen Pro Controller, by mouse and by keyboard, good enough to reach ocarina free play.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ten stories (4.0 to 4.9), ten PRs (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/39" target="_blank" rel="noopener"
&gt;#39&lt;/a&gt; to &lt;a class="link" href="https://github.com/basteez/bonooru/pull/50" target="_blank" rel="noopener"
&gt;#50&lt;/a&gt;), plus the epic close (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/51" target="_blank" rel="noopener"
&gt;#51&lt;/a&gt;) and the retrospective (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/52" target="_blank" rel="noopener"
&gt;#52&lt;/a&gt;), from 26 to 28 November.&lt;/p&gt;
&lt;h2 id="the-spike-pays-off"&gt;The spike pays off
&lt;/h2&gt;&lt;p&gt;Before writing any of the real app I had an agent build a throwaway Rust + egui spike, back in November, to decide between Rust and Python (&lt;a class="link" href="https://bstz.it/p/bonooru-devlog-0/" target="_blank" rel="noopener"
&gt;Devlog #0&lt;/a&gt; has the numbers: 10.9 MB binary, ~115 ms cold start, 0.2 % idle CPU). Epic 4 is where that spike paid off, and not in the way I expected. &lt;strong&gt;Not a single line of its code was reused.&lt;/strong&gt; What was reused is what it found out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;API churn.&lt;/strong&gt; egui 0.37 replaced &lt;code&gt;App::update(ctx)&lt;/code&gt; with &lt;code&gt;App::ui(ui)&lt;/code&gt; and changed the panel API. Most examples online, and the AI&amp;rsquo;s own memory, show the old one. The spike&amp;rsquo;s advice, &amp;ldquo;read the crate source in &lt;code&gt;~/.cargo/registry&lt;/code&gt;, not blog posts&amp;rdquo;, went straight into the dev notes. It turned out to be the most useful sentence of the epic, as you&amp;rsquo;ll see below.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Licences.&lt;/strong&gt; The spike&amp;rsquo;s licence scan had already flagged egui&amp;rsquo;s bundled fonts (OFL-1.1 and the Ubuntu font licence) and BSL-1.0 in two Windows-only clipboard crates. When &lt;code&gt;cargo deny&lt;/code&gt; stopped Story 4.1 on BSL-1.0, the decision took a minute: I allowed it rather than drop the clipboard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The CI recipe.&lt;/strong&gt; Its list of Linux packages became the app&amp;rsquo;s CI step.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The gamepad stub.&lt;/strong&gt; The spike had a 10-button gamepad with three rules that survived into the real one: key and mouse are tracked separately, key auto-repeat is ignored, and everything is released when the window loses focus. That last rule turned out to be much harder than it looked.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The workspace now has three crates that ship and three that don&amp;rsquo;t:&lt;/p&gt;
&lt;figure class="mermaid-figure"&gt;
&lt;pre class="mermaid"&gt;flowchart TB
APP[&amp;#34;ocb-app (binary bonooru)&amp;lt;br/&amp;gt;egui/eframe window, theme, screens&amp;#34;] --&amp;gt; SVC[&amp;#34;ocb-services&amp;lt;br/&amp;gt;serial worker, port adapter, file log&amp;lt;br/&amp;gt;no egui&amp;#34;]
APP --&amp;gt; CORE
SVC --&amp;gt; CORE[&amp;#34;ocb-core&amp;lt;br/&amp;gt;protocol codec, sans-IO link session, port classifier&amp;lt;br/&amp;gt;no I/O, no threads, no clocks&amp;#34;]
SIM[&amp;#34;ocb-sim (dev only)&amp;lt;br/&amp;gt;fake controller, impaired channel&amp;#34;] -.-&amp;gt; CORE
DEV[&amp;#34;ocb-dev, ocb-probe (dev only)&amp;lt;br/&amp;gt;bench tools&amp;#34;] -.-&amp;gt; SVC
DEV -.-&amp;gt; CORE&lt;/pre&gt;
&lt;figcaption class="mermaid-caption"&gt;The app workspace after Epic 4. Only ocb-app depends on egui&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="a-window-that-looks-like-something"&gt;A window that looks like something
&lt;/h2&gt;&lt;p&gt;Story 4.1 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/40" target="_blank" rel="noopener"
&gt;PR #40&lt;/a&gt;) is the shell: a new crate, &lt;code&gt;ocb-app&lt;/code&gt;, with eframe and egui pinned at exactly &lt;code&gt;=0.37.0&lt;/code&gt;, a window of 1280 × 800 points (minimum 1024 × 680), dark only.&lt;/p&gt;
&lt;p&gt;The look comes from the UX spec: warm browns, a parchment card for the notes, amber for focus and for what matters. It evokes the game without taking anything from it. Two fonts, both shipped unmodified with their licence texts: Cormorant Garamond for display text and Nunito Sans for everything else, plus egui&amp;rsquo;s Hack for code.&lt;/p&gt;
&lt;p&gt;A few things I didn&amp;rsquo;t know about egui before this story:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Variable fonts render at their lightest weight by default.&lt;/strong&gt; Without setting the weight axis through &lt;code&gt;FontTweak&lt;/code&gt;, every face came out ExtraLight.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tab order is registration order.&lt;/strong&gt; So the main screen is filled in reading order with &lt;code&gt;scope_builder&lt;/code&gt;, not with egui panels, to make Tab go where the eye goes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No OpenType features.&lt;/strong&gt; egui 0.37 can&amp;rsquo;t select lining or tabular figures, and Cormorant&amp;rsquo;s old-style &amp;ldquo;3&amp;rdquo; at 128 pt dropped into the row below it. Cells are now sized from the glyph&amp;rsquo;s real mesh bounds.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;On Linux, Wayland wins even when you don&amp;rsquo;t want it.&lt;/strong&gt; AccessKit&amp;rsquo;s default features turn on winit&amp;rsquo;s Wayland backend, and winit picks Wayland whenever &lt;code&gt;WAYLAND_DISPLAY&lt;/code&gt; is set, with no fallback. Removing the variable would need &lt;code&gt;unsafe&lt;/code&gt;, which the workspace forbids. So the app forces X11 at run time.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are no pixel snapshot tests. Geometry and colours are checked on egui&amp;rsquo;s &lt;code&gt;FullOutput::shapes&lt;/code&gt;, which is CPU-only and the same on all three OS. One test parses the token table at the top of the design spec and checks every colour both ways, so the spec and the code can&amp;rsquo;t drift. The contrast of every text colour is measured too: body text is 13.49:1 on its panel, the dimmest status colour 5.10:1.&lt;/p&gt;
&lt;h3 id="screen-reader-basic-decided-with-numbers"&gt;Screen reader: &amp;ldquo;basic&amp;rdquo;, decided with numbers
&lt;/h3&gt;&lt;p&gt;Story 4.2 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/41" target="_blank" rel="noopener"
&gt;PR #41&lt;/a&gt;) was a decision, not code: how far to go with screen readers (&lt;a class="link" href="https://github.com/AccessKit/accesskit" target="_blank" rel="noopener"
&gt;AccessKit&lt;/a&gt;, which egui uses).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;None&lt;/strong&gt; would have saved 68 crates on Linux (the D-Bus stack), and left custom widgets invisible to tests too.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Full&lt;/strong&gt; would have cost an estimated 1.5 to 2 weeks, and manual passes with VoiceOver, NVDA and Orca on three OS.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Basic&lt;/strong&gt; costs about one line per widget: every custom widget reports its role and its visible label. It costs nothing at run time, because eframe only builds the tree when a screen reader asks for it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I picked basic. The side effect I like most: the tests now find widgets the way a user does, by role and label (&lt;code&gt;get_by_role_and_label&lt;/code&gt;), not by coordinates.&lt;/p&gt;
&lt;h3 id="painting-helpers-and-a-glow-that-was-too-faint"&gt;Painting helpers, and a glow that was too faint
&lt;/h3&gt;&lt;p&gt;Story 4.3 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/42" target="_blank" rel="noopener"
&gt;PR #42&lt;/a&gt;) built the shared painting helpers (focus ring, glow, text halo, dashed outlines, 12 painted symbols, corner brackets) and the modal dialog.&lt;/p&gt;
&lt;p&gt;My favourite bug of the story came from my own eyes. I looked at the gallery and said the glow was &amp;ldquo;far too faint&amp;rdquo;. The mockups are HTML, and CSS &lt;code&gt;box-shadow&lt;/code&gt; blurs with a Gaussian of σ = blur / 2; epaint&amp;rsquo;s shadow uses a linear feather. Using the CSS number as the feather width kept only 63 % of the light. The fix is a fitted constant, checked against a headless Chrome rendering of the mockup:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;span class="lnt"&gt;7
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt;/// ... The w
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt;/// minimising ∫₀^{4σ} (ramp − α·Q(d/σ))² dd with zero spread (spread is
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt;/// `u8`, it cannot be negative) is w = 3.1 σ = 1.55 B; the largest error is
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt;/// then 0.06 α. Before this the token was used as w directly (w = 2σ), so
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt;/// the halo ended at d = σ, holding 63 % of the CSS halo&amp;#39;s light and half
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt;/// its reach (owner eye check 2026-11-27: &amp;#34;far too faint&amp;#34;).
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="sd"&gt;&lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;CSS_BLUR_TO_FEATHER&lt;/span&gt;: &lt;span class="kt"&gt;f32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.55&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a class="link" href="https://github.com/basteez/bonooru/blob/d947123/app/gui/src/ui/paint.rs#L134-L138" target="_blank" rel="noopener"
&gt;&lt;code&gt;app/gui/src/ui/paint.rs&lt;/code&gt;&lt;/a&gt;, the end of the comment&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The review found the less pretty bugs: a held Enter confirmed the &lt;em&gt;next&lt;/em&gt; queued dialog before I could see it (now a dialog only answers to a key released since it opened), &lt;code&gt;f32::clamp&lt;/code&gt; panicking on an inverted rectangle (it asserts even in release builds), and a dash length of 0 that hung epaint forever.&lt;/p&gt;
&lt;p&gt;The disabled button was redone three times. A 45 % fade made the label unreadable (1.59:1). A readable label &amp;ldquo;no longer looked disabled&amp;rdquo;. The final one is a neutral, opaque button with a muted label and no glow.&lt;/p&gt;
&lt;h2 id="the-worker-the-second-adapter-for-the-same-session"&gt;The worker: the second adapter for the same session
&lt;/h2&gt;&lt;p&gt;In &lt;a class="link" href="https://bstz.it/p/bonooru-devlog-3/" target="_blank" rel="noopener"
&gt;Devlog #3&lt;/a&gt; the link session went into &lt;code&gt;ocb-core&lt;/code&gt; as &lt;strong&gt;sans-IO&lt;/strong&gt; code: it never touches a port or a clock, it takes bytes and a time and gives back bytes, events and its next deadline. &lt;code&gt;ocb-dev&lt;/code&gt; was the first adapter around it. Story 4.4 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/44" target="_blank" rel="noopener"
&gt;PR #44&lt;/a&gt;) wrote the second: the app&amp;rsquo;s serial worker, in a new crate &lt;code&gt;ocb-services&lt;/code&gt; that has no egui in it.&lt;/p&gt;
&lt;p&gt;The best number of this section: &lt;strong&gt;in all of Epic 4, the link session didn&amp;rsquo;t change by one line.&lt;/strong&gt; &lt;code&gt;git diff&lt;/code&gt; over &lt;code&gt;app/core/src/link&lt;/code&gt; between the start and the end of the epic is empty. The only new code in &lt;code&gt;ocb-core&lt;/code&gt; is a pure port classifier.&lt;/p&gt;
&lt;figure class="mermaid-figure"&gt;
&lt;pre class="mermaid"&gt;flowchart LR
subgraph UI[&amp;#34;UI thread (eframe)&amp;#34;]
APP[&amp;#34;App::logic / App::ui&amp;#34;]
end
subgraph W[&amp;#34;bonooru-serial thread&amp;#34;]
CORE[&amp;#34;WorkerCore&amp;lt;br/&amp;gt;port + Session&amp;#34;]
end
subgraph L[&amp;#34;bonooru-log thread&amp;#34;]
LOG[&amp;#34;bonooru.log&amp;lt;br/&amp;gt;1 MiB × 4&amp;#34;]
end
APP -- &amp;#34;WorkerCommand&amp;lt;br/&amp;gt;(Stop, SetState)&amp;#34; --&amp;gt; CORE
CORE -- &amp;#34;events, bounded 1024&amp;#34; --&amp;gt; APP
CORE -- &amp;#34;Arc&amp;amp;lt;LinkSnapshot&amp;amp;gt;, bounded 1&amp;#34; --&amp;gt; APP
CORE -. &amp;#34;waker: request_repaint()&amp;#34; .-&amp;gt; APP
CORE -- &amp;#34;try_send&amp;#34; --&amp;gt; LOG
APP -- &amp;#34;try_send&amp;#34; --&amp;gt; LOG
CORE == &amp;#34;USB CDC 460800&amp;#34; ==&amp;gt; BR[&amp;#34;bridge&amp;#34;]&lt;/pre&gt;
&lt;figcaption class="mermaid-caption"&gt;Threads and channels. The UI thread never blocks: it only calls try_recv&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;One &lt;code&gt;step()&lt;/code&gt; of the worker drains the commands, scans the ports every second, opens the right one, runs one I/O pass and publishes a snapshot if anything changed. The I/O pass is the same dance as in &lt;code&gt;ocb-dev&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;span class="lnt"&gt;22
&lt;/span&gt;&lt;span class="lnt"&gt;23
&lt;/span&gt;&lt;span class="lnt"&gt;24
&lt;/span&gt;&lt;span class="lnt"&gt;25
&lt;/span&gt;&lt;span class="lnt"&gt;26
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;handle_rx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[]),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_rx_us&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PortLost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now_us&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;poll_timeout&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;is_some_and&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;handle_timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;poll_transmit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// ... queue the bytes, count HELLOs and frames ...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="c1"&gt;// A few ms at most per pass: a port that does not drain never holds
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// the worker (scans, shutdown and the log stay on time).
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PortLost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;lost&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;poll_event&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ev&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a class="link" href="https://github.com/basteez/bonooru/blob/d947123/app/services/src/worker.rs#L1103-L1158" target="_blank" rel="noopener"
&gt;&lt;code&gt;app/services/src/worker.rs&lt;/code&gt;&lt;/a&gt;, trimmed&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Two small patterns I&amp;rsquo;m happy with.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Latest-only snapshots.&lt;/strong&gt; The UI only ever needs the newest link state. The snapshot channel has capacity 1, and the worker keeps a clone of the &lt;em&gt;receiver&lt;/em&gt; (crossbeam channels are multi-producer, multi-consumer) so it can throw away a snapshot the UI hasn&amp;rsquo;t read yet:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dirty&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;snap&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Arc&lt;/span&gt;::&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Capacity 1: drop the stale snapshot the UI has not read, so it
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// always gets the latest and nothing grows while the window is
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// hidden (crossbeam channels are MPMC).
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;snap_rx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;try_recv&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;snap_tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;try_send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;waker&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a class="link" href="https://github.com/basteez/bonooru/blob/d947123/app/services/src/worker.rs#L1355-L1364" target="_blank" rel="noopener"
&gt;&lt;code&gt;app/services/src/worker.rs&lt;/code&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A dead worker still wakes the UI.&lt;/strong&gt; egui only repaints when something asks. If the worker panics, nobody asks, and the status strip would keep showing &amp;ldquo;connected&amp;rdquo; until I moved the mouse. So &lt;code&gt;Drop&lt;/code&gt; drops the snapshot sender first and then calls the waker one last time:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt;1
&lt;/span&gt;&lt;span class="lnt"&gt;2
&lt;/span&gt;&lt;span class="lnt"&gt;3
&lt;/span&gt;&lt;span class="lnt"&gt;4
&lt;/span&gt;&lt;span class="lnt"&gt;5
&lt;/span&gt;&lt;span class="lnt"&gt;6
&lt;/span&gt;&lt;span class="lnt"&gt;7
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;: &lt;span class="nc"&gt;Backend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;: &lt;span class="nc"&gt;Clock&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Drop&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;WorkerCore&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;gone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;bounded&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;std&lt;/span&gt;::&lt;span class="n"&gt;mem&lt;/span&gt;::&lt;span class="n"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;snap_tx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;gone&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;waker&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a class="link" href="https://github.com/basteez/bonooru/blob/d947123/app/services/src/worker.rs#L423-L429" target="_blank" rel="noopener"
&gt;&lt;code&gt;app/services/src/worker.rs&lt;/code&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h3 id="finding-my-bridge-and-only-my-bridge"&gt;Finding my bridge, and only my bridge
&lt;/h3&gt;&lt;p&gt;The bridge firmware from Devlog #3 has an identity: VID:PID &lt;code&gt;2E8A:000A&lt;/code&gt;, product string &lt;code&gt;Bonooru Bridge&lt;/code&gt;, and the flash unique ID as serial number. &lt;code&gt;2E8A:000A&lt;/code&gt; is a generic Raspberry Pi ID that other boards use too (the RiiDraw firmware I started with has the same one), so the classifier sorts every port into four classes:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;Rule&lt;/th&gt;
&lt;th&gt;What the app does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ours&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2E8A:000A&lt;/code&gt; and product exactly &lt;code&gt;Bonooru Bridge&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;opens it first&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;unconfirmed&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2E8A:000A&lt;/code&gt;, no usable product string (always the case on Windows, where the driver reports a &amp;ldquo;friendly name&amp;rdquo;)&lt;/td&gt;
&lt;td&gt;probes it, 2 s each in turn&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;foreign&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2E8A:000A&lt;/code&gt;, another product&lt;/td&gt;
&lt;td&gt;never opens it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ignored&lt;/td&gt;
&lt;td&gt;anything else, and on macOS every &lt;code&gt;/dev/tty.*&lt;/code&gt; name&lt;/td&gt;
&lt;td&gt;never opens it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Ports that aren&amp;rsquo;t ours are never opened, so DTR is never raised on someone else&amp;rsquo;s board. And reconnection follows the serial number, not the port name, because macOS renames the port after the USB socket: in the bench, replugging into another socket turned &lt;code&gt;/dev/cu.usbmodem1101&lt;/code&gt; into &lt;code&gt;/dev/cu.usbmodem2101&lt;/code&gt;, and the worker followed it.&lt;/p&gt;
&lt;p&gt;Everything the worker does goes into a rotating file log (&lt;code&gt;~/Library/Logs/Bonooru/bonooru.log&lt;/code&gt; on macOS), written by its own thread with no logging crate. That log turned out to be the bench instrument for the rest of the epic: every bench row below is judged by its timestamped lines.&lt;/p&gt;
&lt;h3 id="at-the-bench-macos"&gt;At the bench (macOS)
&lt;/h3&gt;&lt;p&gt;A new dev-only tool, &lt;code&gt;ocb-probe&lt;/code&gt;, runs the same worker headless and prints lines a script can judge:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Row&lt;/th&gt;
&lt;th&gt;What&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;H.28&lt;/td&gt;
&lt;td&gt;port list&lt;/td&gt;
&lt;td&gt;the bridge once, &lt;code&gt;class=ours&lt;/code&gt;; its &lt;code&gt;/dev/tty.*&lt;/code&gt; twin ignored; the controller (a HID device, &lt;code&gt;057E:2009&lt;/code&gt;) absent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;H.29&lt;/td&gt;
&lt;td&gt;connect, unplug, replug&lt;/td&gt;
&lt;td&gt;INFO 4 ms after opening; loss seen 155 ms after the last byte; after replugging into another socket, INFO 5 ms after the port was listed; scan every 1000 ms (max 1009)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;H.31&lt;/td&gt;
&lt;td&gt;bridge alone, no controller&lt;/td&gt;
&lt;td&gt;100 HELLOs in 10 s, none dropped, no other port written&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;H.32&lt;/td&gt;
&lt;td&gt;the GUI app, unplug and replug&lt;/td&gt;
&lt;td&gt;the window stayed fluid while I moved and resized it; exit 64 ms after the port closed&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The review before the bench found the best kind of bug, one in the bench tool itself: &lt;strong&gt;the unplug step could pass without anyone unplugging anything.&lt;/strong&gt; It accepted any port loss, including a read glitch, and on replug it accepted the next connection without checking that the port had left the list first. Now it needs lost → vanished → the same serial listed again → INFO, and it has a FAIL branch named &amp;ldquo;reconnected without leaving the port list (no physical unplug)&amp;rdquo;.&lt;/p&gt;
&lt;h2 id="three-lights"&gt;Three lights
&lt;/h2&gt;&lt;p&gt;Story 4.5 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/46" target="_blank" rel="noopener"
&gt;PR #46&lt;/a&gt;) is the status strip: three LEDs, one per link. Each has four states, drawn as different shapes so colour isn&amp;rsquo;t the only clue: a filled dot (ok), a triangle (warning), a cross (error), a hollow ring (unknown).&lt;/p&gt;
&lt;p&gt;The model is pure, with no egui in it (a test checks the source): &lt;code&gt;evaluate(snapshot, age, worker health) -&amp;gt; Leds&lt;/code&gt;, a first-match decision table with 12 rows for the bridge, 9 for the controller and 5 for the Switch. It also returns &lt;em&gt;when it will next change&lt;/em&gt;, so the app can ask egui to repaint exactly then and otherwise sleep.&lt;/p&gt;
&lt;figure class="mermaid-figure"&gt;
&lt;pre class="mermaid"&gt;stateDiagram-v2
[*] --&amp;gt; NoPort: no bridge port
NoPort --&amp;gt; Opening: port open (unknown)
Opening --&amp;gt; Ok: INFO → &amp;#34;Controller v0.0.0&amp;#34;
Opening --&amp;gt; NotAnswering: no INFO after 500 ms (error)
Ok --&amp;gt; Stale: no STATUS for &amp;gt; 150 ms (error)
Stale --&amp;gt; Ok: fresh STATUS
Ok --&amp;gt; NoLink: link_ok = 0 (error)
NoLink --&amp;gt; Ok: link back
Ok --&amp;gt; NoPort: port lost
Stale --&amp;gt; NoPort: port lost&lt;/pre&gt;
&lt;figcaption class="mermaid-caption"&gt;The Bridge ↔ Controller LED (simplified). Any state goes to unknown if the worker stalls&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;The 150 ms comes straight from Devlog #3: over 1852 STATUS frames the worst gap was 52.4 ms, so three periods of 50 ms is the staleness limit.&lt;/p&gt;
&lt;h3 id="the-window-that-wasnt-drawing"&gt;The window that wasn&amp;rsquo;t drawing
&lt;/h3&gt;&lt;p&gt;H.33 put the strip on the real rig: Wired Communication off and on, the controller out of the Switch and back, the bridge out of the Mac and back. All three LEDs went ok &lt;strong&gt;15 ms after start&lt;/strong&gt;, 8 ms after the version arrived. &amp;ldquo;Switch – not ready&amp;rdquo; showed up when I turned wired communication off.&lt;/p&gt;
&lt;p&gt;Then step 3 (controller out of the Switch) failed in a strange way. The Controller LED should go red about 150 ms after the last STATUS. It went red after &lt;strong&gt;3380 ms&lt;/strong&gt;. The window was behind my terminal, and &lt;strong&gt;macOS draws no frames for an occluded window.&lt;/strong&gt; Nothing repainted until the worker-stall deadline at 3 s woke it. With the window visible, the same step logged 150.264 ms.&lt;/p&gt;
&lt;p&gt;For a status light that&amp;rsquo;s a cosmetic delay. The rule became a bench checklist item (&amp;ldquo;keep the window visible&amp;rdquo;). But it planted a question that came back three stories later, with a much less cosmetic answer.&lt;/p&gt;
&lt;h3 id="a-test-that-couldnt-catch-its-own-bug"&gt;A test that couldn&amp;rsquo;t catch its own bug
&lt;/h3&gt;&lt;p&gt;The review found that the strip could freeze on &amp;ldquo;connected&amp;rdquo; forever if the worker died: the 150 ms timer fired once, and after that nothing repainted. The fix is the &lt;code&gt;Drop&lt;/code&gt; above. The interesting part is that the existing test, &lt;code&gt;g16_dead_worker_unknown&lt;/code&gt;, &lt;em&gt;couldn&amp;rsquo;t have caught it&lt;/em&gt;: it stepped the UI every 5 ms by hand, so a frame always ran. It was rewritten on a scheduler that runs frames only when egui&amp;rsquo;s repaint callback asks for one, like the real event loop.&lt;/p&gt;
&lt;h2 id="refusing-the-wrong-firmware"&gt;Refusing the wrong firmware
&lt;/h2&gt;&lt;p&gt;Story 4.6 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/47" target="_blank" rel="noopener"
&gt;PR #47&lt;/a&gt;) handles the day the app and the boards disagree on the protocol version. The controller then answers HELLO with a NAK, and the session stays &lt;code&gt;Incompatible&lt;/code&gt;. The app shows a dialog (&amp;ldquo;Firmware update needed&amp;rdquo;, with the reflash steps), turns the gamepad and the future Play button off, and says why in a line under the gamepad. Closing the dialog never lifts the block. A test proves the worker writes &lt;strong&gt;zero bytes&lt;/strong&gt; to the controller while it&amp;rsquo;s incompatible.&lt;/p&gt;
&lt;p&gt;The review found a bug that only an immediate-mode GUI can have. egui 0.37 lays out a new window invisibly in its first pass, so the app asks for that pass to be discarded and drawn again. But eframe gives the frame&amp;rsquo;s input to the first pass only, the one being thrown away. An Esc in that pass dismissed a dialog the user had never seen, and it wouldn&amp;rsquo;t come back for that connection. The dialog now ignores an Esc on the frame it opens.&lt;/p&gt;
&lt;h2 id="stop-in-2-milliseconds"&gt;STOP, in 2 milliseconds
&lt;/h2&gt;&lt;p&gt;Story 4.7 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/48" target="_blank" rel="noopener"
&gt;PR #48&lt;/a&gt;) added the bottom bar and the button I care about most: STOP, 60 points tall, with &amp;ldquo;Esc&amp;rdquo; written under it. The rule from the UX spec is that &lt;strong&gt;Esc is STOP, always&lt;/strong&gt;, in every screen, even with a dialog open. The app reads Esc first thing in every frame without consuming it, so an open dialog then consumes the same press and closes.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;H.34 (macOS)&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Esc&lt;/td&gt;
&lt;td&gt;STOP ACKed 1.833 ms after the key; controller idle 8 ms after the key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;click on STOP&lt;/td&gt;
&lt;td&gt;ACK 1.884 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tab to STOP, then Enter&lt;/td&gt;
&lt;td&gt;one STOP, 2.390 ms; Enter held 2 s: exactly one more&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;five Esc, 150 ms apart&lt;/td&gt;
&lt;td&gt;5 requested, 5 sent, 5 ACKed (1.311 to 2.001 ms)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Esc held 2 s&lt;/td&gt;
&lt;td&gt;exactly one STOP&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;bridge unplugged, Esc&lt;/td&gt;
&lt;td&gt;&lt;code&gt;stop skipped reason=no_port&lt;/code&gt;, nothing written&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The limit is 100 ms. The review fixed the race I&amp;rsquo;d least like to meet in real life: the worker read its command queue with one call and checked for a closed channel with another, and a STOP landing between the two was silently swallowed. The app had logged &amp;ldquo;queued&amp;rdquo;; the worker wrote nothing. Now it&amp;rsquo;s a single &lt;code&gt;try_recv&lt;/code&gt; loop.&lt;/p&gt;
&lt;p&gt;My eye check added one thing: clicking STOP gave no visual feedback. Every button now has hover and pressed states.&lt;/p&gt;
&lt;h2 id="the-gamepad-and-the-window-that-disappears"&gt;The gamepad, and the window that disappears
&lt;/h2&gt;&lt;p&gt;Story 4.8 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/49" target="_blank" rel="noopener"
&gt;PR #49&lt;/a&gt;) is the on-screen Pro Controller: a silhouette with 16 buttons and 2 sticks, drawn in a 300-point panel, with the caption &amp;ldquo;Use it to reach ocarina free play.&amp;rdquo; That&amp;rsquo;s what it&amp;rsquo;s for: walk Link somewhere quiet and take out the ocarina before a song starts.&lt;/p&gt;
&lt;p&gt;The rules:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A press goes out in the frame it arrives. A release is never sent earlier than 50 ms after the press, because the shortest press that always sounds is two frames, 33.3 ms (measured in &lt;a class="link" href="https://bstz.it/p/bonooru-devlog-1/" target="_blank" rel="noopener"
&gt;Epic 1&lt;/a&gt;), and one more 60 Hz frame is the margin.&lt;/li&gt;
&lt;li&gt;The app keeps one canonical controller state and sends it (&lt;code&gt;SET_STATE&lt;/code&gt;, in the controller&amp;rsquo;s DIRECT mode) only when it changes.&lt;/li&gt;
&lt;li&gt;Sticks: full deflection at 17 points, clamped to a circle, back to centre on release.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The D-pad turns four booleans into the controller&amp;rsquo;s hat value, with opposite directions cancelling:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;hat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;up&lt;/span&gt;: &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;down&lt;/span&gt;: &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;left&lt;/span&gt;: &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;right&lt;/span&gt;: &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;-&amp;gt; &lt;span class="kt"&gt;u8&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i8&lt;/span&gt;::&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;down&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i8&lt;/span&gt;::&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;up&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i8&lt;/span&gt;::&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;right&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;i8&lt;/span&gt;::&lt;span class="n"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_UP&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_UP_RIGHT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_RIGHT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_DOWN_RIGHT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_DOWN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_DOWN_LEFT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_LEFT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_UP_LEFT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="no"&gt;HAT_NEUTRAL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a class="link" href="https://github.com/basteez/bonooru/blob/d947123/app/gui/src/gamepad.rs#L511-L525" target="_blank" rel="noopener"
&gt;&lt;code&gt;app/gui/src/gamepad.rs&lt;/code&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;h3 id="safety-logic-doesnt-belong-in-ui"&gt;Safety logic doesn&amp;rsquo;t belong in &lt;code&gt;ui&lt;/code&gt;
&lt;/h3&gt;&lt;p&gt;Here&amp;rsquo;s the question H.33 had planted. A held button has to be released when the window loses focus: that was already a rule in the spike. In the first version of 4.8 the release ran in &lt;code&gt;App::ui&lt;/code&gt;, on the &lt;code&gt;WindowFocused(false)&lt;/code&gt; event.&lt;/p&gt;
&lt;p&gt;The code review read eframe&amp;rsquo;s source (the spike&amp;rsquo;s advice, again) and found this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;show_ui&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// Nothing will be shown, so we run no egui pass at all.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// That way all ui state is left untouched, and is still there
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// when this viewport becomes visible again.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;is_root_viewport&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;viewport_ui_cb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_none&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;is_root_viewport&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The app logic keeps ticking, so it can e.g. ask to be shown again:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;egui&lt;/span&gt;::&lt;span class="n"&gt;LogicOutput&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cm"&gt;/* ... */&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;integration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;update_logic_only&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;as_mut&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;raw_input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// ...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// they should have been processed
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;eframe 0.37.0, &lt;a class="link" href="https://github.com/emilk/egui/blob/0.37.0/crates/eframe/src/native/wgpu_integration.rs#L716-L732" target="_blank" rel="noopener"
&gt;&lt;code&gt;crates/eframe/src/native/wgpu_integration.rs&lt;/code&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For a minimised, hidden or occluded window, eframe calls &lt;code&gt;App::logic&lt;/code&gt; only, &lt;strong&gt;and then clears the window&amp;rsquo;s events.&lt;/strong&gt; So: hold A with the mouse, press Cmd+H. The focus-lost event and the mouse release are thrown away with the events, &lt;code&gt;ui&lt;/code&gt; never runs, and the release never happens. Meanwhile the session keeps the controller&amp;rsquo;s 1-second app timeout from firing (it pings every 250 ms in DIRECT mode, on purpose, so a long note doesn&amp;rsquo;t get cut). &lt;strong&gt;A would stay held on the Switch for as long as the window stayed hidden.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Nobody saw this on the bench: the review caught it first. It&amp;rsquo;s exactly the H.33 symptom, a window that doesn&amp;rsquo;t draw, with a button held instead of a light late.&lt;/p&gt;
&lt;p&gt;The fix moved every piece of safety logic into &lt;code&gt;App::logic&lt;/code&gt;, which runs on every pass whether the window is visible or not: blur detection (a focus-lost event, &lt;em&gt;or&lt;/em&gt; the focus flag falling, &lt;em&gt;or&lt;/em&gt; the viewport not visible), the 50 ms tap timer, the STOP retry and the send. Story 4.9&amp;rsquo;s review later found the same hole for keys: a key-up could also be dropped in a logic-only pass, so &lt;code&gt;logic&lt;/code&gt; reads key releases from the raw events too.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;
&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt"&gt; 1
&lt;/span&gt;&lt;span class="lnt"&gt; 2
&lt;/span&gt;&lt;span class="lnt"&gt; 3
&lt;/span&gt;&lt;span class="lnt"&gt; 4
&lt;/span&gt;&lt;span class="lnt"&gt; 5
&lt;/span&gt;&lt;span class="lnt"&gt; 6
&lt;/span&gt;&lt;span class="lnt"&gt; 7
&lt;/span&gt;&lt;span class="lnt"&gt; 8
&lt;/span&gt;&lt;span class="lnt"&gt; 9
&lt;/span&gt;&lt;span class="lnt"&gt;10
&lt;/span&gt;&lt;span class="lnt"&gt;11
&lt;/span&gt;&lt;span class="lnt"&gt;12
&lt;/span&gt;&lt;span class="lnt"&gt;13
&lt;/span&gt;&lt;span class="lnt"&gt;14
&lt;/span&gt;&lt;span class="lnt"&gt;15
&lt;/span&gt;&lt;span class="lnt"&gt;16
&lt;/span&gt;&lt;span class="lnt"&gt;17
&lt;/span&gt;&lt;span class="lnt"&gt;18
&lt;/span&gt;&lt;span class="lnt"&gt;19
&lt;/span&gt;&lt;span class="lnt"&gt;20
&lt;/span&gt;&lt;span class="lnt"&gt;21
&lt;/span&gt;&lt;span class="lnt"&gt;22
&lt;/span&gt;&lt;span class="lnt"&gt;23
&lt;/span&gt;&lt;span class="lnt"&gt;24
&lt;/span&gt;&lt;span class="lnt"&gt;25
&lt;/span&gt;&lt;span class="lnt"&gt;26
&lt;/span&gt;&lt;span class="lnt"&gt;27
&lt;/span&gt;&lt;span class="lnt"&gt;28
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class="lntd"&gt;
&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-rust" data-lang="rust"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;logic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;: &lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_frame&lt;/span&gt;: &lt;span class="kp"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nc"&gt;mut&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;eframe&lt;/span&gt;::&lt;span class="n"&gt;Frame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// ...
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// The gamepad&amp;#39;s blur, tap timer and send also run when the window is
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// hidden: eframe then calls `logic` only and drops the window&amp;#39;s
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c1"&gt;// events (review 2026-11-27). Idempotent within a frame.
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Mode&lt;/span&gt;::&lt;span class="n"&gt;Main&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;focused&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blur_event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;key_ups&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;focused&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;matches!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;egui&lt;/span&gt;::&lt;span class="n"&gt;Event&lt;/span&gt;::&lt;span class="n"&gt;WindowFocused&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;))),&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter_map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;egui&lt;/span&gt;::&lt;span class="n"&gt;Event&lt;/span&gt;::&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pressed&lt;/span&gt;: &lt;span class="nc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;physical_key&lt;/span&gt;: &lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;pad_keys&lt;/span&gt;::&lt;span class="n"&gt;pad_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collect&lt;/span&gt;::&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pad_background_keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;focused&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;blur_event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;key_ups&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last_pad_wake&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request_repaint_after&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;apply_panel_surrender&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;em&gt;&lt;a class="link" href="https://github.com/basteez/bonooru/blob/d947123/app/gui/src/app.rs#L889-L936" target="_blank" rel="noopener"
&gt;&lt;code&gt;app/gui/src/app.rs&lt;/code&gt;&lt;/a&gt;, reformatted&lt;/em&gt;&lt;/p&gt;
&lt;figure class="mermaid-figure"&gt;
&lt;pre class="mermaid"&gt;flowchart TB
F[&amp;#34;frame&amp;#34;] --&amp;gt; LG[&amp;#34;App::logic (always)&amp;lt;br/&amp;gt;drain worker (pass 0)&amp;lt;br/&amp;gt;blur / hidden → release all&amp;lt;br/&amp;gt;key-ups, tap timer, STOP retry, send&amp;#34;]
LG --&amp;gt; V{&amp;#34;window visible?&amp;#34;}
V -- yes --&amp;gt; UI[&amp;#34;App::ui&amp;lt;br/&amp;gt;Esc = STOP, Space consumed&amp;lt;br/&amp;gt;draw strip, gamepad, bottom bar&amp;lt;br/&amp;gt;dialogs&amp;#34;]
V -- no --&amp;gt; CLR[&amp;#34;events cleared&amp;#34;]&lt;/pre&gt;
&lt;figcaption class="mermaid-caption"&gt;One eframe frame. Only logic is guaranteed to run; ui is skipped for a hidden window&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;There&amp;rsquo;s a test for it, &lt;code&gt;g23_hidden_window_releases&lt;/code&gt;, that drives a frame without calling &lt;code&gt;ui&lt;/code&gt;, and a new bench step: hold A, press Cmd+H.&lt;/p&gt;
&lt;p&gt;The other release paths each have a rule: STOP releases everything on the controller itself, so the pad sends nothing; if the link goes bad while a button is held, the app sends STOP; if the controller drops out of DIRECT mode by itself, the pad forgets what was held. And one from the review: if the worker refused the release (the console wasn&amp;rsquo;t ready), nobody learned about it. A refused release now becomes a STOP.&lt;/p&gt;
&lt;h3 id="h35-free-play-from-a-mouse"&gt;H.35: free play, from a mouse
&lt;/h3&gt;&lt;p&gt;On 28 November, with &lt;em&gt;Ocarina of Time&lt;/em&gt; running on the Switch 2 and the Joy-Cons untouched:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;What I did&lt;/th&gt;
&lt;th&gt;What the log and the Switch said&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;click A&lt;/td&gt;
&lt;td&gt;sent in 0 ms; controller in DIRECT 14 ms later; the console&amp;rsquo;s controller screen needed two more A clicks to close (the first A registers, the second confirms)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;drag the left stick&lt;/td&gt;
&lt;td&gt;249 state changes; Link walks and stops on release&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;D-pad left&lt;/td&gt;
&lt;td&gt;the ocarina comes out&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;A, X, Y, L, R&lt;/td&gt;
&lt;td&gt;five different notes. &lt;strong&gt;M5&amp;rsquo;s gamepad exit criterion, met&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;hold A for 3.5 s&lt;/td&gt;
&lt;td&gt;one continuous note&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6, 7&lt;/td&gt;
&lt;td&gt;STOP (Esc, then Enter) with A held&lt;/td&gt;
&lt;td&gt;ACK 1.778, 0.759 and 1.811 ms; the note stops&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Cmd+Tab, then Cmd+H, with A held&lt;/td&gt;
&lt;td&gt;release sent in the same millisecond; the note stops both times&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;bridge unplugged&lt;/td&gt;
&lt;td&gt;gamepad off 4 ms after the port loss; clicks ignored&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;video src="gamepad-to-free-play.mp4" poster="gamepad-to-free-play-poster.jpg" controls muted loop playsinline preload="metadata" style="display:block;width:100%;max-width:360px;margin:0 auto"&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Filmed with my phone, no audio: the Bonooru window on my Mac at the top, the Switch 2 on the TV at the bottom. Every move Link makes comes from a mouse click or drag on the on-screen pad.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id="the-keyboard-and-a-smaller-window"&gt;The keyboard, and a smaller window
&lt;/h2&gt;&lt;p&gt;Story 4.9 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/50" target="_blank" rel="noopener"
&gt;PR #50&lt;/a&gt;) made the pad playable from the keyboard, without letting the keyboard press anything by accident. The pad only listens when its panel has focus (a click on it, or Tab), shows an amber ring and a &amp;ldquo;Keys active&amp;rdquo; chip, and traps Tab and the arrows so they drive the pad instead of moving focus. Two exits: Esc (which is also STOP) and a click elsewhere.&lt;/p&gt;
&lt;p&gt;The mapping uses physical keys, so it&amp;rsquo;s the same on any keyboard layout: WASD and the arrows for the D-pad, H J K L for Y B X A, Q and E for L and R, Z and C for ZL and ZR, Enter for +, Backspace for −. Repeats are ignored, chords are the union of what&amp;rsquo;s held, opposite directions cancel. Below 1280 points of width, the pad becomes a compact button grid with no sticks.&lt;/p&gt;
&lt;p&gt;H.36 met M5&amp;rsquo;s keyboard exit: L K H Q E played five notes, a 3.8-second hold of L was one note despite the OS key repeat, and a chord went 0x0004 → 0x000c → 0x0004 → 0x0000. Two things surprised me at the bench, and neither was a bug:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Every reply I typed in the terminal took focus away from Bonooru,&lt;/strong&gt; so the pad released and its keys went off, exactly as designed. Each step had to start with a click on the panel.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The pause menu doesn&amp;rsquo;t open during ocarina free play.&lt;/strong&gt; I pressed Enter (+) and nothing happened. Leaving free play with B first, then Enter, opened it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="what-went-wrong-and-what-i-learned"&gt;What went wrong, and what I learned
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Safety logic must live where it always runs.&lt;/strong&gt; eframe skips &lt;code&gt;ui&lt;/code&gt; for a hidden window and clears its events. A held button, a key-up and the worker drain were all found running only in &lt;code&gt;ui&lt;/code&gt;. For Epic 6, where the app will play whole songs, the rule is written down: release and STOP logic live in &lt;code&gt;App::logic&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Checks that can&amp;rsquo;t fail, again.&lt;/strong&gt; The most common review finding, in 8 of 10 stories: a smoke test whose verdict always printed &lt;code&gt;ok&lt;/code&gt;, a worker count that could never be 0, a dead-worker test that always ran a frame, a hint test that passes for any label, a queue-full test that exercised &lt;em&gt;a copy&lt;/em&gt; of the send code instead of the app. The Epic 3 rule (a red proof for every bench tool) now extends to every new test.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slow CI runners fail in the same few ways.&lt;/strong&gt; Six flaky tests in the epic, all on macOS or Windows runners, all from the same causes: tight wall-clock bounds, a time reference taken after the action, waiting for the state but not for the log line, and egui_kittest&amp;rsquo;s default of 4 steps. Those rules now go in every story.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Windows and Linux benches are debt.&lt;/strong&gt; Every bench row of the epic passed on macOS; the Windows and Linux runs wait in &lt;a class="link" href="https://github.com/basteez/bonooru/issues/43" target="_blank" rel="noopener"
&gt;issue #43&lt;/a&gt;, because I don&amp;rsquo;t own either machine. M4 and M5 stay marked TODO in the roadmap until they pass. The next experiment is a Linux VM on the Mac with the bridge passed through over USB.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One open bug.&lt;/strong&gt; If I restart the app while the previous process is still closing the port, the new one hangs in &lt;code&gt;open()&lt;/code&gt; on macOS (&lt;a class="link" href="https://github.com/basteez/bonooru/issues/45" target="_blank" rel="noopener"
&gt;issue #45&lt;/a&gt;). The likely cause is the Darwin tty close waiting for output to drain while the bridge stops taking bytes. For now it&amp;rsquo;s a bench rule: never restart while one is running.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The benches were the best test of all.&lt;/strong&gt; H.33 found the occluded window, H.36 found the free-play pause menu and the terminal stealing focus. None of that shows up in a unit test.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class="mermaid-figure"&gt;
&lt;pre class="mermaid"&gt;xychart-beta
title &amp;#34;Review findings per story&amp;#34;
x-axis [&amp;#34;4.0&amp;#34;, &amp;#34;4.1&amp;#34;, &amp;#34;4.2&amp;#34;, &amp;#34;4.3&amp;#34;, &amp;#34;4.4&amp;#34;, &amp;#34;4.5&amp;#34;, &amp;#34;4.6&amp;#34;, &amp;#34;4.7&amp;#34;, &amp;#34;4.8&amp;#34;, &amp;#34;4.9&amp;#34;]
y-axis &amp;#34;findings&amp;#34; 0 --&amp;gt; 20
bar [10, 14, 10, 16, 17, 19, 16, 14, 15, 15]&lt;/pre&gt;
&lt;figcaption class="mermaid-caption"&gt;Code review findings per story in Epic 4 (about 146 in total, almost all fixed before the bench)&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;h2 id="how-its-made"&gt;How it&amp;rsquo;s made
&lt;/h2&gt;&lt;p&gt;I plan and build Bonooru with the &lt;a class="link" href="https://github.com/bmad-code-org/BMAD-METHOD" target="_blank" rel="noopener"
&gt;BMad Method&lt;/a&gt; and AI agents (Claude). Each story gets a file with its acceptance criteria, a table that says which tool and which log field will measure each number, and every open decision recorded; an agent implements it, three fresh-context reviewers attack it in parallel, and the findings are fixed or recorded. This epic, that was about 146 findings over 10 stories. Before every bench, the bench tools and runbooks are reviewed and dry-run against the simulated controller. What needs eyes and hands is mine: I looked at every screen and asked for changes, unplugged and replugged, and walked Link around with a mouse; the agent wrote the code and the tools and recorded the numbers as the log printed them.&lt;/p&gt;
&lt;p&gt;Epic 4 is 10 story PRs, plus the epic close and the retrospective. At the end, the repo has 44 firmware host tests (ctest, under AddressSanitizer and UndefinedBehaviorSanitizer) and &lt;strong&gt;446 Rust tests&lt;/strong&gt; (up from 105), across &lt;code&gt;ocb-core&lt;/code&gt;, &lt;code&gt;ocb-services&lt;/code&gt;, &lt;code&gt;ocb-app&lt;/code&gt;, &lt;code&gt;ocb-sim&lt;/code&gt; and the tools, green on Ubuntu, Windows and macOS. Story 4.0 (&lt;a class="link" href="https://github.com/basteez/bonooru/pull/39" target="_blank" rel="noopener"
&gt;PR #39&lt;/a&gt;) also closed two leftovers from Epic 3: the five firmware purity gates now share one rule file, and the controller&amp;rsquo;s debug STATUS counts the reply queue overflows. The bench numbers live in &lt;a class="link" href="https://github.com/basteez/bonooru/blob/d947123/docs/test-plan.md" target="_blank" rel="noopener"
&gt;&lt;code&gt;docs/test-plan.md&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id="next-up"&gt;Next up
&lt;/h2&gt;&lt;p&gt;The app can drive the Switch now, but it has nothing to play. Next epic, it learns to read music: open a song, squeeze it into the ocarina&amp;rsquo;s range, work out the fingering of every note, and play it back on the PC before anything gets near the console.&lt;/p&gt;
&lt;p&gt;Four epics in, Bonooru finally has a face, and it lets go of the buttons even when you can&amp;rsquo;t see it.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;This is an unofficial fan project for personal, offline fun. It is not affiliated with, endorsed or sponsored by Nintendo. The Legend of Zelda and Nintendo Switch are trademarks of Nintendo. No game code, assets or console modifications are involved.&lt;/em&gt;&lt;/p&gt;</description></item></channel></rss>