Fix handling of non V1.5 XRandR

Due to the way Xlib handles errors XRRGetMonitors will cause dunst to exit if
the server doesn't support version 1.5 of RandR. The check for null is
effectively dead code but in theory the number of monitors can be < 1 so treat
this as an error. Change the code to fetch the RandR version and fallback if
the version is less than 1.5 when getting monitors.

This fix was brought up by @SteveJones on GitHub
This commit is contained in:
Benedikt Heine 2017-11-02 15:23:49 +01:00
parent 76857b6e7c
commit 1e51edc0df

View File

@ -23,6 +23,11 @@ int screens_len;
bool dunst_follow_errored = false;
int randr_event_base = 0;
static int randr_major_version = 0;
static int randr_minor_version = 0;
void randr_init();
void randr_update();
void xinerama_update();
@ -80,8 +85,6 @@ void alloc_screen_ar(int n)
screens_len = n;
}
int randr_event_base = 0;
void randr_init()
{
int randr_error_base = 0;
@ -89,20 +92,32 @@ void randr_init()
fprintf(stderr, "Could not initialize the RandR extension, falling back to single monitor mode.\n");
return;
}
XRRQueryVersion(xctx.dpy, &randr_major_version, &randr_minor_version);
XRRSelectInput(xctx.dpy, RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)), RRScreenChangeNotifyMask);
}
void randr_update()
{
int n;
XRRMonitorInfo *m = XRRGetMonitors(xctx.dpy, RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)), true, &n);
if (m == NULL || n == -1) {
fprintf(stderr, "(RandR) Could not get screen info, falling back to single monitor mode\n");
if (randr_major_version < 1
|| (randr_major_version == 1 && randr_minor_version < 5)) {
fprintf(stderr, "Server RandR version too low (%i.%i). Falling back to single monitor mode\n",
randr_major_version,
randr_minor_version);
screen_update_fallback();
return;
}
int n = 0;
XRRMonitorInfo *m = XRRGetMonitors(xctx.dpy, RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)), true, &n);
if (n < 1) {
fprintf(stderr, "Get monitors reported %i monitors, falling back to single monitor mode\n", n);
screen_update_fallback();
return;
}
assert(m);
alloc_screen_ar(n);
for (int i = 0; i < n; i++) {