Bugfix: Repeatedly try to find screens if none are available (Thanks mxf)
When rotating your screens (xrandr --output LVDS1 --rotate right), sometimes the X server returned no screens which lead to an exit(1) of i3. Now, i3 tries to find screens for up to 5 seconds and only quits afterwards.
This commit is contained in:
parent
af4d2e6d4e
commit
09c1248571
|
@ -13,6 +13,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xinerama.h>
|
#include <xcb/xinerama.h>
|
||||||
|
@ -156,7 +157,13 @@ static void disable_xinerama(xcb_connection_t *conn) {
|
||||||
static void query_screens(xcb_connection_t *conn, struct screens_head *screenlist) {
|
static void query_screens(xcb_connection_t *conn, struct screens_head *screenlist) {
|
||||||
xcb_xinerama_query_screens_reply_t *reply;
|
xcb_xinerama_query_screens_reply_t *reply;
|
||||||
xcb_xinerama_screen_info_t *screen_info;
|
xcb_xinerama_screen_info_t *screen_info;
|
||||||
|
time_t before_trying = time(NULL);
|
||||||
|
|
||||||
|
/* Try repeatedly to find screens (there might be short timeframes in
|
||||||
|
* which the X server does not return any screens, such as when rotating
|
||||||
|
* screens), but not longer than 5 seconds (strictly speaking, only four
|
||||||
|
* seconds of trying are guaranteed due to the 1-second-resolution) */
|
||||||
|
while ((time(NULL) - before_trying) < 5) {
|
||||||
reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
|
reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
|
||||||
if (!reply) {
|
if (!reply) {
|
||||||
LOG("Couldn't get Xinerama screens\n");
|
LOG("Couldn't get Xinerama screens\n");
|
||||||
|
@ -194,8 +201,11 @@ static void query_screens(xcb_connection_t *conn, struct screens_head *screenlis
|
||||||
free(reply);
|
free(reply);
|
||||||
|
|
||||||
if (num_screens == 0) {
|
if (num_screens == 0) {
|
||||||
LOG("No screens found. This is weird.\n");
|
LOG("No screens found. This is weird. Trying again...\n");
|
||||||
exit(1);
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue