Revert "XCB: Do not create instance of QPlatformIntegration for invalid displays"

This reverts commit 67cc8fea10.

I forgot about this patch and now it makes rebasing the local changes
too time-consuming. Besides, 67cc8fea10 broke a build for -no-xcb-xlib.
I will restore this patch, with adaptations to the new QXcb*Connection
hierarchy.

Task-number: QTBUG-68859
Change-Id: I938f32b5da22ce18f95d761f9b34e77fff923e24
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
This commit is contained in:
Gatis Paeglis 2018-10-14 19:46:20 +02:00
parent 3af4b59e8b
commit a880780ff9
5 changed files with 40 additions and 72 deletions

View File

@ -525,59 +525,31 @@ void QXcbConnection::initializeScreens()
}
}
QXcbConnection *QXcbConnection::create(QXcbNativeInterface *nativeInterface, bool canGrabServer,
xcb_visualid_t defaultVisualId,
const char *displayNameIn)
QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGrabServer, xcb_visualid_t defaultVisualId, const char *displayName)
: m_canGrabServer(canGrabServer)
, m_defaultVisualId(defaultVisualId)
, m_displayName(displayName ? QByteArray(displayName) : qgetenv("DISPLAY"))
, m_nativeInterface(nativeInterface)
{
const QByteArray displayName = displayNameIn ? QByteArray(displayNameIn) : qgetenv("DISPLAY");
int primaryScreenNumber = 0;
void *xlibDisplay = nullptr;
xcb_connection_t *connection = nullptr;
#if QT_CONFIG(xcb_xlib)
Display *dpy = XOpenDisplay(displayName.constData());
Display *dpy = XOpenDisplay(m_displayName.constData());
if (dpy) {
primaryScreenNumber = DefaultScreen(dpy);
connection = XGetXCBConnection(dpy);
m_primaryScreenNumber = DefaultScreen(dpy);
m_connection = XGetXCBConnection(dpy);
XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
XSetErrorHandler(nullErrorHandler);
XSetIOErrorHandler(ioErrorHandler);
xlibDisplay = dpy;
m_xlib_display = dpy;
}
#else
connection = xcb_connect(displayName.constData(), &primaryScreenNumber);
m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreenNumber);
#endif // QT_CONFIG(xcb_xlib)
if (Q_UNLIKELY(connection == nullptr)) {
qWarning("QXcbConnection: Could not connect to display \"%s\"", displayName.constData());
return nullptr;
}
if (Q_UNLIKELY(xcb_connection_has_error(connection))) {
#if QT_CONFIG(xcb_xlib)
XCloseDisplay(static_cast<Display *>(xlibDisplay));
#else
xcb_disconnect(connection);
#endif
qWarning("QXcbConnection: Errors occurred connecting to display \"%s\"", displayName.constData());
return nullptr;
}
return new QXcbConnection(connection, primaryScreenNumber, nativeInterface,
canGrabServer, defaultVisualId, displayName, xlibDisplay);
}
if (Q_UNLIKELY(!m_connection || xcb_connection_has_error(m_connection))) {
qCWarning(lcQpaScreen, "QXcbConnection: Could not connect to display %s", m_displayName.constData());
return;
}
QXcbConnection::QXcbConnection(xcb_connection_t *c, int primaryScreenNumber,
QXcbNativeInterface *nativeInterface, bool canGrabServer,
xcb_visualid_t defaultVisualId, const QByteArray &displayName,
void *xlibDisplay)
: m_connection(c)
, m_canGrabServer(canGrabServer)
, m_defaultVisualId(defaultVisualId)
, m_primaryScreenNumber(primaryScreenNumber)
, m_displayName(displayName)
, m_nativeInterface(nativeInterface)
#if QT_CONFIG(xcb_xlib)
, m_xlib_display(xlibDisplay)
#endif
{
m_reader = new QXcbEventReader(this);
m_reader->start();

View File

@ -380,16 +380,9 @@ class Q_XCB_EXPORT QXcbConnection : public QObject
{
Q_OBJECT
public:
explicit QXcbConnection(xcb_connection_t *c, int primaryScreenNumber,
QXcbNativeInterface *nativeInterface, bool canGrabServer,
xcb_visualid_t defaultVisualId, const QByteArray &displayName,
void *xlibDisplay = nullptr);
QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGrabServer, xcb_visualid_t defaultVisualId, const char *displayName = 0);
~QXcbConnection();
static QXcbConnection *create(QXcbNativeInterface *nativeInterface, bool canGrabServer,
xcb_visualid_t defaultVisualId, const char *displayName = nullptr);
QXcbConnection *connection() const { return const_cast<QXcbConnection *>(this); }
bool isConnected() const;
@ -648,21 +641,21 @@ private:
static bool xi2GetValuatorValueIfSet(const void *event, int valuatorNum, double *value);
#endif
xcb_connection_t *const m_connection;
xcb_connection_t *m_connection = nullptr;
const xcb_setup_t *m_setup = nullptr;
const bool m_canGrabServer;
const xcb_visualid_t m_defaultVisualId;
QList<QXcbVirtualDesktop *> m_virtualDesktops;
QList<QXcbScreen *> m_screens;
const int m_primaryScreenNumber;
int m_primaryScreenNumber = 0;
xcb_atom_t m_allAtoms[QXcbAtom::NAtoms];
xcb_timestamp_t m_time = XCB_CURRENT_TIME;
xcb_timestamp_t m_netWmUserTime = XCB_CURRENT_TIME;
const QByteArray m_displayName;
QByteArray m_displayName;
QXcbKeyboard *m_keyboard = nullptr;
#ifndef QT_NO_CLIPBOARD
@ -675,7 +668,7 @@ private:
QXcbNativeInterface *m_nativeInterface = nullptr;
#if QT_CONFIG(xcb_xlib)
void *const m_xlib_display;
void *m_xlib_display = nullptr;
#endif
QXcbEventReader *m_reader = nullptr;

View File

@ -192,15 +192,25 @@ QXcbIntegration::QXcbIntegration(const QStringList &parameters, int &argc, char
const int numParameters = parameters.size();
m_connections.reserve(1 + numParameters / 2);
auto conn = new QXcbConnection(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, displayName);
if (conn->isConnected())
m_connections << conn;
else
delete conn;
if (QXcbConnection *defaultConnection = QXcbConnection::create(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, displayName)) {
m_connections.append(defaultConnection);
for (int i = 0; i < numParameters - 1; i += 2) {
qCDebug(lcQpaScreen) << "connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
QString display = parameters.at(i) + QLatin1Char(':') + parameters.at(i+1);
if (QXcbConnection *connection = QXcbConnection::create(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, display.toLatin1().constData()))
m_connections.append(connection);
}
for (int i = 0; i < numParameters - 1; i += 2) {
qCDebug(lcQpaScreen) << "connecting to additional display: " << parameters.at(i) << parameters.at(i+1);
QString display = parameters.at(i) + QLatin1Char(':') + parameters.at(i+1);
conn = new QXcbConnection(m_nativeInterface.data(), m_canGrab, m_defaultVisualId, display.toLatin1().constData());
if (conn->isConnected())
m_connections << conn;
else
delete conn;
}
if (m_connections.isEmpty()) {
qCritical("Could not connect to any X display.");
exit(1);
}
m_fontDatabase.reset(new QGenericUnixFontDatabase());

View File

@ -103,7 +103,6 @@ public:
QPlatformTheme *createPlatformTheme(const QString &name) const override;
QVariant styleHint(StyleHint hint) const override;
bool hasDefaultConnection() const { return !m_connections.isEmpty(); }
QXcbConnection *defaultConnection() const { return m_connections.first(); }
QByteArray wmClass() const;

View File

@ -52,16 +52,10 @@ public:
QPlatformIntegration* QXcbIntegrationPlugin::create(const QString& system, const QStringList& parameters, int &argc, char **argv)
{
if (!system.compare(QLatin1String("xcb"), Qt::CaseInsensitive)) {
QXcbIntegration *xcbIntegration = new QXcbIntegration(parameters, argc, argv);
if (!xcbIntegration->hasDefaultConnection()) {
delete xcbIntegration;
return nullptr;
}
return xcbIntegration;
}
if (!system.compare(QLatin1String("xcb"), Qt::CaseInsensitive))
return new QXcbIntegration(parameters, argc, argv);
return nullptr;
return 0;
}
QT_END_NAMESPACE