tdf#139609 avoid fetching unnecessary xid under gtk3

because of the side effects

using a bare GtkGrid as m_pSocket in vcl/unx/gtk3/gtk3gtkobject.cxx
is perhaps a poor choice, getting its xid causes poor side effects
wrt events belonging to its child widgets getting delivered to
the SalFrame widget, so duplicate scrolling after showing a opengl
slide and/or showing a video and lots of flickering

we're (generally at least) not using the xid under gtk3 so don't set it
unless it's explicitly asked for. Happily the gtk Player::createPlayerWindow
doesn't use its arg[0] xid in any case, so don't bother setting it for
that backend.

Change-Id: I1c59a607a332635091782c3b49de10647558f301
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109941
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>

and...

use an accessor for SystemEnvData::aWindow

with an eye to making it on-demand

Change-Id: If6cefd68a336dc6afe23591c857bd71034215b54
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109929
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110005
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx
index 932e1dd..9bc8920 100644
--- a/avmedia/source/gstreamer/gstplayer.cxx
+++ b/avmedia/source/gstreamer/gstplayer.cxx
@@ -880,11 +880,14 @@ uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( co
        g_object_set(G_OBJECT(mpPlaybin), "video-sink", pVideosink, nullptr);
        g_object_set(G_OBJECT(mpPlaybin), "force-aspect-ratio", FALSE, nullptr);

        mnWindowID = pEnvData->aWindow;
        mpDisplay = pEnvData->pDisplay;
        SAL_INFO( "avmedia.gstreamer", AVVERSION "set window id to " << static_cast<int>(mnWindowID) << " XOverlay " << mpXOverlay);
        if (!mbUseGtkSink)
        {
            mnWindowID = pEnvData->GetWindowHandle(pParentWindow->ImplGetFrame());
            mpDisplay = pEnvData->pDisplay;
            SAL_INFO( "avmedia.gstreamer", AVVERSION "set window id to " << static_cast<int>(mnWindowID) << " XOverlay " << mpXOverlay);
        }
        gst_element_set_state( mpPlaybin, GST_STATE_PAUSED );
        if ( mpXOverlay != nullptr )
        if (!mbUseGtkSink && mpXOverlay)
            gst_video_overlay_set_window_handle( mpXOverlay, mnWindowID );
    }

diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx
index 01c25c29..dec4d00 100644
--- a/avmedia/source/viewer/mediawindow_impl.cxx
+++ b/avmedia/source/viewer/mediawindow_impl.cxx
@@ -34,6 +34,7 @@
#include <unotools/securityoptions.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/svapp.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
#include <vcl/ptrstyle.hxx>
@@ -420,7 +421,12 @@ void MediaWindowImpl::onURLChanged()
        const Point aPoint;
        const Size aSize(mpChildWindow->GetSizePixel());

        aArgs[0] <<= mpChildWindow->GetParentWindowHandle();
        sal_IntPtr nParentWindowHandle(0);
        const SystemEnvData* pEnvData = mpChildWindow->GetSystemData();
        // tdf#139609 gtk doesn't need the handle, and fetching it is undesirable
        if (!pEnvData || pEnvData->toolkit != SystemEnvData::Toolkit::Gtk3)
            nParentWindowHandle = mpChildWindow->GetParentWindowHandle();
        aArgs[0] <<= nParentWindowHandle;
        aArgs[1] <<= awt::Rectangle(aPoint.X(), aPoint.Y(), aSize.Width(), aSize.Height());
        aArgs[2] <<= reinterpret_cast<sal_IntPtr>(mpChildWindow.get());

diff --git a/include/vcl/sysdata.hxx b/include/vcl/sysdata.hxx
index 3abf92b..63b7c81 100644
--- a/include/vcl/sysdata.hxx
+++ b/include/vcl/sysdata.hxx
@@ -21,6 +21,9 @@
#define INCLUDED_VCL_SYSDATA_HXX

#include <sal/types.h>
#include <vcl/dllapi.h>

class SalFrame;

#ifdef MACOSX
// predeclare the native classes to avoid header/include problems
@@ -45,8 +48,10 @@ typedef struct CGContext *CGContextRef;
#include <postwin.h>
#endif

