summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Peres <martin.peres@linux.intel.com>2017-01-21 22:31:09 +0200
committerMartin Peres <martin.peres@linux.intel.com>2017-01-21 22:31:09 +0200
commit6347edae5251ee3a5aef5babd2afe1586477ae51 (patch)
tree676e6bfb498f0de3f16d12d6b585b0e4ddbfceb0
parent043a74230f9a1a684a49ae3fd37ad3fe422b6ec8 (diff)
make the code more robustHEADmaster
-rw-r--r--auto-randr.c125
1 files changed, 71 insertions, 54 deletions
diff --git a/auto-randr.c b/auto-randr.c
index 01de5ac..5e5e133 100644
--- a/auto-randr.c
+++ b/auto-randr.c
@@ -135,7 +135,7 @@ do_XRRSetCrtcConfig (XRRScreenResources *resources, RRCrtc crtc, RRMode mode,
if (s != RRSetConfigSuccess)
printf("XRRSetCrtcConfig failed!");
XUngrabServer(dpy);
-
+
return s;
}
@@ -178,61 +178,78 @@ do_RRNotify_OutputChange (XEvent *eventp, XRRScreenResources *screen_resources)
printf (", subpixel_order ");
print_SubPixelOrder (e->subpixel_order);
printf ("\n");
-
- if (e->connection == RR_Connected) {
- XID crtc_avail = None;
-
- /* Now list all the available modes */
- printf (" Found the following modes:\n");
- for (i = 0; i < output_info->nmode; i++) {
- /* Find the corresponding mode */
- for (j = 0; j < screen_resources->nmode; j++)
- if (output_info->modes[i] == screen_resources->modes[j].id)
- mode_info = &screen_resources->modes[j];
-
- printf(" %lu: %s, dotClk=%lu Hz, flags=%lu%s%s\n", mode_info->id,
- mode_info->name, mode_info->dotClock, mode_info->modeFlags,
- mode_info->id == e->mode ? "*" : "",
- i < output_info->npreferred ? "+" : "");
-
- if (highest_mode == NULL ||
- mode_info->width * mode_info->height >
- highest_mode->width * highest_mode->height)
- highest_mode = mode_info;
- }
- if (e->crtc) {
- crtc_avail = e->crtc;
- } else {
- printf (" Search for an available CRTC:\n");
- for (i = 0; i < screen_resources->ncrtc; i++) {
- crtc_info = XRRGetCrtcInfo (dpy, screen_resources,
- screen_resources->crtcs[i]);
- printf(" %lu: %ix%i (mode %lu)\n", screen_resources->crtcs[i],
- crtc_info->width, crtc_info->height, crtc_info->mode);
-
- if (crtc_info->mode == None)
- crtc_avail = screen_resources->crtcs[i];
+
+ if (screen_resources) {
+ if (e->connection == RR_Connected) {
+ XID crtc_avail = None;
+ mode_info = NULL;
+
+ /* Now list all the available modes */
+ printf (" Found the following modes:\n");
+ for (i = 0; i < output_info->nmode; i++) {
+ /* Find the corresponding mode */
+ for (j = 0; j < screen_resources->nmode; j++)
+ if (output_info->modes[i] == screen_resources->modes[j].id)
+ mode_info = &screen_resources->modes[j];
+
+ if (!mode_info) {
+ printf(" %lu: Could not be found in the screen resources!\n",
+ output_info->modes[i]);
+ continue;
+ }
+
+ printf(" %lu: %s, dotClk=%lu Hz, flags=%lu%s%s\n", mode_info->id,
+ mode_info->name, mode_info->dotClock, mode_info->modeFlags,
+ mode_info->id == e->mode ? "*" : "",
+ i < output_info->npreferred ? "+" : "");
+
+ if (highest_mode == NULL ||
+ mode_info->width * mode_info->height >
+ highest_mode->width * highest_mode->height)
+ highest_mode = mode_info;
+ }
+ if (e->crtc) {
+ crtc_avail = e->crtc;
+ } else {
+ printf (" Search for an available CRTC:\n");
+ for (i = 0; i < screen_resources->ncrtc; i++) {
+ crtc_info = XRRGetCrtcInfo (dpy, screen_resources,
+ screen_resources->crtcs[i]);
+ if (!crtc_info) {
+ printf(" %lu: could not be queried!\n",
+ screen_resources->crtcs[i]);
+ continue;
+ }
+ printf(" %lu: %ix%i (mode %lu)\n", screen_resources->crtcs[i],
+ crtc_info->width, crtc_info->height, crtc_info->mode);
+
+ if (crtc_info->mode == None)
+ crtc_avail = screen_resources->crtcs[i];
+ }
}
+
+ if (highest_mode && highest_mode->id == e->mode) {
+ printf (" The highest mode is already selected, nothing to do!\n");
+ } else if (highest_mode && crtc_avail != None) {
+ printf (" Setting the mode %lu (%s, dotClk=%lu Hz) on CRTC %lu\n",
+ highest_mode->id, highest_mode->name, highest_mode->dotClock,
+ crtc_avail);
+
+ do_XRRSetCrtcConfig (screen_resources, crtc_avail, highest_mode->id,
+ &e->output, 1);
+ } else if (highest_mode)
+ printf (" Found no available CRTC, do not set a new mode!\n");
+ else
+ printf (" Found no highest mode!!\n");
+ } else if (e->crtc != None) {
+ printf (" Disable the CRTC %lu\n", e->crtc);
+
+ do_XRRSetCrtcConfig (screen_resources, e->crtc, None, NULL, 0);
}
-
- if (highest_mode->id == e->mode) {
- printf (" The highest mode is already selected, nothing to do!\n");
- } else if (crtc_avail != None) {
- printf (" Setting the mode %lu (%s, dotClk=%lu Hz) on CRTC %lu\n",
- highest_mode->id, highest_mode->name, highest_mode->dotClock,
- crtc_avail);
-
- do_XRRSetCrtcConfig (screen_resources, crtc_avail, highest_mode->id,
- &e->output, 1);
- } else
- printf (" Found no available CRTC, do not set a new mode!\n");
- } else if (e->crtc != None) {
- printf (" Disable the CRTC %lu\n", e->crtc);
-
- do_XRRSetCrtcConfig (screen_resources, e->crtc, None, NULL, 0);
- }
-
- XRRFreeOutputInfo (output_info);
+ } else
+ printf (" Could not query the screen resources, bailed out!\n");
+
+ XRRFreeOutputInfo (output_info);
}
static void