From a1704ee6aa07e8bca7a1c4cf965f40a8255ffbc8 Mon Sep 17 00:00:00 2001 From: Mikolaj Boc Date: Wed, 22 Feb 2023 09:50:54 +0100 Subject: Correctly focus WASM windows on show MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since first requestActivate may happen before the window div is actually displayed on-screen, we need to sync Qt's activation state with DOM as soon as DOM element becomes visible. Focusing an invisible element is impossible. Fixes: QTBUG-79934 Change-Id: I04cf9b4ead006c9b8b135b3b6967d7938c581833 Reviewed-by: Morten Johan Sørvig --- .../wasm/qwasmwindow/qwasmwindow_harness.cpp | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp') diff --git a/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp b/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp index 3a8f0693dfd..eda557e195f 100644 --- a/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp +++ b/tests/manual/wasm/qwasmwindow/qwasmwindow_harness.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include + +#include #include #include #include @@ -26,6 +28,26 @@ private: Q_UNUSED(ev); delete this; } + + void keyPressEvent(QKeyEvent *event) final + { + auto data = emscripten::val::object(); + data.set("type", emscripten::val("keyPress")); + data.set("windowId", emscripten::val(winId())); + data.set("windowTitle", emscripten::val(title().toStdString())); + data.set("key", emscripten::val(event->text().toStdString())); + emscripten::val::global("window")["testSupport"].call("reportEvent", std::move(data)); + } + + void keyReleaseEvent(QKeyEvent *event) final + { + auto data = emscripten::val::object(); + data.set("type", emscripten::val("keyRelease")); + data.set("windowId", emscripten::val(winId())); + data.set("windowTitle", emscripten::val(title().toStdString())); + data.set("key", emscripten::val(event->text().toStdString())); + emscripten::val::global("window")["testSupport"].call("reportEvent", std::move(data)); + } }; using namespace emscripten; @@ -128,7 +150,19 @@ void createWindow(int x, int y, int w, int h, std::string screenId, std::string window->setTitle(QString::fromLatin1(title)); window->setGeometry(x, y, w, h); window->setScreen(*screen_it); - window->showNormal(); +} + +void setWindowVisible(int windowId, bool visible) { + auto windows = qGuiApp->allWindows(); + auto window_it = std::find_if(windows.begin(), windows.end(), [windowId](QWindow *window) { + return window->winId() == WId(windowId); + }); + if (window_it == windows.end()) { + qWarning() << "No such window: " << windowId; + return; + } + + (*window_it)->setVisible(visible); } EMSCRIPTEN_BINDINGS(qwasmwindow) @@ -136,6 +170,7 @@ EMSCRIPTEN_BINDINGS(qwasmwindow) emscripten::function("screenInformation", &screenInformation); emscripten::function("windowInformation", &windowInformation); emscripten::function("createWindow", &createWindow); + emscripten::function("setWindowVisible", &setWindowVisible); } int main(int argc, char **argv) -- cgit v1.2.3