struct SystemEnvData
struct VCL_DLLPUBLIC SystemEnvData
{
    enum class Toolkit { Gen, Gtk3, Qt5 };
    Toolkit             toolkit;        // the toolkit in use
#if defined(_WIN32)
    HWND                hWnd;           // the window hwnd
#elif defined( MACOSX )
@@ -57,40 +62,50 @@ struct SystemEnvData
#elif defined( IOS )
    // Nothing
#elif defined( UNX )
    enum class Toolkit { Gtk3, Qt5, Gen };
    enum class Platform { Wayland, Xcb };

    void*               pDisplay;       // the relevant display connection
    sal_uIntPtr         aWindow;        // the window of the object
    void*               pSalFrame;      // contains a salframe, if object has one
    SalFrame*           pSalFrame;      // contains a salframe, if object has one
    void*               pWidget;        // the corresponding widget
    void*               pVisual;        // the visual in use
    int                 nScreen;        // the current screen of the window
    // note: this is a "long" in Xlib *but* in the protocol it's only 32-bit
    // however, the GTK3 vclplug wants to store pointers in here!
    sal_IntPtr          aShellWindow;   // the window of the frame's shell
    Toolkit             toolkit;        // the toolkit in use
    Platform            platform;       // the windowing system in use
private:
    sal_uIntPtr         aWindow;        // the window of the object
public:

    void SetWindowHandle(sal_uIntPtr nWindow)
    {
        aWindow = nWindow;
    }

    // SalFrame can be any SalFrame, just needed to determine which backend to use
    // to resolve the window handle
    sal_uIntPtr GetWindowHandle(const SalFrame* pReference) const;

#endif

    SystemEnvData()
        : toolkit(Toolkit::Gen)
#if defined(_WIN32)
        : hWnd(nullptr)
        , hWnd(nullptr)
#elif defined( MACOSX )
        : mpNSView(nullptr)
        , mpNSView(nullptr)
        , mbOpenGL(false)
#elif defined( ANDROID )
#elif defined( IOS )
#elif defined( UNX )
        : pDisplay(nullptr)
        , aWindow(0)
        , pDisplay(nullptr)
        , pSalFrame(nullptr)
        , pWidget(nullptr)
        , pVisual(nullptr)
        , nScreen(0)
        , aShellWindow(0)
        , toolkit(Toolkit())
        , platform(Platform())
        , aWindow(0)
#endif
    {
    }
diff --git a/slideshow/source/engine/shapes/viewmediashape.cxx b/slideshow/source/engine/shapes/viewmediashape.cxx
index 950dacc..fdcfde3 100644
--- a/slideshow/source/engine/shapes/viewmediashape.cxx
+++ b/slideshow/source/engine/shapes/viewmediashape.cxx
@@ -24,6 +24,7 @@
#include <sal/log.hxx>
#include <vcl/canvastools.hxx>
#include <vcl/syschild.hxx>
#include <vcl/sysdata.hxx>
#include <vcl/window.hxx>
#include <vcl/graph.hxx>

@@ -432,9 +433,13 @@ namespace slideshow::internal

