summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/qandroidplatformwindow.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Android: improve setting of platform window states and flagsAssam Boudjelthia2025-10-161-26/+13
| | | | | | | | | | | | | | | | | | | | | | | The current implementation had two issues: 1. Setting a flag before the window is shown has no effect, becuase the android platform window had its own flags data, but before the window is shown, the platform window isn't yet created, so that initial flag setting is lost. 2. The system UI was never updated when a flag has changed, as in the case of Qt::ExpandedClientAreaHint which affects the system the system UI visibility. This patch gets rid of rid of the platform window's separate internal tracking of states and flags to make things simpler. Also, it changes the way updateSystemUiVisibility() works by passing states/flags to it to be more flexible to handle all changes and cases. Fixes: QTBUG-140830 Pick-to: 6.10 6.8 6.5 Change-Id: Iff9f1b02a0a71320a3514e462de0cd6c1b8589fd Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: move system ui code to its own QtWindowInsetsController classAssam Boudjelthia2025-10-131-4/+12
| | | | | | | | | | Most of the code dealing with system ui visibility, system bars and insets is under QtDisplayManager which is not exactly the correct place. Instead of that move, move the code its own class named QtWindowInsetsController which has all those utilities. Change-Id: I174f9cc5a1a324c65630cd7edd01c05ee6114c1c Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Android: guard platform plugin egl code behind QT_CONFIG(egl)Assam Boudjelthia2025-10-011-1/+0
| | | | | | | Pick-to: 6.10 6.8 Fixes: QTBUG-140536 Change-Id: Ic2f3fe3fde80af7b84d8df5cf38e03de6b627112 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: don't keep system visibility cache on both C++ and JavaAssam Boudjelthia2025-09-121-6/+2
| | | | | | | | | | | Since Android Java side is managing the system ui visibility calls, keep any cached states there to avoid any inconsistency between the two sides, so Qt always sends the call and Java decides whether it goes through with it or not. Pick-to: 6.10 6.10.0 Change-Id: I68dfb64fe38ecd7d71a6aae5bfa2e32b8f481b04 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: warn instead of assert on invalid winId on windowFocusChangedAssam Boudjelthia2025-09-101-1/+6
| | | | | | Pick-to: 6.9 6.10 Change-Id: I2cb0431dccc1fd87a4d363b4bcc9a18443abbaaf Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: fix rendering glitch after window size changesAssam Boudjelthia2025-09-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | Currently, apps might end up with half of the window size not rendered or not reflecting size changes. When the root layout size changes, the available size is reported but the screen size is not always sent from Android callbacks, this is the case after an orientation change. So make sure here to update the the screen geometry also when receiving the available geometry. This part amends 7dcf58eedbeb0cbfbf01f3aabfb72f8546f96cdf. However, the issue was still present in 6.9 and 6.8 before that above commit, to fix that, it's needed to call sendExpose() to send expose event for the window in the new region, and this after propagating the surface change from QtSurface to the platform window. Pick-to: 6.8 6.9 6.10 6.10.0 Fixes: QTBUG-132718 Fixes: QTBUG-134082 Task-number: QTBUG-124140 Change-Id: I390aaba45f324693dc47d7d0110fdb22dc9aca61 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: report margins only when window is under unsafe areaAssam Boudjelthia2025-09-061-15/+20
| | | | | | | | | | | | | | | | | | | | | To avoid reporting margins/insets when it's not needed, like for some older Android versions, or to avoid wrong or improperly handled resize events, we only report the margins values for a window to reach the safe, otherwise, we could end up with extra padding from Qt safe margins and the system padding. Also, to ensure the root view location is up-to-date and avoid going into a race condition, we post() the safe margins reporting to the root view that way we ensure it's done after the root view has gone through the resize event. On safeAreaMarginsChanged() JNI implementation, don't do JNI calls to get the margin values unless the relevant platform window is found. Fixes: QTBUG-135808 Pick-to: 6.9 6.10 Change-Id: Idda072b8ebbd019c54ae6ae45f672bc7abb195b7 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: hook into pre draw and attach listener to deliver safe areaAssam Boudjelthia2025-09-061-5/+0
| | | | | | | | | | | | | | | | | | Instead of relying only on setOnApplyWindowInsetsListener() and trying to guess when to try and deliver root decor insets in case the setOnApplyWindowInsetsListener() doesn't deliver the view's insets early on, a cleaner way is to hook into addOnAttachStateChangeListener() and OnPreDrawListener() listeners. With this approach we guarantee that at least in one of those cases, especially OnPreDrawListener(), we would be guaranteed to get the insets when the view is attached. With this approach we only need to get once such event and from there forward we rely still on setOnApplyWindowInsetsListener(). Fixes: QTBUG-135808 Pick-to: 6.9 6.10 Change-Id: I05bf3009eb9a33f104d01d29e7f02d780900fc66 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Revert "Re-land: Android: destroy the window surface only after exit transition"Assam Boudjelthia2025-09-021-7/+0
| | | | | | | | | | | | | This reverts commit 5ef73686cfb488dfc6a4077a2ecb12f883de1461. Reason for revert: causes multiple regressions. Pick-to: 6.9 6.10 Task-number: QTBUG-127705 Task-number: QTBUG-139606 Task-number: QTBUG-139659 Change-Id: I446d2aad7babf71ed59aa56e29e01b85eb940867 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: rename m_surfaceCreated to m_androidSurfaceCreatedAssam Boudjelthia2025-09-011-4/+4
| | | | | | | | | This would make it clear that the boolean is tracking the Android surface (QtSurface) and not the egl surface. Pick-to: 6.10 Change-Id: Idd46940b9f18d7c489b0ed3ca8b64780f248bb76 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
* Android: set surface type from Raster to OpenGL in QAndroidPlatformWindowAssam Boudjelthia2025-08-281-1/+2
| | | | | | | | ... instead of the QAndroidPlatformOpenGLWindow. Pick-to: 6.10 6.9 6.8 Change-Id: I3e0b72517d03ca95b55eb40320733c55ebd8e03e Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: remove unnecessary comma in debug messageAssam Boudjelthia2025-08-261-1/+1
| | | | | | Pick-to: 6.10 Change-Id: I3071c27d83123512a8980773c2029115c573a37f Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Re-land: Android: destroy the window surface only after exit transitionJani Korteniemi2025-07-241-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Splash screen (or blank launch screen) is shown when exiting the Android application caused by hiding shown windows and destroying it's surface before application exit. On application exit all windows are first set to invisible then surfaces destroyed and finally removed from layout. Also window opacity change can show underlying splash screen as it is set as theme for the application. When pressing Android device's back button application either should hide current window or exit the application. When exiting current window should be visible during application exit. Add AtomicBoolean m_canBeDestroyed to QtWindow for blocking normal surface removal. Set false by default from QtActivityDelegate.addTopLevelWindow and changed from QAndroidPlatformWindow::setVisible() dependent on if there are more visible windows present. Destroy last window with delay so it can be shown during app exit. Set full screen flags for current window on pre Android 11 so it's decor view can scale to full screen on multi-window mode view is when updated. In QtActivityDelegate.setUpSplashScreen() set layout to use android device's DayNight theme colors to not show splash screen theme if window opacity is changed. Previous reverted change caused crashed tst_qmltc_examples test. Previous SHA e40d9d43614b71c803a92fc640fc66f9a96cb095 Fixes: QTBUG-127705 Task-number: QTBUG-124140 Pick-to: 6.8 6.9 6.10 Change-Id: Ifda904c08c3b4363005e953e5ba9ff15a46e5195 Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Revert "Destroy window surface after exit transition for Qt for Android apps"Assam Boudjelthia2025-06-251-10/+0
| | | | | | | | | | | | | | | This reverts commit e40d9d43614b71c803a92fc640fc66f9a96cb095. Reason for revert: blocks submodule update round QTBUG-137942 Task-number: QTBUG-137942 Task-number: QTBUG-127705 Task-number: QTBUG-124140 Change-Id: Ie5d0c29ccf8814d73efd333cd71b4597b154ff1d Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Lauri Pohjanheimo <lauri.pohjanheimo@qt.io> (cherry picked from commit d1be51d38b2bd4ac81e94ce8692e155219e9535a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
* Revert "Revert "Android: consider DecorView insets at app startup""Assam Boudjelthia2025-06-241-0/+5
| | | | | | | | | | This reverts commit 05f8abc61dd2429d7041a87d5bfc7bffbb105f12. Reason for revert: Quick tests fixed to account for safe margins. Pick-to: 6.10 6.9 Change-Id: I3c9d182267bb22b36ed0031b0fe744f331559b3d Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Destroy window surface after exit transition for Qt for Android appsJani Korteniemi2025-06-191-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Splash screen (or blank launch screen) is shown when exiting the Android application caused by hiding shown windows and destroying it's surface before application exit. On application exit all windows are first set to invisible then surfaces destroyed and finally removed from layout. Also window opacity change can show underlying splash screen as it is set as theme for the application. When pressing Android device's back button application either should hide current window or exit the application. When exiting current window should be visible during application exit. Add AtomicBoolean m_canBeDestroyed to QtWindow for blocking normal surface removal. Set false by default from QtActivityDelegate.addTopLevelWindow and changed from QAndroidPlatformWindow::setVisible() dependent on if there are more visible windows present. Destroy last window with delay so it can be shown during app exit. In QtActivityDelegate.setUpSplashScreen() set layout to use android device's DayNight theme colors to not show splash screen theme if window opacity is changed. Fixes: QTBUG-127705 Fixes: QTBUG-124140 Pickt-to: 6.8 6.9 6.10 Change-Id: I74adf693dac599c0b46b1f427e563683c1033565 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Revert "Android: consider DecorView insets at app startup"Jani Heikkinen2025-06-031-5/+0
| | | | | | | | | | This reverts commit e96a4b84e136d065054600c07bf5fae17f3049ce. Reason for revert: QTBUG-137306 Pick-to: 6.10 6.9 Change-Id: Id5718737f3f426de49ad109d214af1c920e5ae22 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Android: consider DecorView insets at app startupAssam Boudjelthia2025-05-231-0/+5
| | | | | | | | | | | | | | | | | Set the initial safe area margins based on the decor view as a workaround since setOnApplyWindowInsetsListener() is not being called reliably at startups. This way we can get the app's initial insets at startup, then after that rely on each window reporting its insets. And apply this initial inset only for top level windows that match the screen size, i.e. we assume edge-to-edge is enable in that case. Pick-to: 6.9 Task-number: QTBUG-135808 Fixes: QTBUG-135283 Fixes: QTBUG-135227 Change-Id: Ic5771809c94302b927ccc67ccc07c73ccc73b91d Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Fix mixed-type usage of qFuzzyCompareDennis Oberst2025-03-141-1/+1
| | | | | | | | | | | | | | | When building Qt with a non-double qreal type, i.e. QT_COORD_TYPE=float, mixing types on qFuzzyCompare will result in ambiguities since only qFuzzyCompare(float, float) qFuzzyCompare(double, double) are accepted. Pick-to: 6.9 6.8 Change-Id: I4450516ffdf019ef8288aefd99a8e729c039bcd1 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: don't call QPlatformWindow::setGeometry() explicitlyAssam Boudjelthia2025-01-281-2/+0
| | | | | | | | | ... under QAndroidPlatformWindow::setGeometry() since it's going to be called under QWindowSystemInterface::handleGeometryChange(). Task-number: QTBUG-132716 Change-Id: I12d4cfd125fab73e47c5a66caf4275897ba112eb Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
* Android: simplify/refactor QAndroidPlatformWindow::setVisible()Assam Boudjelthia2025-01-281-8/+10
| | | | | | | | Simplify the if condidions in this function for better readability. Task-number: QTBUG-132716 Change-Id: I4a4eee61d4b9111d82272205133d7719b7be4a9e Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
* Android: don't run setSystemUiVisibility with same paramsAssam Boudjelthia2025-01-151-2/+6
| | | | | | | | | | Cache fullscreen and expandedToCutout values and run setSystemUiVisibility() only when changes has been made. Task-number: QTBUG-132720 Change-Id: I51559e485653d4091e79391962bc82042714f7be Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
* Android: pass safe area margins to relevant windows onlyAssam Boudjelthia2025-01-071-10/+7
| | | | | | | | | | | | | | | | | Instead of passing the safe area margins to all windows or top windows, we can instead call the listener for setOnApplyWindowInsetsListener() on specific QtWindow and have it pass the windowId with the callback to C++. What was missing before was that the listner was not reset after removing the window and also, we don't need to necessarily require a window matching the id to be found, so that if no window is found we can assume that the callback is not valid. Task-number: QTBUG-131519 Pick-to: 6.9 Change-Id: Idd411e407ac8f5992aa6684ece70329198de1bc2 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: implement safe areas marginsAssam Boudjelthia2024-12-041-12/+50
| | | | | | | | | | | Rely on Android APIs (old and new) to calculate safe area margins, which takes into account the cutout regions and the system bars. Task-number: QTBUG-131519 Task-number: QTBUG-98989 Change-Id: Ie69e6c54df30c76e67d9ca96518e13f9898e6312 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: improve fullscreen and maximized states handlingAssam Boudjelthia2024-12-031-11/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rework fullscreen and maximized/expanded states handling by simplifying and re-organizing the code, removing some unnecessary code. Also, use newer APIs and handling the cutout regions. For expanded mode, use transparent instead of translucent so that the user can decide what color to use if needed, and in any case using the translucent flags is deprecated. You might still notice some artifacts as in QTBUG-88676, a fix for that is outside the scope of this patch. When going off of fullscreen mode one some cases you might notice a white/black black at the bottom and that's because QtRootLayout.onSizeChanged() is reporting wrong available size which is also an existing issue and outside of this scope. Fixes: QTBUG-96105 Fixes: QTBUG-101968 Fixes: QTBUG-127394 Fixes: QTBUG-121820 Task-number: QTBUG-109878 Task-number: QTBUG-119594 Change-Id: I586775a1d0414ec0adbc968d50b9c1a1ce466422 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: move setSystemUiVisibility() to QAndroidPlatformWindowAssam Boudjelthia2024-12-031-3/+8
| | | | | | | | Move calls for handling system UI visibility to QAndroidPlatformWindow where they belongs. Change-Id: I3802cf9d205ee6678f71b787c5ea4804d3aaeb29 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: rename and move updateWindow native method to QtWindowAssam Boudjelthia2024-12-031-0/+29
| | | | | | | | | | | | That method is related to window management so move it to QtWindow where it belongs, and any related C++ code from androidjnimain.cpp to QAndroidPlatformWindow. Rename the method to updateWindows since it's operating on all windows and not one window. Change-Id: I91e729b0749b6a8168b7126f9140d79c542b23d3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: check Qt::ExpandedClientAreaHint when setting sizeAssam Boudjelthia2024-12-031-1/+1
| | | | | | | | | No need to also check for Qt::WindowMaximized, if we're using Qt::ExpandedClientAreaHint, we would expect the full size to be used. Change-Id: I52db0224aa96409a8f2d984e01192001f9b42440 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Introduce Qt::ExpandedClientAreaHintTor Arne Vestbø2024-11-251-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The hint requests that the window's client area is expanded to fill parts of the window that might be (partially) covered by, or conflicting with, other (system) UI elements, such as the window's title bar, resize controls, or a status bar. The safe area margins of the window will reflect any areas that may have conflicting UI elements. If the client area is expanded into the area previously covered by the frame margins, the frame margins are reduced accordingly, as the frame margins represent the non-client-area parts of the window. This new flag replaces, and overlaps in value, with the existing Qt::MaximizeUsingFullscreenGeometryHint, as the latter was added to cover this exact use-case for mobile platforms. Now that we have the use-case on desktop platforms as well we want to use a more generic flag, so the old flag has been deprecated. Semantically, on iOS and Android, without the flags set, the window can be seen as being maximized to take up the entire screen, but with a frameMargin() that reflects the system status bar and resize controls. That's not technically how we implement things right now, but this is an implementation detail that will be changed in a follow-up. On macOS the flag maps to NSWindowStyleMaskFullSizeContentView, and on Windows we have an implementation cooking that uses the DwmExtendFrameIntoClientArea function. Task-number: QTBUG-127634 Change-Id: I9b6863b1550ccc056c16bce235d87b26a7d239b9 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
* Android: Allow to open Keyboard without touchBartlomiej Moskal2024-10-091-0/+5
| | | | | | | | | | | | | | | After changes in f4050cc5ea7490ba3b8b2bb0a174559d7e72a27e commit, the keyboard can be opened only when internal m_currentEditText is set (what is happening only on touch). Because of that, the keyboard cannot be opened just by setting focus on an item like it was before. To allow open the keyboard not only after touch, QtWindow needs to be informed about each focus change. Fixes: QTBUG-124360 Pick-to: 6.8 Change-Id: Ic3ca4451f53df55bfb1f3e300078fd1916e77155 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add destruction guard in QAndroidPlatformWindowPetri Virkkunen2024-10-021-0/+16
| | | | | | | | | | | | To avoid calling functions in QAndroidPlatformWindow during/after destruction of the object, create a mutex and use lock_guard to synchronize the destruction of the object and native function calls originating from Android events. Task-number: QTBUG-118231 Pick-to: 6.8 Change-Id: I29818386456c6969ca507d74574b722bf8a19019 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: clean up Surface resources when it is destroyedTinja Paavoseppä2024-10-021-1/+5
| | | | | | | | | | | | | | | Clean up any resources using the Android Surface when it has been destroyed. Previously the resource clean up was done only after Qt app state changed to Hidden or below and we initiate the removal of the Surface. However, in the case of QtSurface which is a SurfaceView, it will destroy its Surface before we ever get to that part, leading to the resources holding a reference to a destroyed Surface. Task-number: QTBUG-118231 Pick-to: 6.8 Change-Id: I282ddcc2813bf0a4e19cbb906376258dd2b4004f Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Guard EGLSurface with a mutexTinja Paavoseppä2024-10-021-6/+4
| | | | | | | | | | | | | | | | | | | | QAndroidPlatformOpenGlWindow creates an EGLSurface to wrap the native Android Surface. Once this EGLSurface is returned to QPlatformEglContext, nothing is guarding it anymore, and Android can freely destroy the underlying Surface. This leads to failed EGL operations when leaving from the app or returning to it, as that is when Android destroys/recreates the Surface. Use the mutex from QAndroidPlatformWindow to guard setting the Surface, and during the makeCurrent() and swapBuffers() calls. Locking until returning from these functions ensures Android cannot destroy the Surface in the middle of them. Task-number: QTBUG-118231 Pick-to: 6.8 Change-Id: I614575c42f7f0c2c17022994d3bc542726ebf039 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Don't set geometry when creating surface or adding native viewTor Arne Vestbø2024-08-081-10/+1
| | | | | | | | | | | | | | The window geometry has been propagated to the QtWindow layout already via setGeometry() already, so we don't need the additional plumbing for createSurface and setNativeView. It's enough to set the layout params of the inserted View to match the parent (the QtWindow in this case). Pick-to: 6.8 Change-Id: I40b44282e80ed04b109ffc1958144cb3e3edd11d Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Always apply initial geometry from QWindow to QtWindowTor Arne Vestbø2024-08-081-2/+1
| | | | | | | | | | | We shouldn't rely on the QWindow geometry being propagated through other means, so we should always propagate the geometry when initializing the QAndroidPlatformWindow. Pick-to: 6.8 Change-Id: I489b059ffae7a209005edaaff3674c1f39273bee Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
* Android: Simplify QAndroidPlatformWindow::setGeometry plumbingTor Arne Vestbø2024-08-081-17/+17
| | | | | | | | | | | Instead of splitting the geometry setting into setGeometry and setNativeGeometry we can leave setGeometry to do the right choice of whether to propagate the geometry to the QtWindow layout or not. Pick-to: 6.8 Change-Id: I30291dbf7079df76f4d3a54d6ea3c9c3f1329c90 Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Remove m_surfaceCreated check from setNativeGeometryTor Arne Vestbø2024-08-081-2/+1
| | | | | | | | | | | As long as we have a QtWindow we should be able to set its layout parameters. Adding surfaces or native views later on will adopt the QtWindow's layout params. Pick-to: 6.8 Change-Id: I08591e18f95bfe1e85358bb68507145d35630486 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
* Android: Create QtWindow before applying QWindow geometry during initTor Arne Vestbø2024-08-081-19/+19
| | | | | | | | | | | | | | | | | | | | | | | | | During QAndroidPlatformWindow::initialize() we call setGeometry, which may end up in QAndroidPlatformWindow::setNativeGeometry() via one of the QAndroidPlatformWindow subclasses, i.e. GL, Vulkan, or foreign window. We currently bail out from setNativeGeometry if !m_surfaceCreated, but this is only a workaround for the m_nativeQtWindow not being alive yet. As long as we have a m_nativeQtWindow, we should be able to set the layout parameters of that QtWindow, independently of whether it has a QtSurface or is hosting a foreign Android view. As a start, move the QtWindow initialization earlier in initialize(). The isEmbeddingContainer() check can go at the top, as we shouldn't do any modifications to a window that's purely used to act as a container when embedding Qt in native Android apps. Pick-to: 6.8 Change-Id: Ia3f0b33e6729f5399946d86799f39877d058511b Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
* Android: Don't add QtEditText to foreign windowsTor Arne Vestbø2024-08-081-1/+2
| | | | | | | | | | We don't handle input on behalf of these windows, so we don't need a QtEditText for them. Any Qt managed child QWindow added to a foreign window will get its own QtEditText as normal. Pick-to: 6.8 Change-Id: I32daa83f22487aadca7509379595b6c82b29ea4a Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
* Android: Initialize window in QPlatformWindow::initialize() overrideTor Arne Vestbø2024-08-081-0/+7
| | | | | | | | | | | | | | | | | During the QAndroidPlatformWindow constructor we can't safely call virtual functions of QPlatformWindow and expect them to resolve to subclasses, e.g. QAndroidPlatformForeignWindow. Importantly, this means we can't check isForeignWindow() during construction. QPlatformWindow has a dedicated initialization function for this use-case, so use that instead. The existing order of between QAndroidPlatformForeignWindow and QAndroidPlatformWindow has been kept as is. Pick-to: 6.8 Change-Id: I2a08326fae6a3b079cd153c50a13794310ac3d74 Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
* Android: Implement input backend interfacePetri Virkkunen2024-05-211-3/+10
| | | | | | | | | | | | | | | | | | | Interface for input-related actions, based off of QtInputDelegate. Implements all the QtInputDelegate functions called from native code plus an extra function that allows the native side to get a QtInputConnectionListener object for QtWindow creation. Removed some unused functions and unmarked @UsedFromNativeCode in some that are no longer called from native, but still used from java. Added QtInputConnectionListener null checks in QtInputConnection, due to the possibility of a non-existent InputInterface returning a null QtInputConnectionListener for the QtInputConnection constructor. Task-number: QTBUG-118874 Change-Id: I8d4cde3e0c735471d0fa30d16db20eb13542cdaa Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
* Android: Add QT_ANDROID_SURFACE_CONTAINER_TYPE env varTinja Paavoseppä2024-04-261-4/+13
| | | | | | | | | | | | | | | | | | The Android QPA picks between two types of Views that can provide a Surface for it, SurfaceView and TextureView. Normally, SurfaceView is used if there's just one window in the app, and TextureView is used for any additional windows, since it allows better control over the z order between the windows. Add an environment variable QT_ANDROID_SURFACE_CONTAINER_TYPE that can be used to override the normal choosing strategy, and force the application to use either one of the View classes for all the windows of the app. This helps with testing changes to the Android QPA windowing, as you can use the same app to test both Surface Views easily. Pick-to: 6.7 Change-Id: Icc15fd9675175b854354a379b6ffa7ae5532408e Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Implement input connection listener in QtInputDelegateTinja Paavoseppä2024-02-191-1/+2
| | | | | | | | | | | This way we can just pass the input delegate as the listener for QtEditText when we create it, and having the listener in a separate member doesn't provide a real benefit anyway. Task-number: QTBUG-118139 Pick-to: 6.7 Change-Id: I0125c87ecd39eed550a120ea8326d2c50a1b016e Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: QtActivityDelegateBase listens to focus events from child viewsPetri Virkkunen2024-02-151-1/+19
| | | | | | | | | | | | | In order to detect gaining/losing and moving focus between windows, implement GlobalFocusChangeListener for the root View. Add a surfaceFocusChanged native function in QAndroidPlatformWindow in order to follow these focus changes. Task-number: QTBUG-118139 Pick-to: 6.7 Change-Id: Ia9bf6249c28a420f42793a9829aef31b12757630 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Fix QtTextureView inverted opacity conditionTinja Paavoseppä2024-02-061-1/+1
| | | | | | | | | | | The Android TextureView class wants to know whether the view is opaque, while the condition has been evaluating whether it should be transparent. Invert the condition to let Android know correctly whether the TextureView should have transparency. Pick-to: 6.7 Change-Id: Ic636f78dd3c691e85456c579e4559b8bc7a077a2 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Remove parent before adding window to screenTinja Paavoseppä2024-01-221-1/+1
| | | | | | | | | | | | | When a window's parent is set to null, remove the corresponding native view from its previous parent layout before adding it to the layout for top level windows. If the removal from the previous layout is done after adding the window to the screen, an exception will be thrown due to the view already having a parent. Fixes: QTBUG-121232 Pick-to: 6.7 Change-Id: I1c065b5158d32150042d25fb64f10cf48f83f9f4 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Handle embedding container windows betterTinja Paavoseppä2024-01-161-10/+16
| | | | | | | | | | | Initialize surface container type to TextureView to make sure it's set also for embedding containers. Additional checks for embedding containers when setting parent or changing visibility. Pick-to: 6.7 Change-Id: Iba07bfbb9e8f16804627efbdfe78559ac2580e41 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add support for foreign window acting as embedding containerTinja Paavoseppä2023-12-141-0/+10
| | | | | | | | | | | | | | | | In the case when our foreign window is created to act as a parent for embedding Qt content into a native Android app, we need a more "hands off" approach. If the foreign window represents an Android view which the user has created outside of Qt, we should not try to reparent it since it already has a parent in the view hierarchy. Neither should we try to remove it from the hierarchy, or set its visibility. Pick-to: 6.7 Change-Id: Iea496578a40f45ebdd73947a1bb0e46a7131108c Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: Use TextureView when multiple windows presentTinja Paavoseppä2023-12-141-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | The SurfaceView class is not the best option for when we have multiple windows, as the created Surface can only either be below the window or on top of it, it is not a part of the view hierarchy. Replace the SurfaceView with TextureView when there are more than one window. This way the surface will be a part of the view hierarchy, and will respect z-ordering. When there is only one window, keep using the SurfaceView approach to limit the effect on existing apps, as well as enable some of the benefits SurfaceView has for e.g. game and multimedia apps, such as HDR ability. Move touch handling from QtSurface to QtWindow, so touches are handled also when using TextureView instead of QtSurface aka SurfaceView. Pick-to: 6.7 Task-number: QTBUG-118142 Change-Id: I37dcaf0fb656cfc1ff2eca0a3bfe7259f607411c Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Android: Make winId() return the underlying QtWindow jobjectTinja Paavoseppä2023-12-131-3/+5
| | | | | | | | | | | | | | Previously, winId() returned a simple integer ID, incremented by one for each window, instead of a handle to the underlying window. Note, if constructing a QWindow with fromWinId(), the passed jobject will not be the same one returned by winId(), as the passed jobject, assumed to be a View, will be wrapped inside a QtWindow to ensure child windows can be added to it if needed. Pick-to: 6.7 Change-Id: I9d5d977eeb08d4cc3594f7339660fe94c3a55864 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>