vcl/qt5/QtFrame.cxx |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

New commits:
commit 9497be2e668c19aedc588588bf9dfed9338afe54
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri May 17 17:02:49 2024 +0200
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Sat May 18 15:17:40 2024 +0200

    tdf#160565 tdf#145735 qt: Avoid native window handles for Qt 6
    
    Similar to the tdf#122293 scenario with Qt 5 on Wayland,
    using native windows causes unresponsive UI even with
    the xcb Qt QPA plugin when using Qt 6.
    
    Therefore, don't call `QWidget::winId()` at all when
    using Qt 6, but just refuse to resolve a native window
    handle, the same way that is already done here for the
    wayland Qt QPA plugin with qt5.
    
    Add a comment based on the one originally added with
    
        commit 0e3c3b842e14b9646d3697cf1266be21359e0f13
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Sat May 11 21:31:33 2019 +0200
    
            tdf#122293 qt5: Use "alien widgets" by default on Wayland
    
    that was later dropped during a refactoring.
    
    This code path is triggered when trying to resolve the
    parent window for a file picker (s. `QtFilePicker::initialize`).
    In a quick test in a KDE Plasma 5 Wayland session on Debian testing,
    the modality behavior was unchanged with or without this change in
    place:
    
    * With qt6 xcb, the main window nicely gets grayed out and is
      unresponsive while the file dialog gets shown  when using
      e.g. "File" -> "Open" in Writer.
    
    * With qt6 wayland, the main window is not grayed out and looks
      more "active" still, but doesn't actually accept keyboard
      or mouse input.
    
    This is basically the same in other Qt/KDE applications, e.g.
    a self-compiled Kate from git master, so not LO-specific.
    
    If resolving the parent for the file picker turns out to be necessary,
    maybe something similar to what commit
    
        commit 3ff4800fe400de916c97f587322104af06cc0879
        Author: Caolán McNamara <caol...@redhat.com>
        Date:   Wed Apr 4 10:22:34 2018 +0100
    
            weld SvInsertOleDlg
    
            and
    
            weld SfxInsertFloatingFrameDialog
    
            and smuggle in the parent widget for the Gtk File dialog via
            an XWindow interface
    
    did for gtk3 might be worth looking into.
    
    However, I can at least not reproduce issues like the one described
    for gtk3 in
    
        commit 203d96787969f707c78101be18d51b44ace98f93
        Author: Caolán McNamara <caol...@redhat.com>
        Date:   Mon Jun 21 13:01:52 2021 +0100
    
            give folderpicker an optional parent
    
            so, like a file picker, it can make its parent modal while its
            operating. Otherwise its possible to interact with the parent 
dialog in
            undesirable ways, e.g. file, export as, export as epub, the folder
            picker of 'media directory'
    
    with the qt6 VCL plugin even with this commit in place.
    
    Another scenario relying on a native window handle is video
    playback with GStreamer's x11 video sink.
    
    That still works for qt5 with the xcb plugin as the handle is
    still returned for that one.
    
    For qt6 with the xcb plugin, that didn't work properly
    without this commit either (at least not in my tests with
    current qtbase dev as of commit
    70a2e7f32b9f9ce19d1538f14fbde7b0d1e77ffd), s.
    tdf#145735 comment 7.
    It's now broken a different way than before
    (extra windows show up instead of no video being shown).
    This will be further tracked together with a solution for
    Wayland in tdf#125219.
    
    As a side note, forcing native windows for everything
    using `QT_USE_NATIVE_WINDOWS=1` as described at [1]
    causes more sever brokenness with the qt6 xcb plugin
    (mostly black window in Writer instead of showing the
    actual content).
    
    [1] https://doc.qt.io/qt-6/qwidget.html#native-widgets-vs-alien-widgets
    
    Change-Id: I9718c680bd8bc4ff0574f171403d965c1beac781
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167783
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins
    (cherry picked from commit 2f4103da5625a9b90eb41d5c767a248a8d0b4255)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167813
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index 6aff814aacd2..1c3839a287d9 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -35,6 +35,7 @@
 #include <QtX11Support.hxx>
 #endif
 
+#include <QtCore/QLibraryInfo>
 #include <QtCore/QMimeData>
 #include <QtCore/QPoint>
 #include <QtCore/QSize>
@@ -1339,8 +1340,17 @@ void QtFrame::ResolveWindowHandle(SystemEnvData& rData) 
const
     if (!rData.pWidget)
         return;
     assert(rData.platform != SystemEnvData::Platform::Invalid);
-    if (rData.platform != SystemEnvData::Platform::Wayland)
+    // Calling QWidget::winId() implicitly enables native windows to be used 
instead
+    // of "alien widgets" that don't have a native widget asscoiated with them,
+    // s. https://doc.qt.io/qt-6/qwidget.html#native-widgets-vs-alien-widgets
+    // Avoid native widgets with Qt 5 on Wayland and with Qt 6 altogether as 
they
+    // cause unsresponsive UI, s. tdf#122293/QTBUG-75766 and tdf#160565
+    // (for qt5 xcb, they're needed for video playback)
+    if (rData.platform != SystemEnvData::Platform::Wayland
+        && QLibraryInfo::version().majorVersion() < 6)
+    {
         rData.SetWindowHandle(static_cast<QWidget*>(rData.pWidget)->winId());
+    }
 }
 
 bool QtFrame::GetUseReducedAnimation() const { return 
GetQtInstance()->GetUseReducedAnimation(); }

Reply via email to