Blob Blame History Raw
diff --git a/powerdevil/daemon/backends/upower/powerdevilupowerbackend.cpp b/powerdevil/daemon/backends/upower/powerdevilupowerbackend.cpp
index cc20dc7..297b020 100644
--- a/powerdevil/daemon/backends/upower/powerdevilupowerbackend.cpp
+++ b/powerdevil/daemon/backends/upower/powerdevilupowerbackend.cpp
@@ -75,7 +75,7 @@ bool checkSystemdVersion(uint requiredVersion)
 
 PowerDevilUPowerBackend::PowerDevilUPowerBackend(QObject* parent)
     : BackendInterface(parent),
-      m_brightnessControl(0), m_kbdMaxBrightness(0),
+      m_displayDevice(0), m_brightnessControl(0), m_kbdMaxBrightness(0),
       m_lidIsPresent(false), m_lidIsClosed(false), m_onBattery(false)
 {
 
@@ -451,6 +451,14 @@ void PowerDevilUPowerBackend::enumerateDevices()
         m_devices.insert(device.path(), upowerDevice);
     }
 
+    QDBusReply<QDBusObjectPath> reply = m_upowerInterface->call("GetDisplayDevice");
+    if (reply.isValid()) {
+        const QString path = reply.value().path();
+        if (!path.isEmpty() && path != QLatin1String("/")) {
+            m_displayDevice = new OrgFreedesktopUPowerDeviceInterface(UPOWER_SERVICE, path, QDBusConnection::systemBus(), this);
+        }
+    }
+
     updateDeviceProps();
 
     if (m_onBattery)
@@ -500,14 +508,22 @@ void PowerDevilUPowerBackend::updateDeviceProps()
 {
     qlonglong remainingTime = 0;
 
-    foreach(OrgFreedesktopUPowerDeviceInterface * upowerDevice, m_devices) {
-        const uint type = upowerDevice->type();
-        if (( type == 2 || type == 3) && upowerDevice->powerSupply()) {
-            const uint state = upowerDevice->state();
-            if (state == 1) // charging
-                remainingTime += upowerDevice->timeToFull();
-            else if (state == 2) //discharging
-                remainingTime += upowerDevice->timeToEmpty();
+    if (m_displayDevice && m_displayDevice->isPresent()) {
+        const uint state = m_displayDevice->state();
+        if (state == 1) // charging
+            remainingTime = m_displayDevice->timeToFull();
+        else if (state == 2) //discharging
+            remainingTime = m_displayDevice->timeToEmpty();
+    } else {
+        foreach(OrgFreedesktopUPowerDeviceInterface * upowerDevice, m_devices) {
+            const uint type = upowerDevice->type();
+            if (( type == 2 || type == 3) && upowerDevice->powerSupply()) {
+                const uint state = upowerDevice->state();
+                if (state == 1) // charging
+                    remainingTime += upowerDevice->timeToFull();
+                else if (state == 2) //discharging
+                    remainingTime += upowerDevice->timeToEmpty();
+            }
         }
     }
 
diff --git a/powerdevil/daemon/backends/upower/powerdevilupowerbackend.h b/powerdevil/daemon/backends/upower/powerdevilupowerbackend.h
index c6563b0..14f4c5e 100644
--- a/powerdevil/daemon/backends/upower/powerdevilupowerbackend.h
+++ b/powerdevil/daemon/backends/upower/powerdevilupowerbackend.h
@@ -84,6 +84,7 @@ private slots:
 private:
     // upower devices
     QMap<QString, OrgFreedesktopUPowerDeviceInterface *> m_devices;
+    OrgFreedesktopUPowerDeviceInterface *m_displayDevice;
 
     // brightness
     QMap<BrightnessControlType, float> m_cachedBrightnessMap;