xcb: better error handling if no randr or screen resources query fails

Marc Mutz already reported problems with ssh -X fowarding.  Now all
such errors are treated the same: if we can't get screen output
attributes, just assume there is only one.

Change-Id: I96802fc90072c623de3370ed2898893daf58198a
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
This commit is contained in:
Shawn Rutledge 2012-09-21 13:47:16 +02:00 committed by The Qt Project
parent 1e39e8f53b
commit 9cec2def90

View File

@ -141,31 +141,29 @@ void QXcbConnection::updateScreens()
// which will become virtual siblings.
xcb_screen_t *xcbScreen = it.data;
QList<QPlatformScreen *> siblings;
int outputCount = 0;
if (has_randr_extension) {
xcb_generic_error_t *error = NULL;
xcb_randr_get_output_primary_cookie_t primaryCookie =
xcb_randr_get_output_primary_unchecked(xcb_connection(), xcbScreen->root);
xcb_randr_get_output_primary(xcb_connection(), xcbScreen->root);
xcb_randr_get_screen_resources_current_cookie_t resourcesCookie =
xcb_randr_get_screen_resources_current_unchecked(xcb_connection(), xcbScreen->root);
xcb_randr_get_screen_resources_current(xcb_connection(), xcbScreen->root);
xcb_randr_get_output_primary_reply_t *primary =
xcb_randr_get_output_primary_reply(xcb_connection(), primaryCookie, NULL);
xcb_randr_get_output_primary_reply(xcb_connection(), primaryCookie, &error);
if (!primary || error) {
qWarning("QXcbConnection: Failed to get the primary output of the screen");
free(error);
} else {
xcb_randr_get_screen_resources_current_reply_t *resources =
xcb_randr_get_screen_resources_current_reply(xcb_connection(), resourcesCookie, NULL);
xcb_randr_get_screen_resources_current_reply(xcb_connection(), resourcesCookie, &error);
if (!resources || error) {
qWarning("QXcbConnection: Failed to get the screen resources");
free(error);
} else {
xcb_timestamp_t timestamp = resources->config_timestamp;
int outputCount = xcb_randr_get_screen_resources_current_outputs_length(resources);
outputCount = xcb_randr_get_screen_resources_current_outputs_length(resources);
xcb_randr_output_t *outputs = xcb_randr_get_screen_resources_current_outputs(resources);
if (outputCount == 0) {
// This happens on VNC for example. But there is actually a screen anyway.
#ifdef Q_XCB_DEBUG
qDebug("Found a screen with zero outputs");
#endif
QXcbScreen* screen = findOrCreateScreen(newScreens, xcbScreenNumber, xcbScreen);
siblings << screen;
activeScreens << screen;
if (!primaryScreen)
primaryScreen = screen;
++screenNumber;
}
for (int i = 0; i < outputCount; i++) {
xcb_randr_get_output_info_reply_t *output =
xcb_randr_get_output_info_reply(xcb_connection(),
@ -200,9 +198,17 @@ void QXcbConnection::updateScreens()
}
free(output);
}
free(primary);
}
free(resources);
} else {
}
free(primary);
}
// If there's no randr extension, or there was some error above, or the screen
// doesn't have outputs for some other reason (e.g. on VNC or ssh -X), just assume there is one screen.
if (outputCount == 0) {
#ifdef Q_XCB_DEBUG
qDebug("Found a screen with zero outputs");
#endif
QXcbScreen *screen = findOrCreateScreen(newScreens, xcbScreenNumber, xcbScreen);
siblings << screen;
activeScreens << screen;
@ -214,7 +220,7 @@ void QXcbConnection::updateScreens()
((QXcbScreen*)s)->setVirtualSiblings(siblings);
xcb_screen_next(&it);
++xcbScreenNumber;
}
} // for each xcb screen
// Now activeScreens is the complete set of screens which are active at this time.
// Delete any existing screens which are not in activeScreens