From 22ba8517d13b34d355942532e5c10439c81396ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Sun, 10 May 2026 01:46:39 -0400 Subject: [PATCH] Show + focus the Servo WebView so it stops dropping every input event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: Servo's WebView is hidden+unfocused by default. notify_input_event on a hidden WebView runs paint() hit-test, which returns no hit, and Servo silently absorbs the event as "already handled". Eleven prior commits all patched the GPUI side of input forwarding while every event landed in exactly that black hole. Fix: webview.show() + webview.focus() immediately after WebViewBuilder::build in create_webview_in_context, and again in navigate() only on the should_create_initial_document branch (the load() branch keeps existing visibility+focus, otherwise a background tab finishing navigation would steal focus from the foreground tab — Linus correctness ask). Also unblocks the sidecar binary build, which had been frozen at the May 9 13:53 stale binary because servo-engine feature was broken on two fronts: - ServoHost trait was missing the hover() method that the SoftwareServoHost impl declared (regression from "Plug three holes" commit eb58ce7). - Servo SDK renamed Key::Enter / Backspace / Tab / Escape / Delete / Arrow{Up,Down,Left,Right} / Home / End / Page{Up,Down} to Key::Named(NamedKey::*). keyboard.rs updated to match. Sidecar binary rebuilt: 335 MB at May 10 01:44. The earlier 11 commits were never reaching users because they couldn't recompile the sidecar without these two upstream-API repairs. --- crates/ely_servo_host/src/host.rs | 2 ++ crates/ely_servo_host/src/keyboard.rs | 28 +++++++++++++-------------- crates/ely_servo_host/src/runtime.rs | 10 ++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/crates/ely_servo_host/src/host.rs b/crates/ely_servo_host/src/host.rs index 14fcf90..5e21096 100644 --- a/crates/ely_servo_host/src/host.rs +++ b/crates/ely_servo_host/src/host.rs @@ -318,6 +318,8 @@ pub trait ServoHost { fn click(&mut self, request: MouseClickRequest) -> Result<(), ServoHostError>; + fn hover(&mut self, request: MouseHoverRequest) -> Result<(), ServoHostError>; + fn drag(&mut self, request: MouseDragRequest) -> Result<(), ServoHostError>; fn touch_tap(&mut self, request: TouchTapRequest) -> Result<(), ServoHostError>; diff --git a/crates/ely_servo_host/src/keyboard.rs b/crates/ely_servo_host/src/keyboard.rs index 2c33546..677f8d3 100644 --- a/crates/ely_servo_host/src/keyboard.rs +++ b/crates/ely_servo_host/src/keyboard.rs @@ -1,20 +1,20 @@ -use servo::{Code, Key}; +use servo::{Code, Key, NamedKey}; pub(crate) fn key_and_code_for_character(character: char) -> (Key, Code) { match character { - '\n' | '\r' => (Key::Enter, Code::Enter), - '\x08' => (Key::Backspace, Code::Backspace), - '\t' => (Key::Tab, Code::Tab), - '\x1b' => (Key::Escape, Code::Escape), - '\x7f' => (Key::Delete, Code::Delete), - '\u{F700}' => (Key::ArrowUp, Code::ArrowUp), - '\u{F701}' => (Key::ArrowDown, Code::ArrowDown), - '\u{F702}' => (Key::ArrowLeft, Code::ArrowLeft), - '\u{F703}' => (Key::ArrowRight, Code::ArrowRight), - '\u{F729}' => (Key::Home, Code::Home), - '\u{F72B}' => (Key::End, Code::End), - '\u{F72C}' => (Key::PageUp, Code::PageUp), - '\u{F72D}' => (Key::PageDown, Code::PageDown), + '\n' | '\r' => (Key::Named(NamedKey::Enter), Code::Enter), + '\x08' => (Key::Named(NamedKey::Backspace), Code::Backspace), + '\t' => (Key::Named(NamedKey::Tab), Code::Tab), + '\x1b' => (Key::Named(NamedKey::Escape), Code::Escape), + '\x7f' => (Key::Named(NamedKey::Delete), Code::Delete), + '\u{F700}' => (Key::Named(NamedKey::ArrowUp), Code::ArrowUp), + '\u{F701}' => (Key::Named(NamedKey::ArrowDown), Code::ArrowDown), + '\u{F702}' => (Key::Named(NamedKey::ArrowLeft), Code::ArrowLeft), + '\u{F703}' => (Key::Named(NamedKey::ArrowRight), Code::ArrowRight), + '\u{F729}' => (Key::Named(NamedKey::Home), Code::Home), + '\u{F72B}' => (Key::Named(NamedKey::End), Code::End), + '\u{F72C}' => (Key::Named(NamedKey::PageUp), Code::PageUp), + '\u{F72D}' => (Key::Named(NamedKey::PageDown), Code::PageDown), _ => (Key::Character(character.to_string()), printable_code(character)), } } diff --git a/crates/ely_servo_host/src/runtime.rs b/crates/ely_servo_host/src/runtime.rs index d4fc892..fa95614 100644 --- a/crates/ely_servo_host/src/runtime.rs +++ b/crates/ely_servo_host/src/runtime.rs @@ -148,6 +148,14 @@ impl ServoHost for SoftwareServoHost { .delegate(webview.delegate.clone()) .url(url) .build(); + // Fresh WebView is hidden+unfocused by default; without this + // pair Servo's hit-test silently drops every input event. + // Existing WebViews keep their visibility/focus across loads + // — calling focus() here every navigation would let a + // background tab finishing a load steal focus from the + // foreground tab. + webview.webview.show(); + webview.webview.focus(); } else { webview.webview.load(url); } @@ -357,6 +365,8 @@ impl SoftwareServoHost { let webview = WebViewBuilder::new(&self.servo, rendering_context.clone()) .delegate(delegate.clone()) .build(); + webview.show(); + webview.focus(); self.webviews.insert( webview_id.clone(),