From: Mikko Rasa Date: Thu, 15 Sep 2016 17:22:06 +0000 (+0300) Subject: Get monitor names from EDID if available X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=91d461ab8ef19ba49423dbbbe9b467ffdf0d1584;p=libs%2Fgui.git Get monitor names from EDID if available --- diff --git a/source/graphics/x11/display.cpp b/source/graphics/x11/display.cpp index c23f46d..a48f3f8 100644 --- a/source/graphics/x11/display.cpp +++ b/source/graphics/x11/display.cpp @@ -1,4 +1,5 @@ #include +#include #ifdef WITH_XRANDR #include #endif @@ -111,6 +112,7 @@ Display::Display(const string &disp_name): { XRRScreenResources *res = XRRGetScreenResources(priv->display, priv->root_window); RROutput primary = XRRGetOutputPrimary(priv->display, priv->root_window); + Atom edid_prop = XInternAtom(priv->display, RR_PROPERTY_RANDR_EDID, true); map modes_by_id; for(int i=0; inmode; ++i) @@ -127,6 +129,30 @@ Display::Display(const string &disp_name): monitor.name.assign(output->name, output->nameLen); priv->monitors.push_back(res->outputs[i]); + if(edid_prop) + { + Atom prop_type; + int prop_format; + unsigned long length; + unsigned long overflow; + unsigned char *edid = 0; + XRRGetOutputProperty(priv->display, res->outputs[i], edid_prop, 0, 32, false, false, XA_INTEGER, &prop_type, &prop_format, &length, &overflow, &edid); + if(prop_type==XA_INTEGER && prop_format==8) + { + for(unsigned j=0; j<4; ++j) + { + unsigned offset = 54+j*18; + if(edid[offset]==0 && edid[offset+1]==0 && edid[offset+3]==0xFC) + { + unsigned k; + for(k=0; (k<13 && edid[offset+5+k]!=0x0A); ++k) ; + monitor.name.assign(reinterpret_cast(edid+offset+5), k); + } + } + } + XFree(edid); + } + if(crtc) { monitor.desktop_rotation = rotation_from_sys(crtc->rotation);