diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-03-05 13:37:34 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-03-31 06:15:09 +0000 |
commit | 641b8d2b84896e277678307a3e7bbac9f64cff76 (patch) | |
tree | 299f49fd60dfd51f1506699fa4d0124f1bcfb384 | |
parent | be242ed09479616c0f47aa76cc6329cfc5d52b37 (diff) |
xcb: set WM_NAME window property
Some older window managers and utilities still ignore _NET_WM_NAME.
Task-number: QTBUG-42209
Change-Id: Iff93c8188a0a73b04cdf361add153cd818ac670f
Reviewed-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Martin Gräßlin <mgraesslin@kde.org>
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 1 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.h | 1 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 49 |
3 files changed, 51 insertions, 0 deletions
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 <qpa/qplatformbackingstore.h> #include <qpa/qwindowsysteminterface.h> +#include <QTextCodec> #include <stdio.h> #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 <X11/Xatom.h> + + 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()); } |