diff --git a/src/plugins/platforms/wayland/plugins/decorations/bradient/main.cpp b/src/plugins/platforms/wayland/plugins/decorations/bradient/main.cpp index 3fcf09ea554..7f1b78c101d 100644 --- a/src/plugins/platforms/wayland/plugins/decorations/bradient/main.cpp +++ b/src/plugins/platforms/wayland/plugins/decorations/bradient/main.cpp @@ -142,7 +142,7 @@ void QWaylandBradientDecoration::paint(QPaintDevice *device) } // Window title - QString windowTitleText = window()->title(); + QString windowTitleText = waylandWindow()->windowTitle(); if (!windowTitleText.isEmpty()) { if (m_windowTitle.text() != windowTitleText) { m_windowTitle.setText(windowTitleText); diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 323c4e4df72..a6c0b97b797 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -362,26 +362,33 @@ void QWaylandWindow::setParent(const QPlatformWindow *parent) } } +QString QWaylandWindow::windowTitle() const +{ + return mWindowTitle; +} + void QWaylandWindow::setWindowTitle(const QString &title) { - if (mShellSurface) { - const QString separator = QString::fromUtf8(" \xe2\x80\x94 "); // unicode character U+2014, EM DASH - const QString formatted = formatWindowTitle(title, separator); + const QString separator = QString::fromUtf8(" \xe2\x80\x94 "); // unicode character U+2014, EM DASH + const QString formatted = formatWindowTitle(title, separator); - const int libwaylandMaxBufferSize = 4096; - // Some parts of the buffer is used for metadata, so subtract 100 to be on the safe side. - // Also, QString is in utf-16, which means that in the worst case each character will be - // three bytes when converted to utf-8 (which is what libwayland uses), so divide by three. - const int maxLength = libwaylandMaxBufferSize / 3 - 100; + const int libwaylandMaxBufferSize = 4096; + // Some parts of the buffer is used for metadata, so subtract 100 to be on the safe side. + // Also, QString is in utf-16, which means that in the worst case each character will be + // three bytes when converted to utf-8 (which is what libwayland uses), so divide by three. + const int maxLength = libwaylandMaxBufferSize / 3 - 100; - auto truncated = QStringView{formatted}.left(maxLength); - if (truncated.size() < formatted.size()) { - qCWarning(lcQpaWayland) << "Window titles longer than" << maxLength << "characters are not supported." - << "Truncating window title (from" << formatted.size() << "chars)"; - } - mShellSurface->setTitle(truncated.toString()); + auto truncated = QStringView{formatted}.left(maxLength); + if (truncated.size() < formatted.size()) { + qCWarning(lcQpaWayland) << "Window titles longer than" << maxLength << "characters are not supported." + << "Truncating window title (from" << formatted.size() << "chars)"; } + mWindowTitle = truncated.toString(); + + if (mShellSurface) + mShellSurface->setTitle(mWindowTitle); + if (mWindowDecorationEnabled && window()->isVisible()) mWindowDecoration->update(); } diff --git a/src/plugins/platforms/wayland/qwaylandwindow_p.h b/src/plugins/platforms/wayland/qwaylandwindow_p.h index 8957f7aef3a..2f6d2921bba 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow_p.h +++ b/src/plugins/platforms/wayland/qwaylandwindow_p.h @@ -93,6 +93,7 @@ public: void setVisible(bool visible) override; void setParent(const QPlatformWindow *parent) override; + QString windowTitle() const; void setWindowTitle(const QString &title) override; inline QIcon windowIcon() const; @@ -311,6 +312,7 @@ protected: qreal mScale = 1; QPlatformScreen *mLastReportedScreen = nullptr; + QString mWindowTitle; QIcon mWindowIcon; Qt::WindowFlags mFlags;