From 9af707c7a06b7d97b554544fe40fbdff59db2e7e Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 27 Aug 2013 21:54:48 +0200 Subject: [PATCH] use xrandr for x11gamma (still hacky) --- Makefile | 1 + src/backends/sdl/refresh.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 36226df8..f585d030 100644 --- a/Makefile +++ b/Makefile @@ -239,6 +239,7 @@ ifneq ($(OSTYPE), Darwin) ifeq ($(WITH_X11GAMMA),yes) X11LDFLAGS := $(shell pkg-config x11 --libs) X11LDFLAGS += $(shell pkg-config xxf86vm --libs) +X11LDFLAGS += $(shell pkg-config xrandr --libs) endif endif endif diff --git a/src/backends/sdl/refresh.c b/src/backends/sdl/refresh.c index 605ad020..7369fef7 100644 --- a/src/backends/sdl/refresh.c +++ b/src/backends/sdl/refresh.c @@ -49,6 +49,9 @@ #include #include #include + #include + + #include #endif #if SDL_VERSION_ATLEAST(2, 0, 0) @@ -185,6 +188,34 @@ SetSDLIcon() void UpdateHardwareGamma(void) { +#if 1 + float gamma = (vid_gamma->value); + // RANDR implementation + int i; + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + SDL_GetWindowWMInfo(window, &info); // TODO: check return val + + XRRScreenResources* res = XRRGetScreenResources(info.info.x11.display, info.info.x11.window); + + Uint16 ramp[256]; + SDL_CalculateGammaRamp(gamma, ramp); + size_t rampSize = 256*sizeof(Uint16); + + for(i=0; i < res->ncrtc; ++i) + { + XRRCrtcGamma* gamma = XRRAllocGamma(256); + + memcpy(gamma->red, ramp, rampSize); + memcpy(gamma->green, ramp, rampSize); + memcpy(gamma->blue, ramp, rampSize); + XRRSetCrtcGamma(info.info.x11.display, res->crtcs[i], gamma); + XRRFreeGamma(gamma); + } + + XRRFreeScreenResources(res); + +#else float gamma; XF86VidModeGamma x11_gamma; @@ -198,6 +229,7 @@ UpdateHardwareGamma(void) /* This forces X11 to update the gamma tables */ XF86VidModeGetGamma(dpy, screen, &x11_gamma); +#endif } #else @@ -210,7 +242,9 @@ UpdateHardwareGamma(void) // FIXME: does this work? Uint16 ramp[256]; SDL_CalculateGammaRamp(gamma, ramp); - SDL_SetWindowGammaRamp(window, ramp, ramp, ramp); + if(SDL_SetWindowGammaRamp(window, ramp, ramp, ramp) != 0) { + printf("## setting gamma failed: %s\n", SDL_GetError()); + } #else SDL_SetGamma(gamma, gamma, gamma); #endif