on xenial help sign in
Update Powerd plugin and Shell.qml to accommodate changes in the display power state notification.
7e2ea99Alberto Aguirre
plugins/Powerd/Powerd.cpp+16−16
@@ -19,35 +19,35 @@
19#include "Powerd.h"
19#include "Powerd.h"
20#include <QDBusPendingCall>
20#include <QDBusPendingCall>
21
21
22−void autoBrightnessChanged(GSettings *settings, const gchar *key, QDBusInterface *powerd)
22+void autoBrightnessChanged(GSettings *settings, const gchar *key, QDBusInterface *unityScreen)
23{
23{
24 bool value = g_settings_get_boolean(settings, key);
24 bool value = g_settings_get_boolean(settings, key);
25− powerd->asyncCall("userAutobrightnessEnable", QVariant(value));
25+ unityScreen->asyncCall("userAutobrightnessEnable", QVariant(value));
26}
26}
27
27
28Powerd::Powerd(QObject* parent)
28Powerd::Powerd(QObject* parent)
29 : QObject(parent),
29 : QObject(parent),
30− powerd(NULL)
30+ unityScreen(NULL)
31{
31{
32− powerd = new QDBusInterface("com.canonical.powerd",
32+ unityScreen = new QDBusInterface("com.canonical.Unity.Screen",
33− "/com/canonical/powerd",
33+ "/com/canonical/Unity/Screen",
34− "com.canonical.powerd",
34+ "com.canonical.Unity.Screen",
35− QDBusConnection::SM_BUSNAME(), this);
35+ QDBusConnection::SM_BUSNAME(), this);
36
36
37− powerd->connection().connect("com.canonical.powerd",
37+ unityScreen->connection().connect("com.canonical.Unity.Screen",
38− "/com/canonical/powerd",
38+ "/com/canonical/Unity/Screen",
39− "com.canonical.powerd",
39+ "com.canonical.Unity.Screen",
40− "DisplayPowerStateChange",
40+ "DisplayPowerStateChange",
41− this,
41+ this,
42− SIGNAL(displayPowerStateChange(int, unsigned int)));
42+ SIGNAL(displayPowerStateChange(int, int)));
43
43
44 systemSettings = g_settings_new("com.ubuntu.touch.system");
44 systemSettings = g_settings_new("com.ubuntu.touch.system");
45− g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), powerd);
45+ g_signal_connect(systemSettings, "changed::auto-brightness", G_CALLBACK(autoBrightnessChanged), unityScreen);
46− autoBrightnessChanged(systemSettings, "auto-brightness", powerd);
46+ autoBrightnessChanged(systemSettings, "auto-brightness", unityScreen);
47}
47}
48
48
49Powerd::~Powerd()
49Powerd::~Powerd()
50{
50{
51− g_signal_handlers_disconnect_by_data(systemSettings, powerd);
51+ g_signal_handlers_disconnect_by_data(systemSettings, unityScreen);
52 g_object_unref(systemSettings);
52 g_object_unref(systemSettings);
53}
53}
plugins/Powerd/Powerd.h+8−8
@@ -28,15 +28,15 @@ class Powerd: public QObject
28{
28{
29 Q_OBJECT
29 Q_OBJECT
30 Q_ENUMS(Status)
30 Q_ENUMS(Status)
31− Q_FLAGS(DisplayFlag DisplayFlags)
31+ Q_ENUMS(DisplayStateChangeReason)
32
32
33public:
33public:
34− enum DisplayFlag {
34+ enum DisplayStateChangeReason {
35− UseProximity = 1, // Use proximity sensor to override screen state
35+ Unknown = 0,
36− DisableAutoBrightness = 2, // Force autobrightness to be disabled
36+ Inactivity = 1, // Display changed state due to inactivity
37− Bright = 4, // Request the screen to stay bright
37+ PowerKey = 2, // Display changed state due to user pressing power key
38+ Proximity = 3, // Display changed state due to proximity events
38 };
39 };
39− Q_DECLARE_FLAGS(DisplayFlags, DisplayFlag)
40
40
41 enum Status {
41 enum Status {
42 Off,
42 Off,
@@ -47,10 +47,10 @@ public:
47 ~Powerd();
47 ~Powerd();
48
48
49Q_SIGNALS:
49Q_SIGNALS:
50− void displayPowerStateChange(int status, unsigned int flags);
50+ void displayPowerStateChange(int status, int reason);
51
51
52private:
52private:
53− QDBusInterface *powerd;
53+ QDBusInterface *unityScreen;
54 GSettings *systemSettings;
54 GSettings *systemSettings;
55};
55};
56
56
qml/Shell.qml+1−1
@@ -452,7 +452,7 @@ FocusScope {
452 onDisplayPowerStateChange: {
452 onDisplayPowerStateChange: {
453 // We ignore any display-off signals when the proximity sensor
453 // We ignore any display-off signals when the proximity sensor
454 // is active. This usually indicates something like a phone call.
454 // is active. This usually indicates something like a phone call.
455− if (status == Powerd.Off && (flags & Powerd.UseProximity) == 0) {
455+ if (status == Powerd.Off && reason != Powerd.Proximity) {
456 greeter.showNow();
456 greeter.showNow();
457 }
457 }
458
458
tests/mocks/Powerd/Powerd.h+7−7
@@ -25,15 +25,15 @@ class Powerd: public QObject
25{
25{
26 Q_OBJECT
26 Q_OBJECT
27 Q_ENUMS(Status)
27 Q_ENUMS(Status)
28− Q_FLAGS(DisplayFlag DisplayFlags)
28+ Q_ENUMS(DisplayStateChangeReason)
29
29
30public:
30public:
31− enum DisplayFlag {
31+ enum DisplayStateChangeReason {
32− UseProximity = 1, // Use proximity sensor to override screen state
32+ Unknown = 0,
33− DisableAutoBrightness = 2, // Force autobrightness to be disabled
33+ Inactivity = 1, // Display changed state due to inactivity
34− Bright = 4, // Request the screen to stay bright
34+ PowerKey = 2, // Display changed state due to user pressing power key
35+ Proximity = 3, // Display changed state due to proximity events
35 };
36 };
36− Q_DECLARE_FLAGS(DisplayFlags, DisplayFlag)
37
37
38 enum Status {
38 enum Status {
39 Off,
39 Off,
@@ -43,7 +43,7 @@ public:
43 explicit Powerd(QObject *parent = 0);
43 explicit Powerd(QObject *parent = 0);
44
44
45Q_SIGNALS:
45Q_SIGNALS:
46− void displayPowerStateChange(int status, unsigned int flags);
46+ void displayPowerStateChange(int status, int reason);
47};
47};
48
48
49#endif
49#endif
tests/qmltests/tst_Shell.qml+1−1
@@ -195,7 +195,7 @@ Item {
195 tryCompare(mainApp, "state", ApplicationInfo.Running);
195 tryCompare(mainApp, "state", ApplicationInfo.Running);
196
196
197 // Try to suspend while proximity is engaged...
197 // Try to suspend while proximity is engaged...
198− Powerd.displayPowerStateChange(Powerd.Off, Powerd.UseProximity);
198+ Powerd.displayPowerStateChange(Powerd.Off, Powerd.Proximity);
199 tryCompare(greeter, "showProgress", 0);
199 tryCompare(greeter, "showProgress", 0);
200
200
201 // Now really suspend
201 // Now really suspend