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>
This commit is contained in:
Friedemann Kleint 2012-11-19 13:37:45 +01:00 committed by The Qt Project
parent e8c677a930
commit 433e7cef1e
3 changed files with 25 additions and 14 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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)