Rewrite the event dispatcher to use QWasmSuspendResumeControl
for asyncify suspend/resume.
This includes using the following helper classes which provides
additional functionality on top of QWasmSuspendResumeControl.
- QWasmTimer: manages native timers on the main thread
- QWasmEventHandler and qstdweb::EventCallback: input events
- QWasmAnimationFrameHandler: animation frame events
Initialization differs slightly, depending on if QtGui and
the QPA machinery is in use, or of the app is a QtCore only
application. In the former case, QWasmSuspendResumeControl is
created early by QWasmIntegration in order to support registering
event handlers at startup, before the event dispatcher has
been created.
processEvents() now actually processes native events. This is
done by running a suspend-resume loop until the native event
queue has been exhausted. If WaitForMoreEvents is specified then
processEvents() will, in addition, also suspend and wait for
additional native events.
Timers on secondary threads are now managed by modifying the
wait condition timeout, instead of proxying timers to the main
thread. In effect secondary threads will now sleep until the
next timer should fire, and then wake up and process that timer.
Change-Id: I20e8afb6b67c64a7c52dbd89e9c50ffadba39594
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
requestUpdateHold was not getting enabled properly in some
cases, in particular when using a custom html file to load
the application.
The assert on g_mainThreadEnvetDispatcher is also asserting,
with a following dereference of a null pointer.
Pick-to: 6.8
Change-Id: Ibf77d90b84f8319a894e2df34a134d2e4265fe05
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
emsdk 3.1.62 changes the EM_BOOL type from int to bool. We were
using int in two places in the wasm platform plugin.
Use EM_BOOL instead to stay compatible with emsdk editions earlier
and and later than 3.1.62
Pick-to: 6.8 6.7
Change-Id: I837e76f869225859643dd5a98a28a1eefb5f14a4
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Even Oscar Andersen <even.oscar.andersen@qt.io>
There are two problems
1) internal (not toplevel) windows needs to have the frameLess attribute
set. Without this attribute the window is not visible
2) The backingstore needs to use the correct window, if not the
symptoms are that the display is not always correctly updated.
Seen in the qtdoc/examples/demos/documentviewer demo
Fixes: QTBUG-125856
Change-Id: I040d963c0c130214cc70a607090faa006c02f981
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Qt Gui expects that the platform sends DPR update
notifications if the DPR value has changed, before
sending expose/paint events or delivering update
request events.
The most straightforward implementation is to send
the DPR update event unconditionally and let Qt Gui
determine if the DPR value has changed, especially
if the native platform does not provide DPR change
events.
Pick-to: 6.6 6.7
Change-Id: Ica7a24a458b3b01f1c7b2e1e09d342114dc71331
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Before this fix, such screens would not render due to requestUpdateHold
is initialized to true and never reset.
The fix is to change the requestUpdateHold member to be a static
variable, so that it can be read by screens added after
requestUpdateHold has been called.
Also, add a test that would fail without this fix
Change-Id: Idf2ac916766a03480272cd550f9d1ab7fc5c5158
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
onLoaded and the initial expose/paint should be sequenced
such that onLoaded is fired first, followed by the expose.
This makes sure that we don't spend any time on painting
frames before Qt is completely initialized.
Add a "requestUpdateHold" mode to QWasmCompositor (initially
on) which disables requestUpdate calls, as well
as releaseRequestUpdateHold() which enables requestUpdate
calls again. This is a one-way transition; the mode
can't be enabled again.
This amends commit f2e22774 which implemented the concept
of startup tasks, where onLoaded can be delayed until
for instance font loading has been completed. After
this commit the expose event and initial commit will
be delayed as well.
Change-Id: Icc784306726174fbabe8785d54485860e968745a
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
Setting parents for WASM platform windows is now supported. This means
that windows now reside in a hierarchical window tree, with the screen
and individual windows being nodes (QWasmWindowTreeNode), each
maintaining their own child window stack.
The divs backing windows are properly reparented in response to Qt
window parent changes, so that the html structure reflects what is
happening in Qt.
Change-Id: I55c91d90caf58714342dcd747043967ebfdf96bb
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Don't show a blank frame on app startup.
The wasm update request system supports two types of update
requests: Expose and UpdateRequest. It can happen that both
types of request are made for a single window, in which case
the current code prefers UpdateRequest, since those must be
delivered in order to keep QWindow in a consistent state.
However, if the window is visible but not yet exposed then
delivering the update request will not make the window paint
anything, and we end up with a blank frame.
Ideally this should be handled elsewhere and QWindow::requestUpdate()
should not be called for non-exposed windows, but in the
case does happen then sending an expose here allows us to
recover.
Pick-to: 6.5 6.6
Change-Id: Ib53050c33ad1769ea9b9ad678896af15f87a7ecb
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Removed the two identical functions and directly call the `static_cast`
in their place. This is to resolve a build issue when doing unity build.
Pick-to: 6.5
Task-number: QTBUG-109394
Change-Id: I174b601e06c4acdea45cc66495c09aafba6f48f6
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Some dead code was left after transferring event support to QWasmWindow.
Remove it now.
Change-Id: I40e15bc62bcbb6fff071f53c45223c8a2d12e348
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Now that the browser compositor is used for rendering windows, the
method has become redundant, as windows that got resized during screen
resize will schedule their updates directly with the compositor.
This also fixes an assertion in QPlatformWindow::hasPendingUpdateRequest
as no windows without pending update requests will now have update
requests delivered.
Also offers a significant speedup with multiple restored window setups.
Fixes: QTBUG-112289
Change-Id: Ie5dff69c04d66c4aef8351adef0da8530daf7ab8
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
The window stack will now upkeep three groups of windows, always
on bottom (1), regular (2), always on top (3). Windows belonging to
(3) will always appear on top of (2) and (1), and windows from (2) will
always appear on top of (1).
The first window created in the application gets the (1) status, which
is in line with the root window mechanism used before.
Activation has now been decoupled from the top position on the window
stack as a window in (1) or (2) may be active, in spite of the top
window belonging to a higher group.
Fixes: QTBUG-110098
Change-Id: I51f4d2d47163fab26ce5ef28f7a4f23a522c7f91
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Fractional mouse movements may be reported on hi-dpi. Floating point
event fields help us perform correct calculations in line with the
web platform.
Change-Id: Ic0c457db408c2bf28179ffcfdb032cde64ca8bbd
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
Not all touch points are changed as per emscripten event, so we
do not need to remove or add them to the touch event
Fixes: QTBUG-110941
Pick-to: 6.5
Change-Id: I4799ef0c05750a36361836698eb83e5bf844ece8
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Also, use the embind approach as the rest of the events do, and
introduce a KeyEvent class which simplifies and streamlines event
support.
The event translator has been given a more specific function of
just handling the dead keys. Rest of the translation functionality
is coded directly in KeyEvent for more encapsulation.
Change-Id: I11b0262fc42fe920206ecc6de0d434b9d9ab9998
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Align the wheel event handling with other events - move the handler to
wasm window and create a C++ wrapper class for the js wheel event.
Fixes: QTBUG-109622
Change-Id: I915e502de7c0784ec9a6745a90ddcda062e91b2b
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Drop events are now handled in the wasm window element, which allows
the browser to select the drop target automatically. This also fixes
the case where drop data transfer finishes reading when a window
has already been closed and destroyed - the cancellation flag is now
owned by window so it gets invalidated as soon as window is gone.
The code has also been structured with a new DragEvent passthrough.
Fixes: QTBUG-109581
Change-Id: Ie3eb7446e2181fd540517f39397e8b35f111d009
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
The two-step destruction we used to employ is needed as destroying
a screen which contains a window crashes.
Pick-to: 6.5
Change-Id: I722828be5408a7f079d66e845eeee34ed19cbf34
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
It is now not the screen that handles all of the events and relays
them to individual windows, but the window elements themselves.
This allows us to get rid of manual window targeting logic and let
the browser do its job.
Fixes: QTBUG-107217
Pick-to: 6.5
Change-Id: I4dc5a74b1343f027f72c1da4623b99cd28bfbb38
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
The compositor is redundant in the process of moving the window.
Have the title bar react to move all by itself.
Additionally, a clearer structure in the window was introduced.
The non-client area has been extracted into a separate class, as
was the icon store and free DOM functions used across files.
Since it was now easy, made the window maximize/restore on double click
on the title element.
Fixes: QTBUG-107626
Pick-to: 6.5
Change-Id: Iba7f207e46806ae7162656965892ae5a48ac5ebe
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Based on existing code, it appears that it's always
preferred in wasm to use synchronous delivery
(<QWindowSystemInterface::SynchronousDelivery>),
however, we can simply define this as the default mode
of operation, which will make these unnecessary.
Change-Id: Ia4c78593333e314f91efb266268917317794e2f5
Pick-to: 6.5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
The QWasmScreen's top left coordinate does not precisely translate
to correct page coordinates, especially when fixed position is used
and page margins are set. Also, this is wrong in complicated setups
with e.g. multiple nested elements.
Therefore, to get the correct coordinates in pointer event handlers,
we have to assume the local coordinates of the screen, and translate
those to the (possibly incorrect) coordinates that QWasmScreen thinks
it has in page.
It is another problem to fix the wrong coordinates QWasmScreen thinks
it has in the page.
This has been checked with complicated setups with screens in scroll
containers, screens with fixed position, screens with relative position,
with and without body margins etc.
Change-Id: I749f2507fec7ae278b6f9d7d13ae288e65472dba
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
m_lastMouseTargetWindow pointer may be kept even though the window
has been removed. This leads to memory access problems.
Change-Id: Ie83b607bf5a815540605671dd1d1ad37288074c5
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Introducing a div outline which handles the resize events by itself.
Manual computations in wasm compositor are no longer needed.
The outline reacts to setting css variables (border-width,
resize-outline-width), it sets the correct cursors using css and
always keeps the correct size.
Fixes: QTBUG-107498
Change-Id: I6b0564632af5e17e464fe93a3dfa20820c624292
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Currently, the compositor gets enabled/disabled based on the last
constructed window's surface type. This causes non-OpenGL windows not to
be displayed if any OpenGL window is created last.
The compositor should scan for any non-openGL windows on any change
to the window set to decide if it needs to be disabled or not.
Change-Id: I037470e39a3fbae50fd3a4e29cb6615130d7b114
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Make the browser compositor draw the window non-client area (using css
+ html). Get rid of OpenGL usage in non-OpenGL windows and use canvas
2d context instead to blit the texture (QImage).
Also, as part of the change, remove the deprecated canvas element support
in QScreen.
Fixes: QTBUG-107116
Fixes: QTBUG-107219
Change-Id: I65f0d91831c806315685ca681ac0e416673f5cd5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
Reviewed-by: David Skoland <david.skoland@qt.io>
There might not be a window at the pointer event position on a WASM
screen, especially when the main window is not fullscreen.
Change-Id: I29aac8c410fdf2bf97cd1ed12433d87e18b4a354
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
- Remove the manual destroy methods - destructor should handle
destruction
- Remove the unused enum QWasmStateFlag
- Make public API private where possible
- Adjust handleTouch->processTouch to keep consistency with other
process methods
- Remove dead fields in compositor
- Don't keep a dead screen entry in m_screens in qwasmintegration
Change-Id: I98caf4dbdda5ebd25c4a9c22a40140c7ed1d7aa7
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
IDEs (vscode) have problems with missing includes.
Change-Id: I2618aaaf79c81a2c3566682e13caf31133ece631
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Using two different resizing techniques (one in QSizeGrip, one in
QWasmCompositor) leads to strange behavior while resizing wasm windows.
Redirect the QSizeGrip's resize to wasm's compositor resize (which might
be considered system resize) to avoid that.
Change-Id: Idfc062643caac3ceee879bfb875d943aade28378
Reviewed-by: David Skoland <david.skoland@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
The pointer events weren't captured previously
if, for example, mouse was pressed inside the window
and released outside of the window.
Pick-to: 6.4
Fixes: QTBUG-71948
Change-Id: Ie50e5c132fa03046f0c5b321c35a58cb9f34b67a
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
During the previous refactoring, two exceptions that triggered
native copy/paste events were omitted.
Fixes: QTBUG-106668
Pick-to: 6.4.0 6.4
Change-Id: Ie61dd6a0c1d9d2fdd47bd94be055d0221feae25b
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
The event should be propagated when the native clipboard is available.
A recent regression caused it to be suppressed, which resulted in lack
of copy/paste capabilities.
Pick-to: 6.4 6.4.0
Change-Id: I030a31aa0951c3813ce1d38da9a6526010b3bfc8
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Therefore, no translation to screen coords is needed.
Task-number: QTBUG-106031
Pick-to: 6.4
Change-Id: I0dbbc5e4df79d85f9c6ef47f09ea54f19b67d2d7
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This fixes dock widget undocking - previously, without the capture, any
widget that the mouse accidentally entered would get the event,
resulting in re-docking problems, cursor issues etc.
Fixes: QTBUG-105621
Pick-to: 6.4
Change-Id: Ia1f2c91578018f2ae9df903bc0730200ede17d32
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
The title bar drawing routines belong in QWasmWindow, not in the
compositor. This provides better encapsulation as many properties
don't have to be leaked from QWasmWindow. Extensibility will also
improve.
Change-Id: If73dd4e87602f62bff0de92e1405f89e7a9f3b43
Pick-to: 6.4
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
The types essentially do the same job - the one that is more general
should be used, the other - removed, as it is redundant.
Change-Id: Iec09d3311681abce1405fcf8c2cebfb72f3fd51c
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
- Moved the modal window resolution to
QWasmWindow::requestActivateWindow so that multiple async activation
events are not issued in unpredictable patterns.
- Request activation on added windows and on stack top in case of
window removal
Pick-to: 6.4
Change-Id: I6f02cf1b7e83abb7961caf311ffc83e91c8bf810
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
The method is not used anywhere. Remove it to save tens of LOCs.
Change-Id: Id853d12d238aa30eb197ab3fed7ccc24a2213e31
Pick-to: 6.4
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
The invalidate on window move is redundant - the previous texture can
be reused for the window. Just request another refresh on the compositor
and don't update the window texture. Makes window moves smoother.
Pick-to: 6.4
Change-Id: Ied2922a000d3c8e6143e64d029154d74bc4f3480
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This radically speeds up window resizing and dragging.
Fixes: QTBUG-105709
Pick-to: 6.4
Change-Id: I844601a5b139d21024db0c373482af18f350d0eb
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
The old stack structure used to keep track of windows has been improved
to conform to the actual windowing assumptions: there shall be one root
window, which is always at the bottom. The first created window
immediately becomes the root window. Should the root window be removed,
all windows are non-root, i.e. any of them can become the top-level window
Fixes: QTBUG-105094
Pick-to: 6.4
Change-Id: Ic553244fa9f5bc3ee590b702935e66cfc62d5f8f
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Changed the behavior in which key events are delivered to targets.
Before the change, in case of a EMSCRIPTEN_EVENT_KEYUP event, the key
code and text were not filled in correctly as they should. This resulted
in wrong behavior when event targets expected these codes being available.
Fixes: QTBUG-105213
Change-Id: Ie66b5d6d395d08af655fcb00f1f616ad43d6bea4
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Change listing:
- change names of abbreviated structures/variables (e.g. KeyTbl
-> WebToQtKeyCodeMappings)
- add constants for commonly used magic strings ("Dead", StringTerminator)
- use common idioms for common tasks (find_if, std::optional)
- use binary search as facilitated by the sorted array instead of a full
search - this optimizes the code at no cost
- remove dead code (double translateEmscriptKey in
QWasmEventTranslator::getKey, remove sticky dead key support as it was
write-only, remove the dead setIsMac and g_usePlatformMacSpecifics,
remove the dead getWindowAt).
- cull the public interface on QWasmEventTranslator as some functions are
only used internally (translateEmscriptKey)
- simplify / shorten functions by short-circuiting
- modernize definitions (= default)
- auto-format the changes using clang-format
The file is now much easier to read and understand.
Change-Id: I5ea2bdafd9b9abc009feeb5516ddd87fb0ca212e
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Use a well-known idiom for finding a matching window in the window stack
(std::find_if)
Change-Id: I677ef6ad8ee88bbd9eee1405be592ec2527ca3b9
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
No fields in QWasmCompositedWindow, apart from visible, are used for any
computation. They were write-only. Remove the class entirely and create
a hash of visibility state instead.
Fixes for z-order will follow.
Change-Id: Icb7ff1865d1f9a67c0fde43cfa331ca1242ebcaa
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
QWasmCompositor now delivers non-client area mouse events to windows as
it should, which fixes a lot of issues with window manipulation. One of
such issues is re-docking of dock widgets.
Fixes: QTBUG-105092
Change-Id: I9de45b7e1b1a80b64387031eb0cc0b31a4be2571
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Window dragging has been considerably improved by replacing the mouse
events by pointer events and placing a pointer lock on WASM canvas, so
that off-browser window events are delivered to us.
Translation of the drag origin has been limited to inside the canvas, so
that a window cannot be dragged so far that it becomes offscreen and is
unreachable.
Change-Id: Id177c630a6466f04464a513371d6b97d3a098b6a
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>