messageTray: Use a GIcon for a notification's icon/secondary icon
Using a GIcon instead of an actor means that we can always create a new icon with the right size from an old icon. https://bugzilla.gnome.org/show_bug.cgi?id=680426
This commit is contained in:
parent
b7acb1d488
commit
928ea3bb01
@ -527,33 +527,32 @@ const ChatSource = new Lang.Class({
|
||||
},
|
||||
|
||||
createSecondaryIcon: function() {
|
||||
let iconBox = new St.Bin();
|
||||
iconBox.child = new St.Icon({ style_class: 'secondary-icon' });
|
||||
let iconName;
|
||||
let presenceType = this._contact.get_presence_type();
|
||||
|
||||
switch (presenceType) {
|
||||
case Tp.ConnectionPresenceType.AVAILABLE:
|
||||
iconBox.child.icon_name = 'user-available';
|
||||
iconName = 'user-available';
|
||||
break;
|
||||
case Tp.ConnectionPresenceType.BUSY:
|
||||
iconBox.child.icon_name = 'user-busy';
|
||||
iconName = 'user-busy';
|
||||
break;
|
||||
case Tp.ConnectionPresenceType.OFFLINE:
|
||||
iconBox.child.icon_name = 'user-offline';
|
||||
iconName = 'user-offline';
|
||||
break;
|
||||
case Tp.ConnectionPresenceType.HIDDEN:
|
||||
iconBox.child.icon_name = 'user-invisible';
|
||||
iconName = 'user-invisible';
|
||||
break;
|
||||
case Tp.ConnectionPresenceType.AWAY:
|
||||
iconBox.child.icon_name = 'user-away';
|
||||
iconName = 'user-away';
|
||||
break;
|
||||
case Tp.ConnectionPresenceType.EXTENDED_AWAY:
|
||||
iconBox.child.icon_name = 'user-idle';
|
||||
iconName = 'user-idle';
|
||||
break;
|
||||
default:
|
||||
iconBox.child.icon_name = 'user-offline';
|
||||
iconName = 'user-offline';
|
||||
}
|
||||
return iconBox;
|
||||
return new Gio.ThemedIcon({ name: iconName });
|
||||
},
|
||||
|
||||
_updateAvatarIcon: function() {
|
||||
@ -733,7 +732,7 @@ const ChatSource = new Lang.Class({
|
||||
|
||||
title = GLib.markup_escape_text(this.title, -1);
|
||||
|
||||
this._notification.update(this._notification.title, null, { customContent: true, secondaryIcon: this.createSecondaryIcon() });
|
||||
this._notification.update(this._notification.title, null, { customContent: true, secondaryGIcon: this.createSecondaryIcon() });
|
||||
|
||||
if (message)
|
||||
msg += ' <i>(' + GLib.markup_escape_text(message, -1) + ')</i>';
|
||||
@ -761,7 +760,7 @@ const ChatNotification = new Lang.Class({
|
||||
Extends: MessageTray.Notification,
|
||||
|
||||
_init: function(source) {
|
||||
this.parent(source, source.title, null, { customContent: true, secondaryIcon: source.createSecondaryIcon() });
|
||||
this.parent(source, source.title, null, { customContent: true, secondaryGIcon: source.createSecondaryIcon() });
|
||||
this.setResident(true);
|
||||
|
||||
this._responseEntry = new St.Entry({ style_class: 'chat-response',
|
||||
|
@ -35,8 +35,6 @@ const LONGER_SUMMARY_TIMEOUT = 4;
|
||||
const HIDE_TIMEOUT = 0.2;
|
||||
const LONGER_HIDE_TIMEOUT = 0.6;
|
||||
|
||||
const NOTIFICATION_ICON_SIZE = 24;
|
||||
|
||||
// We delay hiding of the tray if the mouse is within MOUSE_LEFT_ACTOR_THRESHOLD
|
||||
// range from the point where it left the tray.
|
||||
const MOUSE_LEFT_ACTOR_THRESHOLD = 20;
|
||||
@ -291,9 +289,12 @@ function makeCloseButton() {
|
||||
// If @params contains a 'body' parameter, then that text will be added to
|
||||
// the content area (as with addBody()).
|
||||
//
|
||||
// By default, the icon shown is created by calling
|
||||
// source.createIcon(). However, if @params contains an 'icon'
|
||||
// parameter, the passed in icon will be used.
|
||||
// By default, the icon shown is the same as the source's.
|
||||
// However, if @params contains a 'gicon' parameter, the passed in gicon
|
||||
// will be used.
|
||||
//
|
||||
// You can add a secondary icon to the banner with 'secondaryGIcon'. There
|
||||
// is no fallback for this icon.
|
||||
//
|
||||
// If @params contains a 'titleMarkup', 'bannerMarkup', or
|
||||
// 'bodyMarkup' parameter with the value %true, then the corresponding
|
||||
@ -308,6 +309,8 @@ function makeCloseButton() {
|
||||
const Notification = new Lang.Class({
|
||||
Name: 'Notification',
|
||||
|
||||
ICON_SIZE: 24,
|
||||
|
||||
IMAGE_SIZE: 125,
|
||||
|
||||
_init: function(source, title, banner, params) {
|
||||
@ -391,8 +394,8 @@ const Notification = new Lang.Class({
|
||||
update: function(title, banner, params) {
|
||||
params = Params.parse(params, { customContent: false,
|
||||
body: null,
|
||||
icon: null,
|
||||
secondaryIcon: null,
|
||||
gicon: null,
|
||||
secondaryGIcon: null,
|
||||
titleMarkup: false,
|
||||
bannerMarkup: false,
|
||||
bodyMarkup: false,
|
||||
@ -402,12 +405,12 @@ const Notification = new Lang.Class({
|
||||
|
||||
let oldFocus = global.stage.key_focus;
|
||||
|
||||
if (this._icon && (params.icon || params.clear)) {
|
||||
if (this._icon && (params.gicon || params.clear)) {
|
||||
this._icon.destroy();
|
||||
this._icon = null;
|
||||
}
|
||||
|
||||
if (this._secondaryIcon && (params.secondaryIcon || params.clear)) {
|
||||
if (this._secondaryIcon && (params.secondaryGIcon || params.clear)) {
|
||||
this._secondaryIcon.destroy();
|
||||
this._secondaryIcon = null;
|
||||
}
|
||||
@ -437,8 +440,14 @@ const Notification = new Lang.Class({
|
||||
if (!this._scrollArea && !this._actionArea && !this._imageBin)
|
||||
this._table.remove_style_class_name('multi-line-notification');
|
||||
|
||||
if (!this._icon) {
|
||||
this._icon = params.icon || this.source.createIcon(NOTIFICATION_ICON_SIZE);
|
||||
if (params.gicon) {
|
||||
this._icon = new St.Icon({ gicon: params.gicon,
|
||||
icon_size: this.ICON_SIZE });
|
||||
} else {
|
||||
this._icon = this.source.createIcon(this.ICON_SIZE);
|
||||
}
|
||||
|
||||
if (this._icon) {
|
||||
this._table.add(this._icon, { row: 0,
|
||||
col: 0,
|
||||
x_expand: false,
|
||||
@ -447,11 +456,10 @@ const Notification = new Lang.Class({
|
||||
y_align: St.Align.START });
|
||||
}
|
||||
|
||||
if (!this._secondaryIcon) {
|
||||
this._secondaryIcon = params.secondaryIcon;
|
||||
|
||||
if (this._secondaryIcon)
|
||||
this._bannerBox.add_actor(this._secondaryIcon);
|
||||
if (params.secondaryGIcon) {
|
||||
this._secondaryIcon = new St.Icon({ gicon: params.secondaryGIcon,
|
||||
style_class: 'secondary-icon' });
|
||||
this._bannerBox.add_actor(this._secondaryIcon);
|
||||
}
|
||||
|
||||
this.title = title;
|
||||
|
@ -356,12 +356,10 @@ const NotificationDaemon = new Lang.Class({
|
||||
ndata.actions, ndata.hints, ndata.notification];
|
||||
|
||||
let gicon = this._iconForNotificationData(icon, hints);
|
||||
let iconActor = new St.Icon({ gicon: gicon,
|
||||
icon_size: MessageTray.NOTIFICATION_ICON_SIZE });
|
||||
|
||||
if (notification == null) {
|
||||
notification = new MessageTray.Notification(source, summary, body,
|
||||
{ icon: iconActor,
|
||||
{ gicon: gicon,
|
||||
bannerMarkup: true });
|
||||
ndata.notification = notification;
|
||||
notification.connect('destroy', Lang.bind(this,
|
||||
@ -386,7 +384,7 @@ const NotificationDaemon = new Lang.Class({
|
||||
this._emitActionInvoked(ndata.id, actionId);
|
||||
}));
|
||||
} else {
|
||||
notification.update(summary, body, { icon: iconActor,
|
||||
notification.update(summary, body, { gicon: gicon,
|
||||
bannerMarkup: true,
|
||||
clear: true });
|
||||
}
|
||||
|
@ -1747,10 +1747,9 @@ const NMApplet = new Lang.Class({
|
||||
or this._source will be cleared */
|
||||
this._ensureSource();
|
||||
|
||||
let icon = new St.Icon({ icon_name: iconName,
|
||||
icon_size: MessageTray.NOTIFICATION_ICON_SIZE });
|
||||
let gicon = new Gio.ThemedIcon({ name: iconName });
|
||||
device._notification = new MessageTray.Notification(this._source, title, text,
|
||||
{ icon: icon });
|
||||
{ gicon: gicon });
|
||||
device._notification.setUrgency(urgency);
|
||||
device._notification.setTransient(true);
|
||||
device._notification.connect('destroy', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user