Skip to content

Commit

Permalink
[lipstick] Play notification vibra even if display stays off. Fixes J…
Browse files Browse the repository at this point in the history
…B#44343

"Display on" and "vibra feedback" hints both on turned the display on
but didn't play vibra. For consistency could be enough if that case
allowed vibra, but now just ignoring minimum priority level totally.
For what it's worth, Android notification docs talk only about sound
on their priorities.

Other feedback also allowed now if display is requested on.
  • Loading branch information
pvuorela committed Jan 3, 2019
1 parent 8f897ee commit d39dd2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/notifications/notificationfeedbackplayer.cpp
Expand Up @@ -50,8 +50,8 @@ void NotificationFeedbackPlayer::addNotification(uint id)
{
LipstickNotification *notification = NotificationManager::instance()->notification(id);

// feedback on notifications just directly omitted, not expecting practical use for playing feedback on every update
if (notification != 0 && isEnabled(notification) && !notification->hasProgress()) {
// feedback on progress update just directly omitted, not expecting practical use for playing feedback on every update
if (notification != 0 && !notification->hasProgress()) {
// Stop feedback previously generated by this notification, if current
QMultiHash<LipstickNotification *, uint>::iterator it = m_idToEventId.find(notification);
while (it != m_idToEventId.end() && it.key() == notification) {
Expand All @@ -62,7 +62,7 @@ void NotificationFeedbackPlayer::addNotification(uint id)
// Play the feedback related to the notification if any
const QString feedback = notification->hints().value(LipstickNotification::HINT_FEEDBACK).toString();
const QStringList feedbackItems = feedback.split(QStringLiteral(","), QString::SkipEmptyParts);
if (!feedbackItems.isEmpty()) {
if (isEnabled(notification, m_minimumPriority) && !feedbackItems.isEmpty()) {
QMap<QString, QVariant> properties;
if (notification->hints().value(LipstickNotification::HINT_LED_DISABLED_WITHOUT_BODY_AND_SUMMARY, true).toBool() &&
notification->body().isEmpty() &&
Expand All @@ -82,7 +82,9 @@ void NotificationFeedbackPlayer::addNotification(uint id)
m_idToEventId.insert(notification, m_ngfClient->play(item, properties));
}
}
if (notification->hints().value(LipstickNotification::HINT_VIBRA, false).toBool()) {

// vibra played if it's asked regardless of priorities
if (isEnabled(notification, 0) && notification->hints().value(LipstickNotification::HINT_VIBRA, false).toBool()) {
m_ngfClient->stop("vibra");
m_idToEventId.insert(notification, m_ngfClient->play("vibra", QMap<QString, QVariant>()));
}
Expand All @@ -103,7 +105,7 @@ void NotificationFeedbackPlayer::removeNotification(uint id)
}
}

bool NotificationFeedbackPlayer::isEnabled(LipstickNotification *notification)
bool NotificationFeedbackPlayer::isEnabled(LipstickNotification *notification, int minimumPriority)
{
if (notification->hidden() || notification->restored())
return false;
Expand All @@ -118,10 +120,10 @@ bool NotificationFeedbackPlayer::isEnabled(LipstickNotification *notification)
int priority = notification->priority();
int notificationIsCritical = urgency >= 2 || notification->hints().value(LipstickNotification::HINT_DISPLAY_ON).toBool();

return !(urgency < 2 && priority < m_minimumPriority) &&
(mode == AllNotificationsEnabled ||
(mode == ApplicationNotificationsDisabled && notificationIsCritical) ||
(mode == SystemNotificationsDisabled && urgency < 2));
return (priority >= minimumPriority || notificationIsCritical)
&& (mode == AllNotificationsEnabled
|| (mode == ApplicationNotificationsDisabled && notificationIsCritical)
|| (mode == SystemNotificationsDisabled && urgency < 2));
}

int NotificationFeedbackPlayer::minimumPriority() const
Expand Down
2 changes: 1 addition & 1 deletion src/notifications/notificationfeedbackplayer.h
Expand Up @@ -76,7 +76,7 @@ private slots:

private:
//! Check whether feedbacks should be enabled for the given notification
bool isEnabled(LipstickNotification *notification);
bool isEnabled(LipstickNotification *notification, int minimumPriority);

//! Non-graphical feedback player
Ngf::Client *m_ngfClient;
Expand Down

0 comments on commit d39dd2a

Please sign in to comment.