on xenial help sign in
Unify turn-on-screen-upon-notification logic from various daemons into unity8.

Logically, a daemon like telephony-service is just emitting a notification. The presentation of that notification is up to a higher layer (maybe we're on a raspberry pi2 and we present notifications as LED morse code or whatever). It just makes sense that unity8, which is drawing the notification, is the one that knows that the screen needs to be on. It also knows what form factor we are in (I assume we only want to turn screen on for phones/tablets, not desktops). This will also make fixing issues like bug 1426115 easier to fix in the future. Over time, we can drop the setScreenPowerMode calls in other daemons. There is no need to version our dependency on USC for the addition of the Notification reason. It will treat unrecognized reasons as the default reason. Fixes: #1482317 Approved by: Michael Zanetti

commitf2e067adaf20154cd2baecc051b398850c951a88 authorMichael Terry <michael.terry@canonical.com> dateMon 31 Aug 2015, 10:24 (11 years ago) parenta566a03dbe8d46
3 files changed+21−1
plugins/Powerd/Powerd.cpp+7 plugins/Powerd/Powerd.h+4 qml/Notifications/Notification.qml+10−1
plugins/Powerd/Powerd.cpp+7
@@ -74,6 +74,13 @@ Powerd::Status Powerd::status() const
7474 return cachedStatus;
7575}
7676
77+void Powerd::setStatus(Powerd::Status status, DisplayStateChangeReason reason)
78+{
79+ unityScreen->asyncCall("setScreenPowerMode",
80+ status == Powerd::On ? "on" : "off",
81+ static_cast<qint32>(reason));
82+}
83+
7784void Powerd::handleDisplayPowerStateChange(int status, int reason)
7885{
7986 if (cachedStatus != (Status)status) {
plugins/Powerd/Powerd.h+4
@@ -37,6 +37,7 @@ public:
3737 Inactivity = 1, // Display changed state due to inactivity
3838 PowerKey = 2, // Display changed state due to user pressing power key
3939 Proximity = 3, // Display changed state due to proximity events
40+ Notification = 4, // Display changed state due to user notification
4041 };
4142
4243 enum Status {
@@ -49,6 +50,9 @@ public:
4950
5051 Status status() const;
5152
53+ // Not exposed via Q_PROPERTY because we need the 'reason' argument too
54+ Q_INVOKABLE void setStatus(Status status, DisplayStateChangeReason reason);
55+
5256Q_SIGNALS:
5357 void statusChanged(DisplayStateChangeReason reason);
5458
qml/Notifications/Notification.qml+10−1
@@ -16,6 +16,7 @@
1616
1717import QtQuick 2.0
1818import QtMultimedia 5.0
19+import Powerd 0.1
1920import Ubuntu.Components 1.1
2021import Unity.Notifications 1.0
2122import QMenuModel 0.1
@@ -84,8 +85,16 @@ Item {
8485 source: hints["suppress-sound"] !== "true" && hints["sound-file"] !== undefined ? hints["sound-file"] : ""
8586 }
8687
87− // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
8888 Component.onCompleted: {
89+ // Turn on screen as needed (Powerd.Notification means the screen
90+ // stays on for a shorter amount of time)
91+ if (type == Notification.SnapDecision) {
92+ Powerd.setStatus(Powerd.On, Powerd.Unknown);
93+ } else if (type != Notification.Confirmation) {
94+ Powerd.setStatus(Powerd.On, Powerd.Notification);
95+ }
96+
97+ // FIXME: using onCompleted because of LP: #1354406 workaround, has to be onOpacityChanged really
8998 if (opacity == 1.0 && hints["suppress-sound"] !== "true" && sound.source !== "") {
9099 sound.play();
91100 }