From 641b8d2b84896e277678307a3e7bbac9f64cff76 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 5 Mar 2015 13:37:34 +0100 Subject: xcb: set WM_NAME window property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some older window managers and utilities still ignore _NET_WM_NAME. Task-number: QTBUG-42209 Change-Id: Iff93c8188a0a73b04cdf361add153cd818ac670f Reviewed-by: Uli Schlachter Reviewed-by: Martin Gräßlin Reviewed-by: Jørgen Lind --- src/plugins/platforms/xcb/qxcbconnection.cpp | 1 + src/plugins/platforms/xcb/qxcbconnection.h | 1 + src/plugins/platforms/xcb/qxcbwindow.cpp | 49 ++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 2084d7ea5d..f4c633e2d7 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -1480,6 +1480,7 @@ static const char * xcb_atomnames = { "WM_STATE\0" "WM_CHANGE_STATE\0" "WM_CLASS\0" + "WM_NAME\0" // Session management "WM_CLIENT_LEADER\0" diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index de454b5eae..f479c1bc80 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -107,6 +107,7 @@ namespace QXcbAtom { WM_STATE, WM_CHANGE_STATE, WM_CLASS, + WM_NAME, // Session management WM_CLIENT_LEADER, diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index 1406270994..34179a70a4 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -86,6 +86,7 @@ #include #include +#include #include #ifdef XCB_USE_XLIB @@ -243,6 +244,48 @@ static inline bool positionIncludesFrame(QWindow *w) return qt_window_private(w)->positionPolicy == QWindowPrivate::WindowFrameInclusive; } +#ifdef XCB_USE_XLIB +static inline XTextProperty* qstringToXTP(Display *dpy, const QString& s) +{ + #include + + static XTextProperty tp = { 0, 0, 0, 0 }; + static bool free_prop = true; // we can't free tp.value in case it references + // the data of the static QByteArray below. + if (tp.value) { + if (free_prop) + XFree(tp.value); + tp.value = 0; + free_prop = true; + } + + static const QTextCodec* mapper = QTextCodec::codecForLocale(); + int errCode = 0; + if (mapper) { + QByteArray mapped = mapper->fromUnicode(s); + char* tl[2]; + tl[0] = mapped.data(); + tl[1] = 0; + errCode = XmbTextListToTextProperty(dpy, tl, 1, XStdICCTextStyle, &tp); + if (errCode < 0) + qDebug("XmbTextListToTextProperty result code %d", errCode); + } + if (!mapper || errCode < 0) { + mapper = QTextCodec::codecForName("latin1"); + if (!mapper || !mapper->canEncode(s)) + return Q_NULLPTR; + static QByteArray qcs; + qcs = s.toLatin1(); + tp.value = (uchar*)qcs.data(); + tp.encoding = XA_STRING; + tp.format = 8; + tp.nitems = qcs.length(); + free_prop = false; + } + return &tp; +} +#endif // XCB_USE_XLIB + static const char *wm_window_type_property_id = "_q_xcb_wm_window_type"; QXcbWindow::QXcbWindow(QWindow *window) @@ -1423,6 +1466,12 @@ void QXcbWindow::setWindowTitle(const QString &title) 8, ba.length(), ba.constData())); + +#ifdef XCB_USE_XLIB + XTextProperty *text = qstringToXTP(DISPLAY_FROM_XCB(this), title); + if (text) + XSetWMName(DISPLAY_FROM_XCB(this), m_window, text); +#endif xcb_flush(xcb_connection()); } -- cgit v1.2.3