messageTray: Hook SourceActor up to source icon changes automatically
Instead of manually tracking source icon changes, or requiring a manual call to _setSummaryIcon, add a way to emit a signal when we're guaranteed the icon has been changed, and then the source actor will automatically update the icon. _setSummaryIcon is still available for sources such as the notification daemon, that require special treatment for the summary icon (to be used with tray icons) https://bugzilla.gnome.org/show_bug.cgi?id=680426
This commit is contained in:
parent
0171e561f2
commit
5cb9aa9cf3
@ -1039,6 +1039,7 @@ const SourceActor = new Lang.Class({
|
|||||||
|
|
||||||
_init: function(source, size) {
|
_init: function(source, size) {
|
||||||
this._source = source;
|
this._source = source;
|
||||||
|
this._size = size;
|
||||||
|
|
||||||
this.actor = new Shell.GenericContainer();
|
this.actor = new Shell.GenericContainer();
|
||||||
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
||||||
@ -1064,10 +1065,14 @@ const SourceActor = new Lang.Class({
|
|||||||
|
|
||||||
this._source.connect('count-changed', Lang.bind(this, this._updateCount));
|
this._source.connect('count-changed', Lang.bind(this, this._updateCount));
|
||||||
this._updateCount();
|
this._updateCount();
|
||||||
|
|
||||||
|
this._source.connect('icon-updated', Lang.bind(this, this._updateIcon));
|
||||||
|
this._updateIcon();
|
||||||
},
|
},
|
||||||
|
|
||||||
setIcon: function(icon) {
|
setIcon: function(icon) {
|
||||||
this._iconBin.child = icon;
|
this._iconBin.child = icon;
|
||||||
|
this._iconSet = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
_getPreferredWidth: function (actor, forHeight, alloc) {
|
_getPreferredWidth: function (actor, forHeight, alloc) {
|
||||||
@ -1105,13 +1110,21 @@ const SourceActor = new Lang.Class({
|
|||||||
this._counterBin.allocate(childBox, flags);
|
this._counterBin.allocate(childBox, flags);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_updateIcon: function() {
|
||||||
|
if (this._actorDestroyed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!this._iconSet)
|
||||||
|
this._iconBin.child = this._source.createIcon(this._size);
|
||||||
|
},
|
||||||
|
|
||||||
_updateCount: function() {
|
_updateCount: function() {
|
||||||
if (this._actorDestroyed)
|
if (this._actorDestroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this._counterBin.visible = this._source.countVisible;
|
this._counterBin.visible = this._source.countVisible;
|
||||||
this._counterLabel.set_text(this._source.count.toString());
|
this._counterLabel.set_text(this._source.count.toString());
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const Source = new Lang.Class({
|
const Source = new Lang.Class({
|
||||||
@ -1133,7 +1146,6 @@ const Source = new Lang.Class({
|
|||||||
this.notifications = [];
|
this.notifications = [];
|
||||||
|
|
||||||
this.mainIcon = new SourceActor(this, this.ICON_SIZE);
|
this.mainIcon = new SourceActor(this, this.ICON_SIZE);
|
||||||
this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_setCount: function(count, visible) {
|
_setCount: function(count, visible) {
|
||||||
@ -1222,9 +1234,14 @@ const Source = new Lang.Class({
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
iconUpdated: function() {
|
||||||
|
this.emit('icon-updated');
|
||||||
|
},
|
||||||
|
|
||||||
//// Protected methods ////
|
//// Protected methods ////
|
||||||
_setSummaryIcon: function(icon) {
|
_setSummaryIcon: function(icon) {
|
||||||
this.mainIcon.setIcon(icon);
|
this.mainIcon.setIcon(icon);
|
||||||
|
this.iconUpdated();
|
||||||
},
|
},
|
||||||
|
|
||||||
open: function(notification) {
|
open: function(notification) {
|
||||||
|
@ -557,7 +557,8 @@ const Source = new Lang.Class({
|
|||||||
processNotification: function(notification, gicon) {
|
processNotification: function(notification, gicon) {
|
||||||
if (gicon)
|
if (gicon)
|
||||||
this._gicon = gicon;
|
this._gicon = gicon;
|
||||||
this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
|
if (!this.trayIcon)
|
||||||
|
this.iconUpdated();
|
||||||
|
|
||||||
let tracker = Shell.WindowTracker.get_default();
|
let tracker = Shell.WindowTracker.get_default();
|
||||||
if (notification.resident && this.app && tracker.focus_app == this.app)
|
if (notification.resident && this.app && tracker.focus_app == this.app)
|
||||||
@ -625,7 +626,7 @@ const Source = new Lang.Class({
|
|||||||
// notification-based icons (ie, not a trayicon) or if it was unset before
|
// notification-based icons (ie, not a trayicon) or if it was unset before
|
||||||
if (!this.trayIcon) {
|
if (!this.trayIcon) {
|
||||||
this.useNotificationIcon = false;
|
this.useNotificationIcon = false;
|
||||||
this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
|
this.iconUpdated();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -134,9 +134,7 @@ const NotificationsBox = new Lang.Class({
|
|||||||
_makeNotificationSource: function(source) {
|
_makeNotificationSource: function(source) {
|
||||||
let box = new St.BoxLayout({ style_class: 'screen-shield-notification-source' });
|
let box = new St.BoxLayout({ style_class: 'screen-shield-notification-source' });
|
||||||
|
|
||||||
let iconClone = source.createIcon(SUMMARY_ICON_SIZE);
|
|
||||||
let sourceActor = new MessageTray.SourceActor(source, SUMMARY_ICON_SIZE);
|
let sourceActor = new MessageTray.SourceActor(source, SUMMARY_ICON_SIZE);
|
||||||
sourceActor.setIcon(iconClone);
|
|
||||||
box.add(sourceActor.actor, { y_fill: true });
|
box.add(sourceActor.actor, { y_fill: true });
|
||||||
|
|
||||||
let textBox = new St.BoxLayout({ vertical: true });
|
let textBox = new St.BoxLayout({ vertical: true });
|
||||||
|
@ -532,7 +532,7 @@ const ChatSource = new Lang.Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateAvatarIcon: function() {
|
_updateAvatarIcon: function() {
|
||||||
this._setSummaryIcon(this.createIcon(this.ICON_SIZE));
|
this.iconUpdated();
|
||||||
this._notification.update(this._notification.title, null, { customContent: true });
|
this._notification.update(this._notification.title, null, { customContent: true });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user