messageTray: Use NotificationBanner in banner mode

Instead of using the notification's own actor as a banner (and
keeping it around after the banner was displayed to not dismiss
the notification itself), create a separate banner actor from
the information the notification provides, just like we do for
lock screen and message list notifications.
This change breaks notifications with custom content, but only
temporarily - we will soon provide a hook to allow customizations
again.
This commit is contained in:
Florian Müllner 2015-02-17 03:13:56 +01:00
parent 8ecf901dd4
commit 815eaa1d4d

View File

@ -1496,7 +1496,8 @@ const MessageTray = new Lang.Class({
this._notificationFocusGrabber = new FocusGrabber(this.actor); this._notificationFocusGrabber = new FocusGrabber(this.actor);
this._notificationQueue = []; this._notificationQueue = [];
this._notification = null; this._notification = null;
this._notificationClickedId = 0; this._banner = null;
this._bannerClickedId = 0;
this._closeButton = Util.makeCloseButton(); this._closeButton = Util.makeCloseButton();
this._closeButton.hide(); this._closeButton.hide();
@ -1522,7 +1523,6 @@ const MessageTray = new Lang.Class({
this._notificationState = State.HIDDEN; this._notificationState = State.HIDDEN;
this._notificationTimeoutId = 0; this._notificationTimeoutId = 0;
this._notificationExpandedId = 0;
this._notificationRemoved = false; this._notificationRemoved = false;
this.clearableCount = 0; this.clearableCount = 0;
@ -1825,17 +1825,17 @@ const MessageTray = new Lang.Class({
let expired = (this._userActiveWhileNotificationShown && let expired = (this._userActiveWhileNotificationShown &&
this._notificationTimeoutId == 0 && this._notificationTimeoutId == 0 &&
this._notification.urgency != Urgency.CRITICAL && this._notification.urgency != Urgency.CRITICAL &&
!this._notification.focused && !this._banner.focused &&
!this._pointerInNotification) || this._notificationExpired; !this._pointerInNotification) || this._notificationExpired;
let mustClose = (this._notificationRemoved || !hasNotifications || expired); let mustClose = (this._notificationRemoved || !hasNotifications || expired);
if (mustClose) { if (mustClose) {
let animate = hasNotifications && !this._notificationRemoved; let animate = hasNotifications && !this._notificationRemoved;
this._hideNotification(animate); this._hideNotification(animate);
} else if (this._pointerInNotification && !this._notification.expanded) { } else if (this._pointerInNotification && !this._banner.expanded) {
this._expandNotification(false); this._expandBanner(false);
} else if (this._pointerInNotification) { } else if (this._pointerInNotification) {
this._ensureNotificationFocused(); this._ensureBannerFocused();
} }
} }
@ -1890,15 +1890,17 @@ const MessageTray = new Lang.Class({
this.idleMonitor.add_user_active_watch(Lang.bind(this, this._onIdleMonitorBecameActive)); this.idleMonitor.add_user_active_watch(Lang.bind(this, this._onIdleMonitorBecameActive));
} }
this._notificationClickedId = this._notification.connect('done-displaying', this._banner = new NotificationBanner(this._notification);
Lang.bind(this, this._escapeTray)); this._bannerClickedId = this._banner.connect('done-displaying',
this._notificationUnfocusedId = this._notification.connect('unfocused', Lang.bind(this, function() { Lang.bind(this, this._escapeTray));
this._bannerUnfocusedId = this._banner.connect('unfocused', Lang.bind(this, function() {
this._updateState(); this._updateState();
})); }));
this.actor.add_actor(this._notification.actor);
this.actor.add_actor(this._banner.actor);
this.actor.opacity = 0; this.actor.opacity = 0;
this.actor.y = -this._notification.actor.height; this.actor.y = -this._banner.actor.height;
this.actor.show(); this.actor.show();
this._updateShowingNotification(); this._updateShowingNotification();
@ -1928,7 +1930,7 @@ const MessageTray = new Lang.Class({
// is on in the control center. // is on in the control center.
if (this._notification.urgency == Urgency.CRITICAL || if (this._notification.urgency == Urgency.CRITICAL ||
this._notification.source.policy.forceExpanded) this._notification.source.policy.forceExpanded)
this._expandNotification(true); this._expandBanner(true);
// We tween all notifications to full opacity. This ensures that both new notifications and // We tween all notifications to full opacity. This ensures that both new notifications and
// notifications that might have been in the process of hiding get full opacity. // notifications that might have been in the process of hiding get full opacity.
@ -1999,17 +2001,13 @@ const MessageTray = new Lang.Class({
_hideNotification: function(animate) { _hideNotification: function(animate) {
this._notificationFocusGrabber.ungrabFocus(); this._notificationFocusGrabber.ungrabFocus();
if (this._notificationExpandedId) { if (this._bannerClickedId) {
this._notification.disconnect(this._notificationExpandedId); this._banner.disconnect(this._bannerClickedId);
this._notificationExpandedId = 0; this._bannerClickedId = 0;
} }
if (this._notificationClickedId) { if (this._bannerUnfocusedId) {
this._notification.disconnect(this._notificationClickedId); this._banner.disconnect(this._bannerUnfocusedId);
this._notificationClickedId = 0; this._bannerUnfocusedId = 0;
}
if (this._notificationUnfocusedId) {
this._notification.disconnect(this._notificationUnfocusedId);
this._notificationUnfocusedId = 0;
} }
this._resetNotificationLeftTimeout(); this._resetNotificationLeftTimeout();
@ -2035,8 +2033,6 @@ const MessageTray = new Lang.Class({
}, },
_hideNotificationCompleted: function() { _hideNotificationCompleted: function() {
this._notification.collapseCompleted();
let notification = this._notification; let notification = this._notification;
this._notification = null; this._notification = null;
if (notification.isTransient) if (notification.isTransient)
@ -2045,27 +2041,32 @@ const MessageTray = new Lang.Class({
this._closeButton.hide(); this._closeButton.hide();
this._pointerInNotification = false; this._pointerInNotification = false;
this._notificationRemoved = false; this._notificationRemoved = false;
this.actor.remove_actor(notification.actor);
if (notification.resident)
this.actor.remove_actor(this._banner.actor);
else
this._banner.actor.destroy();
this._banner = null;
this.actor.hide(); this.actor.hide();
}, },
_expandActiveNotification: function() { _expandActiveNotification: function() {
if (!this._notification) if (!this._banner)
return; return;
this._expandNotification(false); this._expandBanner(false);
}, },
_expandNotification: function(autoExpanding) { _expandBanner: function(autoExpanding) {
// Don't animate changes in notifications that are auto-expanding. // Don't animate changes in notifications that are auto-expanding.
this._notification.expand(!autoExpanding); this._banner.expand(!autoExpanding);
// Don't focus notifications that are auto-expanding. // Don't focus notifications that are auto-expanding.
if (!autoExpanding) if (!autoExpanding)
this._ensureNotificationFocused(); this._ensureBannerFocused();
}, },
_ensureNotificationFocused: function() { _ensureBannerFocused: function() {
this._notificationFocusGrabber.grabFocus(); this._notificationFocusGrabber.grabFocus();
} }
}); });