]> git.tdb.fi Git - libs/gui.git/commitdiff
Get monitor names from EDID if available
authorMikko Rasa <tdb@tdb.fi>
Thu, 15 Sep 2016 17:22:06 +0000 (20:22 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 15 Sep 2016 17:22:06 +0000 (20:22 +0300)
source/graphics/x11/display.cpp

index c23f46d26a21417cb14483c562401f3bbe7d9575..a48f3f874f1a3600da402f9fd88a1138b7f80c89 100644 (file)
@@ -1,4 +1,5 @@
 #include <X11/Xlib.h>
+#include <X11/Xatom.h>
 #ifdef WITH_XRANDR
 #include <X11/extensions/Xrandr.h>
 #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<RRMode, XRRModeInfo *> modes_by_id;
                        for(int i=0; i<res->nmode; ++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<char *>(edid+offset+5), k);
+                                                       }
+                                               }
+                                       }
+                                       XFree(edid);
+                               }
+
                                if(crtc)
                                {
                                        monitor.desktop_rotation = rotation_from_sys(crtc->rotation);