Attached the patch that works with the current api, just in case somebody 
cares :p
diff --git a/backends/xrandr/xrandrmode.h b/backends/xrandr/xrandrmode.h
index 00eb041..e8056e4 100644
--- a/backends/xrandr/xrandrmode.h
+++ b/backends/xrandr/xrandrmode.h
@@ -37,6 +37,7 @@ class XRandRMode : public QObject
 {
     Q_OBJECT
 
+friend class XRandROutput;
 public:
     typedef QMap<int, XRandRMode*> Map;
 
diff --git a/backends/xrandr/xrandroutput.cpp b/backends/xrandr/xrandroutput.cpp
index 6656927..cf977f9 100644
--- a/backends/xrandr/xrandroutput.cpp
+++ b/backends/xrandr/xrandroutput.cpp
@@ -176,6 +176,7 @@ void XRandROutput::updateOutput(const XRROutputInfo *outputInfo)
         m_connected = isConnected;
         if (!m_connected) {
             m_preferredMode = 0;
+            m_preferredModes.clear();
             qDeleteAll(m_modes);
             m_modes.clear();
             delete m_edid;
@@ -206,11 +207,8 @@ void XRandROutput::updateModes(const XRROutputInfo *outputInfo)
             XRandRMode *mode = new XRandRMode(modeInfo, this);
             m_modes.insert(modeInfo->id, mode);
 
-            /* outputInfo->npreferred is the number of preferred modes,
-               Use the first one found if there is at least one preferred mode. */
-            if (!found && outputInfo->npreferred) {
-                m_preferredMode = modeInfo->id;
-                found = true;
+            if (i < outputInfo->npreferred) {
+                m_preferredModes.append(modeInfo->id);
             }
         }
     }
@@ -224,7 +222,7 @@ KScreen::Output *XRandROutput::toKScreenOutput(KScreen::Config *parent) const
 
     m_changedProperties = 0;
     kscreenOutput->setId(m_id);
-    kscreenOutput->setPreferredMode(m_preferredMode);
+    kscreenOutput->setPreferredMode(biggestPreferredMode());
     updateKScreenOutput(kscreenOutput);
 
     return kscreenOutput;
@@ -257,7 +255,7 @@ void XRandROutput::updateKScreenOutput(KScreen::Output *output) const
     }
 
     if (!m_changedProperties || (m_changedProperties & PropertyPreferredMode)) {
-        output->setPreferredMode(m_preferredMode);
+        output->setPreferredMode(biggestPreferredMode());
     }
 
     if (!m_changedProperties || (m_changedProperties & PropertyModes)) {
@@ -292,4 +290,36 @@ void XRandROutput::updateKScreenOutput(KScreen::Output *output) const
     }
 }
 
+int XRandROutput::biggestPreferredMode() const
+{
+    if (m_preferredModes.isEmpty()) {
+        return 0;
+    }
+
+    int area, total = 0;
+    XRandRMode *mode = 0;
+    XRandRMode *biggest = 0;
+    Q_FOREACH(RRMode modeId, m_preferredModes) {
+        mode = m_modes[modeId];
+        area = mode->m_size.width() * mode->m_size.height();
+        if (area < total) {
+            continue;
+        }
+        if (area == total && biggest && mode->m_refreshRate > biggest->m_refreshRate) {
+            biggest = mode;
+            continue;
+        }
+
+        total = area;
+        biggest = mode;
+    }
+
+    if (!biggest) {
+        qDebug() << "Biggest preferred not found";
+        return 0;
+    }
+
+    return biggest->m_id;
+}
+
 #include "xrandroutput.moc"
diff --git a/backends/xrandr/xrandroutput.h b/backends/xrandr/xrandroutput.h
index 749de83..3db4dc7 100644
--- a/backends/xrandr/xrandroutput.h
+++ b/backends/xrandr/xrandroutput.h
@@ -83,6 +83,7 @@ public:
 private:
     void updateOutput(const XRROutputInfo *outputInfo);
     void updateModes(const XRROutputInfo *outputInfo);
+    int biggestPreferredMode() const;
 
     int m_id;
     QString m_name;
@@ -92,6 +93,7 @@ private:
     QPoint m_position;
     KScreen::Output::Rotation m_rotation;
     int m_currentMode;
+    QList<RRMode> m_preferredModes;
     int m_preferredMode;
     int m_connected : 1;
     int m_enabled : 1;
_______________________________________________
Kde-hardware-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-hardware-devel

Reply via email to