on xenial help sign in
Listen to display-power-changed rather than system-power-changed signals when showing the greeter; ignore such signals when the proximity sensor is active. Fixes: https://bugs.launchpad.net/bugs/1214477.
09b6c6dMichael Terry
Shell.qml+5−3
@@ -497,11 +497,13 @@ FocusScope {
497 }
497 }
498 }
498 }
499
499
500− onPowerStateChange: {
500+ onDisplayPowerStateChange: {
501− if (state == 0) { // suspend
501+ // We ignore any display-off signals when the proximity sensor
502+ // is active. This usually indicates something like a phone call.
503+ if (status == Powerd.Off && (flags & Powerd.UseProximity) == 0) {
502 powerConnection.setFocused(false);
504 powerConnection.setFocused(false);
503 greeter.show();
505 greeter.show();
504− } else if (state == 1) { // active
506+ } else if (status == Powerd.On) {
505 powerConnection.setFocused(true);
507 powerConnection.setFocused(true);
506 }
508 }
507 }
509 }
plugins/Powerd/Powerd.cpp+2−2
@@ -30,7 +30,7 @@ Powerd::Powerd(QObject* parent)
30 powerd->connection().connect("com.canonical.powerd",
30 powerd->connection().connect("com.canonical.powerd",
31 "/com/canonical/powerd",
31 "/com/canonical/powerd",
32 "com.canonical.powerd",
32 "com.canonical.powerd",
33− "SysPowerStateChange",
33+ "DisplayPowerStateChange",
34 this,
34 this,
35− SIGNAL(powerStateChange(int)));
35+ SIGNAL(displayPowerStateChange(int, unsigned int)));
36}
36}
plugins/Powerd/Powerd.h+15−1
@@ -26,12 +26,26 @@
26class Powerd: public QObject
26class Powerd: public QObject
27{
27{
28 Q_OBJECT
28 Q_OBJECT
29+ Q_ENUMS(Status)
30+ Q_FLAGS(DisplayFlag DisplayFlags)
29
31
30public:
32public:
33+ enum DisplayFlag {
34+ UseProximity = 1, // Use proximity sensor to override screen state
35+ DisableAutoBrightness = 2, // Force autobrightness to be disabled
36+ Bright = 4, // Request the screen to stay bright
37+ };
38+ Q_DECLARE_FLAGS(DisplayFlags, DisplayFlag)
39+
40+ enum Status {
41+ Off,
42+ On,
43+ };
44+
31 explicit Powerd(QObject *parent = 0);
45 explicit Powerd(QObject *parent = 0);
32
46
33Q_SIGNALS:
47Q_SIGNALS:
34− void powerStateChange(int state);
48+ void displayPowerStateChange(int status, unsigned int flags);
35
49
36private:
50private:
37 QDBusInterface *powerd;
51 QDBusInterface *powerd;
tests/mocks/Powerd/Powerd.h+15−2
@@ -20,17 +20,30 @@
20#define UNITY_MOCK_POWERD_H
20#define UNITY_MOCK_POWERD_H
21
21
22#include <QtCore/QObject>
22#include <QtCore/QObject>
23−#include <QtDBus/QDBusInterface>
24
23
25class Powerd: public QObject
24class Powerd: public QObject
26{
25{
27 Q_OBJECT
26 Q_OBJECT
27+ Q_ENUMS(Status)
28+ Q_FLAGS(DisplayFlag DisplayFlags)
28
29
29public:
30public:
31+ enum DisplayFlag {
32+ UseProximity = 1, // Use proximity sensor to override screen state
33+ DisableAutoBrightness = 2, // Force autobrightness to be disabled
34+ Bright = 4, // Request the screen to stay bright
35+ };
36+ Q_DECLARE_FLAGS(DisplayFlags, DisplayFlag)
37+
38+ enum Status {
39+ Off,
40+ On,
41+ };
42+
30 explicit Powerd(QObject *parent = 0);
43 explicit Powerd(QObject *parent = 0);
31
44
32Q_SIGNALS:
45Q_SIGNALS:
33− void powerStateChange(int state);
46+ void displayPowerStateChange(int status, unsigned int flags);
34};
47};
35
48
36#endif
49#endif
tests/qmltests/tst_Shell.qml+7−3
@@ -125,13 +125,17 @@ Item {
125 var mainApp = ApplicationManager.mainStageFocusedApplication;
125 var mainApp = ApplicationManager.mainStageFocusedApplication;
126 tryCompareFunction(function() { return mainApp != null; }, true);
126 tryCompareFunction(function() { return mainApp != null; }, true);
127
127
128+ // Try to suspend while proximity is engaged...
129+ Powerd.displayPowerStateChange(Powerd.Off, Powerd.UseProximity);
130+ tryCompare(greeter, "showProgress", 0);
131+
128− // Now suspend
132+ // Now really suspend
129− Powerd.powerStateChange(0);
133+ Powerd.displayPowerStateChange(Powerd.Off, 0);
130 tryCompare(greeter, "showProgress", 1);
134 tryCompare(greeter, "showProgress", 1);
131 tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
135 tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
132
136
133 // And wake up
137 // And wake up
134− Powerd.powerStateChange(1);
138+ Powerd.displayPowerStateChange(Powerd.On, 0);
135 tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
139 tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
136 tryCompare(greeter, "showProgress", 1);
140 tryCompare(greeter, "showProgress", 1);
137 }
141 }