From 35cbf1154021f4cb7fa30ae57030672ca57e47e3 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Mon, 12 Feb 2024 14:09:45 +0100 Subject: tdf#125934 qt: Support module-specific window icons on Wayland MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As discussed in QTBUG-77182 [1], Qt currently doesn't provide API to directly set the app_id for a single window/toplevel on Wayland, but the one set for the application is used when the window gets shown. Make use of that by temporarily setting the app's desktop file name and doing a hide/show cycle in `QtFrame::SetIcon` on Wayland. A big thanks for David Redondo for mentioning that possibility in QTBUG-77182! An alternative would be to use private Qt API and low-level wayland API to set the app_id directly, s. discussion in QTBUG-77182. [1] https://bugreports.qt.io/browse/QTBUG-77182 Change-Id: I2a93cd39756e2ebf55b91486927d73d3896245b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163249 Tested-by: Jenkins Reviewed-by: Michael Weghorn (cherry picked from commit 413138c9178d4def463c4844297832b75dcea689) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163273 Tested-by: Caolán McNamara Reviewed-by: Caolán McNamara --- vcl/qt5/QtFrame.cxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'vcl') diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 24dcb5ff6f61..6aff814aacd2 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -376,6 +376,20 @@ void QtFrame::SetIcon(sal_uInt16 nIcon) QIcon aIcon = QIcon::fromTheme(appicon); m_pQWidget->window()->setWindowIcon(aIcon); + + if (QGuiApplication::platformName() == "wayland" && m_pQWidget->window()->isVisible()) + { + // Qt currently doesn't provide API to directly set the app_id for a single + // window/toplevel on Wayland, but the one set for the application is picked up + // on hide/show, so do that. + // An alternative would be to use private Qt API and low-level wayland API to set the + // app_id directly, s. discussion in QTBUG-77182. + const QString sOrigDesktopFileName = QGuiApplication::desktopFileName(); + QGuiApplication::setDesktopFileName(appicon); + m_pQWidget->window()->hide(); + m_pQWidget->window()->show(); + QGuiApplication::setDesktopFileName(sOrigDesktopFileName); + } } void QtFrame::SetMenu(SalMenu*) {} -- cgit