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.

Approved by Michał Sawicz, PS Jenkins bot.

commit09b6c6de50f7fb2eb9e5dcb98412e3a2ffd3a9dc authorMichael Terry <michael.terry@canonical.com> dateWed 21 Aug 2013, 20:53 (13 years ago) parentdde0fa04f68d70
5 files changed+44−11
Shell.qml+5−3 plugins/Powerd/Powerd.cpp+2−2 plugins/Powerd/Powerd.h+15−1 tests/mocks/Powerd/Powerd.h+15−2 tests/qmltests/tst_Shell.qml+7−3
Shell.qml+5−3
@@ -497,11 +497,13 @@ FocusScope {
497497 }
498498 }
499499
500− onPowerStateChange: {
501− if (state == 0) { // suspend
500+ onDisplayPowerStateChange: {
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) {
502504 powerConnection.setFocused(false);
503505 greeter.show();
504− } else if (state == 1) { // active
506+ } else if (status == Powerd.On) {
505507 powerConnection.setFocused(true);
506508 }
507509 }
plugins/Powerd/Powerd.cpp+2−2
@@ -30,7 +30,7 @@ Powerd::Powerd(QObject* parent)
3030 powerd->connection().connect("com.canonical.powerd",
3131 "/com/canonical/powerd",
3232 "com.canonical.powerd",
33− "SysPowerStateChange",
33+ "DisplayPowerStateChange",
3434 this,
35− SIGNAL(powerStateChange(int)));
35+ SIGNAL(displayPowerStateChange(int, unsigned int)));
3636}
plugins/Powerd/Powerd.h+15−1
@@ -26,12 +26,26 @@
2626class Powerd: public QObject
2727{
2828 Q_OBJECT
29+ Q_ENUMS(Status)
30+ Q_FLAGS(DisplayFlag DisplayFlags)
2931
3032public:
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+
3145 explicit Powerd(QObject *parent = 0);
3246
3347Q_SIGNALS:
34− void powerStateChange(int state);
48+ void displayPowerStateChange(int status, unsigned int flags);
3549
3650private:
3751 QDBusInterface *powerd;
tests/mocks/Powerd/Powerd.h+15−2
@@ -20,17 +20,30 @@
2020#define UNITY_MOCK_POWERD_H
2121
2222#include <QtCore/QObject>
23−#include <QtDBus/QDBusInterface>
2423
2524class Powerd: public QObject
2625{
2726 Q_OBJECT
27+ Q_ENUMS(Status)
28+ Q_FLAGS(DisplayFlag DisplayFlags)
2829
2930public:
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+
3043 explicit Powerd(QObject *parent = 0);
3144
3245Q_SIGNALS:
33− void powerStateChange(int state);
46+ void displayPowerStateChange(int status, unsigned int flags);
3447};
3548
3649#endif
tests/qmltests/tst_Shell.qml+7−3
@@ -125,13 +125,17 @@ Item {
125125 var mainApp = ApplicationManager.mainStageFocusedApplication;
126126 tryCompareFunction(function() { return mainApp != null; }, true);
127127
128− // Now suspend
129− Powerd.powerStateChange(0);
128+ // Try to suspend while proximity is engaged...
129+ Powerd.displayPowerStateChange(Powerd.Off, Powerd.UseProximity);
130+ tryCompare(greeter, "showProgress", 0);
131+
132+ // Now really suspend
133+ Powerd.displayPowerStateChange(Powerd.Off, 0);
130134 tryCompare(greeter, "showProgress", 1);
131135 tryCompare(ApplicationManager, "mainStageFocusedApplication", null);
132136
133137 // And wake up
134− Powerd.powerStateChange(1);
138+ Powerd.displayPowerStateChange(Powerd.On, 0);
135139 tryCompare(ApplicationManager, "mainStageFocusedApplication", mainApp);
136140 tryCompare(greeter, "showProgress", 1);
137141 }