From e8f86b0ac2832aebc250bf4296fd1bdaf9f93d1f Mon Sep 17 00:00:00 2001 From: Mollusk Date: Mon, 25 May 2026 03:50:02 -0400 Subject: [PATCH] feat(gui): focus the viewer code field when the View screen opens Entering View now grabs keyboard focus on the code field (once, via a one-shot flag so it doesn't steal focus every frame), so the user can paste or type the share code immediately without clicking into it first. Co-Authored-By: Claude Opus 4.7 --- src/gui/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gui/mod.rs b/src/gui/mod.rs index e0bc247..dd7519b 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -211,6 +211,9 @@ struct ViewerState { /// Short endpoint id we're dialing, decoded from the ticket at Connect. /// Shown in the "Connecting to …" line so a dead host is identifiable. connecting_to: Option, + /// Set when the View screen opens so the code field grabs focus once + /// (cleared on use, so it doesn't steal focus every frame). + focus_ticket: bool, error: Option, } @@ -613,6 +616,11 @@ impl PixelPassApp { ) }) .inner; + // Grab focus once on screen entry so the user can paste/type straight + // away without first clicking into the field. + if std::mem::take(&mut self.viewer.focus_ticket) { + ticket_resp.request_focus(); + } // Enter in the field connects (gated on a decodable code below). let enter_pressed = ticket_resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)); @@ -702,6 +710,7 @@ impl PixelPassApp { { self.viewer.ticket_input = text.trim().to_string(); } + self.viewer.focus_ticket = true; } fn start_viewer(&mut self, ctx: egui::Context) {