                        if( mxPlayer.is() )
                        {
                            aArgs[ 0 ] <<=
                                sal::static_int_cast< sal_IntPtr >( mpMediaWindow->GetParentWindowHandle() );
                            sal_IntPtr nParentWindowHandle(0);
                            const SystemEnvData* pEnvData = mpMediaWindow->GetSystemData();
                            // tdf#139609 gtk doesn't need the handle, and fetching it is undesirable
                            if (!pEnvData || pEnvData->toolkit != SystemEnvData::Toolkit::Gtk3)
                                nParentWindowHandle = mpMediaWindow->GetParentWindowHandle();

                            aArgs[ 0 ] <<= nParentWindowHandle;
                            aAWTRect.X = aAWTRect.Y = 0;
                            aArgs[ 1 ] <<= aAWTRect;
                            aArgs[ 2 ] <<= reinterpret_cast< sal_IntPtr >( mpMediaWindow.get() );
diff --git a/toolkit/source/awt/vclxsystemdependentwindow.cxx b/toolkit/source/awt/vclxsystemdependentwindow.cxx
index 2c53edf..37d7f86 100644
--- a/toolkit/source/awt/vclxsystemdependentwindow.cxx
+++ b/toolkit/source/awt/vclxsystemdependentwindow.cxx
@@ -102,7 +102,7 @@ css::uno::Any VCLXSystemDependentWindow::getWindowHandle( const css::uno::Sequen
            {
                css::awt::SystemDependentXWindow aSD;
                aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
                aSD.WindowHandle = pSysData->aWindow;
                aSD.WindowHandle = pSysData->GetWindowHandle(pWindow->ImplGetFrame());
                aRet <<= aSD;
            }
#endif
diff --git a/toolkit/source/awt/vclxtopwindow.cxx b/toolkit/source/awt/vclxtopwindow.cxx
index e9fcd24..196e4a0 100644
--- a/toolkit/source/awt/vclxtopwindow.cxx
+++ b/toolkit/source/awt/vclxtopwindow.cxx
@@ -79,7 +79,7 @@ css::uno::Any VCLXTopWindow::getWindowHandle( const css::uno::Sequence< sal_Int8
            {
                css::awt::SystemDependentXWindow aSD;
                aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
                aSD.WindowHandle = pSysData->aWindow;
                aSD.WindowHandle = pSysData->GetWindowHandle(pWindow->ImplGetFrame());
                aRet <<= aSD;
            }
#endif
diff --git a/vcl/inc/salframe.hxx b/vcl/inc/salframe.hxx
index d55a40b..f79ae07 100644
--- a/vcl/inc/salframe.hxx
+++ b/vcl/inc/salframe.hxx
@@ -215,6 +215,10 @@ public:
    virtual const SystemEnvData*
                            GetSystemData() const = 0;

    // tdf#139609 SystemEnvData::GetWindowHandle() calls this to on-demand fill the aWindow
    // member of SystemEnvData for backends that want to defer doing that
    virtual void            ResolveWindowHandle(SystemEnvData& /*rData*/) const {};

    // get current modifier, button mask and mouse position
    struct SalPointerState
    {
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index dcfdddb..3f88218 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -462,6 +462,8 @@ public:
    // returns system data (most prominent: window handle)
    virtual const SystemEnvData*    GetSystemData() const override;

    virtual void                ResolveWindowHandle(SystemEnvData& rData) const override;

    // get current modifier and button mask
    virtual SalPointerState     GetPointerState() override;

@@ -503,7 +505,7 @@ public:

    static GtkSalFrame         *getFromWindow( GtkWidget *pWindow );

    sal_uIntPtr                 GetNativeWindowHandle(GtkWidget *pWidget);
    sal_uIntPtr                 GetNativeWindowHandle(GtkWidget *pWidget) const;
    virtual sal_uIntPtr         GetNativeWindowHandle() override;

    //Call the usual SalFrame Callback, but catch uno exceptions and delegate
diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx
index 81351e3..6571652 100644
--- a/vcl/opengl/x11/gdiimpl.cxx
+++ b/vcl/opengl/x11/gdiimpl.cxx
@@ -249,7 +249,7 @@ SystemWindowData X11OpenGLContext::generateWinData(vcl::Window* pParent, bool /*
    const SystemEnvData* sysData(pParent->GetSystemData());

    Display *dpy = static_cast<Display*>(sysData->pDisplay);
    Window win = sysData->aWindow;
    Window win = sysData->GetWindowHandle(pParent->ImplGetFrame());

    if( dpy == nullptr || !glXQueryExtension( dpy, nullptr, nullptr ) )
        return aWinData;
@@ -515,7 +515,7 @@ void X11OpenGLContext::initWindow()
    InitChildWindow(m_pChildWindow.get());

    m_aGLWin.dpy = static_cast<Display*>(pChildSysData->pDisplay);
    m_aGLWin.win = pChildSysData->aWindow;
    m_aGLWin.win = pChildSysData->GetWindowHandle(m_pChildWindow->ImplGetFrame());
    m_aGLWin.screen = pChildSysData->nScreen;

    Visual* pVisual = static_cast<Visual*>(pChildSysData->pVisual);
diff --git a/vcl/qt5/Qt5FilePicker.cxx b/vcl/qt5/Qt5FilePicker.cxx
index 9dea45e..18e2458 100644
--- a/vcl/qt5/Qt5FilePicker.cxx
+++ b/vcl/qt5/Qt5FilePicker.cxx
@@ -844,7 +844,7 @@ void SAL_CALL Qt5FilePicker::initialize(const uno::Sequence<uno::Any>& args)
    const auto it
        = std::find_if(pFrames.begin(), pFrames.end(), [&aWindowHandle](auto pFrame) -> bool {
              const SystemEnvData* pData = pFrame->GetSystemData();
              return pData && tools::Long(pData->aWindow) == aWindowHandle;
              return pData && tools::Long(pData->GetWindowHandle(pFrame)) == aWindowHandle;
          });
    if (it != pFrames.end())
        m_pParentWidget = static_cast<Qt5Frame*>(*it)->asChild();
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 06984b9..cbe31b8 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -184,7 +184,7 @@ Qt5Frame::Qt5Frame(Qt5Frame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo)
    // s. tdf#122293/QTBUG-75766
    const bool bWayland = QGuiApplication::platformName() == "wayland";
    if (!bWayland)
        m_aSystemData.aWindow = m_pQWidget->winId();
        m_aSystemData.SetWindowHandle(m_pQWidget->winId());
    else
    {
        // TODO implement as needed for Wayland,
diff --git a/vcl/qt5/Qt5Object.cxx b/vcl/qt5/Qt5Object.cxx
index 29bcb98..6313216 100644
--- a/vcl/qt5/Qt5Object.cxx
+++ b/vcl/qt5/Qt5Object.cxx
@@ -51,7 +51,7 @@ Qt5Object::Qt5Object(Qt5Frame* pParent, bool bShow)
    if (!bWayland)
    {
        m_aSystemData.platform = SystemEnvData::Platform::Xcb;
        m_aSystemData.aWindow = m_pQWindow->winId(); // ID of the embedded window
        m_aSystemData.SetWindowHandle(m_pQWindow->winId()); // ID of the embedded window
    }
    else
    {
diff --git a/vcl/source/window/syschild.cxx b/vcl/source/window/syschild.cxx
index 81cbc43..7e72d10 100644
--- a/vcl/source/window/syschild.cxx
+++ b/vcl/source/window/syschild.cxx
@@ -23,6 +23,7 @@
#include <vcl/syschild.hxx>

#include <window.h>
#include <salframe.hxx>
#include <salinst.hxx>
#include <salobj.hxx>
#include <svdata.hxx>
@@ -173,7 +174,7 @@ sal_IntPtr SystemChildWindow::GetParentWindowHandle() const
#elif defined IOS
    // Nothing
#elif defined UNX
    nRet = GetSystemData()->aWindow;
    nRet = GetSystemData()->GetWindowHandle(ImplGetFrame());
#endif

    return nRet;
@@ -184,4 +185,16 @@ void* SystemChildWindow::CreateGStreamerSink()
    return ImplGetSVData()->mpDefInst->CreateGStreamerSink(this);
}

#if defined( MACOSX )
#elif defined( ANDROID )
#elif defined( IOS )
#elif defined( UNX )
sal_uIntPtr SystemEnvData::GetWindowHandle(const SalFrame* pReference) const
{
    if (!aWindow && pReference)
        pReference->ResolveWindowHandle(const_cast<SystemEnvData&>(*this));
    return aWindow;
}
#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/generic/app/i18n_ic.cxx b/vcl/unx/generic/app/i18n_ic.cxx
index 8f1a814..32390a88 100644
--- a/vcl/unx/generic/app/i18n_ic.cxx
+++ b/vcl/unx/generic/app/i18n_ic.cxx
@@ -164,7 +164,7 @@ SalI18N_InputContext::SalI18N_InputContext ( SalFrame *pFrame ) :
    {
        const SystemEnvData* pEnv = pFrame->GetSystemData();
        ::Window  aClientWindow = pEnv->aShellWindow;
        ::Window  aFocusWindow  = pEnv->aWindow;
        ::Window  aFocusWindow  = pEnv->GetWindowHandle(pFrame);

        // for status callbacks and commit string callbacks
#define PREEDIT_BUFSZ 16
@@ -548,7 +548,7 @@ SalI18N_InputContext::SetICFocus( SalFrame* pFocusFrame )

    const SystemEnvData* pEnv   = pFocusFrame->GetSystemData();
    ::Window  aClientWindow  = pEnv->aShellWindow;
    ::Window  aFocusWindow   = pEnv->aWindow;
    ::Window  aFocusWindow   = pEnv->GetWindowHandle(pFocusFrame);

    XSetICValues( maContext,
                  XNFocusWindow,       aFocusWindow,
diff --git a/vcl/unx/generic/app/saldisp.cxx b/vcl/unx/generic/app/saldisp.cxx
index 94e3c41..8a28f0e 100644
--- a/vcl/unx/generic/app/saldisp.cxx
+++ b/vcl/unx/generic/app/saldisp.cxx
@@ -1882,7 +1882,7 @@ int SalDisplay::CaptureMouse( SalFrame *pCapture )
    if( !pEnv || !*pEnv )
    {
        int ret = XGrabPointer( GetDisplay(),
                                static_cast<::Window>(pEnvData->aWindow),
                                static_cast<::Window>(pEnvData->GetWindowHandle(pCapture)),
                                False,
                                PointerMotionMask| ButtonPressMask|ButtonReleaseMask,
                                GrabModeAsync,
diff --git a/vcl/unx/generic/gdi/cairo_xlib_cairo.cxx b/vcl/unx/generic/gdi/cairo_xlib_cairo.cxx
index aba0667..2382240 100644
--- a/vcl/unx/generic/gdi/cairo_xlib_cairo.cxx
+++ b/vcl/unx/generic/gdi/cairo_xlib_cairo.cxx
@@ -68,9 +68,9 @@ namespace cairo
        pRenderFormat(pSysDat.pXRenderFormat)
    {}

    X11SysData::X11SysData( const SystemEnvData& pSysDat ) :
    X11SysData::X11SysData( const SystemEnvData& pSysDat, const SalFrame* pReference ) :
        pDisplay(pSysDat.pDisplay),
        hDrawable(pSysDat.aWindow),
        hDrawable(pSysDat.GetWindowHandle(pReference)),
        pVisual(pSysDat.pVisual),
        nScreen(pSysDat.nScreen),
        pRenderFormat(nullptr)
diff --git a/vcl/unx/generic/gdi/cairo_xlib_cairo.hxx b/vcl/unx/generic/gdi/cairo_xlib_cairo.hxx
index 398522c..9b0dfb0 100644
--- a/vcl/unx/generic/gdi/cairo_xlib_cairo.hxx
+++ b/vcl/unx/generic/gdi/cairo_xlib_cairo.hxx
@@ -25,6 +25,7 @@
#include <vcl/salgtype.hxx>

struct BitmapSystemData;
class SalFrame;
struct SystemEnvData;
struct SystemGraphicsData;

@@ -35,7 +36,7 @@ namespace cairo {
    {
        X11SysData();
        explicit X11SysData( const SystemGraphicsData& );
        explicit X11SysData( const SystemEnvData& );
        explicit X11SysData( const SystemEnvData&, const SalFrame* pReference );

        void*   pDisplay;       // the relevant display connection
        Drawable hDrawable;     // a drawable
diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx
index 4390b4c..92a5893 100644
--- a/vcl/unx/generic/gdi/salgdi.cxx
+++ b/vcl/unx/generic/gdi/salgdi.cxx
@@ -528,7 +528,7 @@ namespace
        if( !pSysData )
            return cairo::X11SysData();
        else
            return cairo::X11SysData(*pSysData);
            return cairo::X11SysData(*pSysData, rWindow.ImplGetFrame());
    }

    cairo::X11SysData getSysData( const VirtualDevice& rVirDev )
diff --git a/vcl/unx/generic/gdi/salgdi2.cxx b/vcl/unx/generic/gdi/salgdi2.cxx
index fca6051..d688f00 100644
--- a/vcl/unx/generic/gdi/salgdi2.cxx
+++ b/vcl/unx/generic/gdi/salgdi2.cxx
@@ -51,7 +51,7 @@ void X11SalGraphics::YieldGraphicsExpose()
        for (auto pSalFrame : vcl_sal::getSalDisplay(GetGenericUnixSalData())->getFrames() )
        {
            const SystemEnvData* pEnvData = pSalFrame->GetSystemData();
            if( Drawable(pEnvData->aWindow) == aWindow )
            if( Drawable(pEnvData->GetWindowHandle(pSalFrame)) == aWindow )
            {
                pFrame = pSalFrame;
                break;
diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx
index b8a3d2a..1b54b43 100644
--- a/vcl/unx/generic/window/salframe.cxx
+++ b/vcl/unx/generic/window/salframe.cxx
@@ -949,7 +949,7 @@ const SystemEnvData* X11SalFrame::GetSystemData() const
{
    X11SalFrame *pFrame = const_cast<X11SalFrame*>(this);
    pFrame->maSystemChildData.pDisplay      = GetXDisplay();
    pFrame->maSystemChildData.aWindow       = pFrame->GetWindow();
    pFrame->maSystemChildData.SetWindowHandle(pFrame->GetWindow());
    pFrame->maSystemChildData.pSalFrame     = pFrame;
    pFrame->maSystemChildData.pWidget       = nullptr;
    pFrame->maSystemChildData.pVisual       = GetDisplay()->GetVisual( m_nXScreen ).GetVisual();
diff --git a/vcl/unx/generic/window/salobj.cxx b/vcl/unx/generic/window/salobj.cxx
index 04368e7..c24e138 100644
--- a/vcl/unx/generic/window/salobj.cxx
+++ b/vcl/unx/generic/window/salobj.cxx
@@ -62,7 +62,7 @@ X11SalObject* X11SalObject::CreateObject( SalFrame* pParent, SystemWindowData* p
    SalDisplay* pSalDisp        = vcl_sal::getSalDisplay(GetGenericUnixSalData());
    const SystemEnvData* pEnv   = pParent->GetSystemData();
    Display* pDisp              = pSalDisp->GetDisplay();
    ::Window aObjectParent      = static_cast<::Window>(pEnv->aWindow);
    ::Window aObjectParent      = static_cast<::Window>(pEnv->GetWindowHandle(pParent));
    pObject->maParentWin = aObjectParent;

    // find out on which screen that window is
@@ -157,7 +157,7 @@ X11SalObject* X11SalObject::CreateObject( SalFrame* pParent, SystemWindowData* p
    }

    pObjData->pDisplay      = pDisp;
    pObjData->aWindow       = pObject->maSecondary;
    pObjData->SetWindowHandle(pObject->maSecondary);
    pObjData->pWidget       = nullptr;
    pObjData->pVisual       = pVisual;

@@ -224,7 +224,7 @@ X11SalObject::X11SalObject()
    , mbVisible(false)
{
    maSystemChildData.pDisplay  = vcl_sal::getSalDisplay(GetGenericUnixSalData())->GetDisplay();
    maSystemChildData.aWindow       = None;
    maSystemChildData.SetWindowHandle(None);
    maSystemChildData.pSalFrame = nullptr;
    maSystemChildData.pWidget       = nullptr;
    maSystemChildData.pVisual       = nullptr;
@@ -332,7 +332,7 @@ X11SalObject::SetPosSize( tools::Long nX, tools::Long nY, tools::Long nWidth, to
void
X11SalObject::Show( bool bVisible )
{
    if  ( ! maSystemChildData.aWindow )
    if (!maSystemChildData.GetWindowHandle(mpParent))
        return;

    if ( bVisible ) {
@@ -353,7 +353,7 @@ void X11SalObject::GrabFocus()
{
    if( mbVisible )
         XSetInputFocus( static_cast<Display*>(maSystemChildData.pDisplay),
                         maSystemChildData.aWindow,
                         maSystemChildData.GetWindowHandle(mpParent),
                         RevertToNone,
                         CurrentTime );
}
diff --git a/vcl/unx/gtk3/gtk3gtkdata.cxx b/vcl/unx/gtk3/gtk3gtkdata.cxx
index cef4b3e..1e46fd6 100644
--- a/vcl/unx/gtk3/gtk3gtkdata.cxx
+++ b/vcl/unx/gtk3/gtk3gtkdata.cxx
@@ -782,7 +782,7 @@ GtkWidget* GtkSalDisplay::findGtkWidgetForNativeHandle(sal_uIntPtr hWindow) cons
    for (auto pSalFrame : m_aFrames )
    {
        const SystemEnvData* pEnvData = pSalFrame->GetSystemData();
        if (pEnvData->aWindow == hWindow)
        if (pEnvData->GetWindowHandle(pSalFrame) == hWindow)
            return GTK_WIDGET(pEnvData->pWidget);
    }
    return nullptr;
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index 91292048..4240940 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -951,7 +951,7 @@ void GtkSalFrame::InitCommon()
    gtk_widget_realize( m_pWindow );

    //system data
    m_aSystemData.aWindow       = GetNativeWindowHandle(m_pWindow);
    m_aSystemData.SetWindowHandle(GetNativeWindowHandle(m_pWindow));
    m_aSystemData.aShellWindow  = reinterpret_cast<sal_IntPtr>(this);
    m_aSystemData.pSalFrame     = this;
    m_aSystemData.pWidget       = m_pWindow;
@@ -2313,6 +2313,14 @@ const SystemEnvData* GtkSalFrame::GetSystemData() const
    return &m_aSystemData;
}

void GtkSalFrame::ResolveWindowHandle(SystemEnvData& rData) const
{
    if (!rData.pWidget)
        return;
    SAL_WARN("vcl.gtk3", "its undesirable to need the NativeWindowHandle, see tdf#139609");
    rData.SetWindowHandle(GetNativeWindowHandle(static_cast<GtkWidget*>(rData.pWidget)));
}

void GtkSalFrame::SetParent( SalFrame* pNewParent )
{
    GtkWindow* pWindow = GTK_IS_WINDOW(m_pWindow) ? GTK_WINDOW(m_pWindow) : nullptr;
@@ -4475,7 +4483,7 @@ Size GtkSalDisplay::GetScreenSize( int nDisplayScreen )
    return Size( aRect.GetWidth(), aRect.GetHeight() );
}

sal_uIntPtr GtkSalFrame::GetNativeWindowHandle(GtkWidget *pWidget)
sal_uIntPtr GtkSalFrame::GetNativeWindowHandle(GtkWidget *pWidget) const
{
    (void) this;                // Silence loplugin:staticmethods
    GdkDisplay *pDisplay = getGdkDisplay();
diff --git a/vcl/unx/gtk3/gtk3gtkobject.cxx b/vcl/unx/gtk3/gtk3gtkobject.cxx
index 173e1b0..5dc6765 100644
--- a/vcl/unx/gtk3/gtk3gtkobject.cxx
+++ b/vcl/unx/gtk3/gtk3gtkobject.cxx
@@ -65,7 +65,8 @@ void GtkSalObjectBase::Init()
    gtk_widget_realize( m_pSocket );

    // system data
    m_aSystemData.aWindow       = m_pParent->GetNativeWindowHandle(m_pSocket);
    // tdf#139609 deliberately defer using m_pParent->GetNativeWindowHandle(m_pSocket)) to set m_aSystemData.aWindow
    // unless its explicitly needed
    m_aSystemData.aShellWindow  = reinterpret_cast<sal_IntPtr>(this);
    m_aSystemData.pSalFrame     = nullptr;
    m_aSystemData.pWidget       = m_pSocket;
diff --git a/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker_ipc.cxx b/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker_ipc.cxx
index 80c1593..b20878d 100644
--- a/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker_ipc.cxx
+++ b/vcl/unx/gtk3_kde5/gtk3_kde5_filepicker_ipc.cxx
@@ -193,7 +193,7 @@ std::function<void()> Gtk3KDE5FilePickerIpc::blockMainWindow()
    if (!pSysData)
        return {};

    sendCommand(Commands::SetWinId, pSysData->aWindow);
    sendCommand(Commands::SetWinId, pSysData->GetWindowHandle(pParentWin->ImplGetFrame()));

    auto* pMainWindow = static_cast<GtkWidget*>(pSysData->pWidget);
    if (!pMainWindow)