From be2371deb0fd3a12a6f93c147cbb6c64799829e5 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 21 Oct 2026 23:54:40 +0000 Subject: [PATCH] Focus the drawer's search and raise the keyboard when the drawer opens Swiping down to the app drawer puts the cursor in its search box. A WebView won't show the keyboard for a script focus(), so the shell does it through new Android.showKeyboard/hideKeyboard bridge calls; closing the drawer hides it again. Pick mode (adding apps) stays keyboard-free. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_0169wSWnZqnXBsJKMPAiCCNG --- .../java/dev/ultra/launcher/MainActivity.java | 17 ++++++++++++++ tests/e2e.cjs | 1 + web/index.html | 22 ++++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java index 5e23586..60b2135 100644 --- a/android/app/src/main/java/dev/ultra/launcher/MainActivity.java +++ b/android/app/src/main/java/dev/ultra/launcher/MainActivity.java @@ -35,6 +35,7 @@ import android.view.View; import android.view.ViewConfiguration; import android.view.Window; import android.view.WindowInsets; +import android.view.inputmethod.InputMethodManager; import android.webkit.JavascriptInterface; import android.webkit.RenderProcessGoneDetail; import android.webkit.WebResourceRequest; @@ -751,6 +752,22 @@ public class MainActivity extends Activity { HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING)); } + /** The page focused the drawer's search box; show the keyboard for it. */ + @JavascriptInterface public void showKeyboard() { + main.postDelayed(() -> { + web.requestFocus(); + InputMethodManager imm = getSystemService(InputMethodManager.class); + if (imm != null) imm.showSoftInput(web, InputMethodManager.SHOW_IMPLICIT); + }, 50); + } + + @JavascriptInterface public void hideKeyboard() { + main.post(() -> { + InputMethodManager imm = getSystemService(InputMethodManager.class); + if (imm != null) imm.hideSoftInputFromWindow(web.getWindowToken(), 0); + }); + } + @JavascriptInterface public void openSettings() { main.post(() -> startIntent(new Intent(Settings.ACTION_SETTINGS))); } diff --git a/tests/e2e.cjs b/tests/e2e.cjs index 0e9dbaa..135b957 100644 --- a/tests/e2e.cjs +++ b/tests/e2e.cjs @@ -77,6 +77,7 @@ const BASE = process.env.BASE || "http://localhost:8000"; await swipe(200, 500); await p.waitForSelector(".drawer", { timeout: 2000 }); assert.equal(await p.$$eval("[data-wid]", (ws) => ws.length), 0); + assert.ok(await p.$eval(".drawer input", (i) => i === document.activeElement), "opening the drawer focuses its search"); await p.fill(".drawer input", "ma"); await settle(); assert.deepEqual(await p.$$eval(".apps .name", (ns) => ns.map((n) => n.textContent)), ["Gmail", "Maps"]); await p.press(".drawer input", "Enter"); await settle(); diff --git a/web/index.html b/web/index.html index a2d5d9b..a302c33 100644 --- a/web/index.html +++ b/web/index.html @@ -32,6 +32,8 @@ openSettings: () => toast("Open system settings"), pickWallpaper: () => toast("Pick a wallpaper"), openRecents: () => toast("Show open windows"), + showKeyboard: () => {}, + hideKeyboard: () => {}, haptic: () => navigator.vibrate?.(10), }; if (!window.Android) document.documentElement.classList.add("demo"); @@ -54,6 +56,24 @@ }; let excluded = "[]"; + // Opening the drawer puts the cursor in its search box and raises the keyboard + // (a WebView won't show it for a focus() the user didn't tap, so the shell does). + // Picking apps to add is for scrolling, so that stays keyboard-free. + let drawerOpen = false; + const watchDrawer = () => { + const d = document.querySelector(".drawer"); + if (!!d === drawerOpen) return; + drawerOpen = !!d; + if (d) { + if (d.classList.contains("picking")) return; + d.querySelector(".drawer-head input")?.focus({ preventScroll: true }); + host.showKeyboard?.(); + } else { + document.activeElement?.blur?.(); + host.hideKeyboard?.(); + } + }; + // Icons: each gets its src from here. On a phone the // shell draws icons on its own thread and hands them back as data: URIs in batches // (ultraIcons), so the WebView never loads icons through request interception. @@ -95,7 +115,7 @@ window.ultraIcons = gotIcons; // the shell calls this before ultraHome exists, too const app = await mount("#app", "./app.wasm", { - onRender: () => { fillIcons(); place(); }, + onRender: () => { fillIcons(); place(); watchDrawer(); }, imports: ({ strs }) => ({ launch: (h) => host.launch(strs[h]), app_info: (h) => host.appInfo(strs[h]),