avmedia/source/gstreamer/gstplayer.cxx | 2 - include/vcl/Platform.hxx | 20 +++++++++++++++++++ include/vcl/svapp.hxx | 4 +++ include/vcl/sysdata.hxx | 4 --- vcl/inc/qt5/QtInstance.hxx | 1 vcl/inc/salinst.hxx | 2 + vcl/inc/unx/gtk/gtkinst.hxx | 1 vcl/inc/unx/salinst.h | 1 vcl/qt5/QtFrame.cxx | 34 +++++++-------------------------- vcl/qt5/QtInstance.cxx | 16 ++++++++++++++- vcl/source/app/svapp.cxx | 2 + vcl/unx/generic/app/salinst.cxx | 2 + vcl/unx/generic/window/salframe.cxx | 1 vcl/unx/generic/window/salobj.cxx | 1 vcl/unx/gtk3/gtkframe.cxx | 4 --- vcl/unx/gtk3/gtkinst.cxx | 16 +++++++++++++++ vcl/unx/gtk3/gtkobject.cxx | 4 --- 17 files changed, 73 insertions(+), 42 deletions(-)
New commits: commit 055ace1eda4444e24a117c3b4d5d9c4e00d72611 Author: Michael Weghorn <[email protected]> AuthorDate: Thu Mar 12 12:28:43 2026 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Fri Mar 13 07:41:48 2026 +0100 vcl: Get Platform from SalInstance, not SystemEnvData Similar to how previous commit Change-Id: I052f122e991bec745af88d3f43847e4d77fb4ba4 Author: Michael Weghorn <[email protected]> Date: Thu Mar 12 11:40:22 2026 +0100 vcl: Get Toolkit from SalInstance, not SystemEnvData had done for the Toolkit, also retrieve the Platform from the SalInstance instead of storing it in the frame/object-specific SystemEnvData. Also stop letting the availability be dependent on #elif defined( UNX ) and rename Platform::Invalid to Platform::Other. Initially, the latter is used everywhere where nothing was explicitly set so far (and for the non-UNX platforms that didn't have SystemEnvData::platform at all so far). This can be further adjusted in the future. Not making it UNX-specific also removes one challenge on the way to make the qt6 VCL plugin available on Windows (see WIP change at [1]) because the existing logic can now be used on all platforms. [1] https://gerrit.libreoffice.org/c/core/+/199615 Change-Id: I383ad8ab287680f1d50dfc65d7d4d83eab3af5c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201537 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx index b78d478a9afa..48622c5b8c02 100644 --- a/avmedia/source/gstreamer/gstplayer.cxx +++ b/avmedia/source/gstreamer/gstplayer.cxx @@ -897,7 +897,7 @@ uno::Reference< ::media::XPlayerWindow > SAL_CALL Player::createPlayerWindow( co } else { - if (pEnvData->platform == SystemEnvData::Platform::Wayland) + if (Application::GetPlatform() == Platform::Wayland) pVideosink = gst_element_factory_make("waylandsink", "video-output"); else pVideosink = gst_element_factory_make("autovideosink", "video-output"); diff --git a/include/vcl/Platform.hxx b/include/vcl/Platform.hxx new file mode 100644 index 000000000000..67e9b66afb45 --- /dev/null +++ b/include/vcl/Platform.hxx @@ -0,0 +1,20 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +enum class Platform +{ + Wayland, + Xcb, + WASM, + Other +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx index e7014161c6d3..92fd27ed637f 100644 --- a/include/vcl/svapp.hxx +++ b/include/vcl/svapp.hxx @@ -35,6 +35,7 @@ #include <tools/long.hxx> #include <vcl/dllapi.h> #include <vcl/IDialogRenderable.hxx> +#include <vcl/Platform.hxx> #include <vcl/Toolkit.hxx> #include <vcl/inputtypes.hxx> #include <i18nlangtag/lang.h> @@ -961,6 +962,9 @@ public: */ static OUString GetDisplayName(); + /** Get the platform. */ + static Platform GetPlatform(); + /** Get the toolkit. */ static Toolkit GetToolkit(); diff --git a/include/vcl/sysdata.hxx b/include/vcl/sysdata.hxx index 7d89098143fb..fa6c23d2acd1 100644 --- a/include/vcl/sysdata.hxx +++ b/include/vcl/sysdata.hxx @@ -61,14 +61,11 @@ struct VCL_DLLPUBLIC SystemEnvData #elif defined( IOS ) // Nothing #elif defined( UNX ) - enum class Platform { Invalid, Wayland, Xcb, WASM }; - void* pDisplay; // the relevant display connection 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 - Platform platform; // the windowing system in use private: sal_uIntPtr aWindow; // the window of the object public: @@ -98,7 +95,6 @@ public: , pWidget(nullptr) , pVisual(nullptr) , nScreen(0) - , platform(Platform::Invalid) , aWindow(0) #endif { diff --git a/vcl/inc/qt5/QtInstance.hxx b/vcl/inc/qt5/QtInstance.hxx index 448399944987..a791cd31828f 100644 --- a/vcl/inc/qt5/QtInstance.hxx +++ b/vcl/inc/qt5/QtInstance.hxx @@ -205,6 +205,7 @@ public: virtual css::uno::Reference<css::datatransfer::dnd::XDropTarget> ImplCreateDropTarget(const SystemEnvData& rSysEnv) override; + virtual Platform GetPlatform() const override; virtual Toolkit GetToolkit() const override; // for qt font options diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx index 5187ecdd4dcd..eaaeb53332ed 100644 --- a/vcl/inc/salinst.hxx +++ b/vcl/inc/salinst.hxx @@ -23,6 +23,7 @@ #include <o3tl/sorted_vector.hxx> #include <rtl/ref.hxx> #include <vcl/ColorDialog.hxx> +#include <vcl/Platform.hxx> #include <vcl/Toolkit.hxx> #include <vcl/dllapi.h> #include <vcl/salgtype.hxx> @@ -222,6 +223,7 @@ public: /// get information about underlying versions virtual OUString getOSVersion() { return u"-"_ustr; } + virtual Platform GetPlatform() const { return Platform::Other; } virtual Toolkit GetToolkit() const { return Toolkit::Invalid; } const OUString& GetToolkitName() { return m_sToolkitName; }; diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx index 92e374903b85..9446d1c5e0a6 100644 --- a/vcl/inc/unx/gtk/gtkinst.hxx +++ b/vcl/inc/unx/gtk/gtkinst.hxx @@ -285,6 +285,7 @@ public: CreateColorChooserDialog(weld::Window* pParent, vcl::ColorPickerMode eMode) override; virtual weld::Window* GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow) override; + virtual Platform GetPlatform() const override; virtual Toolkit GetToolkit() const override; virtual const cairo_font_options_t* GetCairoFontOptions() override; diff --git a/vcl/inc/unx/salinst.h b/vcl/inc/unx/salinst.h index c7161cefa206..7980f64019e9 100644 --- a/vcl/inc/unx/salinst.h +++ b/vcl/inc/unx/salinst.h @@ -89,6 +89,7 @@ public: ImplCreateDropTarget(const SystemEnvData& rSysEnv) override; virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override; + virtual Platform GetPlatform() const override; virtual Toolkit GetToolkit() const override; /** Get the DisplayConnection. It allows to send display events to the application. */ diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 3afb7785a4ae..7c5b924971e0 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -160,21 +160,6 @@ void QtFrame::screenChanged(QScreen*) { m_pQWidget->fakeResize(); } void QtFrame::FillSystemEnvData(SystemEnvData& rData, QWidget* pWidget, QtFrame* pFrame) { - assert(rData.platform == SystemEnvData::Platform::Invalid); - if (QGuiApplication::platformName() == "wayland") - rData.platform = SystemEnvData::Platform::Wayland; - else if (QGuiApplication::platformName() == "xcb") - rData.platform = SystemEnvData::Platform::Xcb; - else if (QGuiApplication::platformName() == "wasm") - rData.platform = SystemEnvData::Platform::WASM; - else - { - // maybe add a SystemEnvData::Platform::Unsupported to avoid special cases and not abort? - SAL_WARN("vcl.qt", - "Unsupported qt VCL platform: " << toOUString(QGuiApplication::platformName())); - std::abort(); - } - rData.pSalFrame = pFrame; rData.pWidget = pWidget; } @@ -267,18 +252,18 @@ QWindow* QtFrame::windowHandle() const // set attribute 'Qt::WA_NativeWindow' first to make sure a window handle actually exists QWidget* pChild = asChild(); assert(pChild->window() == pChild); - switch (m_aSystemData.platform) + switch (GetQtInstance().GetPlatform()) { - case SystemEnvData::Platform::WASM: + case Platform::WASM: #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // no idea, why Qt::WA_NativeWindow breaks the menubar for EMSCRIPTEN break; #endif - case SystemEnvData::Platform::Wayland: - case SystemEnvData::Platform::Xcb: + case Platform::Wayland: + case Platform::Xcb: pChild->setAttribute(Qt::WA_NativeWindow); break; - case SystemEnvData::Platform::Invalid: + case Platform::Other: std::abort(); break; } @@ -724,8 +709,6 @@ void QtFrame::ShowFullScreen(bool bFullScreen, sal_Int32 nScreen) void QtFrame::StartPresentation(bool bStart) { #if !defined EMSCRIPTEN - assert(m_aSystemData.platform != SystemEnvData::Platform::Invalid); - #if CHECK_QT5_USING_X11 unsigned int nRootWindow(0); std::optional<Display*> aDisplay; @@ -1247,8 +1230,7 @@ void QtFrame::SetScreenNumber(unsigned int nScreen) void QtFrame::SetApplicationID(const OUString& rWMClass) { #if CHECK_QT5_USING_X11 - assert(m_aSystemData.platform != SystemEnvData::Platform::Invalid); - if (m_aSystemData.platform != SystemEnvData::Platform::Xcb || !m_pTopLevel) + if (GetQtInstance().GetPlatform() != Platform::Xcb || !m_pTopLevel) return; QtX11Support::setApplicationID(m_pTopLevel->winId(), rWMClass); @@ -1261,14 +1243,14 @@ void QtFrame::ResolveWindowHandle(SystemEnvData& rData) const { if (!rData.pWidget) return; - assert(rData.platform != SystemEnvData::Platform::Invalid); + // Calling QWidget::winId() implicitly enables native windows to be used instead // of "alien widgets" that don't have a native widget associated 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 unresponsive UI, s. tdf#122293/QTBUG-75766 and tdf#160565 // (for qt5 xcb, they're needed for video playback) - if (rData.platform != SystemEnvData::Platform::Wayland + if (GetQtInstance().GetPlatform() != Platform::Wayland && QLibraryInfo::version().majorVersion() < 6) { rData.SetWindowHandle(static_cast<QWidget*>(rData.pWidget)->winId()); diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx index 8a08bef03b08..190ea2725cc2 100644 --- a/vcl/qt5/QtInstance.cxx +++ b/vcl/qt5/QtInstance.cxx @@ -693,6 +693,20 @@ QtInstance::ImplCreateDropTarget(const SystemEnvData& rSysEnv) return pDropTarget; } +Platform QtInstance::GetPlatform() const +{ + const QString sPlatformName = QGuiApplication::platformName(); + if (sPlatformName == u"wayland") + return Platform::Wayland; + if (sPlatformName == u"xcb") + return Platform::Xcb; + if (sPlatformName == u"wasm") + return Platform::WASM; + + assert(false && "Unsupported qt VCL platform"); + return Platform::Other; +} + Toolkit QtInstance::GetToolkit() const { return Toolkit::Qt; } const cairo_font_options_t* QtInstance::GetCairoFontOptions() @@ -736,7 +750,7 @@ void* QtInstance::CreateGStreamerSink(const SystemChildWindow* pWindow) if (!pEnvData) return nullptr; - if (pEnvData->platform != SystemEnvData::Platform::Wayland) + if (GetQtInstance().GetPlatform() != Platform::Wayland) return nullptr; GstElement* pVideosink = pSymbol("qwidget5videosink", "qwidget5videosink"); diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx index 1ed02ccd4fd7..928eb2e6e43d 100644 --- a/vcl/source/app/svapp.cxx +++ b/vcl/source/app/svapp.cxx @@ -1420,6 +1420,8 @@ Help* Application::GetHelp() return ImplGetSVData()->maAppData.mpHelp; } +Platform Application::GetPlatform() { return GetSalInstance()->GetPlatform(); } + Toolkit Application::GetToolkit() { return GetSalInstance()->GetToolkit(); } const OUString & Application::GetToolkitName() diff --git a/vcl/unx/generic/app/salinst.cxx b/vcl/unx/generic/app/salinst.cxx index deed1041c859..2a17b9258ec5 100644 --- a/vcl/unx/generic/app/salinst.cxx +++ b/vcl/unx/generic/app/salinst.cxx @@ -220,6 +220,8 @@ std::shared_ptr<SalBitmap> X11SalInstance::CreateSalBitmap() return std::make_shared<SvpSalBitmap>(); } +Platform X11SalInstance::GetPlatform() const { return Platform::Xcb; } + Toolkit X11SalInstance::GetToolkit() const { return Toolkit::Gen; } rtl::Reference<X11DisplayConnectionDispatch> X11SalInstance::GetDisplayConnection() diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index 5b5fb1af242e..845edd142e7d 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -846,7 +846,6 @@ const SystemEnvData& X11SalFrame::GetSystemData() const pFrame->maSystemChildData.pWidget = nullptr; pFrame->maSystemChildData.pVisual = GetDisplay()->GetVisual( m_nXScreen ).GetVisual(); pFrame->maSystemChildData.nScreen = m_nXScreen.getXScreen(); - pFrame->maSystemChildData.platform = SystemEnvData::Platform::Xcb; return maSystemChildData; } diff --git a/vcl/unx/generic/window/salobj.cxx b/vcl/unx/generic/window/salobj.cxx index c3f42f711e5e..12fcd7e9035d 100644 --- a/vcl/unx/generic/window/salobj.cxx +++ b/vcl/unx/generic/window/salobj.cxx @@ -229,7 +229,6 @@ X11SalObject::X11SalObject() maSystemChildData.pSalFrame = nullptr; maSystemChildData.pWidget = nullptr; maSystemChildData.pVisual = nullptr; - maSystemChildData.platform = SystemEnvData::Platform::Xcb; std::list<SalObject*>& rObjects = vcl_sal::getSalDisplay()->getSalObjects(); rObjects.push_back( this ); diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx index 0e3b2f0cf7b1..cb5bbca5533f 100644 --- a/vcl/unx/gtk3/gtkframe.cxx +++ b/vcl/unx/gtk3/gtkframe.cxx @@ -1257,7 +1257,6 @@ void GtkSalFrame::InitCommon() if (DLSYM_GDK_IS_X11_DISPLAY(pDisplay)) { m_aSystemData.pDisplay = gdk_x11_display_get_xdisplay(pDisplay); - m_aSystemData.platform = SystemEnvData::Platform::Xcb; #if !GTK_CHECK_VERSION(4,0,0) GdkScreen* pScreen = gtk_widget_get_screen(m_pWindow); GdkVisual* pVisual = gdk_screen_get_system_visual(pScreen); @@ -1267,10 +1266,7 @@ void GtkSalFrame::InitCommon() #endif #if defined(GDK_WINDOWING_WAYLAND) if (DLSYM_GDK_IS_WAYLAND_DISPLAY(pDisplay)) - { m_aSystemData.pDisplay = gdk_wayland_display_get_wl_display(pDisplay); - m_aSystemData.platform = SystemEnvData::Platform::Wayland; - } #endif m_bGraphics = false; diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index d98e306e9a13..b733f99e79ed 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -545,6 +545,22 @@ std::unique_ptr<GenPspGraphics> GtkInstance::CreatePrintGraphics() return SvpSalInstance::CreatePrintGraphics(); } +Platform GtkInstance::GetPlatform() const +{ + GdkDisplay* pDisplay = GetGtkSalData()->GetGdkDisplay(); +#if defined(GDK_WINDOWING_X11) + if (DLSYM_GDK_IS_X11_DISPLAY(pDisplay)) + return Platform::Xcb; +#endif +#if defined(GDK_WINDOWING_WAYLAND) + if (DLSYM_GDK_IS_WAYLAND_DISPLAY(pDisplay)) + return Platform::Wayland; +#endif + + assert(false && "Unknown platform"); + return Platform::Other; +} + Toolkit GtkInstance::GetToolkit() const { return Toolkit::Gtk; } const cairo_font_options_t* GtkInstance::GetCairoFontOptions() diff --git a/vcl/unx/gtk3/gtkobject.cxx b/vcl/unx/gtk3/gtkobject.cxx index c16e85b65c92..a71a2a71fc41 100644 --- a/vcl/unx/gtk3/gtkobject.cxx +++ b/vcl/unx/gtk3/gtkobject.cxx @@ -73,15 +73,11 @@ void GtkSalObjectBase::Init() { m_aSystemData.pDisplay = gdk_x11_display_get_xdisplay(pDisplay); m_aSystemData.pVisual = gdk_x11_visual_get_xvisual(pVisual); - m_aSystemData.platform = SystemEnvData::Platform::Xcb; } #endif #if defined(GDK_WINDOWING_WAYLAND) if (DLSYM_GDK_IS_WAYLAND_DISPLAY(pDisplay)) - { m_aSystemData.pDisplay = gdk_wayland_display_get_wl_display(pDisplay); - m_aSystemData.platform = SystemEnvData::Platform::Wayland; - } #endif g_signal_connect( G_OBJECT(m_pSocket), "button-press-event", G_CALLBACK(signalButton), this );
