summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-11-19 13:37:45 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-19 17:12:58 +0100
commit433e7cef1e05181e717419d0eda3af777106dadf (patch)
treea3b649c3fdb297537b16ef2f859fa14a74bea5aa /src
parente8c677a9305f9485d65135eb59ca5b63c2106287 (diff)
QSystemTrayIcon/X11: Use display obtained as native screen resource.
Previously, the screen name was used, which contained the display name. This was changed to return the xrandr-name. Task-number: QTBUG-5416 Change-Id: I560143d6d459a8051c9640079cf7d39a3caebfec Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.cpp19
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.h1
-rw-r--r--src/widgets/util/qsystemtrayicon_x11.cpp19
3 files changed, 25 insertions, 14 deletions
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
index fa5f5f43d0..a44e7fb959 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
@@ -104,6 +104,25 @@ void *QXcbNativeInterface::nativeResourceForContext(const QByteArray &resourceSt
return result;
}
+void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resource, QScreen *screen)
+{
+ const QXcbResourceMap::const_iterator it = qXcbResourceMap()->constFind(resource.toLower());
+ if (it == qXcbResourceMap()->constEnd() || !screen->handle())
+ return 0;
+ const QXcbScreen *xcbScreen = static_cast<QXcbScreen *>(screen->handle());
+ switch (it.value()) {
+ case Display:
+#ifdef XCB_USE_XLIB
+ return xcbScreen->connection()->xlib_display();
+#else
+ break;
+#endif
+ default:
+ break;
+ }
+ return 0;
+}
+
void *QXcbNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
{
QByteArray lowerCaseResource = resourceString.toLower();
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.h b/src/plugins/platforms/xcb/qxcbnativeinterface.h
index c15d00255a..a7e0a207cb 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.h
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.h
@@ -65,6 +65,7 @@ public:
QXcbNativeInterface();
void *nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context);
+ void *nativeResourceForScreen(const QByteArray &resource, QScreen *screen);
void *nativeResourceForWindow(const QByteArray &resourceString, QWindow *window);
NativeResourceForContextFunction nativeResourceFunctionForContext(const QByteArray &resource);
diff --git a/src/widgets/util/qsystemtrayicon_x11.cpp b/src/widgets/util/qsystemtrayicon_x11.cpp
index 62dab8fa11..5fefa08f77 100644
--- a/src/widgets/util/qsystemtrayicon_x11.cpp
+++ b/src/widgets/util/qsystemtrayicon_x11.cpp
@@ -102,21 +102,14 @@ QX11SystemTrayContext::QX11SystemTrayContext() : m_display(0), m_screenNumber(0)
qWarning("%s: No screen.", Q_FUNC_INFO);
return;
}
- // Open display using screen name and retrieve screen number from "hostname:0.0"
- const QByteArray name = screen->name().toLocal8Bit();
- const int dotPos = name.lastIndexOf('.');
- if (dotPos != -1) {
- bool ok;
- const int n = name.mid(dotPos + 1).toInt(&ok);
- if (ok)
- m_screenNumber = n;
- }
- m_display = XOpenDisplay(name.constData());
- if (!m_display) {
- qWarning("%s: Cannot open display '%s'.", Q_FUNC_INFO, name.constData());
+ void *displayV = QGuiApplication::platformNativeInterface()->nativeResourceForScreen(QByteArrayLiteral("display"), screen);
+ if (!displayV) {
+ qWarning("%s: Unable to obtain X11 display of primary screen.", Q_FUNC_INFO);
return;
}
+ m_display = static_cast<Display *>(displayV);
+
const QByteArray netSysTray = "_NET_SYSTEM_TRAY_S" + QByteArray::number(m_screenNumber);
m_systemTraySelection = XInternAtom(m_display, netSysTray.constData(), False);
if (!m_systemTraySelection) {
@@ -134,8 +127,6 @@ Window QX11SystemTrayContext::locateSystemTray() const
QX11SystemTrayContext::~QX11SystemTrayContext()
{
- if (m_display)
- XCloseDisplay(m_display);
}
Q_GLOBAL_STATIC(QX11SystemTrayContext, qX11SystemTrayContext)