diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-09-13 11:09:48 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-09-15 17:06:10 +0200 |
commit | 088b364e4b220ffe3acf28842444c6a80601f2bb (patch) | |
tree | 6d9715ea8e843d16560ec3bbe0dd178c2975ab79 /src | |
parent | 46039092bdabcea76f5899b492e3429d6b571bfa (diff) |
QEventDispatcherWasm: handle EventLoopExec
Call emscripten_set_main_loop like the old GUI event
dispatcher did, with one difference that requestAnimationFrame
updates are now no longer handled by the event dispatcher.
Change-Id: If02d90ae9c45d7b38999567d733a237af842cded
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_wasm.cpp | 18 | ||||
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_wasm_p.h | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index 61b49fdc55..7632b2ca55 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -208,6 +208,8 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) if (flags & QEventLoop::DialogExec) handleDialogExec(); + else if (flags & QEventLoop::EventLoopExec) + handleEventLoopExec(); if (!(flags & QEventLoop::ExcludeUserInputEvents)) pollForNativeEvents(); @@ -364,6 +366,22 @@ void QEventDispatcherWasm::wakeUp() emscripten_async_call(&QEventDispatcherWasm::callProcessEvents, this, 0); } +void QEventDispatcherWasm::handleEventLoopExec() +{ + // Start the main loop, and then stop it on the first callback. This + // is done for the "simulateInfiniteLoop" functionality where + // emscripten_set_main_loop() throws a JS exception which returns + // control to the browser while preserving the C++ stack. + // + // Note that we don't use asyncify here: Emscripten supports one level of + // asyncify only and we want to reserve that for dialog exec() instead of + // using it for the one qApp exec(). + const bool simulateInfiniteLoop = true; + emscripten_set_main_loop([](){ + emscripten_pause_main_loop(); + }, 0, simulateInfiniteLoop); +} + void QEventDispatcherWasm::handleDialogExec() { #if !QT_HAVE_EMSCRIPTEN_ASYNCIFY diff --git a/src/corelib/kernel/qeventdispatcher_wasm_p.h b/src/corelib/kernel/qeventdispatcher_wasm_p.h index 75db11723c..7eea28b052 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm_p.h +++ b/src/corelib/kernel/qeventdispatcher_wasm_p.h @@ -90,6 +90,7 @@ private: bool isMainThreadEventDispatcher(); bool isSecondaryThreadEventDispatcher(); + void handleEventLoopExec(); void handleDialogExec(); void pollForNativeEvents(); bool waitForForEvents(); |