From 0af92174300fead7e2ab4a4ee248181432033d56 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 26 Mar 2012 21:02:22 +0200 Subject: XCB: Simplify xcb error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of getting errors just to feed them to the default error handle, the corresponding unchecked request is used which automatically makes errors go to the default error handler. Change-Id: Ib213a860affb72de6f9896f68505e283a809d58f Signed-off-by: Uli Schlachter Reviewed-by: Samuel Rødal Reviewed-by: Robin Burchell --- src/plugins/platforms/xcb/qxcbimage.cpp | 9 +-- src/plugins/platforms/xcb/qxcbscreen.cpp | 69 +++++------------------ src/plugins/platforms/xcb/qxcbwindow.cpp | 85 +++++++---------------------- src/plugins/platforms/xcb/qxcbwmsupport.cpp | 10 ++-- 4 files changed, 41 insertions(+), 132 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbimage.cpp b/src/plugins/platforms/xcb/qxcbimage.cpp index 12979bfb68..6a1209e6cf 100644 --- a/src/plugins/platforms/xcb/qxcbimage.cpp +++ b/src/plugins/platforms/xcb/qxcbimage.cpp @@ -84,20 +84,15 @@ QPixmap qt_xcb_pixmapFromXPixmap(QXcbConnection *connection, xcb_pixmap_t pixmap const xcb_visualtype_t *visual) { xcb_connection_t *conn = connection->xcb_connection(); - xcb_generic_error_t *error = 0; xcb_get_image_cookie_t get_image_cookie = - xcb_get_image(conn, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, + xcb_get_image_unchecked(conn, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, 0, 0, width, height, 0xffffffff); xcb_get_image_reply_t *image_reply = - xcb_get_image_reply(conn, get_image_cookie, &error); + xcb_get_image_reply(conn, get_image_cookie, NULL); if (!image_reply) { - if (error) { - connection->handleXcbError(error); - free(error); - } return QPixmap(); } diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index a076dd4282..ae5e4cce34 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -76,13 +76,11 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int num xcb_change_window_attributes(xcb_connection(), screen->root, mask, values); - xcb_generic_error_t *error; - xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), - xcb_get_property(xcb_connection(), false, screen->root, + xcb_get_property_unchecked(xcb_connection(), false, screen->root, atom(QXcbAtom::_NET_SUPPORTING_WM_CHECK), - XCB_ATOM_WINDOW, 0, 1024), &error); + XCB_ATOM_WINDOW, 0, 1024), NULL); if (reply && reply->format == 32 && reply->type == XCB_ATOM_WINDOW) { xcb_window_t windowManager = *((xcb_window_t *)xcb_get_property_value(reply)); @@ -90,24 +88,18 @@ QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int num if (windowManager != XCB_WINDOW_NONE) { xcb_get_property_reply_t *windowManagerReply = xcb_get_property_reply(xcb_connection(), - xcb_get_property(xcb_connection(), false, windowManager, + xcb_get_property_unchecked(xcb_connection(), false, windowManager, atom(QXcbAtom::_NET_WM_NAME), - atom(QXcbAtom::UTF8_STRING), 0, 1024), &error); + atom(QXcbAtom::UTF8_STRING), 0, 1024), NULL); if (windowManagerReply && windowManagerReply->format == 8 && windowManagerReply->type == atom(QXcbAtom::UTF8_STRING)) { m_windowManagerName = QString::fromUtf8((const char *)xcb_get_property_value(windowManagerReply), xcb_get_property_value_length(windowManagerReply)); #ifdef Q_XCB_DEBUG qDebug("Running window manager: %s", qPrintable(m_windowManagerName)); #endif - } else if (error) { - connection->handleXcbError(error); - free(error); } free(windowManagerReply); } - } else if (error) { - connection->handleXcbError(error); - free(error); } free(reply); @@ -171,23 +163,17 @@ QWindow *QXcbScreen::topLevelAt(const QPoint &p) const int x = p.x(); int y = p.y(); - xcb_generic_error_t *error; - xcb_window_t parent = root; xcb_window_t child = root; do { xcb_translate_coordinates_cookie_t translate_cookie = - xcb_translate_coordinates(xcb_connection(), parent, child, x, y); + xcb_translate_coordinates_unchecked(xcb_connection(), parent, child, x, y); xcb_translate_coordinates_reply_t *translate_reply = - xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, &error); + xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, NULL); if (!translate_reply) { - if (error) { - connection()->handleXcbError(error); - free(error); - } return 0; } @@ -252,17 +238,12 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) if (width == 0 || height == 0) return QPixmap(); - xcb_get_geometry_cookie_t geometry_cookie = xcb_get_geometry(xcb_connection(), window); + xcb_get_geometry_cookie_t geometry_cookie = xcb_get_geometry_unchecked(xcb_connection(), window); - xcb_generic_error_t *error; xcb_get_geometry_reply_t *reply = - xcb_get_geometry_reply(xcb_connection(), geometry_cookie, &error); + xcb_get_geometry_reply(xcb_connection(), geometry_cookie, NULL); if (!reply) { - if (error) { - connection()->handleXcbError(error); - free(error); - } return QPixmap(); } @@ -274,15 +255,11 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) // TODO: handle multiple screens QXcbScreen *screen = const_cast(this); xcb_window_t root = screen->root(); - geometry_cookie = xcb_get_geometry(xcb_connection(), root); + geometry_cookie = xcb_get_geometry_unchecked(xcb_connection(), root); xcb_get_geometry_reply_t *root_reply = - xcb_get_geometry_reply(xcb_connection(), geometry_cookie, &error); + xcb_get_geometry_reply(xcb_connection(), geometry_cookie, NULL); if (!root_reply) { - if (error) { - connection()->handleXcbError(error); - free(error); - } free(reply); return QPixmap(); } @@ -294,16 +271,12 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) // map x and y to the root window xcb_translate_coordinates_cookie_t translate_cookie = - xcb_translate_coordinates(xcb_connection(), window, root, x, y); + xcb_translate_coordinates_unchecked(xcb_connection(), window, root, x, y); xcb_translate_coordinates_reply_t *translate_reply = - xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, &error); + xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, NULL); if (!translate_reply) { - if (error) { - connection()->handleXcbError(error); - free(error); - } free(reply); free(root_reply); return QPixmap(); @@ -323,13 +296,9 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) } xcb_get_window_attributes_reply_t *attributes_reply = - xcb_get_window_attributes_reply(xcb_connection(), xcb_get_window_attributes(xcb_connection(), window), &error); + xcb_get_window_attributes_reply(xcb_connection(), xcb_get_window_attributes_unchecked(xcb_connection(), window), NULL); if (!attributes_reply) { - if (error) { - connection()->handleXcbError(error); - free(error); - } free(reply); return QPixmap(); } @@ -338,11 +307,7 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) free(attributes_reply); xcb_pixmap_t pixmap = xcb_generate_id(xcb_connection()); - error = xcb_request_check(xcb_connection(), xcb_create_pixmap_checked(xcb_connection(), reply->depth, pixmap, window, width, height)); - if (error) { - connection()->handleXcbError(error); - free(error); - } + xcb_create_pixmap(xcb_connection(), reply->depth, pixmap, window, width, height); uint32_t gc_value_mask = XCB_GC_SUBWINDOW_MODE; uint32_t gc_value_list[] = { XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS }; @@ -350,11 +315,7 @@ QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) xcb_gcontext_t gc = xcb_generate_id(xcb_connection()); xcb_create_gc(xcb_connection(), gc, pixmap, gc_value_mask, gc_value_list); - error = xcb_request_check(xcb_connection(), xcb_copy_area_checked(xcb_connection(), window, pixmap, gc, x, y, 0, 0, width, height)); - if (error) { - connection()->handleXcbError(error); - free(error); - } + xcb_copy_area(xcb_connection(), window, pixmap, gc, x, y, 0, 0, width, height); QPixmap result = qt_xcb_pixmapFromXPixmap(connection(), pixmap, width, height, reply->depth, visual); diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index ba4a6f7c5e..5a8f90b7ad 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -66,6 +66,7 @@ #ifdef XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS #define xcb_get_wm_hints_reply xcb_icccm_get_wm_hints_reply #define xcb_get_wm_hints xcb_icccm_get_wm_hints +#define xcb_get_wm_hints_unchecked xcb_icccm_get_wm_hints_unchecked #define xcb_set_wm_hints xcb_icccm_set_wm_hints #define xcb_set_wm_normal_hints xcb_icccm_set_wm_normal_hints #define xcb_size_hints_set_base_size xcb_icccm_size_hints_set_base_size @@ -420,10 +421,9 @@ QMargins QXcbWindow::frameMargins() const connection()->wmSupport()->virtualRoots(); while (!foundRoot) { - xcb_query_tree_cookie_t cookie = xcb_query_tree(xcb_connection(), parent); + xcb_query_tree_cookie_t cookie = xcb_query_tree_unchecked(xcb_connection(), parent); - xcb_generic_error_t *error; - xcb_query_tree_reply_t *reply = xcb_query_tree_reply(xcb_connection(), cookie, &error); + xcb_query_tree_reply_t *reply = xcb_query_tree_reply(xcb_connection(), cookie, NULL); if (reply) { if (reply->root == reply->parent || virtualRoots.indexOf(reply->parent) != -1) { foundRoot = true; @@ -434,11 +434,6 @@ QMargins QXcbWindow::frameMargins() const free(reply); } else { - if (error) { - connection()->handleXcbError(error); - free(error); - } - m_dirtyFrameMargins = false; m_frameMargins = QMargins(); return m_frameMargins; @@ -447,25 +442,22 @@ QMargins QXcbWindow::frameMargins() const QPoint offset; - xcb_generic_error_t *error; xcb_translate_coordinates_reply_t *reply = xcb_translate_coordinates_reply( xcb_connection(), xcb_translate_coordinates(xcb_connection(), window, parent, 0, 0), - &error); + NULL); if (reply) { offset = QPoint(reply->dst_x, reply->dst_y); free(reply); - } else if (error) { - free(error); } xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply( xcb_connection(), xcb_get_geometry(xcb_connection(), parent), - &error); + NULL); if (geom) { // -- @@ -485,8 +477,6 @@ QMargins QXcbWindow::frameMargins() const m_frameMargins = QMargins(left, top, right, bottom); free(geom); - } else if (error) { - free(error); } m_dirtyFrameMargins = false; @@ -506,17 +496,10 @@ void QXcbWindow::setVisible(bool visible) void QXcbWindow::show() { if (window()->isTopLevel()) { - xcb_get_property_cookie_t cookie = xcb_get_wm_hints(xcb_connection(), m_window); - - xcb_generic_error_t *error; + xcb_get_property_cookie_t cookie = xcb_get_wm_hints_unchecked(xcb_connection(), m_window); xcb_wm_hints_t hints; - xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, &error); - - if (error) { - connection()->handleXcbError(error); - free(error); - } + xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, NULL); if (window()->windowState() & Qt::WindowMinimized) xcb_wm_hints_set_iconic(&hints); @@ -616,20 +599,15 @@ static QtMotifWmHints getMotifWmHints(QXcbConnection *c, xcb_window_t window) QtMotifWmHints hints; xcb_get_property_cookie_t get_cookie = - xcb_get_property(c->xcb_connection(), 0, window, c->atom(QXcbAtom::_MOTIF_WM_HINTS), + xcb_get_property_unchecked(c->xcb_connection(), 0, window, c->atom(QXcbAtom::_MOTIF_WM_HINTS), c->atom(QXcbAtom::_MOTIF_WM_HINTS), 0, 20); - xcb_generic_error_t *error; - xcb_get_property_reply_t *reply = - xcb_get_property_reply(c->xcb_connection(), get_cookie, &error); + xcb_get_property_reply(c->xcb_connection(), get_cookie, NULL); if (reply && reply->format == 32 && reply->type == c->atom(QXcbAtom::_MOTIF_WM_HINTS)) { hints = *((QtMotifWmHints *)xcb_get_property_value(reply)); - } else if (error) { - c->handleXcbError(error); - free(error); - + } else { hints.flags = 0L; hints.functions = MWM_FUNC_ALL; hints.decorations = MWM_DECOR_ALL; @@ -683,13 +661,11 @@ QVector QXcbWindow::getNetWmState() QVector result; xcb_get_property_cookie_t get_cookie = - xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::_NET_WM_STATE), + xcb_get_property_unchecked(xcb_connection(), 0, m_window, atom(QXcbAtom::_NET_WM_STATE), XCB_ATOM_ATOM, 0, 1024); - xcb_generic_error_t *error; - xcb_get_property_reply_t *reply = - xcb_get_property_reply(xcb_connection(), get_cookie, &error); + xcb_get_property_reply(xcb_connection(), get_cookie, NULL); if (reply && reply->format == 32 && reply->type == XCB_ATOM_ATOM) { result.resize(reply->length); @@ -702,9 +678,6 @@ QVector QXcbWindow::getNetWmState() #endif free(reply); - } else if (error) { - connection()->handleXcbError(error); - free(error); } else { #ifdef NET_WM_STATE_DEBUG printf("getting net wm state (%x), empty\n", m_window); @@ -1084,16 +1057,10 @@ void QXcbWindow::setTransparentForMouseEvents(bool transparent) void QXcbWindow::updateDoesNotAcceptFocus(bool doesNotAcceptFocus) { - xcb_get_property_cookie_t cookie = xcb_get_wm_hints(xcb_connection(), m_window); - - xcb_generic_error_t *error; + xcb_get_property_cookie_t cookie = xcb_get_wm_hints_unchecked(xcb_connection(), m_window); xcb_wm_hints_t hints; - xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, &error); - - if (error) { - connection()->handleXcbError(error); - free(error); + if (!xcb_get_wm_hints_reply(xcb_connection(), cookie, &hints, NULL)) { return; } @@ -1314,14 +1281,11 @@ void QXcbWindow::handleConfigureNotifyEvent(const xcb_configure_notify_event_t * // Do not trust the position, query it instead. xcb_translate_coordinates_cookie_t cookie = xcb_translate_coordinates(xcb_connection(), xcb_window(), m_screen->root(), 0, 0); - xcb_generic_error_t *error; - xcb_translate_coordinates_reply_t *reply = xcb_translate_coordinates_reply(xcb_connection(), cookie, &error); + xcb_translate_coordinates_reply_t *reply = xcb_translate_coordinates_reply(xcb_connection(), cookie, NULL); if (reply) { pos.setX(reply->dst_x); pos.setY(reply->dst_y); free(reply); - } else if (error) { - free(error); } } @@ -1498,19 +1462,14 @@ void QXcbWindow::handlePropertyNotifyEvent(const xcb_property_notify_event_t *ev xcb_get_property(xcb_connection(), 0, m_window, atom(QXcbAtom::WM_STATE), XCB_ATOM_ANY, 0, 1024); - xcb_generic_error_t *error; - xcb_get_property_reply_t *reply = - xcb_get_property_reply(xcb_connection(), get_cookie, &error); + xcb_get_property_reply(xcb_connection(), get_cookie, NULL); xcb_atom_t wm_state = XCB_WM_STATE_WITHDRAWN; if (reply && reply->format == 32 && reply->type == atom(QXcbAtom::WM_STATE)) { if (reply->length != 0) wm_state = ((long *)xcb_get_property_value(reply))[0]; free(reply); - } else if (error) { - connection()->handleXcbError(error); - free(error); } QVector netWmState = getNetWmState(); @@ -1576,11 +1535,9 @@ bool QXcbWindow::setKeyboardGrabEnabled(bool grab) xcb_grab_keyboard_cookie_t cookie = xcb_grab_keyboard(xcb_connection(), false, m_window, XCB_TIME_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); - xcb_generic_error_t *err; - xcb_grab_keyboard_reply_t *reply = xcb_grab_keyboard_reply(xcb_connection(), cookie, &err); - bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS); + xcb_grab_keyboard_reply_t *reply = xcb_grab_keyboard_reply(xcb_connection(), cookie, NULL); + bool result = !(!reply || reply->status != XCB_GRAB_STATUS_SUCCESS); free(reply); - free(err); return result; } @@ -1597,11 +1554,9 @@ bool QXcbWindow::setMouseGrabEnabled(bool grab) XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_WINDOW_NONE, XCB_CURSOR_NONE, XCB_TIME_CURRENT_TIME); - xcb_generic_error_t *err; - xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(xcb_connection(), cookie, &err); - bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS); + xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(xcb_connection(), cookie, NULL); + bool result = !(!reply || reply->status != XCB_GRAB_STATUS_SUCCESS); free(reply); - free(err); return result; } diff --git a/src/plugins/platforms/xcb/qxcbwmsupport.cpp b/src/plugins/platforms/xcb/qxcbwmsupport.cpp index c9f4ca69dd..e164c7ae2d 100644 --- a/src/plugins/platforms/xcb/qxcbwmsupport.cpp +++ b/src/plugins/platforms/xcb/qxcbwmsupport.cpp @@ -68,10 +68,9 @@ void QXcbWMSupport::updateNetWMAtoms() int offset = 0; int remaining = 0; do { - xcb_generic_error_t *error = 0; xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_SUPPORTED), XCB_ATOM_ATOM, offset, 1024); - xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, &error); - if (!reply || error) + xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, NULL); + if (!reply) break; remaining = 0; @@ -103,10 +102,9 @@ void QXcbWMSupport::updateVirtualRoots() int offset = 0; int remaining = 0; do { - xcb_generic_error_t *error = 0; xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_VIRTUAL_ROOTS), XCB_ATOM_ATOM, offset, 1024); - xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, &error); - if (!reply || error) + xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, NULL); + if (!reply) break; remaining = 0; -- cgit v1.2.3