[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [libkscreen] backends/xrandr: Try to get the type from XRandR, if not fallback to Output::name
From:       Àlex_Fiestas <afiestas () kde ! org>
Date:       2013-04-30 18:30:55
Message-ID: 20130430183055.B49BBA6071 () git ! kde ! org
[Download RAW message or body]

Git commit 46033acb774327e4b12ff182a314ce4ba9031b4d by Àlex Fiestas.
Committed on 30/04/2013 at 20:29.
Pushed by afiestas into branch 'master'.

Try to get the type from XRandR, if not fallback to Output::name

M  +102  -1    backends/xrandr/xrandroutput.cpp
M  +4    -1    backends/xrandr/xrandroutput.h

http://commits.kde.org/libkscreen/46033acb774327e4b12ff182a314ce4ba9031b4d

diff --git a/backends/xrandr/xrandroutput.cpp b/backends/xrandr/xrandroutput.cpp
index 6cbf63c..ed2b163 100644
--- a/backends/xrandr/xrandroutput.cpp
+++ b/backends/xrandr/xrandroutput.cpp
@@ -27,12 +27,14 @@
 
 #include <QRect>
 
+#include <KDebug>
+
 Q_DECLARE_METATYPE(QList<int>)
 
 XRandROutput::XRandROutput(int id, bool primary, XRandRConfig *config)
     : QObject(config)
     , m_id(id)
-    , m_type("unknown")
+    , m_type(KScreen::Output::Unknown)
     , m_rotation(KScreen::Output::None)
     , m_connected(0)
     , m_enabled(0)
@@ -218,6 +220,105 @@ void XRandROutput::updateModes(const XRROutputInfo *outputInfo)
     XRRFreeScreenResources(resources);
 }
 
+void XRandROutput::fetchType()
+{
+    QByteArray type = typeFromProperty();
+    if (type.isEmpty()) {
+        m_type = typeFromName();
+        return;
+    }
+
+    if (type.contains("VGA")) {
+        m_type = KScreen::Output::VGA;
+    } else if (type.contains("DVI")) {
+        m_type = KScreen::Output::DVI;
+    } else if (type.contains("DVI-I")) {
+        m_type = KScreen::Output::DVII;
+    } else if (type.contains("DVI-A")) {
+        m_type = KScreen::Output::DVIA;
+    } else if (type.contains("DVI-D")) {
+        m_type = KScreen::Output::DVID;
+    } else if (type.contains("HDMI")) {
+        m_type = KScreen::Output::HDMI;
+    } else if (type.contains("Panel")) {
+        m_type = KScreen::Output::Panel;
+    } else if (type.contains("TV")) {
+        m_type = KScreen::Output::TV;
+    } else if (type.contains("TV-Composite")) {
+        m_type = KScreen::Output::TVComposite;
+    } else if (type.contains("TV-SVideo")) {
+        m_type = KScreen::Output::TVSVideo;
+    } else if (type.contains("TV-Component")) {
+        m_type = KScreen::Output::TVComponent;
+    } else if (type.contains("TV-SCART")) {
+        m_type = KScreen::Output::TVSCART;
+    } else if (type.contains("TV-C4")) {
+        m_type = KScreen::Output::TVC4;
+    } else if (type.contains("DisplayPort")) {
+        m_type = KScreen::Output::DisplayPort;
+    } else if (type.contains("unknown")) {
+        m_type = KScreen::Output::Unknown;
+    } else {
+//         kDebug() << "Output Type not translated:" << type;
+    }
+
+}
+
+KScreen::Output::Type XRandROutput::typeFromName()
+{
+    QStringList embedded;
+    embedded << "LVDS";
+    embedded << "IDP";
+    embedded << "EDP";
+    embedded << "LCD";
+
+    Q_FOREACH(const QString &pre, embedded) {
+        if (m_name.toUpper().startsWith(pre)) {
+            return KScreen::Output::Panel;
+        }
+    }
+
+    return KScreen::Output::Unknown;
+}
+
+QByteArray XRandROutput::typeFromProperty() const
+{
+    QByteArray type;
+
+    Atom atomType = XInternAtom (XRandR::display(), RR_PROPERTY_CONNECTOR_TYPE, True);
+    if (atomType == None) {
+        return type;
+    }
+
+    char *result;
+    unsigned char *prop;
+    int actualFormat;
+    unsigned long nitems, bytes_after;
+    Atom actualType;
+    char *connectorType;
+
+    if (XRRGetOutputProperty (XRandR::display(), m_id, atomType, 0, 100, False,
+            False, AnyPropertyType, &actualType, &actualFormat, &nitems,
+            &bytes_after, &prop) != Success) {
+
+        return type;
+    }
+
+    if (!(actualType == XA_ATOM && actualFormat == 32 && nitems == 1)) {
+        return type;
+    }
+
+    connectorType = XGetAtomName (XRandR::display(), *((Atom *) prop));
+    if (!connectorType) {
+        return type;
+    }
+
+    type = connectorType;
+    XFree (connectorType);
+
+
+    return type;
+}
 
 KScreen::Output *XRandROutput::toKScreenOutput(KScreen::Config *parent) const
 {
diff --git a/backends/xrandr/xrandroutput.h b/backends/xrandr/xrandroutput.h
index 6969385..3c7cdab 100644
--- a/backends/xrandr/xrandroutput.h
+++ b/backends/xrandr/xrandroutput.h
@@ -90,10 +90,13 @@ public:
 private:
     void updateOutput(const XRROutputInfo *outputInfo);
     void updateModes(const XRROutputInfo *outputInfo);
+    void fetchType();
+    KScreen::Output::Type typeFromName();
+    QByteArray typeFromProperty() const;
 
     int m_id;
     QString m_name;
-    QString m_type;
+    KScreen::Output::Type m_type;
     QString m_icon;
     XRandRMode::Map m_modes;
     QPoint m_position;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic