tdf#173803 Set WM_CLASS with Qt6 on X11

The setApplicationID method is now called for all Qt versions on
X11. For Qt6, xcb_connection_t* is obtained in a new way, by
calling QNativeInterface::QX11Application, instead of the
deprecated X11Helper.

This change is based on these Qt6 docs:
https://doc.qt.io/qt-6/extras-changes-qt6.html#changes-to-qt-x11-extras

Change-Id: I51da53dd7d4cd7e080812cfd0c59d6197cac4a6f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211643
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Vladislav Tarakanov
2026-10-01 08:45:20 +02:00
committed by Michael Weghorn
parent dabd91337a
commit e5856e9912
2 changed files with 11 additions and 6 deletions
+1 -1
View File
@@ -1177,7 +1177,7 @@ void QtFrame::SetScreenNumber(unsigned int nScreen)
void QtFrame::SetApplicationID(const OUString& rWMClass)
{
#if CHECK_QT5_USING_X11
#if CHECK_ANY_QT_USING_X11
if (GetQtInstance().GetPlatform() != Platform::Xcb || !m_pTopLevel)
return;
+10 -5
View File
@@ -20,7 +20,16 @@
void QtX11Support::setApplicationID(const xcb_window_t nWinId, std::u16string_view rWMClass)
{
xcb_connection_t* pConnection = nullptr;
#if CHECK_QT5_USING_X11
pConnection = QX11Info::connection();
#else
auto* x11Application = qGuiApp->nativeInterface<QNativeInterface::QX11Application>();
if (x11Application)
pConnection = x11Application->connection();
#endif
if (!pConnection)
return;
OString aResClass = OUStringToOString(rWMClass, RTL_TEXTENCODING_ASCII_US);
const char* pResClass
= !aResClass.isEmpty() ? aResClass.getStr() : X11Helper::getFrameClassName();
@@ -32,13 +41,9 @@ void QtX11Support::setApplicationID(const xcb_window_t nWinId, std::u16string_vi
memcpy(data, aResName.getStr(), aResName.getLength() + 1);
memcpy(data + aResName.getLength() + 1, pResClass, strlen(pResClass) + 1);
xcb_change_property(QX11Info::connection(), XCB_PROP_MODE_REPLACE, nWinId, XCB_ATOM_WM_CLASS,
xcb_change_property(pConnection, XCB_PROP_MODE_REPLACE, nWinId, XCB_ATOM_WM_CLASS,
XCB_ATOM_STRING, 8, data_len, data);
delete[] data;
#else
Q_UNUSED(nWinId);
Q_UNUSED(rWMClass);
#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */