diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2017-10-10 19:19:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-10 19:19:33 -0700 |
commit | ad7444e337e813c8280684890b8c95586fb1059c (patch) | |
tree | 3421382a759334d7818c2ef94691d8234ba039cf /src | |
parent | Merge pull request #511 from jonls/preserve-by-default (diff) | |
parent | Fix #523: Retry SetDeviceGammaRamp before giving up (diff) | |
download | redshift-ng-ad7444e337e813c8280684890b8c95586fb1059c.tar.gz redshift-ng-ad7444e337e813c8280684890b8c95586fb1059c.tar.bz2 redshift-ng-ad7444e337e813c8280684890b8c95586fb1059c.tar.xz |
Merge pull request #524 from dev7355608/w32gdi
Fix #523: Retry SetDeviceGammaRamp before giving up
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); |