From 6c7e121738dbf22b1b0acbe2a63481c54053f014 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 20 Jan 2020 11:08:21 +0000 Subject: Revert "Do not read Xft.dpi on platforms that shouldn't be using Xft settings" This reverts commit c7fec68e1936576070d0fbac6cf40b818366d298. This commit introduces a behavioural change within 5.14. It's designed to special case plasma with a fix, but in practice it will cause us more problems. It will break: - font size on plasmashell and kwin on xcb which do not use Qt scaling - xwayland on projectors/headless tests The original bug of double scaling that this was trying to fix is fixed by b31852c4caa36cc564e25adbdacfa534e1dfe7c0 which is in 5.14.1 which works in combination with the environment variables we set in plasma so this is not needed. Fixes: QTBUG-81532 Change-Id: I2f1b8ae4aecf7b80be4dbee812e6b4a64244fb1f Reviewed-by: Allan Sandfeld Jensen --- src/plugins/platforms/xcb/qxcbscreen.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 44d0bb3f55..e937464c62 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -41,7 +41,6 @@ #include "qxcbwindow.h" #include "qxcbcursor.h" #include "qxcbimage.h" -#include "qxcbintegration.h" #include "qnamespace.h" #include "qxcbxsettings.h" @@ -50,7 +49,6 @@ #include #include -#include #include #include #include @@ -368,15 +366,6 @@ static QFontEngine::SubpixelAntialiasingType parseXftRgba(const QByteArray& stri void QXcbVirtualDesktop::readXResources() { - const QPlatformServices *services = QXcbIntegration::instance()->services(); - bool useXftConf = false; - if (services) { - const QList desktopEnv = services->desktopEnvironment().split(':'); - useXftConf = desktopEnv.contains("GNOME") || desktopEnv.contains("UNITY") || desktopEnv.contains("XFCE"); - } - if (!useXftConf) - return; - int offset = 0; QByteArray resources; while (true) { -- cgit v1.2.3 From 6c23f006e07b774b0eef863cccd36a992274ca32 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 Jan 2020 16:34:15 +0100 Subject: Windows QPA: Prospective fix for crash occurring when changing screen during session lock Check on currentScreen in QWindowsWindow::checkForScreenChanged(). Fixes: QTBUG-80436 Change-Id: I19e34b9e2c32c9cfc8e5e5b758783c0ab89d5556 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowswindow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index ea91e3bb2d..496b18ba1a 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1935,12 +1935,13 @@ void QWindowsWindow::checkForScreenChanged(ScreenChangeMode mode) if (newScreen == nullptr || newScreen == currentScreen) return; // For screens with different DPI: postpone until WM_DPICHANGE - if (mode == FromGeometryChange + // Check on currentScreen as it can be 0 when resuming a session (QTBUG-80436). + if (mode == FromGeometryChange && currentScreen != nullptr && !equalDpi(currentScreen->logicalDpi(), newScreen->logicalDpi())) { return; } qCDebug(lcQpaWindows).noquote().nospace() << __FUNCTION__ - << ' ' << window() << " \"" << currentScreen->name() + << ' ' << window() << " \"" << (currentScreen ? currentScreen->name() : QString()) << "\"->\"" << newScreen->name() << '"'; if (mode == FromGeometryChange) setFlag(SynchronousGeometryChangeEvent); -- cgit v1.2.3 From 3bbd21ccc40805fce3437cf95bb238fc52bbf026 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Mon, 20 Jan 2020 16:50:21 +0200 Subject: Release the local ref immediately The local refs are released by the JVM when we exit the function, but if we need tons of local refs, JVM will not be happy. Fixes: QTBUG-81077 Change-Id: Ic38a5be1a563cb9c2465f9f902ff6ae6c61e698b Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp index fcc08ea00d..625473964d 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp @@ -146,7 +146,7 @@ public: jobjectArray jFiles = static_cast(files.object()); const jint nFiles = env->GetArrayLength(jFiles); for (int i = 0; i < nFiles; ++i) { - AssetItem item{QJNIObjectPrivate(env->GetObjectArrayElement(jFiles, i)).toString()}; + AssetItem item{QJNIObjectPrivate::fromLocalRef(env->GetObjectArrayElement(jFiles, i)).toString()}; insert(std::upper_bound(begin(), end(), item, [](const auto &a, const auto &b){ return a.name < b.name; }), item); -- cgit v1.2.3 From a611c632bb906cf77dd3af29ddd7b166f79ad1b0 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 6 Feb 2018 17:21:13 +0100 Subject: Add QWindow::startSystemMove and startSystemResize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This can be used to create custom client side window decorations. Refactors the xcb implementation to use edges instead of corners and we now use the last mouse position for `root_x` and `root_y` in the `_NET_WM_MOVERESIZE` event. Touch has also been changed, so just pick a point that's currently being pressed. The workaround for QTBUG-69716 has now been moved to QSizeGrip, as the comment in the bug report says that it should ideally be fixed at the widget level. On Windows, we no longer abort when GetSystemMenu returns false. I assume this code was added to check whether the window didn't have any decorations and not resize in that case. However, since the point of this patch is to let windows without native decorations resize/move, it makes most sense to remove the check. Adds a manual test, which calls QWindow::startSystemMove and startSystemResize on touch and mouse events. [ChangeLog][QtGui] Added API for starting interactive window resize and move operations handled by the system. Fixes: QTBUG-73011 Change-Id: I7e47a0b2cff182af71d3d479d6e3746f08ea30aa Reviewed-by: Friedemann Kleint Reviewed-by: Qt CI Bot Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoawindow.h | 2 + src/plugins/platforms/cocoa/qcocoawindow.mm | 16 ++++++ src/plugins/platforms/windows/qwindowswindow.cpp | 50 ++++++++++--------- src/plugins/platforms/windows/qwindowswindow.h | 4 +- src/plugins/platforms/xcb/qxcbconnection.h | 4 +- src/plugins/platforms/xcb/qxcbconnection_xi2.cpp | 13 ++--- src/plugins/platforms/xcb/qxcbwindow.cpp | 62 +++++++++++++++--------- src/plugins/platforms/xcb/qxcbwindow.h | 9 ++-- 8 files changed, 100 insertions(+), 60 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index fef72bc496..b15c0ac31c 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -218,6 +218,8 @@ protected: void toggleFullScreen(); bool isTransitioningToFullScreen() const; + bool startSystemMove() override; + // private: public: // for QNSView friend class QCocoaBackingStore; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 69d192b4f5..9cb4470e02 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -299,6 +299,22 @@ void QCocoaWindow::setCocoaGeometry(const QRect &rect) // will call QPlatformWindow::setGeometry(rect) during resize confirmation (see qnsview.mm) } +bool QCocoaWindow::startSystemMove() +{ + switch (NSApp.currentEvent.type) { + case NSEventTypeLeftMouseDown: + case NSEventTypeRightMouseDown: + case NSEventTypeOtherMouseDown: + case NSEventTypeMouseMoved: + // The documentation only describes starting a system move + // based on mouse down events, but move events also work. + [m_view.window performWindowDragWithEvent:NSApp.currentEvent]; + return true; + default: + return false; + } +} + void QCocoaWindow::setVisible(bool visible) { qCDebug(lcQpaWindow) << "QCocoaWindow::setVisible" << window() << visible; diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index b7536066d0..e2f9c6cbb0 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2604,37 +2604,41 @@ bool QWindowsWindow::setMouseGrabEnabled(bool grab) return grab; } -static inline DWORD cornerToWinOrientation(Qt::Corner corner) -{ - switch (corner) { - case Qt::TopLeftCorner: - return 0xf004; // SZ_SIZETOPLEFT; - case Qt::TopRightCorner: - return 0xf005; // SZ_SIZETOPRIGHT - case Qt::BottomLeftCorner: - return 0xf007; // SZ_SIZEBOTTOMLEFT - case Qt::BottomRightCorner: - return 0xf008; // SZ_SIZEBOTTOMRIGHT - } - return 0; -} - -bool QWindowsWindow::startSystemResize(const QPoint &, Qt::Corner corner) -{ - if (!GetSystemMenu(m_data.hwnd, FALSE)) +static inline DWORD edgesToWinOrientation(Qt::Edges edges) +{ + if (edges == Qt::LeftEdge) + return 0xf001; // SC_SIZELEFT; + else if (edges == (Qt::RightEdge)) + return 0xf002; // SC_SIZERIGHT + else if (edges == (Qt::TopEdge)) + return 0xf003; // SC_SIZETOP + else if (edges == (Qt::TopEdge | Qt::LeftEdge)) + return 0xf004; // SC_SIZETOPLEFT + else if (edges == (Qt::TopEdge | Qt::RightEdge)) + return 0xf005; // SC_SIZETOPRIGHT + else if (edges == (Qt::BottomEdge)) + return 0xf006; // SC_SIZEBOTTOM + else if (edges == (Qt::BottomEdge | Qt::LeftEdge)) + return 0xf007; // SC_SIZEBOTTOMLEFT + else if (edges == (Qt::BottomEdge | Qt::RightEdge)) + return 0xf008; // SC_SIZEBOTTOMRIGHT + + return 0xf000; // SC_SIZE +} + +bool QWindowsWindow::startSystemResize(Qt::Edges edges) +{ + if (Q_UNLIKELY(!(window()->flags() & Qt::MSWindowsFixedSizeDialogHint))) return false; ReleaseCapture(); - PostMessage(m_data.hwnd, WM_SYSCOMMAND, cornerToWinOrientation(corner), 0); + PostMessage(m_data.hwnd, WM_SYSCOMMAND, edgesToWinOrientation(edges), 0); setFlag(SizeGripOperation); return true; } -bool QWindowsWindow::startSystemMove(const QPoint &) +bool QWindowsWindow::startSystemMove() { - if (!GetSystemMenu(m_data.hwnd, FALSE)) - return false; - ReleaseCapture(); PostMessage(m_data.hwnd, WM_SYSCOMMAND, 0xF012 /*SC_DRAGMOVE*/, 0); return true; diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 7c37c6b115..e1f7908687 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -277,8 +277,8 @@ public: bool setMouseGrabEnabled(bool grab) override; inline bool hasMouseCapture() const { return GetCapture() == m_data.hwnd; } - bool startSystemResize(const QPoint &pos, Qt::Corner corner) override; - bool startSystemMove(const QPoint &pos) override; + bool startSystemResize(Qt::Edges edges) override; + bool startSystemMove() override; void setFrameStrutEventsEnabled(bool enabled) override; bool frameStrutEventsEnabled() const override { return testFlag(FrameStrutEventsEnabled); } diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 2d89b971dc..8a4b577d2e 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -230,7 +230,7 @@ public: bool xi2MouseEventsDisabled() const; Qt::MouseButton xiToQtMouseButton(uint32_t b); void xi2UpdateScrollingDevices(); - bool startSystemMoveResizeForTouchBegin(xcb_window_t window, const QPoint &point, int corner); + bool startSystemMoveResizeForTouch(xcb_window_t window, int edges); void abortSystemMoveResizeForTouch(); bool isTouchScreen(int id); @@ -334,7 +334,7 @@ private: xcb_window_t window = XCB_NONE; uint16_t deviceid; uint32_t pointid; - int corner; + int edges; } m_startSystemMoveResizeInfo; const bool m_canGrabServer; diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp index 2d114c51b3..4620f0fd1d 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp @@ -753,7 +753,7 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo xcb_input_xi_allow_events(xcb_connection(), XCB_CURRENT_TIME, xiDeviceEvent->deviceid, XCB_INPUT_EVENT_MODE_REJECT_TOUCH, xiDeviceEvent->detail, xiDeviceEvent->event); - window->doStartSystemMoveResize(QPoint(x, y), m_startSystemMoveResizeInfo.corner); + window->doStartSystemMoveResize(QPoint(x, y), m_startSystemMoveResizeInfo.edges); m_startSystemMoveResizeInfo.window = XCB_NONE; } } @@ -787,19 +787,20 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo touchPoint.state = Qt::TouchPointStationary; } -bool QXcbConnection::startSystemMoveResizeForTouchBegin(xcb_window_t window, const QPoint &point, int corner) +bool QXcbConnection::startSystemMoveResizeForTouch(xcb_window_t window, int edges) { QHash::const_iterator devIt = m_touchDevices.constBegin(); for (; devIt != m_touchDevices.constEnd(); ++devIt) { TouchDeviceData deviceData = devIt.value(); if (deviceData.qtTouchDevice->type() == QTouchDevice::TouchScreen) { - QHash::const_iterator pointIt = deviceData.pointPressedPosition.constBegin(); - for (; pointIt != deviceData.pointPressedPosition.constEnd(); ++pointIt) { - if (pointIt.value().toPoint() == point) { + auto pointIt = deviceData.touchPoints.constBegin(); + for (; pointIt != deviceData.touchPoints.constEnd(); ++pointIt) { + Qt::TouchPointState state = pointIt.value().state; + if (state == Qt::TouchPointMoved || state == Qt::TouchPointPressed || state == Qt::TouchPointStationary) { m_startSystemMoveResizeInfo.window = window; m_startSystemMoveResizeInfo.deviceid = devIt.key(); m_startSystemMoveResizeInfo.pointid = pointIt.key(); - m_startSystemMoveResizeInfo.corner = corner; + m_startSystemMoveResizeInfo.edges = edges; return true; } } diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index adca902c69..96cd3a70ed 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -2161,6 +2161,7 @@ QXcbWindow *QXcbWindow::toWindow() { return this; } void QXcbWindow::handleMouseEvent(xcb_timestamp_t time, const QPoint &local, const QPoint &global, Qt::KeyboardModifiers modifiers, QEvent::Type type, Qt::MouseEventSource source) { + m_lastPointerPosition = local; connection()->setTime(time); Qt::MouseButton button = type == QEvent::MouseMove ? Qt::NoButton : connection()->button(); QWindowSystemInterface::handleMouseEvent(window(), time, local, global, @@ -2345,45 +2346,66 @@ bool QXcbWindow::windowEvent(QEvent *event) return QPlatformWindow::windowEvent(event); } -bool QXcbWindow::startSystemResize(const QPoint &pos, Qt::Corner corner) +bool QXcbWindow::startSystemResize(Qt::Edges edges) { - return startSystemMoveResize(pos, corner); + return startSystemMoveResize(m_lastPointerPosition, edges); } -bool QXcbWindow::startSystemMove(const QPoint &pos) +bool QXcbWindow::startSystemMove() { - return startSystemMoveResize(pos, 4); + return startSystemMoveResize(m_lastPointerPosition, 16); } -bool QXcbWindow::startSystemMoveResize(const QPoint &pos, int corner) +bool QXcbWindow::startSystemMoveResize(const QPoint &pos, int edges) { - return false; // ### FIXME QTBUG-69716 const xcb_atom_t moveResize = connection()->atom(QXcbAtom::_NET_WM_MOVERESIZE); if (!connection()->wmSupport()->isSupportedByWM(moveResize)) return false; - const QPoint globalPos = QHighDpi::toNativePixels(window()->mapToGlobal(pos), window()->screen()); - // ### FIXME QTBUG-53389 - bool startedByTouch = connection()->startSystemMoveResizeForTouchBegin(m_window, globalPos, corner); + bool startedByTouch = connection()->startSystemMoveResizeForTouch(m_window, edges); if (startedByTouch) { - if (connection()->isUnity() || connection()->isGnome()) { - // These desktops fail to move/resize via _NET_WM_MOVERESIZE (WM bug?). + if (connection()->isUnity()) { + // Unity fails to move/resize via _NET_WM_MOVERESIZE (WM bug?). connection()->abortSystemMoveResizeForTouch(); return false; } - // KWin, Openbox, AwesomeWM have been tested to work with _NET_WM_MOVERESIZE. + // KWin, Openbox, AwesomeWM and Gnome have been tested to work with _NET_WM_MOVERESIZE. } else { // Started by mouse press. if (connection()->isUnity()) return false; // _NET_WM_MOVERESIZE on this WM is bouncy (WM bug?). - doStartSystemMoveResize(globalPos, corner); + const QPoint globalPos = QHighDpi::toNativePixels(window()->mapToGlobal(pos), window()->screen()); + doStartSystemMoveResize(globalPos, edges); } return true; } -void QXcbWindow::doStartSystemMoveResize(const QPoint &globalPos, int corner) +static uint qtEdgesToXcbMoveResizeDirection(Qt::Edges edges) +{ + if (edges == (Qt::TopEdge | Qt::LeftEdge)) + return 0; + if (edges == Qt::TopEdge) + return 1; + if (edges == (Qt::TopEdge | Qt::RightEdge)) + return 2; + if (edges == Qt::RightEdge) + return 3; + if (edges == (Qt::RightEdge | Qt::BottomEdge)) + return 4; + if (edges == Qt::BottomEdge) + return 5; + if (edges == (Qt::BottomEdge | Qt::LeftEdge)) + return 6; + if (edges == Qt::LeftEdge) + return 7; + + qWarning() << "Cannot convert " << edges << "to _NET_WM_MOVERESIZE direction."; + return 0; +} + +void QXcbWindow::doStartSystemMoveResize(const QPoint &globalPos, int edges) { const xcb_atom_t moveResize = connection()->atom(QXcbAtom::_NET_WM_MOVERESIZE); xcb_client_message_event_t xev; @@ -2394,16 +2416,10 @@ void QXcbWindow::doStartSystemMoveResize(const QPoint &globalPos, int corner) xev.format = 32; xev.data.data32[0] = globalPos.x(); xev.data.data32[1] = globalPos.y(); - if (corner == 4) { + if (edges == 16) xev.data.data32[2] = 8; // move - } else { - const bool bottom = corner == Qt::BottomRightCorner || corner == Qt::BottomLeftCorner; - const bool left = corner == Qt::BottomLeftCorner || corner == Qt::TopLeftCorner; - if (bottom) - xev.data.data32[2] = left ? 6 : 4; // bottomleft/bottomright - else - xev.data.data32[2] = left ? 0 : 2; // topleft/topright - } + else + xev.data.data32[2] = qtEdgesToXcbMoveResizeDirection(Qt::Edges(edges)); xev.data.data32[3] = XCB_BUTTON_INDEX_1; xev.data.data32[4] = 0; xcb_ungrab_pointer(connection()->xcb_connection(), XCB_CURRENT_TIME); diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index 976a442b11..d6f370eebe 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -107,8 +107,8 @@ public: bool windowEvent(QEvent *event) override; - bool startSystemResize(const QPoint &pos, Qt::Corner corner) override; - bool startSystemMove(const QPoint &pos) override; + bool startSystemResize(Qt::Edges edges) override; + bool startSystemMove() override; void setOpacity(qreal level) override; void setMask(const QRegion ®ion) override; @@ -168,8 +168,8 @@ public: QXcbScreen *xcbScreen() const; - bool startSystemMoveResize(const QPoint &pos, int corner); - void doStartSystemMoveResize(const QPoint &globalPos, int corner); + bool startSystemMoveResize(const QPoint &pos, int edges); + void doStartSystemMoveResize(const QPoint &globalPos, int edges); static bool isTrayIconWindow(QWindow *window) { @@ -264,6 +264,7 @@ protected: QRegion m_exposeRegion; QSize m_oldWindowSize; + QPoint m_lastPointerPosition; xcb_visualid_t m_visualId = 0; // Last sent state. Initialized to an invalid state, on purpose. -- cgit v1.2.3 From f998e630e74a8921e2e48e84fc0153ff81850def Mon Sep 17 00:00:00 2001 From: Alexandra Cherdantseva Date: Wed, 29 Jan 2020 17:38:41 +0300 Subject: wasm: fix QWasmString::toQString assertion for emscripten 1.39.4 In emscripten 1.39.4 `maxBytesToWrite` argument is required for function `stringToUTF16(str, outPtr, maxBytesToWrite)` Fixes: QTBUG-81728 Change-Id: I634134a30454ae09a9a05593428397b40464b31f Reviewed-by: jian liang Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmstring.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wasm/qwasmstring.cpp b/src/plugins/platforms/wasm/qwasmstring.cpp index 05b571c459..b1be405eeb 100644 --- a/src/plugins/platforms/wasm/qwasmstring.cpp +++ b/src/plugins/platforms/wasm/qwasmstring.cpp @@ -52,9 +52,10 @@ QString QWasmString::toQString(const val &v) val::global("Module")["stringToUTF16"]); static const val length("length"); - result.resize(v[length].as()); + int len = v[length].as(); + result.resize(len); auto ptr = quintptr(result.utf16()); - stringToUTF16(v, val(ptr)); + stringToUTF16(v, val(ptr), val((len + 1) * 2)); return result; } -- cgit v1.2.3 From aec3c6a9cb1286d391f0ba9d7b8d1499a7003580 Mon Sep 17 00:00:00 2001 From: James McDonnell Date: Mon, 9 Dec 2019 17:30:29 -0500 Subject: Add EglDisplay resource to the QNX platform plugin QtWayland requires this resource. Change-Id: I41f83d93582bfe7c471208e8ca844e24dc2c6da5 Reviewed-by: Dan Cape Reviewed-by: Johan Helsing --- src/plugins/platforms/qnx/qqnxnativeinterface.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/qnx/qqnxnativeinterface.cpp b/src/plugins/platforms/qnx/qqnxnativeinterface.cpp index 3bd6a86b59..25f7b09a60 100644 --- a/src/plugins/platforms/qnx/qqnxnativeinterface.cpp +++ b/src/plugins/platforms/qnx/qqnxnativeinterface.cpp @@ -94,6 +94,11 @@ void *QQnxNativeInterface::nativeResourceForIntegration(const QByteArray &resour if (resource == "screenContext") return m_integration->screenContext(); +#if QT_CONFIG(opengl) + if (resource.toLower() == "egldisplay") + return m_integration->eglDisplay(); +#endif + return 0; } -- cgit v1.2.3 From aadf21b25cad7026f07a5fe7bf19fbedfb1866b7 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Fri, 31 Jan 2020 16:47:46 +0100 Subject: Fix 'the the' typo in comments Change-Id: I00fcb1c2374e7ca168b6240f9d41c0323fb0867c Reviewed-by: Giuseppe D'Angelo --- src/plugins/platforms/ios/qiostextinputoverlay.mm | 2 +- src/plugins/platforms/ios/qiosviewcontroller.mm | 2 +- src/plugins/platforms/wasm/qwasmintegration.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm index 0561a826c6..3da4ba5480 100644 --- a/src/plugins/platforms/ios/qiostextinputoverlay.mm +++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm @@ -511,7 +511,7 @@ static void executeBlockWithoutAnimation(Block block) - (void)createLoupe { - // We magnify the the desktop view. But the loupe itself will be added as a child + // We magnify the desktop view. But the loupe itself will be added as a child // of the desktop view's parent, so it doesn't become a part of what we magnify. _loupeLayer = [[self createLoupeLayer] retain]; _loupeLayer.targetView = _desktopView; diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm index ce2aa96ca5..cd4af46ef7 100644 --- a/src/plugins/platforms/ios/qiosviewcontroller.mm +++ b/src/plugins/platforms/ios/qiosviewcontroller.mm @@ -452,7 +452,7 @@ if (!focusWindow->screen() || focusWindow->screen()->handle() != self.platformScreen) return; - // All decisions are based on the the top level window + // All decisions are based on the top level window focusWindow = qt_window_private(focusWindow)->topLevelWindow(); #ifndef Q_OS_TVOS diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index fd53cd0bae..ee3f6afb73 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -133,7 +133,7 @@ QWasmIntegration::QWasmIntegration() Q_UNUSED(userData); // This resize event is called when the HTML window is resized. Depending - // on the page layout the the canvas(es) might also have been resized, so we + // on the page layout the canvas(es) might also have been resized, so we // update the Qt screen sizes (and canvas render sizes). if (QWasmIntegration *integration = QWasmIntegration::get()) integration->resizeAllScreens(); -- cgit v1.2.3 From 9d49475e91d57e9fb26172c5558f502fe838cd91 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 30 Jan 2020 12:05:46 +0200 Subject: xcb: Compute correct global pointer position in startSystemMoveResize QWindow::mapToGlobal() expects pos to be in device-independent pixels, while in reality it's in device pixels. We need to use QXcbWindow::mapToGlobal(), which operates on physical pixels. Change-Id: I8dcad5cc1f5d55df7950b36d97af5ce4b983ed54 Reviewed-by: Johan Helsing --- src/plugins/platforms/xcb/qxcbwindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 96cd3a70ed..71ec47b053 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -2375,8 +2375,7 @@ bool QXcbWindow::startSystemMoveResize(const QPoint &pos, int edges) if (connection()->isUnity()) return false; // _NET_WM_MOVERESIZE on this WM is bouncy (WM bug?). - const QPoint globalPos = QHighDpi::toNativePixels(window()->mapToGlobal(pos), window()->screen()); - doStartSystemMoveResize(globalPos, edges); + doStartSystemMoveResize(mapToGlobal(pos), edges); } return true; -- cgit v1.2.3 From 0947cf66e5b310ddc2318b3d9c9f415e49dd82aa Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Mon, 20 Jan 2020 16:47:16 +0200 Subject: Fix AndroidAbstractFileEngine "" it's the root folder of the assets, setting m_fileName = "" will make AndroidAbstractFileEngine::setFileName to fail and it will not set the proper flags. Fixes: QTBUG-81535 Change-Id: I0653f83b55ee790c8edf188889ccb30ef54584c0 Reviewed-by: Andy Shaw --- src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp index 625473964d..ca16efe34f 100644 --- a/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp +++ b/src/plugins/platforms/android/qandroidassetsfileenginehandler.cpp @@ -110,6 +110,8 @@ public: static AssetItem::Type fileType(const QString &filePath) { + if (filePath.isEmpty()) + return AssetItem::Type::Folder; const QStringList paths = filePath.split(QLatin1Char('/')); QString fullPath; AssetItem::Type res = AssetItem::Type::Invalid; @@ -399,7 +401,8 @@ public: private: AAsset *m_assetFile = nullptr; AAssetManager *m_assetManager = nullptr; - QString m_fileName; + // initialize with a name that can't be used as a file name + QString m_fileName = QLatin1String("."); bool m_isFolder = false; }; -- cgit v1.2.3 From 7dd6d32657cb079f8b3e1ff6b1dc27248ec0a2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 31 Jan 2020 11:31:03 +0000 Subject: wasm: Specify event targets by CSS selectors; Support emsdk >= 1.39.5 DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR is now on by default, which means that functions like emscripten_set_keydown_callback() now expects CSS selectors (e.g. "#canvas_id" instead of "canvas_id"). In addition, Module.canvas is no more. Add a deprecation warning in case someone is setting it and expects Qt to use it. (qtloader.js sets qtCanvasElements instead). This bumps the minimum supported emsdk version to 1.39.5. Fixes: QTBUG-74601 Change-Id: I8c46ce170143f969e6281824f78b1bb809c267ab Reviewed-by: Lorn Potter --- .../platforms/wasm/qwasmeventtranslator.cpp | 25 +++++++++++----------- src/plugins/platforms/wasm/qwasmintegration.cpp | 9 ++++---- src/plugins/platforms/wasm/qwasmopenglcontext.cpp | 3 ++- src/plugins/platforms/wasm/qwasmscreen.cpp | 4 ++-- 4 files changed, 21 insertions(+), 20 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index d99c202c48..62ada796db 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -339,8 +339,7 @@ QWasmEventTranslator::QWasmEventTranslator(QWasmScreen *screen) void QWasmEventTranslator::initEventHandlers() { - QByteArray _canvasId = screen()->canvasId().toUtf8(); - const char *canvasId = _canvasId.constData(); + QByteArray canvasSelector = "#" + screen()->canvasId().toUtf8(); // The Platform Detect: expand coverage and move as needed enum Platform { @@ -364,21 +363,21 @@ void QWasmEventTranslator::initEventHandlers() } } - emscripten_set_keydown_callback(canvasId, (void *)this, 1, &keyboard_cb); - emscripten_set_keyup_callback(canvasId, (void *)this, 1, &keyboard_cb); + emscripten_set_keydown_callback(canvasSelector.constData(), (void *)this, 1, &keyboard_cb); + emscripten_set_keyup_callback(canvasSelector.constData(), (void *)this, 1, &keyboard_cb); - emscripten_set_mousedown_callback(canvasId, (void *)this, 1, &mouse_cb); - emscripten_set_mouseup_callback(canvasId, (void *)this, 1, &mouse_cb); - emscripten_set_mousemove_callback(canvasId, (void *)this, 1, &mouse_cb); + emscripten_set_mousedown_callback(canvasSelector.constData(), (void *)this, 1, &mouse_cb); + emscripten_set_mouseup_callback(canvasSelector.constData(), (void *)this, 1, &mouse_cb); + emscripten_set_mousemove_callback(canvasSelector.constData(), (void *)this, 1, &mouse_cb); - emscripten_set_focus_callback(canvasId, (void *)this, 1, &focus_cb); + emscripten_set_focus_callback(canvasSelector.constData(), (void *)this, 1, &focus_cb); - emscripten_set_wheel_callback(canvasId, (void *)this, 1, &wheel_cb); + emscripten_set_wheel_callback(canvasSelector.constData(), (void *)this, 1, &wheel_cb); - emscripten_set_touchstart_callback(canvasId, (void *)this, 1, &touchCallback); - emscripten_set_touchend_callback(canvasId, (void *)this, 1, &touchCallback); - emscripten_set_touchmove_callback(canvasId, (void *)this, 1, &touchCallback); - emscripten_set_touchcancel_callback(canvasId, (void *)this, 1, &touchCallback); + emscripten_set_touchstart_callback(canvasSelector.constData(), (void *)this, 1, &touchCallback); + emscripten_set_touchend_callback(canvasSelector.constData(), (void *)this, 1, &touchCallback); + emscripten_set_touchmove_callback(canvasSelector.constData(), (void *)this, 1, &touchCallback); + emscripten_set_touchcancel_callback(canvasSelector.constData(), (void *)this, 1, &touchCallback); } template diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index ee3f6afb73..9934f5ac19 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -108,9 +108,8 @@ QWasmIntegration::QWasmIntegration() s_instance = this; // We expect that qtloader.js has populated Module.qtCanvasElements with one or more canvases. - // Also check Module.canvas, which may be set if the emscripen or a custom loader is used. emscripten::val qtCanvaseElements = val::module_property("qtCanvasElements"); - emscripten::val canvas = val::module_property("canvas"); + emscripten::val canvas = val::module_property("canvas"); // TODO: remove for Qt 6.0 if (!qtCanvaseElements.isUndefined()) { int screenCount = qtCanvaseElements["length"].as(); @@ -119,7 +118,9 @@ QWasmIntegration::QWasmIntegration() QString canvasId = QWasmString::toQString(canvas["id"]); addScreen(canvasId); } - } else if (!canvas.isUndefined()){ + } else if (!canvas.isUndefined()) { + qWarning() << "Module.canvas is deprecated. A future version of Qt will stop reading this property. " + << "Instead, set Module.qtCanvasElements to be an array of canvas elements, or use qtloader.js."; QString canvasId = QWasmString::toQString(canvas["id"]); addScreen(canvasId); } @@ -139,7 +140,7 @@ QWasmIntegration::QWasmIntegration() integration->resizeAllScreens(); return 0; }; - emscripten_set_resize_callback(nullptr, nullptr, 1, onWindowResize); + emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, 1, onWindowResize); } QWasmIntegration::~QWasmIntegration() diff --git a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp index 501ab99116..4ddd56fd8c 100644 --- a/src/plugins/platforms/wasm/qwasmopenglcontext.cpp +++ b/src/plugins/platforms/wasm/qwasmopenglcontext.cpp @@ -106,7 +106,8 @@ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE QWasmOpenGLContext::createEmscriptenContext(cons attributes.depth = useDepthStencil; attributes.stencil = useDepthStencil; - EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(canvasId.toUtf8().constData(), &attributes); + QByteArray convasSelector = "#" + canvasId.toUtf8(); + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(convasSelector.constData(), &attributes); return context; } diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index 5e6f94b9ed..ba14421255 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -180,10 +180,10 @@ void QWasmScreen::updateQScreenAndCanvasRenderSize() // Setting the render size to a value larger than the CSS size enables high-dpi // rendering. - QByteArray canvasId = m_canvasId.toUtf8(); + QByteArray canvasSelector = "#" + m_canvasId.toUtf8(); double css_width; double css_height; - emscripten_get_element_css_size(canvasId.constData(), &css_width, &css_height); + emscripten_get_element_css_size(canvasSelector.constData(), &css_width, &css_height); QSizeF cssSize(css_width, css_height); QSizeF canvasSize = cssSize * devicePixelRatio(); -- cgit v1.2.3 From 6839d297b3964047a207375a4955f6cedcb1c959 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Fri, 31 Jan 2020 17:04:54 +0200 Subject: Android: Fix native open fileDialog crash on Android Unregister the ActivityResultListener() after the result is handled. Fixes: QTBUG-78912 Change-Id: Ia2b45eca002e854492c409c70a3876fa8ce98de1 Reviewed-by: Andy Shaw --- src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp index 4fb271a75c..7585b7eb95 100644 --- a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp +++ b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp @@ -104,6 +104,7 @@ void QAndroidPlatformFileDialogHelper::exec() void QAndroidPlatformFileDialogHelper::hide() { + QtAndroidPrivate::unregisterActivityResultListener(this); } QString QAndroidPlatformFileDialogHelper::selectedNameFilter() const -- cgit v1.2.3 From 6d6ca70538851e8334eb01550a93b60ceba75d34 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Thu, 16 Jan 2020 16:09:33 +0200 Subject: Android: Allow requesting qtvirtualkeyboard with QT_IM_MODULE Allow Android apps to request qtvirtualkeyboard using environment variable QT_IM_MODULE. Similar to commit b46fe39d940712c5d401e731e171a7ccfadfe648 for Windows platform. Task-number: QTBUG-80357 Change-Id: I584859729e60f5d73943ca5840a9dcd169cc9ecb Reviewed-by: Mitch Curtis Reviewed-by: Andy Shaw --- .../platforms/android/qandroidplatformintegration.cpp | 13 ++++++++++++- src/plugins/platforms/android/qandroidplatformintegration.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp index e0c437be27..c81cc66166 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.cpp +++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp @@ -74,6 +74,8 @@ #include "qandroidplatformvulkaninstance.h" #endif +#include + QT_BEGIN_NAMESPACE int QAndroidPlatformIntegration::m_defaultGeometryWidth = 320; @@ -255,6 +257,15 @@ static bool needsBasicRenderloopWorkaround() return needsWorkaround; } +void QAndroidPlatformIntegration::initialize() +{ + const QString icStr = QPlatformInputContextFactory::requested(); + if (icStr.isNull()) + m_inputContext.reset(new QAndroidInputContext); + else + m_inputContext.reset(QPlatformInputContextFactory::create(icStr)); +} + bool QAndroidPlatformIntegration::hasCapability(Capability cap) const { switch (cap) { @@ -366,7 +377,7 @@ QPlatformClipboard *QAndroidPlatformIntegration::clipboard() const QPlatformInputContext *QAndroidPlatformIntegration::inputContext() const { - return &m_platformInputContext; + return m_inputContext.data(); } QPlatformNativeInterface *QAndroidPlatformIntegration::nativeInterface() const diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h index c795c499bc..ecbde4f951 100644 --- a/src/plugins/platforms/android/qandroidplatformintegration.h +++ b/src/plugins/platforms/android/qandroidplatformintegration.h @@ -81,6 +81,8 @@ public: QAndroidPlatformIntegration(const QStringList ¶mList); ~QAndroidPlatformIntegration(); + void initialize() override; + bool hasCapability(QPlatformIntegration::Capability cap) const override; QPlatformWindow *createPlatformWindow(QWindow *window) const override; @@ -167,7 +169,7 @@ private: mutable QPlatformAccessibility *m_accessibility; #endif - mutable QAndroidInputContext m_platformInputContext; + QScopedPointer m_inputContext; }; QT_END_NAMESPACE -- cgit v1.2.3 From a84c895b17089c36f950ae565fd5f6b98bcc7a14 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Fri, 31 Jan 2020 17:04:54 +0200 Subject: Android: Fix native fileDialog not waiting for user selection Add an event loop to wait for user file selection in native fileDialog Task-number: QTBUG-77214 Change-Id: I3d97d6c3f46cf2a8ed0ee6f98e555e8d62e12cc3 Reviewed-by: Ville Voutilainen Reviewed-by: Andy Shaw --- src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp | 3 +++ src/plugins/platforms/android/qandroidplatformfiledialoghelper.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp index 7585b7eb95..fb979ab6cc 100644 --- a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp +++ b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp @@ -100,10 +100,13 @@ bool QAndroidPlatformFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::Win void QAndroidPlatformFileDialogHelper::exec() { + m_eventLoop.exec(QEventLoop::DialogExec); } void QAndroidPlatformFileDialogHelper::hide() { + if (m_eventLoop.isRunning()) + m_eventLoop.exit(); QtAndroidPrivate::unregisterActivityResultListener(this); } diff --git a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.h b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.h index e445aa2fef..5cd26af7c9 100644 --- a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.h +++ b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.h @@ -41,6 +41,7 @@ #define QANDROIDPLATFORMFILEDIALOGHELPER_H #include +#include #include #include @@ -72,6 +73,7 @@ public: bool handleActivityResult(jint requestCode, jint resultCode, jobject data) override; private: + QEventLoop m_eventLoop; QUrl m_selectedFile; }; -- cgit v1.2.3 From 2b0af50c8ba534a6032a31297f1915b50a100241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Sun, 2 Feb 2020 01:22:24 +0100 Subject: wasm: store and pass canvases as emscripten::val Store and pass canvases as emscripten::val instead of a QString containing the element id. This simplifies code which interacts with the canvas using the emscripten::val API, by removing the need to look up with getElementById. The Emscripten C event API does not accept emscripten::val, and using the element id is still needed here. emscripten::val does not provide a hash key suitable for use with QHash, but does provide an equality-compare in the form of val::equals(). Change the canvas->screen mapping code to use a QVector instead of a QHash. Change-Id: I1dbdbbc8fb06bb869031f1500e83ae2d64780a7f Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qwasmclipboard.cpp | 5 +- src/plugins/platforms/wasm/qwasmclipboard.h | 3 +- src/plugins/platforms/wasm/qwasmcursor.cpp | 4 +- .../platforms/wasm/qwasmeventtranslator.cpp | 4 +- src/plugins/platforms/wasm/qwasmintegration.cpp | 58 ++++++++++++---------- src/plugins/platforms/wasm/qwasmintegration.h | 10 ++-- src/plugins/platforms/wasm/qwasmscreen.cpp | 31 ++++++------ src/plugins/platforms/wasm/qwasmscreen.h | 7 ++- 8 files changed, 63 insertions(+), 59 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/wasm/qwasmclipboard.cpp b/src/plugins/platforms/wasm/qwasmclipboard.cpp index f02c2c6ccb..890b01fa3c 100644 --- a/src/plugins/platforms/wasm/qwasmclipboard.cpp +++ b/src/plugins/platforms/wasm/qwasmclipboard.cpp @@ -192,15 +192,12 @@ void QWasmClipboard::initClipboardEvents() permissions.call("query", writePermissionsMap); } -void QWasmClipboard::installEventHandlers(const QString &canvasId) +void QWasmClipboard::installEventHandlers(const emscripten::val &canvas) { if (hasClipboardApi) return; // Fallback path for browsers which do not support direct clipboard access - val document = val::global("document"); - val canvas = document.call("getElementById", QWasmString::fromQString(canvasId)); - canvas.call("addEventListener", val("cut"), val::module_property("qtClipboardCutTo")); canvas.call("addEventListener", val("copy"), diff --git a/src/plugins/platforms/wasm/qwasmclipboard.h b/src/plugins/platforms/wasm/qwasmclipboard.h index 00aae8fead..3b28e2c381 100644 --- a/src/plugins/platforms/wasm/qwasmclipboard.h +++ b/src/plugins/platforms/wasm/qwasmclipboard.h @@ -36,6 +36,7 @@ #include #include +#include class QWasmClipboard : public QObject, public QPlatformClipboard { @@ -51,7 +52,7 @@ public: static void qWasmClipboardPaste(QMimeData *mData); void initClipboardEvents(); - void installEventHandlers(const QString &canvasId); + void installEventHandlers(const emscripten::val &canvas); bool hasClipboardApi; void readTextFromClipboard(); void writeTextToClipboard(); diff --git a/src/plugins/platforms/wasm/qwasmcursor.cpp b/src/plugins/platforms/wasm/qwasmcursor.cpp index 616456b2fa..61204517ce 100644 --- a/src/plugins/platforms/wasm/qwasmcursor.cpp +++ b/src/plugins/platforms/wasm/qwasmcursor.cpp @@ -57,9 +57,7 @@ void QWasmCursor::changeCursor(QCursor *windowCursor, QWindow *window) htmlCursorName = "auto"; // Set cursor on the canvas - val jsCanvasId = QWasmString::fromQString(QWasmScreen::get(screen)->canvasId()); - val document = val::global("document"); - val canvas = document.call("getElementById", jsCanvasId); + val canvas = QWasmScreen::get(screen)->canvas(); val canvasStyle = canvas["style"]; canvasStyle.set("cursor", val(htmlCursorName.constData())); } diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index 62ada796db..3e6043b083 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -354,9 +354,7 @@ void QWasmEventTranslator::initEventHandlers() g_useNaturalScrolling = false; // make this !default on macOS if (emscripten::val::global("window")["safari"].isUndefined()) { - val document = val::global("document"); - val jsCanvasId = QWasmString::fromQString(screen()->canvasId()); - val canvas = document.call("getElementById", jsCanvasId); + val canvas = screen()->canvas(); canvas.call("addEventListener", val("wheel"), val::module_property("qtMouseWheelEvent")); diff --git a/src/plugins/platforms/wasm/qwasmintegration.cpp b/src/plugins/platforms/wasm/qwasmintegration.cpp index 9934f5ac19..45bc49e382 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.cpp +++ b/src/plugins/platforms/wasm/qwasmintegration.cpp @@ -68,20 +68,17 @@ static void browserBeforeUnload(emscripten::val) static void addCanvasElement(emscripten::val canvas) { - QString canvasId = QWasmString::toQString(canvas["id"]); - QWasmIntegration::get()->addScreen(canvasId); + QWasmIntegration::get()->addScreen(canvas); } static void removeCanvasElement(emscripten::val canvas) { - QString canvasId = QWasmString::toQString(canvas["id"]); - QWasmIntegration::get()->removeScreen(canvasId); + QWasmIntegration::get()->removeScreen(canvas); } static void resizeCanvasElement(emscripten::val canvas) { - QString canvasId = QWasmString::toQString(canvas["id"]); - QWasmIntegration::get()->resizeScreen(canvasId); + QWasmIntegration::get()->resizeScreen(canvas); } static void qtUpdateDpi() @@ -114,15 +111,12 @@ QWasmIntegration::QWasmIntegration() if (!qtCanvaseElements.isUndefined()) { int screenCount = qtCanvaseElements["length"].as(); for (int i = 0; i < screenCount; ++i) { - emscripten::val canvas = qtCanvaseElements[i].as(); - QString canvasId = QWasmString::toQString(canvas["id"]); - addScreen(canvasId); + addScreen(qtCanvaseElements[i].as()); } } else if (!canvas.isUndefined()) { qWarning() << "Module.canvas is deprecated. A future version of Qt will stop reading this property. " << "Instead, set Module.qtCanvasElements to be an array of canvas elements, or use qtloader.js."; - QString canvasId = QWasmString::toQString(canvas["id"]); - addScreen(canvasId); + addScreen(canvas); } emscripten::val::global("window").set("onbeforeunload", val::module_property("qtBrowserBeforeUnload")); @@ -148,8 +142,8 @@ QWasmIntegration::~QWasmIntegration() delete m_fontDb; delete m_desktopServices; - for (auto it = m_screens.constBegin(); it != m_screens.constEnd(); ++it) - QWindowSystemInterface::handleScreenRemoved(*it); + for (const auto &canvasAndScreen : m_screens) + QWindowSystemInterface::handleScreenRemoved(canvasAndScreen.second); m_screens.clear(); s_instance = nullptr; @@ -271,24 +265,37 @@ QPlatformClipboard* QWasmIntegration::clipboard() const return m_clipboard; } -void QWasmIntegration::addScreen(const QString &canvasId) +void QWasmIntegration::addScreen(const emscripten::val &canvas) { - QWasmScreen *screen = new QWasmScreen(canvasId); - m_clipboard->installEventHandlers(canvasId); - m_screens.insert(canvasId, screen); + QWasmScreen *screen = new QWasmScreen(canvas); + m_screens.append(qMakePair(canvas, screen)); + m_clipboard->installEventHandlers(canvas); QWindowSystemInterface::handleScreenAdded(screen); } -void QWasmIntegration::removeScreen(const QString &canvasId) +void QWasmIntegration::removeScreen(const emscripten::val &canvas) { - QWasmScreen *exScreen = m_screens.take(canvasId); + auto it = std::find_if(m_screens.begin(), m_screens.end(), + [&] (const QPair &candidate) { return candidate.first.equals(canvas); }); + if (it == m_screens.end()) { + qWarning() << "Attempting to remove non-existing screen for canvas" << QWasmString::toQString(canvas["id"]);; + return; + } + QWasmScreen *exScreen = it->second; + m_screens.erase(it); exScreen->destroy(); // clean up before deleting the screen QWindowSystemInterface::handleScreenRemoved(exScreen); } -void QWasmIntegration::resizeScreen(const QString &canvasId) +void QWasmIntegration::resizeScreen(const emscripten::val &canvas) { - m_screens.value(canvasId)->updateQScreenAndCanvasRenderSize(); + auto it = std::find_if(m_screens.begin(), m_screens.end(), + [&] (const QPair &candidate) { return candidate.first.equals(canvas); }); + if (it == m_screens.end()) { + qWarning() << "Attempting to resize non-existing screen for canvas" << QWasmString::toQString(canvas["id"]);; + return; + } + it->second->updateQScreenAndCanvasRenderSize(); } void QWasmIntegration::updateDpi() @@ -297,15 +304,14 @@ void QWasmIntegration::updateDpi() if (dpi.isUndefined()) return; qreal dpiValue = dpi.as(); - for (QWasmScreen *screen : m_screens) - QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen->screen(), dpiValue, dpiValue); + for (const auto &canvasAndScreen : m_screens) + QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(canvasAndScreen.second->screen(), dpiValue, dpiValue); } void QWasmIntegration::resizeAllScreens() { - qDebug() << "resizeAllScreens"; - for (QWasmScreen *screen : m_screens) - screen->updateQScreenAndCanvasRenderSize(); + for (const auto &canvasAndScreen : m_screens) + canvasAndScreen.second->updateQScreenAndCanvasRenderSize(); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasmintegration.h b/src/plugins/platforms/wasm/qwasmintegration.h index 2102f5c226..08b68cb5f7 100644 --- a/src/plugins/platforms/wasm/qwasmintegration.h +++ b/src/plugins/platforms/wasm/qwasmintegration.h @@ -40,6 +40,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -83,9 +84,9 @@ public: static QWasmIntegration *get() { return s_instance; } static void QWasmBrowserExit(); - void addScreen(const QString &canvasId); - void removeScreen(const QString &canvasId); - void resizeScreen(const QString &canvasId); + void addScreen(const emscripten::val &canvas); + void removeScreen(const emscripten::val &canvas); + void resizeScreen(const emscripten::val &canvas); void resizeAllScreens(); void updateDpi(); @@ -93,8 +94,7 @@ private: mutable QWasmFontDatabase *m_fontDb; mutable QWasmServices *m_desktopServices; mutable QHash m_backingStores; - - QHash m_screens; + QVector> m_screens; mutable QWasmClipboard *m_clipboard; qreal m_fontDpi = -1; mutable QScopedPointer m_inputContext; diff --git a/src/plugins/platforms/wasm/qwasmscreen.cpp b/src/plugins/platforms/wasm/qwasmscreen.cpp index ba14421255..a2bcd4fcb4 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.cpp +++ b/src/plugins/platforms/wasm/qwasmscreen.cpp @@ -50,15 +50,13 @@ using namespace emscripten; QT_BEGIN_NAMESPACE -QWasmScreen::QWasmScreen(const QString &canvasId) - : m_canvasId(canvasId) - +QWasmScreen::QWasmScreen(const emscripten::val &canvas) + : m_canvas(canvas) { m_compositor = new QWasmCompositor(this); m_eventTranslator = new QWasmEventTranslator(this); updateQScreenAndCanvasRenderSize(); - emscripten::val canvas = emscripten::val::global(m_canvasId.toUtf8().constData()); - canvas.call("focus"); + m_canvas.call("focus"); } QWasmScreen::~QWasmScreen() @@ -91,9 +89,14 @@ QWasmEventTranslator *QWasmScreen::eventTranslator() return m_eventTranslator; } +emscripten::val QWasmScreen::canvas() const +{ + return m_canvas; +} + QString QWasmScreen::canvasId() const { - return m_canvasId; + return QWasmString::toQString(m_canvas["id"]); } QRect QWasmScreen::geometry() const @@ -134,7 +137,7 @@ qreal QWasmScreen::devicePixelRatio() const QString QWasmScreen::name() const { - return m_canvasId; + return canvasId(); } QPlatformCursor *QWasmScreen::cursor() const @@ -180,24 +183,22 @@ void QWasmScreen::updateQScreenAndCanvasRenderSize() // Setting the render size to a value larger than the CSS size enables high-dpi // rendering. - QByteArray canvasSelector = "#" + m_canvasId.toUtf8(); + QByteArray canvasSelector = "#" + canvasId().toUtf8(); double css_width; double css_height; emscripten_get_element_css_size(canvasSelector.constData(), &css_width, &css_height); QSizeF cssSize(css_width, css_height); QSizeF canvasSize = cssSize * devicePixelRatio(); - val document = val::global("document"); - val canvas = document.call("getElementById", QWasmString::fromQString(m_canvasId)); - canvas.set("width", canvasSize.width()); - canvas.set("height", canvasSize.height()); + m_canvas.set("width", canvasSize.width()); + m_canvas.set("height", canvasSize.height()); QPoint offset; - offset.setX(canvas["offsetTop"].as()); - offset.setY(canvas["offsetLeft"].as()); + offset.setX(m_canvas["offsetTop"].as()); + offset.setY(m_canvas["offsetLeft"].as()); - emscripten::val rect = canvas.call("getBoundingClientRect"); + emscripten::val rect = m_canvas.call("getBoundingClientRect"); QPoint position(rect["left"].as() - offset.x(), rect["top"].as() - offset.y()); setGeometry(QRect(position, cssSize.toSize())); diff --git a/src/plugins/platforms/wasm/qwasmscreen.h b/src/plugins/platforms/wasm/qwasmscreen.h index fcf693681c..ea7ffc4193 100644 --- a/src/plugins/platforms/wasm/qwasmscreen.h +++ b/src/plugins/platforms/wasm/qwasmscreen.h @@ -37,6 +37,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE class QPlatformOpenGLContext; @@ -50,12 +52,13 @@ class QWasmScreen : public QObject, public QPlatformScreen { Q_OBJECT public: - QWasmScreen(const QString &canvasId); + QWasmScreen(const emscripten::val &canvas); ~QWasmScreen(); void destroy(); static QWasmScreen *get(QPlatformScreen *screen); static QWasmScreen *get(QScreen *screen); + emscripten::val canvas() const; QString canvasId() const; QWasmCompositor *compositor(); @@ -80,7 +83,7 @@ public slots: void setGeometry(const QRect &rect); private: - QString m_canvasId; + emscripten::val m_canvas; QWasmCompositor *m_compositor = nullptr; QWasmEventTranslator *m_eventTranslator = nullptr; QRect m_geometry = QRect(0, 0, 100, 100); -- cgit v1.2.3