From 9241252c6765738d9b5f0ac31f5e08b5ac1a5c3e Mon Sep 17 00:00:00 2001 From: Liu Jie Date: Wed, 26 Apr 2023 10:40:58 +0800 Subject: [PATCH] update keyboard focus when grabbing popup closed For example, a wayland qt widget has an qlineedit with qcompleter. 1. Input some words make qcompleter's popup window show. PopupInputFilter::keyEvent will set keyboard focus on the qcompleter's popup window. 2. Continue to press a key which can make the qcompleter's popup window hidden and do not release it. 3. Press the backspace key to make the qcompleter's popup window show again. Result: Qcompleter's popup window will be created as an independent xdg_toplevel.This is because QT sets the surface of the focused window as the transient parent window of the popup window. If not found, QT will create a independent toplevel window. After step 2, the focused window is the qcompleter's popup window which has be hidden. QT can not find the transient parent of the qcompleter's popup window, finally creat the popup window as a independent xdg_toplevel. Signed-off-by: Liu Jie --- src/popup_input_filter.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/popup_input_filter.cpp b/src/popup_input_filter.cpp index c5a9e32dea..381d29ea91 100644 --- a/src/popup_input_filter.cpp +++ b/src/popup_input_filter.cpp @@ -7,6 +7,7 @@ #include "popup_input_filter.h" #include "input_event.h" #include "internalwindow.h" +#include "keyboard_input.h" #include "wayland/seat_interface.h" #include "wayland_server.h" #include "window.h" @@ -31,6 +32,13 @@ void PopupInputFilter::handleWindowAdded(Window *window) m_popupWindows << window; connect(window, &Window::closed, this, [this, window]() { m_popupWindows.removeOne(window); + // Move focus to the parent popup. If that's the last popup, then move focus back to the parent + if (!m_popupWindows.isEmpty() && m_popupWindows.last()->surface()) { + auto seat = waylandServer()->seat(); + seat->setFocusedKeyboardSurface(m_popupWindows.last()->surface()); + } else { + input()->keyboard()->update(); + } }); } }