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) {