From 20863c5ed3a52d713343667095ab74aba8d78b49 Mon Sep 17 00:00:00 2001 From: fryshorts Date: Mon, 22 Dec 2014 01:12:58 +0100 Subject: [PATCH] UI: Fix bug with xinerama on linux Refactor the screen enumeration code a little to make sure xinerama is present and active before using it. If the extension is present but not active it will no longer fail. --- obs/platform-x11.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/obs/platform-x11.cpp b/obs/platform-x11.cpp index 65e0a621d..424a8f78f 100644 --- a/obs/platform-x11.cpp +++ b/obs/platform-x11.cpp @@ -70,21 +70,24 @@ void GetMonitors(vector &monitors) monitors.clear(); xcb_conn = xcb_connect(NULL, NULL); + bool use_xinerama = false; if (xcb_get_extension_data(xcb_conn, &xcb_xinerama_id)->present) { xcb_xinerama_is_active_cookie_t xinerama_cookie; xcb_xinerama_is_active_reply_t* xinerama_reply = NULL; - xcb_xinerama_query_screens_cookie_t screens_cookie; - xcb_xinerama_query_screens_reply_t* screens_reply = NULL; - xcb_xinerama_screen_info_iterator_t iter; xinerama_cookie = xcb_xinerama_is_active(xcb_conn); xinerama_reply = xcb_xinerama_is_active_reply(xcb_conn, xinerama_cookie, NULL); - if (xinerama_reply == NULL || xinerama_reply->state == 0) { - free(xinerama_reply); - goto err; - } + if (xinerama_reply && xinerama_reply->state != 0) + use_xinerama = true; + free(xinerama_reply); + } + + if (use_xinerama) { + xcb_xinerama_query_screens_cookie_t screens_cookie; + xcb_xinerama_query_screens_reply_t* screens_reply = NULL; + xcb_xinerama_screen_info_iterator_t iter; screens_cookie = xcb_xinerama_query_screens(xcb_conn); screens_reply = xcb_xinerama_query_screens_reply(xcb_conn, @@ -98,7 +101,6 @@ void GetMonitors(vector &monitors) iter.data->width, iter.data->height); } - free(xinerama_reply); free(screens_reply); } else { // no xinerama so fall back to basic x11 calls @@ -111,7 +113,6 @@ void GetMonitors(vector &monitors) } } -err: xcb_disconnect(xcb_conn); }