diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-07-17 14:39:42 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-18 15:12:37 +0200 |
commit | 81addcc1edddaefa19080ad90c27df49f92b53a6 (patch) | |
tree | dbfe7f0838c69b09c605784b532f3d749b071e8b /src/plugins/platforms/xcb/qxcbintegration.cpp | |
parent | 07bc5302503ef855541f5bc39296798127a06de1 (diff) |
XCB: Set WM_CLASS.
Set the instance name and class name of the application windows.
Task-number: QTBUG-29396
Change-Id: Ia1fb492ab169108c3779deb8964bb731b322dd89
Reviewed-by: Uli Schlachter <psychon@znc.in>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbintegration.cpp')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 77c265fd09..cf7e99023a 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -369,4 +369,48 @@ QVariant QXcbIntegration::styleHint(QPlatformIntegration::StyleHint hint) const return QPlatformIntegration::styleHint(hint); } +static QString argv0BaseName() +{ + QString result; + const QStringList arguments = QCoreApplication::arguments(); + if (!arguments.isEmpty() && !arguments.front().isEmpty()) { + result = arguments.front(); + const int lastSlashPos = result.lastIndexOf(QLatin1Char('/')); + if (lastSlashPos != -1) + result.remove(0, lastSlashPos + 1); + } + return result; +} + +static const char resourceNameVar[] = "RESOURCE_NAME"; + +QByteArray QXcbIntegration::wmClass() const +{ + if (m_wmClass.isEmpty()) { + // Instance name according to ICCCM 4.1.2.5 + QString name; + if (name.isEmpty() && qEnvironmentVariableIsSet(resourceNameVar)) + name = QString::fromLocal8Bit(qgetenv(resourceNameVar)); + if (name.isEmpty()) + name = argv0BaseName(); + + // Note: QCoreApplication::applicationName() cannot be called from the QGuiApplication constructor, + // hence this delayed initialization. + QString className = QCoreApplication::applicationName(); + if (className.isEmpty()) { + className = argv0BaseName(); + if (!className.isEmpty() && className.at(0).isLower()) + className[0] = className.at(0).toUpper(); + } + + if (!name.isEmpty() && !className.isEmpty()) { + m_wmClass = name.toLocal8Bit(); + m_wmClass.append('\0'); + m_wmClass.append(className.toLocal8Bit()); + m_wmClass.append('\0'); + } + } + return m_wmClass; +} + QT_END_NAMESPACE |