Fix xrandr version check for gamma ramp modification

SaveDefaultGammaRamp: Don't crash if primary output is not connected

Instead, use the first connected output from the list of all outputs.
This happens on my computer, probably because the desktop environment
does not set the correct primary output.

SaveDefaultGammaRamp: Return true if everything worked correctly
stable-5.3
Armin Burgmeier 2012-12-02 15:10:27 +01:00 committed by Nicolas Hake
parent bf6e701ad7
commit 52a0ab8d05
1 changed files with 44 additions and 22 deletions

View File

@ -210,25 +210,53 @@ bool C4AbstractApp::GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32
return false;
}
static XRROutputInfo* GetXRROutputInfoForWindow(Display* dpy, Window w)
{
XRRScreenResources * r = XRRGetScreenResources(dpy, w);
if (!r) return NULL;
XRROutputInfo * info = XRRGetOutputInfo(dpy, r, XRRGetOutputPrimary(dpy, w));
if (!info)
{
XRRFreeScreenResources(r);
return NULL;
}
if(info->connection == RR_Disconnected || info->crtc == 0)
{
// The default "primary" output does not seem to be connected
// to a piece of actual hardware. As a fallback, go through
// all outputs and choose the first active one.
XRRFreeOutputInfo(info);
info = NULL;
for(int i = 0; i < r->noutput; ++i)
{
info = XRRGetOutputInfo(dpy, r, r->outputs[i]);
if(info->connection != RR_Disconnected && info->crtc != 0)
break;
XRRFreeOutputInfo(info);
info = NULL;
}
}
XRRFreeScreenResources(r);
if(!info) return NULL;
return info;
}
bool C4AbstractApp::ApplyGammaRamp(_D3DGAMMARAMP& ramp, bool fForce)
{
fprintf(stderr,"ApplyGammaRamp\n");
if (!Active && !fForce) return false;
if (Priv->xrandr_major_version < 1 || Priv->xrandr_minor_version < 3) return false;
if (Priv->xrandr_major_version < 1 || (Priv->xrandr_major_version == 1 && Priv->xrandr_minor_version < 3)) return false;
if (Priv->gammasize != 256) return false;
Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default());
XRRCrtcGamma g = { Priv->gammasize, ramp.red, ramp.green, ramp.blue };
XRRScreenResources * r = XRRGetScreenResources(dpy, pWindow->wnd);
if (!r)
{
Log(" Error setting gamma ramp: XRRGetScreenResources");
return false;
}
XRROutputInfo * i = XRRGetOutputInfo(dpy, r, XRRGetOutputPrimary(dpy, pWindow->wnd));
XRRFreeScreenResources(r);
XRROutputInfo* i = GetXRROutputInfoForWindow(dpy, pWindow->wnd);
if (!i)
{
Log(" Error setting gamma ramp: XRRGetOutputInfo");
Log(" Error setting gamma ramp: No XRROutputInfo available");
return false;
}
XRRSetCrtcGamma(dpy, i->crtc, &g);
@ -238,22 +266,15 @@ bool C4AbstractApp::ApplyGammaRamp(_D3DGAMMARAMP& ramp, bool fForce)
bool C4AbstractApp::SaveDefaultGammaRamp(_D3DGAMMARAMP& ramp)
{
fprintf(stderr,"SaveDefaultGammaRamp\n");
if (Priv->xrandr_major_version < 1 || Priv->xrandr_minor_version < 3) return false;
if (Priv->xrandr_major_version < 1 || (Priv->xrandr_major_version == 1 && Priv->xrandr_minor_version < 3)) return false;
Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default());
XRRScreenResources * r = XRRGetScreenResources(dpy, pWindow->wnd);
if (!r)
{
Log(" Error getting default gamma ramp: XRRGetScreenResources");
return false;
}
XRROutputInfo * i = XRRGetOutputInfo(dpy, r, XRRGetOutputPrimary(dpy, pWindow->wnd));
XRRFreeScreenResources(r);
XRROutputInfo* i = GetXRROutputInfoForWindow(dpy, pWindow->wnd);
if (!i)
{
Log(" Error getting default gamma ramp: XRRGetOutputInfo");
Log(" Error getting default gamma ramp: No XRROutputInfo available");
return false;
}
XRRCrtcGamma * g = XRRGetCrtcGamma(dpy, i->crtc);
XRRFreeOutputInfo(i);
if (!g)
@ -273,6 +294,7 @@ bool C4AbstractApp::SaveDefaultGammaRamp(_D3DGAMMARAMP& ramp)
memcpy(ramp.blue, g->blue, sizeof(ramp.blue));
}
XRRFreeGamma(g);
return true;
}
// Copy the text to the clipboard or the primary selection