diff options
author | dev7355608 <dev7355608@gmail.com> | 2017-09-27 15:48:14 +0200 |
---|---|---|
committer | dev7355608 <dev7355608@gmail.com> | 2017-09-27 16:20:47 +0200 |
commit | d9d7218cc802e8040e18759d55c797105d4fbf4c (patch) | |
tree | 3421382a759334d7818c2ef94691d8234ba039cf /src | |
parent | Merge pull request #511 from jonls/preserve-by-default (diff) | |
download | redshift-ng-d9d7218cc802e8040e18759d55c797105d4fbf4c.tar.gz redshift-ng-d9d7218cc802e8040e18759d55c797105d4fbf4c.tar.bz2 redshift-ng-d9d7218cc802e8040e18759d55c797105d4fbf4c.tar.xz |
Fix #523: Retry SetDeviceGammaRamp before giving up
We have to retry SetDeviceGammaRamp a few times before giving up
because some buggy drivers fail on the first invocation just to
succeed on the second.
Diffstat (limited to 'src')
-rw-r--r-- | src/gamma-w32gdi.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c index 836b2d1..3d67331 100644 --- a/src/gamma-w32gdi.c +++ b/src/gamma-w32gdi.c @@ -37,6 +37,7 @@ #include "colorramp.h" #define GAMMA_RAMP_SIZE 256 +#define MAX_ATTEMPTS 10 int @@ -136,7 +137,13 @@ w32gdi_restore(w32gdi_state_t *state) } /* Restore gamma ramps */ - BOOL r = SetDeviceGammaRamp(hDC, state->saved_ramps); + BOOL r = FALSE; + for (int i = 0; i < MAX_ATTEMPTS && !r; i++) { + /* We retry a few times before giving up because some + buggy drivers fail on the first invocation of + SetDeviceGammaRamp just to succeed on the second. */ + r = SetDeviceGammaRamp(hDC, state->saved_ramps); + } if (!r) fputs(_("Unable to restore gamma ramps.\n"), stderr); /* Release device context */ @@ -187,11 +194,14 @@ w32gdi_set_temperature(w32gdi_state_t *state, setting); /* Set new gamma ramps */ - r = SetDeviceGammaRamp(hDC, gamma_ramps); + r = FALSE; + for (int i = 0; i < MAX_ATTEMPTS && !r; i++) { + /* We retry a few times before giving up because some + buggy drivers fail on the first invocation of + SetDeviceGammaRamp just to succeed on the second. */ + r = SetDeviceGammaRamp(hDC, gamma_ramps); + } if (!r) { - /* TODO it happens that SetDeviceGammaRamp returns FALSE on - occasions where the adjustment seems to be successful. - Does this only happen with multiple monitors connected? */ fputs(_("Unable to set gamma ramps.\n"), stderr); free(gamma_ramps); ReleaseDC(NULL, hDC); |