From 0d8cde441d58b192fd6d74de7af9b81a6c5fd6e0 Mon Sep 17 00:00:00 2001 From: Ivy233 Date: Mon, 18 May 2026 11:39:14 +0800 Subject: [PATCH] fix: enforce baseLayer focus when launcher becomes visible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To address the low-probability issue where the launcher loses keyboard focus upon opening (preventing direct text input), this commit explicitly calls forceActiveFocus() on the baseLayer (InputEventItem) when LauncherController.visible becomes true. The focus acquisition check is deferred via Qt.callLater() to avoid false warnings caused by QML's asynchronous focus event processing. Unlike previous attempts that focused the searchEdit directly (which violated the design requirement of not activating the search bar visually upon open), this approach ensures the root item safely receives key events and forwards them to the search edit without triggering unwanted visual states. 修复启动器以极低概率打开时丢失键盘焦点(无法直接输入文本)的问题。 在启动器显示(LauncherController.visible 为 true)时,显式调用 baseLayer (InputEventItem) 的 forceActiveFocus() 强制获取活跃焦点。 焦点获取检查通过 Qt.callLater() 延迟执行,避免因 QML 焦点事件的 异步处理特性导致的误报警告。 与之前直接聚焦 searchEdit 的尝试(违背了打开时不直接激活搜索框 的设计要求)不同,此方法确保根节点能安全地接收按键事件并将其转发 给搜索框,同时不会触发不需要的视觉激活状态。 PMS: BUG-301743 --- qml/FullscreenFrame.qml | 11 +++++++++-- qml/windowed/WindowedFrame.qml | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/qml/FullscreenFrame.qml b/qml/FullscreenFrame.qml index 1c1f6cf4..51cbf752 100644 --- a/qml/FullscreenFrame.qml +++ b/qml/FullscreenFrame.qml @@ -887,8 +887,15 @@ InputEventItem { Connections { target: LauncherController function onVisibleChanged() { - // only do these clean-up steps on launcher get hide - if (LauncherController.visible) return + if (LauncherController.visible) { + baseLayer.forceActiveFocus() + Qt.callLater(() => { + if (!baseLayer.activeFocus) { + console.warn("[LaunchpadFocus] FullscreenFrame: BUG_WARNING - baseLayer failed to acquire activeFocus after forceActiveFocus()!") + } + }) + return + } // clear searchEdit text searchEdit.text = "" if (listviewPage.currentItem) { diff --git a/qml/windowed/WindowedFrame.qml b/qml/windowed/WindowedFrame.qml index 2b7eda8b..10df3b08 100644 --- a/qml/windowed/WindowedFrame.qml +++ b/qml/windowed/WindowedFrame.qml @@ -305,8 +305,15 @@ InputEventItem { Connections { target: LauncherController function onVisibleChanged() { - // only do these clean-up steps on launcher get hide - if (LauncherController.visible) return + if (LauncherController.visible) { + baseLayer.forceActiveFocus() + Qt.callLater(() => { + if (!baseLayer.activeFocus) { + console.warn("[LaunchpadFocus] WindowedFrame: BUG_WARNING - baseLayer failed to acquire activeFocus after forceActiveFocus()!") + } + }) + return + } // clear searchEdit text bottomBar.searchEdit.text = ""