diff options
author | Uli Schlachter <psychon@znc.in> | 2014-04-08 23:12:28 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-10 05:33:38 +0200 |
commit | b1afb91ffe7727ec59e4baf0124d16e03b1d5539 (patch) | |
tree | 499db99fdbf188dc6adcb3d82b71d4fe04311e6e /src/plugins/platforms | |
parent | 02ecd3ae40d8e10c56f5c92060257422a8ba9f92 (diff) |
XCB: Print error code on Xlib I/O errors
When Xlib detects that its underlying XCB connection got into an error
state, it calls its I/O error handler. However, the default
implementation doesn't print the error code from XCB which might be
useful for debugging.
This commit adds an I/O error handler which prints the error code from
XCB with a string describing the error and then calls Xlib's default
error handler.
Change-Id: I7f1fb3f1e8d0fdc3ac9db03ae7d154330c31db0c
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 66b8401ea2..f5f6c712c5 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -93,10 +93,37 @@ QT_BEGIN_NAMESPACE #ifdef XCB_USE_XLIB +static const char * const xcbConnectionErrors[] = { + "No error", /* Error 0 */ + "I/O error", /* XCB_CONN_ERROR */ + "Unsupported extension used", /* XCB_CONN_CLOSED_EXT_NOTSUPPORTED */ + "Out of memory", /* XCB_CONN_CLOSED_MEM_INSUFFICIENT */ + "Maximum allowed requested length exceeded", /* XCB_CONN_CLOSED_REQ_LEN_EXCEED */ + "Failed to parse display string", /* XCB_CONN_CLOSED_PARSE_ERR */ + "No such screen on display", /* XCB_CONN_CLOSED_INVALID_SCREEN */ + "Error during FD passing" /* XCB_CONN_CLOSED_FDPASSING_FAILED */ +}; + static int nullErrorHandler(Display *, XErrorEvent *) { return 0; } + +static int ioErrorHandler(Display *dpy) +{ + xcb_connection_t *conn = XGetXCBConnection(dpy); + if (conn != NULL) { + /* Print a message with a textual description of the error */ + int code = xcb_connection_has_error(conn); + const char *str = "Unknown error"; + int arrayLength = sizeof(xcbConnectionErrors) / sizeof(xcbConnectionErrors[0]); + if (code >= 0 && code < arrayLength) + str = xcbConnectionErrors[code]; + + qWarning("The X11 connection broke: %s (code %d)", str, code); + } + return _XDefaultIOError(dpy); +} #endif QXcbScreen* QXcbConnection::findOrCreateScreen(QList<QXcbScreen *>& newScreens, @@ -284,6 +311,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra m_connection = XGetXCBConnection(dpy); XSetEventQueueOwner(dpy, XCBOwnsEventQueue); XSetErrorHandler(nullErrorHandler); + XSetIOErrorHandler(ioErrorHandler); m_xlib_display = dpy; } #else |