2010-01-13 15:05:20 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
2010-11-23 18:27:47 -05:00
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const Gio = imports.gi.Gio;
|
2010-02-22 14:23:36 -05:00
|
|
|
const Gtk = imports.gi.Gtk;
|
2010-01-13 15:05:20 -05:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const Mainloop = imports.mainloop;
|
2010-09-09 16:18:07 -04:00
|
|
|
const Meta = imports.gi.Meta;
|
2010-02-01 12:10:38 -05:00
|
|
|
const Pango = imports.gi.Pango;
|
2010-01-28 12:04:26 -05:00
|
|
|
const Shell = imports.gi.Shell;
|
2010-01-13 15:05:20 -05:00
|
|
|
const Signals = imports.signals;
|
2010-01-28 12:04:26 -05:00
|
|
|
const St = imports.gi.St;
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-10-19 15:17:36 -04:00
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2011-02-19 10:49:56 -05:00
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
|
|
|
const Main = imports.ui.main;
|
2011-02-11 14:43:01 -05:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2010-08-18 16:01:33 -04:00
|
|
|
const Params = imports.misc.params;
|
2011-02-19 10:49:56 -05:00
|
|
|
const Tweener = imports.ui.tweener;
|
2010-11-30 11:16:10 -05:00
|
|
|
const Util = imports.misc.util;
|
2010-01-13 15:05:20 -05:00
|
|
|
|
|
|
|
const ANIMATION_TIME = 0.2;
|
|
|
|
const NOTIFICATION_TIMEOUT = 4;
|
2010-01-28 13:39:00 -05:00
|
|
|
const SUMMARY_TIMEOUT = 1;
|
2011-02-19 10:49:56 -05:00
|
|
|
const LONGER_SUMMARY_TIMEOUT = 4;
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-02-25 14:42:18 -05:00
|
|
|
const HIDE_TIMEOUT = 0.2;
|
2010-08-31 15:50:18 -04:00
|
|
|
const LONGER_HIDE_TIMEOUT = 0.6;
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-06-23 15:20:39 -04:00
|
|
|
const MAX_SOURCE_TITLE_WIDTH = 180;
|
|
|
|
|
2010-10-30 15:54:43 -04:00
|
|
|
// 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;
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
const State = {
|
|
|
|
HIDDEN: 0,
|
|
|
|
SHOWING: 1,
|
|
|
|
SHOWN: 2,
|
|
|
|
HIDING: 3
|
2010-01-28 13:39:00 -05:00
|
|
|
};
|
|
|
|
|
2011-01-27 18:26:53 -05:00
|
|
|
// These reasons are useful when we destroy the notifications received through
|
|
|
|
// the notification daemon. We use EXPIRED for transient notifications that the
|
|
|
|
// user did not interact with, DISMISSED for all other notifications that were
|
|
|
|
// destroyed as a result of a user action, and SOURCE_CLOSED for the notifications
|
|
|
|
// that were requested to be destroyed by the associated source.
|
|
|
|
const NotificationDestroyedReason = {
|
|
|
|
EXPIRED: 1,
|
|
|
|
DISMISSED: 2,
|
2011-01-28 13:31:16 -05:00
|
|
|
SOURCE_CLOSED: 3
|
2011-01-27 18:26:53 -05:00
|
|
|
};
|
|
|
|
|
2011-01-04 04:34:57 -05:00
|
|
|
// Message tray has its custom Urgency enumeration. LOW, NORMAL and CRITICAL
|
|
|
|
// urgency values map to the corresponding values for the notifications received
|
|
|
|
// through the notification daemon. HIGH urgency value is used for chats received
|
|
|
|
// through the Telepathy client.
|
|
|
|
const Urgency = {
|
|
|
|
LOW: 0,
|
|
|
|
NORMAL: 1,
|
|
|
|
HIGH: 2,
|
|
|
|
CRITICAL: 3
|
|
|
|
}
|
|
|
|
|
2010-11-23 18:31:55 -05:00
|
|
|
function _fixMarkup(text, allowMarkup) {
|
|
|
|
if (allowMarkup) {
|
|
|
|
// Support &, ", ', < and >, escape all other
|
|
|
|
// occurrences of '&'.
|
|
|
|
let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&');
|
2011-05-04 11:15:45 -04:00
|
|
|
|
2010-11-23 18:31:55 -05:00
|
|
|
// Support <b>, <i>, and <u>, escape anything else
|
|
|
|
// so it displays as raw markup.
|
2011-05-04 11:15:45 -04:00
|
|
|
_text = _text.replace(/<(?!\/?[biu]>)/g, '<');
|
|
|
|
|
|
|
|
try {
|
|
|
|
Pango.parse_markup(_text, -1, '');
|
|
|
|
return _text;
|
|
|
|
} catch (e) {}
|
2010-11-23 18:31:55 -05:00
|
|
|
}
|
2011-05-04 11:15:45 -04:00
|
|
|
|
|
|
|
// !allowMarkup, or invalid markup
|
|
|
|
return GLib.markup_escape_text(text, -1);
|
2010-02-01 15:23:49 -05:00
|
|
|
}
|
|
|
|
|
2010-11-23 18:31:55 -05:00
|
|
|
function URLHighlighter(text, lineWrap, allowMarkup) {
|
|
|
|
this._init(text, lineWrap, allowMarkup);
|
2010-11-23 18:27:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
URLHighlighter.prototype = {
|
2010-11-23 18:31:55 -05:00
|
|
|
_init: function(text, lineWrap, allowMarkup) {
|
2010-11-23 18:27:47 -05:00
|
|
|
if (!text)
|
|
|
|
text = '';
|
|
|
|
this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter' });
|
|
|
|
this._linkColor = '#ccccff';
|
|
|
|
this.actor.connect('style-changed', Lang.bind(this, function() {
|
2011-02-14 09:20:22 -05:00
|
|
|
let [hasColor, color] = this.actor.get_theme_node().lookup_color('link-color', false);
|
2010-11-23 18:27:47 -05:00
|
|
|
if (hasColor) {
|
|
|
|
let linkColor = color.to_string().substr(0, 7);
|
|
|
|
if (linkColor != this._linkColor) {
|
|
|
|
this._linkColor = linkColor;
|
|
|
|
this._highlightUrls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
if (lineWrap) {
|
|
|
|
this.actor.clutter_text.line_wrap = true;
|
|
|
|
this.actor.clutter_text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
|
|
|
|
this.actor.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
}
|
|
|
|
|
2010-11-23 18:31:55 -05:00
|
|
|
this.setMarkup(text, allowMarkup);
|
2011-03-27 11:58:23 -04:00
|
|
|
this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
|
2011-08-29 19:10:14 -04:00
|
|
|
// Don't try to URL highlight when invisible.
|
|
|
|
// The MessageTray doesn't actually hide us, so
|
|
|
|
// we need to check for paint opacities as well.
|
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return false;
|
|
|
|
|
2011-03-23 16:05:38 -04:00
|
|
|
// Keep Notification.actor from seeing this and taking
|
|
|
|
// a pointer grab, which would block our button-release-event
|
2011-03-27 11:58:23 -04:00
|
|
|
// handler, if an URL is clicked
|
|
|
|
return this._findUrlAtPos(event) != -1;
|
|
|
|
}));
|
2010-11-23 18:27:47 -05:00
|
|
|
this.actor.connect('button-release-event', Lang.bind(this, function (actor, event) {
|
2011-08-29 19:10:14 -04:00
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return false;
|
|
|
|
|
2010-11-23 18:27:47 -05:00
|
|
|
let urlId = this._findUrlAtPos(event);
|
|
|
|
if (urlId != -1) {
|
|
|
|
let url = this._urls[urlId].url;
|
|
|
|
if (url.indexOf(':') == -1)
|
|
|
|
url = 'http://' + url;
|
|
|
|
try {
|
|
|
|
Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context());
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
// TODO: remove this after gnome 3 release
|
2010-11-17 11:43:08 -05:00
|
|
|
Util.spawn(['gvfs-open', url]);
|
2010-11-23 18:27:47 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
this.actor.connect('motion-event', Lang.bind(this, function(actor, event) {
|
2011-08-29 19:10:14 -04:00
|
|
|
if (!actor.visible || actor.get_paint_opacity() == 0)
|
|
|
|
return false;
|
|
|
|
|
2010-11-23 18:27:47 -05:00
|
|
|
let urlId = this._findUrlAtPos(event);
|
|
|
|
if (urlId != -1 && !this._cursorChanged) {
|
|
|
|
global.set_cursor(Shell.Cursor.POINTING_HAND);
|
|
|
|
this._cursorChanged = true;
|
|
|
|
} else if (urlId == -1) {
|
|
|
|
global.unset_cursor();
|
|
|
|
this._cursorChanged = false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
this.actor.connect('leave-event', Lang.bind(this, function() {
|
2011-08-29 19:10:14 -04:00
|
|
|
if (!this.actor.visible || this.actor.get_paint_opacity() == 0)
|
|
|
|
return;
|
|
|
|
|
2010-11-23 18:27:47 -05:00
|
|
|
if (this._cursorChanged) {
|
|
|
|
this._cursorChanged = false;
|
|
|
|
global.unset_cursor();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2010-11-23 18:31:55 -05:00
|
|
|
setMarkup: function(text, allowMarkup) {
|
|
|
|
text = text ? _fixMarkup(text, allowMarkup) : '';
|
2010-11-23 18:27:47 -05:00
|
|
|
this._text = text;
|
|
|
|
|
|
|
|
this.actor.clutter_text.set_markup(text);
|
|
|
|
/* clutter_text.text contain text without markup */
|
2010-11-30 11:16:10 -05:00
|
|
|
this._urls = Util.findUrls(this.actor.clutter_text.text);
|
2010-11-23 18:27:47 -05:00
|
|
|
this._highlightUrls();
|
|
|
|
},
|
|
|
|
|
|
|
|
_highlightUrls: function() {
|
|
|
|
// text here contain markup
|
2010-11-30 11:16:10 -05:00
|
|
|
let urls = Util.findUrls(this._text);
|
2010-11-23 18:27:47 -05:00
|
|
|
let markup = '';
|
|
|
|
let pos = 0;
|
|
|
|
for (let i = 0; i < urls.length; i++) {
|
|
|
|
let url = urls[i];
|
|
|
|
let str = this._text.substr(pos, url.pos - pos);
|
|
|
|
markup += str + '<span foreground="' + this._linkColor + '"><u>' + url.url + '</u></span>';
|
|
|
|
pos = url.pos + url.url.length;
|
|
|
|
}
|
|
|
|
markup += this._text.substr(pos);
|
|
|
|
this.actor.clutter_text.set_markup(markup);
|
|
|
|
},
|
|
|
|
|
|
|
|
_findUrlAtPos: function(event) {
|
|
|
|
let success;
|
|
|
|
let [x, y] = event.get_coords();
|
|
|
|
[success, x, y] = this.actor.transform_stage_point(x, y);
|
|
|
|
let find_pos = -1;
|
|
|
|
for (let i = 0; i < this.actor.clutter_text.text.length; i++) {
|
|
|
|
let [success, px, py, line_height] = this.actor.clutter_text.position_to_coords(i);
|
|
|
|
if (py > y || py + line_height < y || x < px)
|
|
|
|
continue;
|
|
|
|
find_pos = i;
|
|
|
|
}
|
|
|
|
if (find_pos != -1) {
|
|
|
|
for (let i = 0; i < this._urls.length; i++)
|
|
|
|
if (find_pos >= this._urls[i].pos &&
|
|
|
|
this._urls[i].pos + this._urls[i].url.length > find_pos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
function FocusGrabber() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
FocusGrabber.prototype = {
|
|
|
|
_init: function() {
|
|
|
|
this.actor = null;
|
|
|
|
|
|
|
|
this._hasFocus = false;
|
|
|
|
// We use this._prevFocusedWindow and this._prevKeyFocusActor to return the
|
|
|
|
// focus where it previously belonged after a focus grab, unless the user
|
|
|
|
// has explicitly changed that.
|
|
|
|
this._prevFocusedWindow = null;
|
|
|
|
this._prevKeyFocusActor = null;
|
|
|
|
|
|
|
|
this._focusActorChangedId = 0;
|
|
|
|
this._stageInputModeChangedId = 0;
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
this._togglingFocusGrabMode = false;
|
|
|
|
|
|
|
|
Main.overview.connect('showing', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._toggleFocusGrabMode();
|
|
|
|
}));
|
|
|
|
Main.overview.connect('hidden', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._toggleFocusGrabMode();
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
grabFocus: function(actor) {
|
|
|
|
if (this._hasFocus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.actor = actor;
|
|
|
|
|
2011-07-13 12:34:31 -04:00
|
|
|
this._prevFocusedWindow = global.display.focus_window;
|
2011-02-09 22:45:50 -05:00
|
|
|
this._prevKeyFocusActor = global.stage.get_key_focus();
|
|
|
|
|
|
|
|
if (!Main.overview.visible)
|
|
|
|
global.set_stage_input_mode(Shell.StageInputMode.FOCUSED);
|
|
|
|
|
|
|
|
// Use captured-event to notice clicks outside the focused actor
|
|
|
|
// without consuming them.
|
|
|
|
this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent));
|
|
|
|
|
|
|
|
this._stageInputModeChangedId = global.connect('notify::stage-input-mode', Lang.bind(this, this._stageInputModeChanged));
|
|
|
|
this._focusActorChangedId = global.stage.connect('notify::key-focus', Lang.bind(this, this._focusActorChanged));
|
|
|
|
|
|
|
|
this._hasFocus = true;
|
|
|
|
|
|
|
|
this.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
|
|
|
|
this.emit('focus-grabbed');
|
|
|
|
},
|
|
|
|
|
|
|
|
_focusActorChanged: function() {
|
|
|
|
let focusedActor = global.stage.get_key_focus();
|
|
|
|
if (!focusedActor || !this.actor.contains(focusedActor)) {
|
|
|
|
this._prevKeyFocusActor = null;
|
|
|
|
this.ungrabFocus();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_stageInputModeChanged: function() {
|
|
|
|
this.ungrabFocus();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onCapturedEvent: function(actor, event) {
|
|
|
|
let source = event.get_source();
|
|
|
|
switch (event.type()) {
|
|
|
|
case Clutter.EventType.BUTTON_PRESS:
|
2011-09-08 16:50:32 -04:00
|
|
|
if (!this.actor.contains(source) &&
|
|
|
|
!Main.layoutManager.keyboardBox.contains(source))
|
2011-02-15 18:37:33 -05:00
|
|
|
this.emit('button-pressed', source);
|
2011-02-09 22:45:50 -05:00
|
|
|
break;
|
|
|
|
case Clutter.EventType.KEY_PRESS:
|
|
|
|
let symbol = event.get_key_symbol();
|
|
|
|
if (symbol == Clutter.Escape) {
|
|
|
|
this.emit('escape-pressed');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
ungrabFocus: function() {
|
|
|
|
if (!this._hasFocus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._focusActorChangedId > 0) {
|
|
|
|
global.stage.disconnect(this._focusActorChangedId);
|
|
|
|
this._focusActorChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._stageInputModeChangedId) {
|
|
|
|
global.disconnect(this._stageInputModeChangedId);
|
|
|
|
this._stageInputModeChangedId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._capturedEventId > 0) {
|
|
|
|
global.stage.disconnect(this._capturedEventId);
|
|
|
|
this._capturedEventId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._hasFocus = false;
|
|
|
|
this.emit('focus-ungrabbed');
|
|
|
|
|
2011-07-13 12:34:31 -04:00
|
|
|
if (this._prevFocusedWindow && !global.display.focus_window) {
|
|
|
|
global.display.set_input_focus_window(this._prevFocusedWindow, false, global.get_current_time());
|
2011-02-09 22:45:50 -05:00
|
|
|
this._prevFocusedWindow = null;
|
|
|
|
}
|
|
|
|
if (this._prevKeyFocusActor) {
|
|
|
|
global.stage.set_key_focus(this._prevKeyFocusActor);
|
|
|
|
this._prevKeyFocusActor = null;
|
|
|
|
} else {
|
|
|
|
// We don't want to keep any actor inside the previously focused actor focused.
|
|
|
|
let focusedActor = global.stage.get_key_focus();
|
|
|
|
if (focusedActor && this.actor.contains(focusedActor))
|
|
|
|
global.stage.set_key_focus(null);
|
|
|
|
}
|
|
|
|
if (!this._togglingFocusGrabMode)
|
|
|
|
this.actor = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Because we grab focus differently in the overview
|
|
|
|
// and in the main view, we need to change how it is
|
|
|
|
// done when we move between the two.
|
|
|
|
_toggleFocusGrabMode: function() {
|
|
|
|
if (this._hasFocus) {
|
|
|
|
this._togglingFocusGrabMode = true;
|
|
|
|
this.ungrabFocus();
|
|
|
|
this.grabFocus(this.actor);
|
|
|
|
this._togglingFocusGrabMode = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Signals.addSignalMethods(FocusGrabber.prototype);
|
|
|
|
|
2010-02-01 12:10:38 -05:00
|
|
|
// Notification:
|
|
|
|
// @source: the notification's Source
|
|
|
|
// @title: the title
|
|
|
|
// @banner: the banner text
|
2010-08-18 16:01:33 -04:00
|
|
|
// @params: optional additional params
|
2010-02-01 12:10:38 -05:00
|
|
|
//
|
2010-08-30 16:03:08 -04:00
|
|
|
// Creates a notification. In the banner mode, the notification
|
|
|
|
// will show an icon, @title (in bold) and @banner, all on a single
|
|
|
|
// line (with @banner ellipsized if necessary).
|
2010-02-09 11:25:10 -05:00
|
|
|
//
|
2010-08-30 16:03:08 -04:00
|
|
|
// The notification will be expandable if either it has additional
|
|
|
|
// elements that were added to it or if the @banner text did not
|
|
|
|
// fit fully in the banner mode. When the notification is expanded,
|
|
|
|
// the @banner text from the top line is always removed. The complete
|
|
|
|
// @banner text is added as the first element in the content section,
|
|
|
|
// unless 'customContent' parameter with the value 'true' is specified
|
|
|
|
// in @params.
|
2010-08-05 13:09:27 -04:00
|
|
|
//
|
2010-08-30 16:03:08 -04:00
|
|
|
// Additional notification content can be added with addActor() and
|
|
|
|
// addBody() methods. The notification content is put inside a
|
2010-02-22 14:23:36 -05:00
|
|
|
// scrollview, so if it gets too tall, the notification will scroll
|
2010-08-30 16:03:08 -04:00
|
|
|
// rather than continue to grow. In addition to this main content
|
|
|
|
// area, there is also a single-row action area, which is not
|
|
|
|
// scrolled and can contain a single actor. The action area can
|
|
|
|
// be set by calling setActionArea() method. There is also a
|
|
|
|
// convenience method addButton() for adding a button to the action
|
|
|
|
// area.
|
|
|
|
//
|
|
|
|
// @params can contain values for 'customContent', 'body', 'icon',
|
2010-11-23 18:31:55 -05:00
|
|
|
// 'titleMarkup', 'bannerMarkup', 'bodyMarkup', and 'clear'
|
|
|
|
// parameters.
|
2010-08-30 16:03:08 -04:00
|
|
|
//
|
|
|
|
// If @params contains a 'customContent' parameter with the value %true,
|
|
|
|
// then @banner will not be shown in the body of the notification when the
|
|
|
|
// notification is expanded and calls to update() will not clear the content
|
|
|
|
// unless 'clear' parameter with value %true is explicitly specified.
|
|
|
|
//
|
|
|
|
// If @params contains a 'body' parameter, then that text will be added to
|
|
|
|
// the content area (as with addBody()).
|
2010-02-09 11:25:10 -05:00
|
|
|
//
|
2010-08-30 16:03:08 -04:00
|
|
|
// By default, the icon shown is created by calling
|
|
|
|
// source.createNotificationIcon(). However, if @params contains an 'icon'
|
|
|
|
// parameter, the passed in icon will be used.
|
|
|
|
//
|
2010-11-23 18:31:55 -05:00
|
|
|
// If @params contains a 'titleMarkup', 'bannerMarkup', or
|
|
|
|
// 'bodyMarkup' parameter with the value %true, then the corresponding
|
|
|
|
// element is assumed to use pango markup. If the parameter is not
|
|
|
|
// present for an element, then anything that looks like markup in
|
|
|
|
// that element will appear literally in the output.
|
|
|
|
//
|
2010-08-30 16:03:08 -04:00
|
|
|
// If @params contains a 'clear' parameter with the value %true, then
|
|
|
|
// the content and the action area of the notification will be cleared.
|
|
|
|
// The content area is also always cleared if 'customContent' is false
|
|
|
|
// because it might contain the @banner that didn't fit in the banner mode.
|
2010-08-18 16:01:33 -04:00
|
|
|
function Notification(source, title, banner, params) {
|
|
|
|
this._init(source, title, banner, params);
|
2010-01-13 15:05:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Notification.prototype = {
|
2011-08-29 13:11:24 -04:00
|
|
|
IMAGE_SIZE: 125,
|
|
|
|
|
2010-08-18 16:01:33 -04:00
|
|
|
_init: function(source, title, banner, params) {
|
2010-01-28 13:39:00 -05:00
|
|
|
this.source = source;
|
2011-09-21 16:46:08 -04:00
|
|
|
this.title = title;
|
2011-01-04 04:34:57 -05:00
|
|
|
this.urgency = Urgency.NORMAL;
|
2010-12-16 15:49:47 -05:00
|
|
|
this.resident = false;
|
2010-12-15 16:30:50 -05:00
|
|
|
// 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
|
|
|
|
this.isTransient = false;
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this.expanded = false;
|
2011-01-30 18:33:49 -05:00
|
|
|
this._destroyed = false;
|
2010-10-30 02:29:21 -04:00
|
|
|
this._useActionIcons = false;
|
2010-08-30 16:03:08 -04:00
|
|
|
this._customContent = false;
|
|
|
|
this._bannerBodyText = null;
|
2010-11-23 18:31:55 -05:00
|
|
|
this._bannerBodyMarkup = false;
|
2010-08-29 01:34:27 -04:00
|
|
|
this._titleFitsInBannerMode = true;
|
2011-04-06 12:23:49 -04:00
|
|
|
this._titleDirection = St.TextDirection.NONE;
|
2010-08-26 16:05:27 -04:00
|
|
|
this._spacing = 0;
|
2011-03-22 03:40:53 -04:00
|
|
|
this._scrollPolicy = Gtk.PolicyType.AUTOMATIC;
|
2011-08-29 13:11:24 -04:00
|
|
|
this._imageBin = null;
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2011-01-30 18:08:20 -05:00
|
|
|
source.connect('destroy', Lang.bind(this,
|
2011-03-21 17:43:34 -04:00
|
|
|
function (source, reason) {
|
|
|
|
this.destroy(reason);
|
2011-01-30 18:08:20 -05:00
|
|
|
}));
|
2010-07-14 17:07:06 -04:00
|
|
|
|
2011-03-03 15:14:52 -05:00
|
|
|
this.actor = new St.Button();
|
2011-03-21 17:43:34 -04:00
|
|
|
this.actor._delegate = this;
|
2011-03-03 15:14:52 -05:00
|
|
|
this.actor.connect('clicked', Lang.bind(this, this._onClicked));
|
2011-03-02 19:47:58 -05:00
|
|
|
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
|
2010-06-13 10:17:35 -04:00
|
|
|
|
2011-03-03 15:14:52 -05:00
|
|
|
this._table = new St.Table({ name: 'notification',
|
|
|
|
reactive: true });
|
|
|
|
this._table.connect('style-changed', Lang.bind(this, this._styleChanged));
|
|
|
|
this.actor.set_child(this._table);
|
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
this._buttonFocusManager = St.FocusManager.get_for_stage(global.stage);
|
|
|
|
|
2010-07-28 11:02:32 -04:00
|
|
|
// The first line should have the title, followed by the
|
|
|
|
// banner text, but ellipsized if they won't both fit. We can't
|
|
|
|
// make St.Table or St.BoxLayout do this the way we want (don't
|
|
|
|
// show banner at all if title needs to be ellipsized), so we
|
|
|
|
// use Shell.GenericContainer.
|
|
|
|
this._bannerBox = new Shell.GenericContainer();
|
|
|
|
this._bannerBox.connect('get-preferred-width', Lang.bind(this, this._bannerBoxGetPreferredWidth));
|
|
|
|
this._bannerBox.connect('get-preferred-height', Lang.bind(this, this._bannerBoxGetPreferredHeight));
|
|
|
|
this._bannerBox.connect('allocate', Lang.bind(this, this._bannerBoxAllocate));
|
2011-03-03 15:14:52 -05:00
|
|
|
this._table.add(this._bannerBox, { row: 0,
|
|
|
|
col: 1,
|
2011-08-29 13:11:24 -04:00
|
|
|
col_span: 2,
|
|
|
|
x_expand: false,
|
2011-03-03 15:14:52 -05:00
|
|
|
y_expand: false,
|
|
|
|
y_fill: false });
|
2010-07-28 11:02:32 -04:00
|
|
|
|
2011-08-29 13:11:24 -04:00
|
|
|
// This is an empty cell that overlaps with this._bannerBox cell to ensure
|
|
|
|
// that this._bannerBox cell expands horizontally, while not forcing the
|
|
|
|
// this._imageBin that is also in col: 2 to expand horizontally.
|
|
|
|
this._table.add(new St.Bin(), { row: 0,
|
|
|
|
col: 2,
|
|
|
|
y_expand: false,
|
|
|
|
y_fill: false });
|
|
|
|
|
2010-07-28 11:02:32 -04:00
|
|
|
this._titleLabel = new St.Label();
|
|
|
|
this._bannerBox.add_actor(this._titleLabel);
|
2010-11-23 18:27:47 -05:00
|
|
|
this._bannerUrlHighlighter = new URLHighlighter();
|
|
|
|
this._bannerLabel = this._bannerUrlHighlighter.actor;
|
2010-07-28 11:02:32 -04:00
|
|
|
this._bannerBox.add_actor(this._bannerLabel);
|
|
|
|
|
2010-08-18 16:01:33 -04:00
|
|
|
this.update(title, banner, params);
|
2010-02-09 11:25:10 -05:00
|
|
|
},
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-02-09 11:25:10 -05:00
|
|
|
// update:
|
|
|
|
// @title: the new title
|
|
|
|
// @banner: the new banner
|
2010-08-18 16:01:33 -04:00
|
|
|
// @params: as in the Notification constructor
|
2010-02-09 11:25:10 -05:00
|
|
|
//
|
|
|
|
// Updates the notification by regenerating its icon and updating
|
2010-08-18 16:01:33 -04:00
|
|
|
// the title/banner. If @params.clear is %true, it will also
|
|
|
|
// remove any additional actors/action buttons previously added.
|
|
|
|
update: function(title, banner, params) {
|
2010-08-30 16:03:08 -04:00
|
|
|
params = Params.parse(params, { customContent: false,
|
2010-08-18 16:01:33 -04:00
|
|
|
body: null,
|
2010-08-05 13:09:27 -04:00
|
|
|
icon: null,
|
2010-11-23 18:31:55 -05:00
|
|
|
titleMarkup: false,
|
|
|
|
bannerMarkup: false,
|
|
|
|
bodyMarkup: false,
|
2010-08-18 16:01:33 -04:00
|
|
|
clear: false });
|
|
|
|
|
2010-08-30 16:03:08 -04:00
|
|
|
this._customContent = params.customContent;
|
|
|
|
|
2011-03-02 09:48:29 -05:00
|
|
|
let oldFocus = global.stage.key_focus;
|
|
|
|
|
2011-09-21 16:47:49 -04:00
|
|
|
if (this._icon && (params.icon || params.clear)) {
|
2010-02-22 14:23:36 -05:00
|
|
|
this._icon.destroy();
|
2011-09-21 16:47:49 -04:00
|
|
|
this._icon = null;
|
|
|
|
}
|
|
|
|
|
2010-08-30 16:03:08 -04:00
|
|
|
// We always clear the content area if we don't have custom
|
|
|
|
// content because it might contain the @banner that didn't
|
|
|
|
// fit in the banner mode.
|
|
|
|
if (this._scrollArea && (!this._customContent || params.clear)) {
|
2011-03-02 09:48:29 -05:00
|
|
|
if (oldFocus && this._scrollArea.contains(oldFocus))
|
|
|
|
this.actor.grab_key_focus();
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
this._scrollArea.destroy();
|
|
|
|
this._scrollArea = null;
|
|
|
|
this._contentArea = null;
|
2010-02-09 11:25:10 -05:00
|
|
|
}
|
2010-08-18 16:01:33 -04:00
|
|
|
if (this._actionArea && params.clear) {
|
2011-03-02 09:48:29 -05:00
|
|
|
if (oldFocus && this._actionArea.contains(oldFocus))
|
|
|
|
this.actor.grab_key_focus();
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
this._actionArea.destroy();
|
|
|
|
this._actionArea = null;
|
|
|
|
this._buttonBox = null;
|
2010-02-09 11:25:10 -05:00
|
|
|
}
|
2011-08-29 13:11:24 -04:00
|
|
|
if (this._imageBin && params.clear)
|
|
|
|
this.unsetImage();
|
|
|
|
|
|
|
|
if (!this._scrollArea && !this._actionArea && !this._imageBin)
|
2011-03-03 15:14:52 -05:00
|
|
|
this._table.remove_style_class_name('multi-line-notification');
|
2010-02-09 11:25:10 -05:00
|
|
|
|
2011-09-21 16:47:49 -04:00
|
|
|
if (!this._icon) {
|
|
|
|
this._icon = params.icon || this.source.createNotificationIcon();
|
|
|
|
this._table.add(this._icon, { row: 0,
|
|
|
|
col: 0,
|
|
|
|
x_expand: false,
|
|
|
|
y_expand: false,
|
|
|
|
y_fill: false,
|
|
|
|
y_align: St.Align.START });
|
|
|
|
}
|
2010-02-01 12:10:38 -05:00
|
|
|
|
2011-09-21 16:46:08 -04:00
|
|
|
this.title = title;
|
2010-11-23 18:31:55 -05:00
|
|
|
title = title ? _fixMarkup(title.replace(/\n/g, ' '), params.titleMarkup) : '';
|
2010-02-09 11:20:51 -05:00
|
|
|
this._titleLabel.clutter_text.set_markup('<b>' + title + '</b>');
|
2010-02-01 12:10:38 -05:00
|
|
|
|
2011-04-06 12:23:49 -04:00
|
|
|
if (Pango.find_base_dir(title, -1) == Pango.Direction.RTL)
|
|
|
|
this._titleDirection = St.TextDirection.RTL;
|
|
|
|
else
|
|
|
|
this._titleDirection = St.TextDirection.LTR;
|
|
|
|
|
|
|
|
// Let the title's text direction control the overall direction
|
|
|
|
// of the notification - in case where different scripts are used
|
|
|
|
// in the notification, this is the right thing for the icon, and
|
|
|
|
// arguably for action buttons as well. Labels other than the title
|
|
|
|
// will be allocated at the available width, so that their alignment
|
|
|
|
// is done correctly automatically.
|
|
|
|
this._table.set_direction(this._titleDirection);
|
|
|
|
|
2010-08-30 16:03:08 -04:00
|
|
|
// Unless the notification has custom content, we save this._bannerBodyText
|
|
|
|
// to add it to the content of the notification if the notification is
|
|
|
|
// expandable due to other elements in its content area or due to the banner
|
|
|
|
// not fitting fully in the single-line mode.
|
|
|
|
this._bannerBodyText = this._customContent ? null : banner;
|
2010-11-23 18:31:55 -05:00
|
|
|
this._bannerBodyMarkup = params.bannerMarkup;
|
2010-02-09 11:25:10 -05:00
|
|
|
|
2010-11-23 18:27:47 -05:00
|
|
|
banner = banner ? banner.replace(/\n/g, ' ') : '';
|
|
|
|
|
2010-11-23 18:31:55 -05:00
|
|
|
this._bannerUrlHighlighter.setMarkup(banner, params.bannerMarkup);
|
2010-07-28 11:02:32 -04:00
|
|
|
this._bannerLabel.queue_relayout();
|
2010-04-29 10:54:05 -04:00
|
|
|
|
|
|
|
// Add the bannerBody now if we know for sure we'll need it
|
|
|
|
if (this._bannerBodyText && this._bannerBodyText.indexOf('\n') > -1)
|
|
|
|
this._addBannerBody();
|
2010-08-30 16:03:08 -04:00
|
|
|
|
|
|
|
if (params.body)
|
2010-11-23 18:31:55 -05:00
|
|
|
this.addBody(params.body, params.bodyMarkup);
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updated();
|
2010-02-09 11:25:10 -05:00
|
|
|
},
|
2010-02-01 12:10:38 -05:00
|
|
|
|
2011-03-21 17:43:34 -04:00
|
|
|
setIconVisible: function(visible) {
|
|
|
|
this._icon.visible = visible;
|
|
|
|
},
|
|
|
|
|
2011-03-22 03:40:53 -04:00
|
|
|
enableScrolling: function(enableScrolling) {
|
|
|
|
this._scrollPolicy = enableScrolling ? Gtk.PolicyType.AUTOMATIC : Gtk.PolicyType.NEVER;
|
|
|
|
if (this._scrollArea)
|
|
|
|
this._scrollArea.vscrollbar_policy = this._scrollPolicy;
|
|
|
|
},
|
|
|
|
|
2011-03-09 07:56:35 -05:00
|
|
|
_createScrollArea: function() {
|
2011-03-03 15:14:52 -05:00
|
|
|
this._table.add_style_class_name('multi-line-notification');
|
2011-03-09 07:56:35 -05:00
|
|
|
this._scrollArea = new St.ScrollView({ name: 'notification-scrollview',
|
2011-03-22 03:40:53 -04:00
|
|
|
vscrollbar_policy: this._scrollPolicy,
|
2011-03-09 07:56:35 -05:00
|
|
|
hscrollbar_policy: Gtk.PolicyType.NEVER,
|
2011-06-03 17:44:57 -04:00
|
|
|
style_class: 'vfade' });
|
2011-08-29 13:11:24 -04:00
|
|
|
this._table.add(this._scrollArea, { row: 1,
|
|
|
|
col: 2 });
|
|
|
|
this._updateLastColumnSettings();
|
2011-03-09 07:56:35 -05:00
|
|
|
this._contentArea = new St.BoxLayout({ name: 'notification-body',
|
|
|
|
vertical: true });
|
|
|
|
this._scrollArea.add_actor(this._contentArea);
|
|
|
|
// If we know the notification will be expandable, we need to add
|
|
|
|
// the banner text to the body as the first element.
|
|
|
|
this._addBannerBody();
|
|
|
|
},
|
|
|
|
|
2010-02-09 11:25:10 -05:00
|
|
|
// addActor:
|
2010-02-22 14:23:36 -05:00
|
|
|
// @actor: actor to add to the body of the notification
|
2010-02-09 11:25:10 -05:00
|
|
|
//
|
2010-02-22 14:23:36 -05:00
|
|
|
// Appends @actor to the notification's body
|
2010-11-25 09:29:41 -05:00
|
|
|
addActor: function(actor, style) {
|
2010-02-22 14:23:36 -05:00
|
|
|
if (!this._scrollArea) {
|
2011-03-09 07:56:35 -05:00
|
|
|
this._createScrollArea();
|
2010-02-01 12:10:38 -05:00
|
|
|
}
|
2010-02-01 15:23:49 -05:00
|
|
|
|
2010-11-25 09:29:41 -05:00
|
|
|
this._contentArea.add(actor, style ? style : {});
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updated();
|
2010-02-01 15:41:22 -05:00
|
|
|
},
|
|
|
|
|
2010-02-09 11:25:10 -05:00
|
|
|
// addBody:
|
|
|
|
// @text: the text
|
2010-11-23 18:31:55 -05:00
|
|
|
// @markup: %true if @text contains pango markup
|
2010-11-25 09:29:41 -05:00
|
|
|
// @style: style to use when adding the actor containing the text
|
2010-02-09 11:25:10 -05:00
|
|
|
//
|
|
|
|
// Adds a multi-line label containing @text to the notification.
|
2010-02-22 14:23:36 -05:00
|
|
|
//
|
|
|
|
// Return value: the newly-added label
|
2010-11-25 09:29:41 -05:00
|
|
|
addBody: function(text, markup, style) {
|
2010-11-23 18:31:55 -05:00
|
|
|
let label = new URLHighlighter(text, true, markup);
|
2010-02-09 11:25:10 -05:00
|
|
|
|
2010-11-25 09:29:41 -05:00
|
|
|
this.addActor(label.actor, style);
|
2010-11-23 18:27:47 -05:00
|
|
|
return label.actor;
|
2010-02-09 11:25:10 -05:00
|
|
|
},
|
|
|
|
|
2010-02-12 15:15:03 -05:00
|
|
|
_addBannerBody: function() {
|
2010-08-30 16:03:08 -04:00
|
|
|
if (this._bannerBodyText) {
|
|
|
|
let text = this._bannerBodyText;
|
|
|
|
this._bannerBodyText = null;
|
2010-11-23 18:31:55 -05:00
|
|
|
this.addBody(text, this._bannerBodyMarkup);
|
2010-08-30 16:03:08 -04:00
|
|
|
}
|
2010-02-12 15:15:03 -05:00
|
|
|
},
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
// scrollTo:
|
|
|
|
// @side: St.Side.TOP or St.Side.BOTTOM
|
|
|
|
//
|
|
|
|
// Scrolls the content area (if scrollable) to the indicated edge
|
|
|
|
scrollTo: function(side) {
|
|
|
|
let adjustment = this._scrollArea.vscroll.adjustment;
|
|
|
|
if (side == St.Side.TOP)
|
|
|
|
adjustment.value = adjustment.lower;
|
|
|
|
else if (side == St.Side.BOTTOM)
|
|
|
|
adjustment.value = adjustment.upper;
|
|
|
|
},
|
|
|
|
|
|
|
|
// setActionArea:
|
|
|
|
// @actor: the actor
|
|
|
|
// @props: (option) St.Table child properties
|
|
|
|
//
|
|
|
|
// Puts @actor into the action area of the notification, replacing
|
|
|
|
// the previous contents
|
|
|
|
setActionArea: function(actor, props) {
|
|
|
|
if (this._actionArea) {
|
|
|
|
this._actionArea.destroy();
|
|
|
|
this._actionArea = null;
|
|
|
|
if (this._buttonBox)
|
|
|
|
this._buttonBox = null;
|
2010-10-06 17:25:15 -04:00
|
|
|
} else {
|
|
|
|
this._addBannerBody();
|
2010-02-22 14:23:36 -05:00
|
|
|
}
|
|
|
|
this._actionArea = actor;
|
|
|
|
|
|
|
|
if (!props)
|
|
|
|
props = {};
|
|
|
|
props.row = 2;
|
2011-08-29 13:11:24 -04:00
|
|
|
props.col = 2;
|
2010-02-22 14:23:36 -05:00
|
|
|
|
2011-03-03 15:14:52 -05:00
|
|
|
this._table.add_style_class_name('multi-line-notification');
|
|
|
|
this._table.add(this._actionArea, props);
|
2011-08-29 13:11:24 -04:00
|
|
|
this._updateLastColumnSettings();
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updated();
|
2010-02-22 14:23:36 -05:00
|
|
|
},
|
|
|
|
|
2011-08-29 13:11:24 -04:00
|
|
|
_updateLastColumnSettings: function() {
|
|
|
|
if (this._scrollArea)
|
|
|
|
this._table.child_set(this._scrollArea, { col: this._imageBin ? 2 : 1,
|
|
|
|
col_span: this._imageBin ? 1 : 2 });
|
|
|
|
if (this._actionArea)
|
|
|
|
this._table.child_set(this._actionArea, { col: this._imageBin ? 2 : 1,
|
|
|
|
col_span: this._imageBin ? 1 : 2 });
|
|
|
|
},
|
|
|
|
|
|
|
|
setImage: function(image) {
|
|
|
|
if (this._imageBin)
|
|
|
|
this.unsetImage();
|
|
|
|
this._imageBin = new St.Bin();
|
|
|
|
this._imageBin.child = image;
|
|
|
|
this._imageBin.opacity = 230;
|
2011-08-29 15:18:52 -04:00
|
|
|
this._table.add_style_class_name('multi-line-notification');
|
2011-08-29 13:11:24 -04:00
|
|
|
this._table.add_style_class_name('notification-with-image');
|
|
|
|
this._updateLastColumnSettings();
|
|
|
|
this._table.add(this._imageBin, { row: 1,
|
|
|
|
col: 1,
|
|
|
|
row_span: 2,
|
|
|
|
x_expand: false,
|
|
|
|
y_expand: false,
|
|
|
|
x_fill: false,
|
|
|
|
y_fill: false });
|
|
|
|
},
|
|
|
|
|
|
|
|
unsetImage: function() {
|
|
|
|
if (this._imageBin) {
|
|
|
|
this._table.remove_style_class_name('notification-with-image');
|
|
|
|
this._table.remove_actor(this._imageBin);
|
|
|
|
this._imageBin = null;
|
|
|
|
this._updateLastColumnSettings();
|
2011-08-29 15:18:52 -04:00
|
|
|
if (!this._scrollArea && !this._actionArea)
|
|
|
|
this._table.remove_style_class_name('multi-line-notification');
|
2011-08-29 13:11:24 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
// addButton:
|
2010-02-09 11:25:10 -05:00
|
|
|
// @id: the action ID
|
|
|
|
// @label: the label for the action's button
|
|
|
|
//
|
|
|
|
// Adds a button with the given @label to the notification. All
|
|
|
|
// action buttons will appear in a single row at the bottom of
|
|
|
|
// the notification.
|
|
|
|
//
|
|
|
|
// If the button is clicked, the notification will emit the
|
|
|
|
// %action-invoked signal with @id as a parameter
|
2010-02-22 14:23:36 -05:00
|
|
|
addButton: function(id, label) {
|
|
|
|
if (!this._buttonBox) {
|
2010-02-12 15:15:03 -05:00
|
|
|
|
2010-02-09 11:25:10 -05:00
|
|
|
let box = new St.BoxLayout({ name: 'notification-actions' });
|
2010-02-22 14:23:36 -05:00
|
|
|
this.setActionArea(box, { x_expand: false,
|
2011-08-29 13:11:24 -04:00
|
|
|
y_expand: false,
|
2010-02-22 14:23:36 -05:00
|
|
|
x_fill: false,
|
2011-08-29 13:11:24 -04:00
|
|
|
y_fill: false,
|
2010-02-22 14:23:36 -05:00
|
|
|
x_align: St.Align.END });
|
|
|
|
this._buttonBox = box;
|
2010-02-01 15:41:22 -05:00
|
|
|
}
|
|
|
|
|
2011-01-20 00:16:47 -05:00
|
|
|
let button = new St.Button({ can_focus: true });
|
2010-06-11 17:19:18 -04:00
|
|
|
|
2010-10-30 02:29:21 -04:00
|
|
|
if (this._useActionIcons && Gtk.IconTheme.get_default().has_icon(id)) {
|
2010-06-11 17:19:18 -04:00
|
|
|
button.add_style_class_name('notification-icon-button');
|
2010-11-02 18:33:22 -04:00
|
|
|
button.child = new St.Icon({ icon_name: id });
|
2010-06-11 17:19:18 -04:00
|
|
|
} else {
|
|
|
|
button.add_style_class_name('notification-button');
|
|
|
|
button.label = label;
|
|
|
|
}
|
|
|
|
|
2011-01-20 00:16:47 -05:00
|
|
|
if (this._buttonBox.get_children().length > 0)
|
|
|
|
this._buttonFocusManager.remove_group(this._buttonBox);
|
|
|
|
|
2010-02-22 14:23:36 -05:00
|
|
|
this._buttonBox.add(button);
|
2011-01-20 00:16:47 -05:00
|
|
|
this._buttonFocusManager.add_group(this._buttonBox);
|
2010-12-16 15:49:47 -05:00
|
|
|
button.connect('clicked', Lang.bind(this, this._onActionInvoked, id));
|
2011-01-20 00:16:47 -05:00
|
|
|
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updated();
|
2010-02-01 12:10:38 -05:00
|
|
|
},
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2011-01-04 04:34:57 -05:00
|
|
|
setUrgency: function(urgency) {
|
|
|
|
this.urgency = urgency;
|
2010-04-28 15:34:27 -04:00
|
|
|
},
|
|
|
|
|
2010-12-16 15:49:47 -05:00
|
|
|
setResident: function(resident) {
|
|
|
|
this.resident = resident;
|
|
|
|
},
|
|
|
|
|
2010-12-15 16:30:50 -05:00
|
|
|
setTransient: function(isTransient) {
|
|
|
|
this.isTransient = isTransient;
|
|
|
|
},
|
|
|
|
|
2010-10-30 02:29:21 -04:00
|
|
|
setUseActionIcons: function(useIcons) {
|
|
|
|
this._useActionIcons = useIcons;
|
|
|
|
},
|
|
|
|
|
2010-04-29 10:54:05 -04:00
|
|
|
_styleChanged: function() {
|
2011-03-03 15:14:52 -05:00
|
|
|
this._spacing = this._table.get_theme_node().get_length('spacing-columns');
|
2010-04-29 10:54:05 -04:00
|
|
|
},
|
|
|
|
|
2010-02-01 12:10:38 -05:00
|
|
|
_bannerBoxGetPreferredWidth: function(actor, forHeight, alloc) {
|
2010-02-09 11:20:51 -05:00
|
|
|
let [titleMin, titleNat] = this._titleLabel.get_preferred_width(forHeight);
|
|
|
|
let [bannerMin, bannerNat] = this._bannerLabel.get_preferred_width(forHeight);
|
2010-01-28 13:39:00 -05:00
|
|
|
|
2010-02-01 12:10:38 -05:00
|
|
|
alloc.min_size = titleMin;
|
2010-04-29 10:54:05 -04:00
|
|
|
alloc.natural_size = titleNat + this._spacing + bannerNat;
|
2010-02-01 12:10:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_bannerBoxGetPreferredHeight: function(actor, forWidth, alloc) {
|
|
|
|
[alloc.min_size, alloc.natural_size] =
|
2010-02-09 11:20:51 -05:00
|
|
|
this._titleLabel.get_preferred_height(forWidth);
|
2010-02-01 12:10:38 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_bannerBoxAllocate: function(actor, box, flags) {
|
|
|
|
let availWidth = box.x2 - box.x1;
|
|
|
|
|
2011-09-20 15:52:42 -04:00
|
|
|
let [titleMinW, titleNatW] = this._titleLabel.get_preferred_width(-1);
|
|
|
|
let [titleMinH, titleNatH] = this._titleLabel.get_preferred_height(availWidth);
|
|
|
|
let [bannerMinW, bannerNatW] = this._bannerLabel.get_preferred_width(availWidth);
|
|
|
|
|
2010-02-01 12:10:38 -05:00
|
|
|
let titleBox = new Clutter.ActorBox();
|
2011-04-06 12:23:49 -04:00
|
|
|
let titleBoxW = Math.min(titleNatW, availWidth);
|
|
|
|
if (this._titleDirection == St.TextDirection.RTL) {
|
|
|
|
titleBox.x1 = availWidth - titleBoxW;
|
|
|
|
titleBox.x2 = availWidth;
|
|
|
|
} else {
|
|
|
|
titleBox.x1 = 0;
|
|
|
|
titleBox.x2 = titleBoxW;
|
|
|
|
}
|
|
|
|
titleBox.y1 = 0;
|
2010-02-01 12:10:38 -05:00
|
|
|
titleBox.y2 = titleNatH;
|
2010-02-09 11:20:51 -05:00
|
|
|
this._titleLabel.allocate(titleBox, flags);
|
2010-08-29 01:34:27 -04:00
|
|
|
this._titleFitsInBannerMode = (titleNatW <= availWidth);
|
2010-02-01 12:10:38 -05:00
|
|
|
|
2010-08-26 16:05:27 -04:00
|
|
|
let bannerFits = true;
|
2011-04-06 12:23:49 -04:00
|
|
|
if (titleBoxW + this._spacing > availWidth) {
|
2010-09-10 13:35:11 -04:00
|
|
|
this._bannerLabel.opacity = 0;
|
2010-08-26 16:05:27 -04:00
|
|
|
bannerFits = false;
|
2010-02-03 15:15:12 -05:00
|
|
|
} else {
|
|
|
|
let bannerBox = new Clutter.ActorBox();
|
2011-04-06 12:23:49 -04:00
|
|
|
|
|
|
|
if (this._titleDirection == St.TextDirection.RTL) {
|
|
|
|
bannerBox.x1 = 0;
|
|
|
|
bannerBox.x2 = titleBox.x1 - this._spacing;
|
|
|
|
|
|
|
|
bannerFits = (bannerBox.x2 - bannerNatW >= 0);
|
|
|
|
} else {
|
|
|
|
bannerBox.x1 = titleBox.x2 + this._spacing;
|
|
|
|
bannerBox.x2 = availWidth;
|
|
|
|
|
|
|
|
bannerFits = (bannerBox.x1 + bannerNatW <= availWidth);
|
|
|
|
}
|
2010-02-03 15:15:12 -05:00
|
|
|
bannerBox.y1 = 0;
|
|
|
|
bannerBox.y2 = titleNatH;
|
2010-02-09 11:20:51 -05:00
|
|
|
this._bannerLabel.allocate(bannerBox, flags);
|
2010-09-10 13:35:11 -04:00
|
|
|
|
|
|
|
// Make _bannerLabel visible if the entire notification
|
|
|
|
// fits on one line, or if the notification is currently
|
|
|
|
// unexpanded and only showing one line anyway.
|
2011-03-03 15:14:52 -05:00
|
|
|
if (!this.expanded || (bannerFits && this._table.row_count == 1))
|
2010-09-10 13:35:11 -04:00
|
|
|
this._bannerLabel.opacity = 255;
|
2010-02-09 11:25:10 -05:00
|
|
|
}
|
2010-08-26 16:05:27 -04:00
|
|
|
|
2010-08-30 16:03:08 -04:00
|
|
|
// If the banner doesn't fully fit in the banner box, we possibly need to add the
|
|
|
|
// banner to the body. We can't do that from here though since that will force a
|
|
|
|
// relayout, so we add it to the main loop.
|
2011-03-27 14:57:34 -04:00
|
|
|
if (!bannerFits && this._canExpandContent())
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW,
|
|
|
|
Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
if (this._canExpandContent()) {
|
2010-08-26 16:05:27 -04:00
|
|
|
this._addBannerBody();
|
2011-03-27 14:57:34 -04:00
|
|
|
this._table.add_style_class_name('multi-line-notification');
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updated();
|
2011-03-27 14:57:34 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
_canExpandContent: function() {
|
|
|
|
return this._bannerBodyText ||
|
|
|
|
(!this._titleFitsInBannerMode && !this._table.has_style_class_name('multi-line-notification'));
|
2010-02-01 12:10:38 -05:00
|
|
|
},
|
|
|
|
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
_updated: function() {
|
|
|
|
if (this.expanded)
|
|
|
|
this.expand(false);
|
|
|
|
},
|
|
|
|
|
|
|
|
expand: function(animate) {
|
|
|
|
this.expanded = true;
|
2010-08-29 01:34:27 -04:00
|
|
|
// The banner is never shown when the title did not fit, so this
|
|
|
|
// can be an if-else statement.
|
|
|
|
if (!this._titleFitsInBannerMode) {
|
|
|
|
// Remove ellipsization from the title label and make it wrap so that
|
|
|
|
// we show the full title when the notification is expanded.
|
|
|
|
this._titleLabel.clutter_text.line_wrap = true;
|
|
|
|
this._titleLabel.clutter_text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
|
|
|
|
this._titleLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
2011-03-03 15:14:52 -05:00
|
|
|
} else if (this._table.row_count > 1 && this._bannerLabel.opacity != 0) {
|
2010-08-29 01:34:27 -04:00
|
|
|
// We always hide the banner if the notification has additional content.
|
|
|
|
//
|
|
|
|
// We don't need to wrap the banner that doesn't fit the way we wrap the
|
|
|
|
// title that doesn't fit because we won't have a notification with
|
|
|
|
// row_count=1 that has a banner that doesn't fully fit. We'll either add
|
|
|
|
// that banner to the content of the notification in _bannerBoxAllocate()
|
|
|
|
// or the notification will have custom content.
|
|
|
|
if (animate)
|
|
|
|
Tweener.addTween(this._bannerLabel,
|
|
|
|
{ opacity: 0,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad' });
|
|
|
|
else
|
|
|
|
this._bannerLabel.opacity = 0;
|
|
|
|
}
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this.emit('expanded');
|
2010-02-01 12:10:38 -05:00
|
|
|
},
|
|
|
|
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
collapseCompleted: function() {
|
2011-03-02 19:47:58 -05:00
|
|
|
if (this._destroyed)
|
|
|
|
return;
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this.expanded = false;
|
2010-08-29 01:34:27 -04:00
|
|
|
// Make sure we don't line wrap the title, and ellipsize it instead.
|
|
|
|
this._titleLabel.clutter_text.line_wrap = false;
|
|
|
|
this._titleLabel.clutter_text.ellipsize = Pango.EllipsizeMode.END;
|
|
|
|
// Restore banner opacity in case the notification is shown in the
|
|
|
|
// banner mode again on update.
|
2010-08-29 00:04:33 -04:00
|
|
|
this._bannerLabel.opacity = 255;
|
2011-05-27 05:08:32 -04:00
|
|
|
this.emit('collapsed');
|
2010-02-22 17:19:32 -05:00
|
|
|
},
|
|
|
|
|
2011-02-08 02:06:42 -05:00
|
|
|
_onActionInvoked: function(actor, mouseButtonClicked, id) {
|
2010-12-16 15:49:47 -05:00
|
|
|
this.emit('action-invoked', id);
|
|
|
|
if (!this.resident) {
|
|
|
|
// We don't hide a resident notification when the user invokes one of its actions,
|
|
|
|
// because it is common for such notifications to update themselves with new
|
|
|
|
// information based on the action. We'd like to display the updated information
|
|
|
|
// in place, rather than pop-up a new notification.
|
|
|
|
this.emit('done-displaying');
|
|
|
|
this.destroy();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onClicked: function() {
|
|
|
|
this.emit('clicked');
|
|
|
|
// We hide all types of notifications once the user clicks on them because the common
|
|
|
|
// outcome of clicking should be the relevant window being brought forward and the user's
|
|
|
|
// attention switching to the window.
|
|
|
|
this.emit('done-displaying');
|
|
|
|
if (!this.resident)
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
|
2011-03-02 19:47:58 -05:00
|
|
|
_onDestroy: function() {
|
2011-01-30 18:33:49 -05:00
|
|
|
if (this._destroyed)
|
|
|
|
return;
|
|
|
|
this._destroyed = true;
|
2011-03-02 19:47:58 -05:00
|
|
|
if (!this._destroyedReason)
|
|
|
|
this._destroyedReason = NotificationDestroyedReason.DISMISSED;
|
|
|
|
this.emit('destroy', this._destroyedReason);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function(reason) {
|
|
|
|
this._destroyedReason = reason;
|
|
|
|
this.actor.destroy();
|
2011-03-21 17:43:34 -04:00
|
|
|
this.actor._delegate = null;
|
2010-01-13 15:05:20 -05:00
|
|
|
}
|
|
|
|
};
|
2010-02-01 15:41:22 -05:00
|
|
|
Signals.addSignalMethods(Notification.prototype);
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-08-05 13:09:27 -04:00
|
|
|
function Source(title) {
|
|
|
|
this._init(title);
|
2010-01-13 15:05:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Source.prototype = {
|
2010-08-05 13:09:27 -04:00
|
|
|
ICON_SIZE: 24,
|
|
|
|
|
|
|
|
_init: function(title) {
|
2010-06-23 15:20:39 -04:00
|
|
|
this.title = title;
|
2011-06-24 15:46:55 -04:00
|
|
|
|
|
|
|
this.actor = new Shell.GenericContainer();
|
|
|
|
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
|
|
|
|
this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
|
|
|
|
this.actor.connect('allocate', Lang.bind(this, this._allocate));
|
2011-07-12 19:18:58 -04:00
|
|
|
this.actor.connect('destroy', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._actorDestroyed = true;
|
|
|
|
}));
|
|
|
|
this._actorDestroyed = false;
|
2011-06-24 15:46:55 -04:00
|
|
|
|
|
|
|
this._counterLabel = new St.Label();
|
|
|
|
this._counterBin = new St.Bin({ style_class: 'summary-source-counter',
|
|
|
|
child: this._counterLabel });
|
|
|
|
this._counterBin.hide();
|
|
|
|
|
2010-08-05 13:09:27 -04:00
|
|
|
this._iconBin = new St.Bin({ width: this.ICON_SIZE,
|
2011-03-19 13:51:34 -04:00
|
|
|
height: this.ICON_SIZE,
|
|
|
|
x_fill: true,
|
|
|
|
y_fill: true });
|
2011-06-24 15:46:55 -04:00
|
|
|
|
|
|
|
this.actor.add_actor(this._iconBin);
|
|
|
|
this.actor.add_actor(this._counterBin);
|
|
|
|
|
2010-12-15 16:30:50 -05:00
|
|
|
this.isTransient = false;
|
2010-12-30 16:09:56 -05:00
|
|
|
this.isChat = false;
|
2011-03-21 17:43:34 -04:00
|
|
|
|
|
|
|
this.notifications = [];
|
2010-12-15 16:30:50 -05:00
|
|
|
},
|
|
|
|
|
2011-06-24 15:46:55 -04:00
|
|
|
_getPreferredWidth: function (actor, forHeight, alloc) {
|
|
|
|
let [min, nat] = this._iconBin.get_preferred_width(forHeight);
|
|
|
|
alloc.min_size = min; alloc.nat_size = nat;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getPreferredHeight: function (actor, forWidth, alloc) {
|
|
|
|
let [min, nat] = this._iconBin.get_preferred_height(forWidth);
|
|
|
|
alloc.min_size = min; alloc.nat_size = nat;
|
|
|
|
},
|
|
|
|
|
|
|
|
_allocate: function(actor, box, flags) {
|
|
|
|
// the iconBin should fill our entire box
|
|
|
|
this._iconBin.allocate(box, flags);
|
|
|
|
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
|
|
|
let [minWidth, minHeight, naturalWidth, naturalHeight] = this._counterBin.get_preferred_size();
|
|
|
|
let direction = this.actor.get_direction();
|
|
|
|
|
|
|
|
if (direction == St.TextDirection.LTR) {
|
|
|
|
// allocate on the right in LTR
|
|
|
|
childBox.x1 = box.x2 - naturalWidth;
|
|
|
|
childBox.x2 = box.x2;
|
|
|
|
} else {
|
|
|
|
// allocate on the left in RTL
|
|
|
|
childBox.x1 = 0;
|
|
|
|
childBox.x2 = naturalWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
childBox.y1 = box.y2 - naturalHeight;
|
|
|
|
childBox.y2 = box.y2;
|
|
|
|
|
|
|
|
this._counterBin.allocate(childBox, flags);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setCount: function(count, visible) {
|
2011-07-07 09:35:37 -04:00
|
|
|
if (isNaN(parseInt(count)))
|
2011-06-24 15:46:55 -04:00
|
|
|
throw new Error("Invalid notification count: " + count);
|
|
|
|
|
2011-07-13 16:23:03 -04:00
|
|
|
if (this._actorDestroyed)
|
|
|
|
return;
|
|
|
|
|
2011-06-24 15:46:55 -04:00
|
|
|
this._counterBin.visible = visible;
|
|
|
|
this._counterLabel.set_text(count.toString());
|
|
|
|
},
|
|
|
|
|
2011-06-24 15:47:24 -04:00
|
|
|
_updateCount: function() {
|
|
|
|
let count = this.notifications.length;
|
|
|
|
this._setCount(count, count > 1);
|
|
|
|
},
|
|
|
|
|
2010-12-15 16:30:50 -05:00
|
|
|
setTransient: function(isTransient) {
|
|
|
|
this.isTransient = isTransient;
|
2010-08-05 13:09:27 -04:00
|
|
|
},
|
|
|
|
|
2011-06-08 02:27:57 -04:00
|
|
|
setTitle: function(newTitle) {
|
|
|
|
this.title = newTitle;
|
|
|
|
this.emit('title-changed');
|
|
|
|
},
|
|
|
|
|
2010-08-05 13:09:27 -04:00
|
|
|
// Called to create a new icon actor (of size this.ICON_SIZE).
|
|
|
|
// Must be overridden by the subclass if you do not pass icons
|
|
|
|
// explicitly to the Notification() constructor.
|
|
|
|
createNotificationIcon: function() {
|
|
|
|
throw new Error('no implementation of createNotificationIcon in ' + this);
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2010-08-05 13:09:27 -04:00
|
|
|
// Unlike createNotificationIcon, this always returns the same actor;
|
|
|
|
// there is only one summary icon actor for a Source.
|
|
|
|
getSummaryIcon: function() {
|
2011-06-24 15:46:55 -04:00
|
|
|
return this.actor;
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2011-02-28 13:13:32 -05:00
|
|
|
pushNotification: function(notification) {
|
2011-03-21 17:43:34 -04:00
|
|
|
if (this.notifications.indexOf(notification) < 0) {
|
|
|
|
this.notifications.push(notification);
|
|
|
|
this.emit('notification-added', notification);
|
MessageTray: untangle click notifications
Previously, when you clicked on a notification, it would call
this.source.clicked(), which would emit a 'clicked' signal on the
source, and then various other stuff would happen from there. This
used to make a little bit of sense, when clicking on a notification
was supposed to do the same thing as clicking on its source, but makes
less sense now, when clicking on the source itself *doesn't* call
source.clicked()...
Change it so that when you click on a notification, the notification
emits 'clicked' itself, and the source notices that and calls its
notificationClicked() method, and the various source subclasses do
what they need to do with that, and Source no longer has a clicked
method/signal.
https://bugzilla.gnome.org/show_bug.cgi?id=631042
2010-09-30 16:41:38 -04:00
|
|
|
}
|
2010-02-25 14:42:18 -05:00
|
|
|
|
2011-03-21 17:43:34 -04:00
|
|
|
notification.connect('clicked', Lang.bind(this, this.open));
|
|
|
|
notification.connect('destroy', Lang.bind(this,
|
2010-02-25 14:42:18 -05:00
|
|
|
function () {
|
2011-03-21 17:43:34 -04:00
|
|
|
let index = this.notifications.indexOf(notification);
|
|
|
|
if (index < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.notifications.splice(index, 1);
|
|
|
|
if (this.notifications.length == 0)
|
|
|
|
this._lastNotificationRemoved();
|
2011-06-24 15:47:24 -04:00
|
|
|
|
|
|
|
this._updateCount();
|
2010-02-25 14:42:18 -05:00
|
|
|
}));
|
2011-06-24 15:47:24 -04:00
|
|
|
|
|
|
|
this._updateCount();
|
2011-02-28 13:13:32 -05:00
|
|
|
},
|
2010-02-25 14:42:18 -05:00
|
|
|
|
2011-02-28 13:13:32 -05:00
|
|
|
notify: function(notification) {
|
|
|
|
this.pushNotification(notification);
|
2010-02-01 15:23:49 -05:00
|
|
|
this.emit('notify', notification);
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2011-03-21 17:43:34 -04:00
|
|
|
destroy: function(reason) {
|
|
|
|
this.emit('destroy', reason);
|
2010-08-05 13:09:27 -04:00
|
|
|
},
|
|
|
|
|
2011-01-13 15:04:37 -05:00
|
|
|
// A subclass can redefine this to "steal" clicks from the
|
|
|
|
// summaryitem; Use Clutter.get_current_event() to get the
|
|
|
|
// details, return true to prevent the default handling from
|
|
|
|
// ocurring.
|
|
|
|
handleSummaryClick: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2010-08-05 13:09:27 -04:00
|
|
|
//// Protected methods ////
|
|
|
|
|
|
|
|
// The subclass must call this at least once to set the summary icon.
|
|
|
|
_setSummaryIcon: function(icon) {
|
|
|
|
if (this._iconBin.child)
|
|
|
|
this._iconBin.child.destroy();
|
|
|
|
this._iconBin.child = icon;
|
MessageTray: untangle click notifications
Previously, when you clicked on a notification, it would call
this.source.clicked(), which would emit a 'clicked' signal on the
source, and then various other stuff would happen from there. This
used to make a little bit of sense, when clicking on a notification
was supposed to do the same thing as clicking on its source, but makes
less sense now, when clicking on the source itself *doesn't* call
source.clicked()...
Change it so that when you click on a notification, the notification
emits 'clicked' itself, and the source notices that and calls its
notificationClicked() method, and the various source subclasses do
what they need to do with that, and Source no longer has a clicked
method/signal.
https://bugzilla.gnome.org/show_bug.cgi?id=631042
2010-09-30 16:41:38 -04:00
|
|
|
},
|
|
|
|
|
2010-12-16 15:49:47 -05:00
|
|
|
// Default implementation is to do nothing, but subclasses can override
|
2011-02-11 14:43:01 -05:00
|
|
|
open: function(notification) {
|
2010-12-16 15:49:47 -05:00
|
|
|
},
|
|
|
|
|
2011-03-21 17:43:34 -04:00
|
|
|
destroyNonResidentNotifications: function() {
|
|
|
|
for (let i = this.notifications.length - 1; i >= 0; i--)
|
|
|
|
if (!this.notifications[i].resident)
|
|
|
|
this.notifications[i].destroy();
|
2011-06-24 15:47:24 -04:00
|
|
|
|
|
|
|
this._updateCount();
|
2011-03-21 17:43:34 -04:00
|
|
|
},
|
|
|
|
|
2010-12-16 15:49:47 -05:00
|
|
|
// Default implementation is to destroy this source, but subclasses can override
|
2011-03-21 17:43:34 -04:00
|
|
|
_lastNotificationRemoved: function() {
|
2010-12-16 15:49:47 -05:00
|
|
|
this.destroy();
|
2010-01-13 15:05:20 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
Signals.addSignalMethods(Source.prototype);
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
function SummaryItem(source) {
|
|
|
|
this._init(source);
|
2010-06-23 15:20:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SummaryItem.prototype = {
|
2010-09-24 16:04:56 -04:00
|
|
|
_init: function(source) {
|
2010-06-23 15:20:39 -04:00
|
|
|
this.source = source;
|
2011-03-21 17:43:34 -04:00
|
|
|
this.source.connect('notification-added', Lang.bind(this, this._notificationAddedToSource));
|
|
|
|
|
2010-06-23 15:20:39 -04:00
|
|
|
this.actor = new St.Button({ style_class: 'summary-source-button',
|
2011-03-21 21:22:02 -04:00
|
|
|
y_fill: true,
|
2010-06-23 15:20:39 -04:00
|
|
|
reactive: true,
|
2011-01-13 15:04:37 -05:00
|
|
|
button_mask: St.ButtonMask.ONE | St.ButtonMask.TWO | St.ButtonMask.THREE,
|
2010-06-23 15:20:39 -04:00
|
|
|
track_hover: true });
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
this._sourceBox = new St.BoxLayout({ style_class: 'summary-source' });
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2010-08-05 13:09:27 -04:00
|
|
|
this._sourceIcon = source.getSummaryIcon();
|
2010-09-24 16:04:56 -04:00
|
|
|
this._sourceTitleBin = new St.Bin({ y_align: St.Align.MIDDLE,
|
|
|
|
x_fill: true,
|
|
|
|
clip_to_allocation: true });
|
2010-06-23 15:20:39 -04:00
|
|
|
this._sourceTitle = new St.Label({ style_class: 'source-title',
|
|
|
|
text: source.title });
|
|
|
|
this._sourceTitle.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
|
|
|
|
this._sourceTitleBin.child = this._sourceTitle;
|
2010-09-24 16:04:56 -04:00
|
|
|
this._sourceTitleBin.width = 0;
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2011-06-08 02:27:57 -04:00
|
|
|
this.source.connect('title-changed',
|
|
|
|
Lang.bind(this, function() {
|
|
|
|
this._sourceTitle.text = source.title;
|
|
|
|
}));
|
|
|
|
|
2011-03-21 21:22:02 -04:00
|
|
|
this._sourceBox.add(this._sourceIcon, { y_fill: false });
|
|
|
|
this._sourceBox.add(this._sourceTitleBin, { expand: true, y_fill: false });
|
2010-06-23 15:20:39 -04:00
|
|
|
this.actor.child = this._sourceBox;
|
2011-03-21 17:43:34 -04:00
|
|
|
|
2011-03-22 03:40:53 -04:00
|
|
|
this.notificationStackView = new St.ScrollView({ name: source.isChat ? '' : 'summary-notification-stack-scrollview',
|
|
|
|
vscrollbar_policy: source.isChat ? Gtk.PolicyType.NEVER : Gtk.PolicyType.AUTOMATIC,
|
|
|
|
hscrollbar_policy: Gtk.PolicyType.NEVER,
|
2011-06-03 17:44:57 -04:00
|
|
|
style_class: 'vfade' });
|
2011-03-21 17:43:34 -04:00
|
|
|
this.notificationStack = new St.BoxLayout({ name: 'summary-notification-stack',
|
|
|
|
vertical: true });
|
2011-03-22 03:40:53 -04:00
|
|
|
this.notificationStackView.add_actor(this.notificationStack);
|
2011-09-08 00:40:58 -04:00
|
|
|
this._stackedNotifications = [];
|
2011-03-21 17:43:34 -04:00
|
|
|
|
2011-03-22 03:40:53 -04:00
|
|
|
this._oldMaxScrollAdjustment = 0;
|
|
|
|
|
|
|
|
this.notificationStackView.vscroll.adjustment.connect('changed', Lang.bind(this, function(adjustment) {
|
|
|
|
let currentValue = adjustment.value + adjustment.page_size;
|
|
|
|
if (currentValue == this._oldMaxScrollAdjustment)
|
|
|
|
this.scrollTo(St.Side.BOTTOM);
|
|
|
|
this._oldMaxScrollAdjustment = adjustment.upper;
|
|
|
|
}));
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
this.rightClickMenu = new St.BoxLayout({ name: 'summary-right-click-menu',
|
|
|
|
vertical: true });
|
|
|
|
|
|
|
|
let item;
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Open"));
|
|
|
|
item.connect('activate', Lang.bind(this, function() {
|
|
|
|
source.open();
|
2011-03-21 17:43:34 -04:00
|
|
|
this.emit('done-displaying-content');
|
2011-02-11 14:43:01 -05:00
|
|
|
}));
|
|
|
|
this.rightClickMenu.add(item.actor);
|
|
|
|
|
|
|
|
item = new PopupMenu.PopupMenuItem(_("Remove"));
|
|
|
|
item.connect('activate', Lang.bind(this, function() {
|
|
|
|
source.destroy();
|
2011-03-21 17:43:34 -04:00
|
|
|
this.emit('done-displaying-content');
|
2011-02-11 14:43:01 -05:00
|
|
|
}));
|
|
|
|
this.rightClickMenu.add(item.actor);
|
|
|
|
|
|
|
|
let focusManager = St.FocusManager.get_for_stage(global.stage);
|
|
|
|
focusManager.add_group(this.rightClickMenu);
|
2010-06-23 15:20:39 -04:00
|
|
|
},
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
// getTitleNaturalWidth, getTitleWidth, and setTitleWidth include
|
|
|
|
// the spacing between the icon and title (which is actually
|
|
|
|
// _sourceTitle's padding-left) as part of the width.
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
getTitleNaturalWidth: function() {
|
|
|
|
let [minWidth, naturalWidth] = this._sourceTitle.get_preferred_width(-1);
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
return Math.min(naturalWidth, MAX_SOURCE_TITLE_WIDTH);
|
2010-06-23 15:20:39 -04:00
|
|
|
},
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
getTitleWidth: function() {
|
|
|
|
return this._sourceTitleBin.width;
|
2010-06-23 15:20:39 -04:00
|
|
|
},
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
setTitleWidth: function(width) {
|
|
|
|
width = Math.round(width);
|
|
|
|
if (width != this._sourceTitleBin.width)
|
|
|
|
this._sourceTitleBin.width = width;
|
2010-06-23 15:20:39 -04:00
|
|
|
},
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
setEllipsization: function(mode) {
|
|
|
|
this._sourceTitle.clutter_text.ellipsize = mode;
|
2011-03-21 17:43:34 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
prepareNotificationStackForShowing: function() {
|
|
|
|
if (this.notificationStack.get_children().length > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (let i = 0; i < this.source.notifications.length; i++) {
|
|
|
|
this._appendNotificationToStack(this.source.notifications[i]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
doneShowingNotificationStack: function() {
|
|
|
|
let notificationActors = this.notificationStack.get_children();
|
2011-09-08 00:40:58 -04:00
|
|
|
for (let i = 0; i < this._stackedNotifications.length; i++) {
|
|
|
|
let stackedNotification = this._stackedNotifications[i];
|
|
|
|
let notification = stackedNotification.notification;
|
|
|
|
notification.collapseCompleted();
|
|
|
|
notification.disconnect(stackedNotification.notificationExpandedId);
|
|
|
|
notification.disconnect(stackedNotification.notificationDoneDisplayingId);
|
|
|
|
notification.disconnect(stackedNotification.notificationDestroyedId);
|
|
|
|
if (notification.actor.get_parent() == this.notificationStack)
|
|
|
|
this.notificationStack.remove_actor(notification.actor);
|
|
|
|
notification.setIconVisible(true);
|
|
|
|
notification.enableScrolling(true);
|
2011-03-21 17:43:34 -04:00
|
|
|
}
|
2011-09-08 00:40:58 -04:00
|
|
|
this._stackedNotifications = [];
|
2011-03-21 17:43:34 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_notificationAddedToSource: function(source, notification) {
|
|
|
|
if (this.notificationStack.mapped)
|
|
|
|
this._appendNotificationToStack(notification);
|
|
|
|
},
|
|
|
|
|
|
|
|
_appendNotificationToStack: function(notification) {
|
2011-09-08 00:40:58 -04:00
|
|
|
let stackedNotification = {};
|
|
|
|
stackedNotification.notification = notification;
|
|
|
|
stackedNotification.notificationExpandedId = notification.connect('expanded', Lang.bind(this, this._contentUpdated));
|
|
|
|
stackedNotification.notificationDoneDisplayingId = notification.connect('done-displaying', Lang.bind(this, this._notificationDoneDisplaying));
|
|
|
|
stackedNotification.notificationDestroyedId = notification.connect('destroy', Lang.bind(this, this._notificationDestroyed));
|
|
|
|
this._stackedNotifications.push(stackedNotification);
|
2011-03-22 03:40:53 -04:00
|
|
|
if (!this.source.isChat)
|
|
|
|
notification.enableScrolling(false);
|
2011-03-21 17:43:34 -04:00
|
|
|
if (this.notificationStack.get_children().length > 0)
|
|
|
|
notification.setIconVisible(false);
|
|
|
|
this.notificationStack.add(notification.actor);
|
|
|
|
notification.expand(false);
|
|
|
|
},
|
|
|
|
|
2011-03-22 03:40:53 -04:00
|
|
|
// scrollTo:
|
|
|
|
// @side: St.Side.TOP or St.Side.BOTTOM
|
|
|
|
//
|
|
|
|
// Scrolls the notifiction stack to the indicated edge
|
|
|
|
scrollTo: function(side) {
|
|
|
|
let adjustment = this.notificationStackView.vscroll.adjustment;
|
|
|
|
if (side == St.Side.TOP)
|
|
|
|
adjustment.value = adjustment.lower;
|
|
|
|
else if (side == St.Side.BOTTOM)
|
|
|
|
adjustment.value = adjustment.upper;
|
|
|
|
},
|
|
|
|
|
2011-03-21 17:43:34 -04:00
|
|
|
_contentUpdated: function() {
|
|
|
|
this.emit('content-updated');
|
|
|
|
},
|
|
|
|
|
|
|
|
_notificationDoneDisplaying: function() {
|
|
|
|
this.emit('done-displaying-content');
|
|
|
|
},
|
|
|
|
|
|
|
|
_notificationDestroyed: function(notification) {
|
2011-09-08 00:40:58 -04:00
|
|
|
for (let i = 0; i < this._stackedNotifications.length; i++) {
|
|
|
|
if (this._stackedNotifications[i].notification == notification) {
|
|
|
|
let stackedNotification = this._stackedNotifications[i];
|
|
|
|
notification.disconnect(stackedNotification.notificationExpandedId);
|
|
|
|
notification.disconnect(stackedNotification.notificationDoneDisplayingId);
|
|
|
|
notification.disconnect(stackedNotification.notificationDestroyedId);
|
|
|
|
this._stackedNotifications.splice(i, 1);
|
|
|
|
this._contentUpdated();
|
|
|
|
break;
|
|
|
|
}
|
2011-03-21 17:43:34 -04:00
|
|
|
}
|
2011-09-08 00:40:58 -04:00
|
|
|
|
2011-03-21 17:43:34 -04:00
|
|
|
if (this.notificationStack.get_children().length > 0)
|
|
|
|
this.notificationStack.get_children()[0]._delegate.setIconVisible(true);
|
2010-06-23 15:20:39 -04:00
|
|
|
}
|
|
|
|
};
|
2011-02-11 14:43:01 -05:00
|
|
|
Signals.addSignalMethods(SummaryItem.prototype);
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2010-01-13 15:05:20 -05:00
|
|
|
function MessageTray() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageTray.prototype = {
|
|
|
|
_init: function() {
|
2011-02-19 10:49:56 -05:00
|
|
|
this._presence = new GnomeSession.Presence();
|
|
|
|
this._userStatus = GnomeSession.PresenceStatus.AVAILABLE;
|
|
|
|
this._busy = false;
|
|
|
|
this._backFromAway = false;
|
|
|
|
this._presence.connect('StatusChanged', Lang.bind(this, this._onStatusChanged));
|
|
|
|
this._presence.getStatus(Lang.bind(this, this._onStatusChanged));
|
|
|
|
|
2010-03-21 20:39:49 -04:00
|
|
|
this.actor = new St.Group({ name: 'message-tray',
|
|
|
|
reactive: true,
|
|
|
|
track_hover: true });
|
2010-03-15 12:20:10 -04:00
|
|
|
this.actor.connect('notify::hover', Lang.bind(this, this._onTrayHoverChanged));
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-04-08 14:36:20 -04:00
|
|
|
this._notificationBin = new St.Bin();
|
2010-03-21 20:39:49 -04:00
|
|
|
this.actor.add_actor(this._notificationBin);
|
2010-01-28 12:04:26 -05:00
|
|
|
this._notificationBin.hide();
|
2010-01-13 15:05:20 -05:00
|
|
|
this._notificationQueue = [];
|
2010-02-01 15:23:49 -05:00
|
|
|
this._notification = null;
|
2010-12-16 15:49:47 -05:00
|
|
|
this._notificationClickedId = 0;
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2011-01-07 11:59:20 -05:00
|
|
|
this._summaryBin = new St.Bin({ x_align: St.Align.END });
|
2010-03-21 20:39:49 -04:00
|
|
|
this.actor.add_actor(this._summaryBin);
|
2010-02-09 13:31:39 -05:00
|
|
|
this._summary = new St.BoxLayout({ name: 'summary-mode',
|
2010-03-15 12:20:10 -04:00
|
|
|
reactive: true,
|
|
|
|
track_hover: true });
|
|
|
|
this._summary.connect('notify::hover', Lang.bind(this, this._onSummaryHoverChanged));
|
|
|
|
this._summaryBin.child = this._summary;
|
2010-02-11 15:39:43 -05:00
|
|
|
this._summaryBin.opacity = 0;
|
2010-02-09 13:31:39 -05:00
|
|
|
|
2010-10-19 15:17:36 -04:00
|
|
|
this._summaryMotionId = 0;
|
2011-09-09 09:45:39 -04:00
|
|
|
this._trayMotionId = 0;
|
2010-10-19 15:17:36 -04:00
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointer = new BoxPointer.BoxPointer(St.Side.BOTTOM,
|
2011-07-27 10:03:30 -04:00
|
|
|
{ reactive: true,
|
|
|
|
track_hover: true });
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointer.actor.style_class = 'summary-boxpointer';
|
|
|
|
this._summaryBoxPointer.actor.hide();
|
2011-07-25 09:53:19 -04:00
|
|
|
Main.layoutManager.addChrome(this._summaryBoxPointer.actor, { visibleInFullscreen: true });
|
2010-10-19 15:17:36 -04:00
|
|
|
|
2011-03-21 17:43:34 -04:00
|
|
|
this._summaryBoxPointerItem = null;
|
|
|
|
this._summaryBoxPointerContentUpdatedId = 0;
|
|
|
|
this._summaryBoxPointerDoneDisplayingId = 0;
|
2010-06-23 15:20:39 -04:00
|
|
|
this._clickedSummaryItem = null;
|
2011-02-11 14:43:01 -05:00
|
|
|
this._clickedSummaryItemMouseButton = -1;
|
2010-10-19 15:17:36 -04:00
|
|
|
this._clickedSummaryItemAllocationChangedId = 0;
|
2010-09-24 16:04:56 -04:00
|
|
|
this._expandedSummaryItem = null;
|
|
|
|
this._summaryItemTitleWidth = 0;
|
2011-03-18 08:27:06 -04:00
|
|
|
this._pointerBarrier = 0;
|
2010-09-24 16:04:56 -04:00
|
|
|
|
|
|
|
// To simplify the summary item animation code, we pretend
|
|
|
|
// that there's an invisible SummaryItem to the left of the
|
|
|
|
// leftmost real summary item, and that it's expanded when all
|
|
|
|
// of the other items are collapsed.
|
|
|
|
this._imaginarySummaryItemTitleWidth = 0;
|
2010-02-25 14:42:18 -05:00
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
this._focusGrabber = new FocusGrabber();
|
|
|
|
this._focusGrabber.connect('focus-grabbed', Lang.bind(this,
|
|
|
|
function() {
|
2011-02-11 14:43:01 -05:00
|
|
|
if (this._summaryBoxPointer.bin.child)
|
2011-02-09 22:45:50 -05:00
|
|
|
this._lock();
|
|
|
|
}));
|
|
|
|
this._focusGrabber.connect('focus-ungrabbed', Lang.bind(this, this._unlock));
|
2011-02-15 18:37:33 -05:00
|
|
|
this._focusGrabber.connect('button-pressed', Lang.bind(this,
|
|
|
|
function(focusGrabber, source) {
|
|
|
|
if (this._clickedSummaryItem && !this._clickedSummaryItem.actor.contains(source))
|
|
|
|
this._unsetClickedSummaryItem();
|
|
|
|
this._focusGrabber.ungrabFocus();
|
|
|
|
}));
|
2011-02-09 22:45:50 -05:00
|
|
|
this._focusGrabber.connect('escape-pressed', Lang.bind(this, this._escapeTray));
|
|
|
|
|
2011-09-09 10:56:51 -04:00
|
|
|
Main.layoutManager.keyboardBox.connect('notify::hover', Lang.bind(this, this._onKeyboardHoverChanged));
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._trayState = State.HIDDEN;
|
2010-07-21 00:42:37 -04:00
|
|
|
this._locked = false;
|
2011-08-29 11:11:22 -04:00
|
|
|
this._traySummoned = false;
|
2010-08-31 15:50:18 -04:00
|
|
|
this._useLongerTrayLeftTimeout = false;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._trayLeftTimeoutId = 0;
|
|
|
|
this._pointerInTray = false;
|
2011-09-09 10:56:51 -04:00
|
|
|
this._pointerInKeyboard = false;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._summaryState = State.HIDDEN;
|
|
|
|
this._summaryTimeoutId = 0;
|
|
|
|
this._pointerInSummary = false;
|
|
|
|
this._notificationState = State.HIDDEN;
|
|
|
|
this._notificationTimeoutId = 0;
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._notificationExpandedId = 0;
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointerState = State.HIDDEN;
|
2011-03-21 17:43:34 -04:00
|
|
|
this._summaryBoxPointerTimeoutId = 0;
|
2010-07-21 01:19:25 -04:00
|
|
|
this._overviewVisible = Main.overview.visible;
|
2010-02-22 17:19:32 -05:00
|
|
|
this._notificationRemoved = false;
|
2011-03-21 17:43:34 -04:00
|
|
|
this._reNotifyAfterHideNotification = null;
|
2010-02-09 13:31:39 -05:00
|
|
|
|
2011-07-25 14:25:51 -04:00
|
|
|
Main.layoutManager.trayBox.add_actor(this.actor);
|
|
|
|
this.actor.y = -1;
|
|
|
|
Main.layoutManager.trackChrome(this.actor);
|
2011-07-25 09:53:19 -04:00
|
|
|
Main.layoutManager.trackChrome(this._notificationBin);
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2011-06-13 09:54:05 -04:00
|
|
|
Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._setSizePosition));
|
2010-06-03 11:14:58 -04:00
|
|
|
|
2010-01-28 12:04:26 -05:00
|
|
|
this._setSizePosition();
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-02-18 19:42:09 -05:00
|
|
|
Main.overview.connect('showing', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._overviewVisible = true;
|
2011-02-15 18:37:33 -05:00
|
|
|
if (this._locked) {
|
|
|
|
this._unsetClickedSummaryItem();
|
2011-02-09 22:45:50 -05:00
|
|
|
this._unlock();
|
2011-02-15 18:37:33 -05:00
|
|
|
} else {
|
2010-07-21 01:19:25 -04:00
|
|
|
this._updateState();
|
2011-02-15 18:37:33 -05:00
|
|
|
}
|
2010-02-18 19:42:09 -05:00
|
|
|
}));
|
|
|
|
Main.overview.connect('hiding', Lang.bind(this,
|
|
|
|
function() {
|
|
|
|
this._overviewVisible = false;
|
2011-02-15 18:37:33 -05:00
|
|
|
if (this._locked) {
|
|
|
|
this._unsetClickedSummaryItem();
|
2011-02-09 22:45:50 -05:00
|
|
|
this._unlock();
|
2011-02-15 18:37:33 -05:00
|
|
|
} else {
|
2010-07-21 01:19:25 -04:00
|
|
|
this._updateState();
|
2011-02-15 18:37:33 -05:00
|
|
|
}
|
2010-02-18 19:42:09 -05:00
|
|
|
}));
|
2010-02-12 12:33:00 -05:00
|
|
|
|
2010-08-09 13:18:15 -04:00
|
|
|
this._summaryItems = [];
|
2010-09-30 17:02:16 -04:00
|
|
|
// We keep a list of new summary items that were added to the summary since the last
|
|
|
|
// time it was shown to the user. We automatically show the summary to the user if there
|
|
|
|
// are items in this list once the notifications are done showing or once an item gets
|
|
|
|
// added to the summary without a notification being shown.
|
|
|
|
this._newSummaryItems = [];
|
2010-06-23 15:20:39 -04:00
|
|
|
this._longestSummaryItem = null;
|
2010-12-30 16:09:56 -05:00
|
|
|
this._chatSummaryItemsCount = 0;
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2010-01-25 13:28:35 -05:00
|
|
|
_setSizePosition: function() {
|
2011-06-13 10:37:10 -04:00
|
|
|
let monitor = Main.layoutManager.bottomMonitor;
|
2010-04-08 14:36:20 -04:00
|
|
|
this._notificationBin.x = 0;
|
2011-06-13 10:37:10 -04:00
|
|
|
this._notificationBin.width = monitor.width;
|
2011-01-07 11:59:20 -05:00
|
|
|
this._summaryBin.x = 0;
|
2011-06-13 10:37:10 -04:00
|
|
|
this._summaryBin.width = monitor.width;
|
2010-01-25 13:28:35 -05:00
|
|
|
},
|
|
|
|
|
2010-01-13 15:05:20 -05:00
|
|
|
contains: function(source) {
|
2010-08-09 13:18:15 -04:00
|
|
|
return this._getIndexOfSummaryItemForSource(source) >= 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getIndexOfSummaryItemForSource: function(source) {
|
|
|
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
|
|
|
if (this._summaryItems[i].source == source)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
add: function(source) {
|
|
|
|
if (this.contains(source)) {
|
2010-08-09 13:18:15 -04:00
|
|
|
log('Trying to re-add source ' + source.title);
|
2010-01-13 15:05:20 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
let summaryItem = new SummaryItem(source);
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2010-12-30 16:09:56 -05:00
|
|
|
if (source.isChat) {
|
|
|
|
this._summary.insert_actor(summaryItem.actor, 0);
|
|
|
|
this._chatSummaryItemsCount++;
|
|
|
|
} else {
|
|
|
|
this._summary.insert_actor(summaryItem.actor, this._chatSummaryItemsCount);
|
|
|
|
}
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
let titleWidth = summaryItem.getTitleNaturalWidth();
|
|
|
|
if (titleWidth > this._summaryItemTitleWidth) {
|
|
|
|
this._summaryItemTitleWidth = titleWidth;
|
|
|
|
if (!this._expandedSummaryItem)
|
|
|
|
this._imaginarySummaryItemTitleWidth = titleWidth;
|
2010-06-23 15:20:39 -04:00
|
|
|
this._longestSummaryItem = summaryItem;
|
|
|
|
}
|
|
|
|
|
2010-08-09 13:18:15 -04:00
|
|
|
this._summaryItems.push(summaryItem);
|
2010-12-15 16:30:50 -05:00
|
|
|
|
|
|
|
// We keep this._newSummaryItems to track any new sources that were added to the
|
|
|
|
// summary and show the summary with them to the user for a short period of time
|
|
|
|
// after notifications are done showing. However, we don't want that to happen for
|
|
|
|
// transient sources, which are removed after the notification is shown, but are
|
|
|
|
// not removed fast enough because of the callbacks to avoid the summary popping up.
|
2011-09-15 05:27:11 -04:00
|
|
|
// So we just don't add transient sources to this._newSummaryItems.
|
|
|
|
// We don't want that to happen for chat sources neither, because they
|
|
|
|
// can be added when the user starts a chat from Empathy and they are not transient.
|
|
|
|
// The notification will popup on incoming message anyway. See bug #657249.
|
|
|
|
if (!source.isTransient && !source.isChat)
|
2010-12-15 16:30:50 -05:00
|
|
|
this._newSummaryItems.push(summaryItem);
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-01-28 13:12:03 -05:00
|
|
|
source.connect('notify', Lang.bind(this, this._onNotify));
|
|
|
|
|
2010-06-23 15:20:39 -04:00
|
|
|
summaryItem.actor.connect('notify::hover', Lang.bind(this,
|
2010-02-25 14:42:18 -05:00
|
|
|
function () {
|
2010-06-23 15:20:39 -04:00
|
|
|
this._onSummaryItemHoverChanged(summaryItem);
|
2010-02-25 14:42:18 -05:00
|
|
|
}));
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2011-01-13 15:04:37 -05:00
|
|
|
summaryItem.actor.connect('clicked', Lang.bind(this,
|
|
|
|
function (actor, button) {
|
|
|
|
this._onSummaryItemClicked(summaryItem, button);
|
2010-01-13 15:05:20 -05:00
|
|
|
}));
|
|
|
|
|
2011-03-02 19:47:58 -05:00
|
|
|
source.connect('destroy', Lang.bind(this, this._onSourceDestroy));
|
2010-09-09 16:18:07 -04:00
|
|
|
|
|
|
|
// We need to display the newly-added summary item, but if the
|
|
|
|
// caller is about to post a notification, we want to show that
|
|
|
|
// *first* and not show the summary item until after it hides.
|
|
|
|
// So postpone calling _updateState() a tiny bit.
|
|
|
|
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() { this._updateState(); return false; }));
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2011-03-02 19:47:58 -05:00
|
|
|
_onSourceDestroy: function(source) {
|
2010-08-09 13:18:15 -04:00
|
|
|
let index = this._getIndexOfSummaryItemForSource(source);
|
|
|
|
if (index == -1)
|
2010-01-13 15:05:20 -05:00
|
|
|
return;
|
|
|
|
|
2011-03-06 16:29:11 -05:00
|
|
|
let summaryItemToRemove = this._summaryItems[index];
|
2010-06-23 15:20:39 -04:00
|
|
|
|
2010-09-30 17:02:16 -04:00
|
|
|
let newSummaryItemsIndex = this._newSummaryItems.indexOf(this._summaryItems[index]);
|
|
|
|
if (newSummaryItemsIndex != -1)
|
|
|
|
this._newSummaryItems.splice(newSummaryItemsIndex, 1);
|
|
|
|
|
2010-08-09 13:18:15 -04:00
|
|
|
this._summaryItems.splice(index, 1);
|
2010-12-30 16:09:56 -05:00
|
|
|
|
|
|
|
if (source.isChat)
|
|
|
|
this._chatSummaryItemsCount--;
|
|
|
|
|
2011-03-06 16:29:11 -05:00
|
|
|
if (this._expandedSummaryItem == summaryItemToRemove)
|
|
|
|
this._expandedSummaryItem = null;
|
|
|
|
|
2010-06-23 15:20:39 -04:00
|
|
|
if (this._longestSummaryItem.source == source) {
|
2010-09-24 16:04:56 -04:00
|
|
|
let newTitleWidth = 0;
|
2010-06-23 15:20:39 -04:00
|
|
|
this._longestSummaryItem = null;
|
2010-08-09 13:18:15 -04:00
|
|
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
|
|
|
let summaryItem = this._summaryItems[i];
|
2010-09-24 16:04:56 -04:00
|
|
|
let titleWidth = summaryItem.getTitleNaturalWidth();
|
|
|
|
if (titleWidth > newTitleWidth) {
|
|
|
|
newTitleWidth = titleWidth;
|
2010-06-23 15:20:39 -04:00
|
|
|
this._longestSummaryItem = summaryItem;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 16:04:56 -04:00
|
|
|
|
|
|
|
this._summaryItemTitleWidth = newTitleWidth;
|
|
|
|
if (!this._expandedSummaryItem)
|
|
|
|
this._imaginarySummaryItemTitleWidth = newTitleWidth;
|
2010-06-23 15:20:39 -04:00
|
|
|
}
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
|
2010-02-25 14:42:18 -05:00
|
|
|
let needUpdate = false;
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
if (this._notification && this._notification.source == source) {
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updateNotificationTimeout(0);
|
2010-02-22 17:19:32 -05:00
|
|
|
this._notificationRemoved = true;
|
2010-02-25 14:42:18 -05:00
|
|
|
needUpdate = true;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
}
|
2011-03-06 16:29:11 -05:00
|
|
|
if (this._clickedSummaryItem == summaryItemToRemove) {
|
2010-10-19 15:17:36 -04:00
|
|
|
this._unsetClickedSummaryItem();
|
2010-02-25 14:42:18 -05:00
|
|
|
needUpdate = true;
|
|
|
|
}
|
|
|
|
|
2011-03-06 16:29:11 -05:00
|
|
|
summaryItemToRemove.actor.destroy();
|
|
|
|
|
2011-10-07 16:22:08 -04:00
|
|
|
if (needUpdate)
|
2010-02-25 14:42:18 -05:00
|
|
|
this._updateState();
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2011-03-02 19:47:58 -05:00
|
|
|
_onNotificationDestroy: function(notification) {
|
2010-02-22 17:19:32 -05:00
|
|
|
if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) {
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updateNotificationTimeout(0);
|
2010-02-22 17:19:32 -05:00
|
|
|
this._notificationRemoved = true;
|
|
|
|
this._updateState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let index = this._notificationQueue.indexOf(notification);
|
2011-03-02 19:47:58 -05:00
|
|
|
notification.destroy();
|
2010-02-22 17:19:32 -05:00
|
|
|
if (index != -1)
|
|
|
|
this._notificationQueue.splice(index, 1);
|
|
|
|
},
|
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
_lock: function() {
|
2010-02-22 14:23:36 -05:00
|
|
|
this._locked = true;
|
|
|
|
},
|
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
_unlock: function() {
|
2010-07-21 01:19:25 -04:00
|
|
|
if (!this._locked)
|
|
|
|
return;
|
2010-02-22 14:23:36 -05:00
|
|
|
this._locked = false;
|
2011-07-27 10:03:30 -04:00
|
|
|
this._pointerInTray = this.actor.hover;
|
2010-02-22 14:23:36 -05:00
|
|
|
this._updateState();
|
|
|
|
},
|
|
|
|
|
2011-08-29 11:11:22 -04:00
|
|
|
toggle: function() {
|
|
|
|
this._traySummoned = !this._traySummoned;
|
|
|
|
this._updateState();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this._traySummoned = false;
|
|
|
|
this.actor.set_hover(false);
|
|
|
|
this._summary.set_hover(false);
|
|
|
|
this._updateState();
|
|
|
|
},
|
|
|
|
|
2010-02-01 15:23:49 -05:00
|
|
|
_onNotify: function(source, notification) {
|
2011-03-21 17:43:34 -04:00
|
|
|
if (this._summaryBoxPointerItem && this._summaryBoxPointerItem.source == source) {
|
|
|
|
if (this._summaryBoxPointerState == State.HIDING)
|
|
|
|
// We are in the process of hiding the summary box pointer.
|
|
|
|
// If there is an update for one of the notifications or
|
|
|
|
// a new notification to be added to the notification stack
|
|
|
|
// while it is in the process of being hidden, we show it as
|
|
|
|
// a new notification. However, we first wait till the hide
|
|
|
|
// is complete. This is especially important if one of the
|
|
|
|
// notifications in the stack was updated because we will
|
|
|
|
// need to be able to re-parent its actor to a different
|
|
|
|
// part of the stage.
|
|
|
|
this._reNotifyAfterHideNotification = notification;
|
2010-04-07 15:32:47 -04:00
|
|
|
return;
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
}
|
2010-04-07 15:32:47 -04:00
|
|
|
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
if (this._notification == notification) {
|
|
|
|
// If a notification that is being shown is updated, we update
|
|
|
|
// how it is shown and extend the time until it auto-hides.
|
|
|
|
// If a new notification is updated while it is being hidden,
|
|
|
|
// we stop hiding it and show it again.
|
|
|
|
this._updateShowingNotification();
|
|
|
|
} else if (this._notificationQueue.indexOf(notification) < 0) {
|
2010-02-22 17:19:32 -05:00
|
|
|
notification.connect('destroy',
|
2011-03-02 19:47:58 -05:00
|
|
|
Lang.bind(this, this._onNotificationDestroy));
|
2011-01-04 04:34:57 -05:00
|
|
|
this._notificationQueue.push(notification);
|
|
|
|
this._notificationQueue.sort(function(notification1, notification2) {
|
|
|
|
return (notification2.urgency - notification1.urgency);
|
|
|
|
});
|
2010-02-22 17:19:32 -05:00
|
|
|
}
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._updateState();
|
2010-01-28 13:12:03 -05:00
|
|
|
},
|
|
|
|
|
2010-06-23 15:20:39 -04:00
|
|
|
_onSummaryItemHoverChanged: function(summaryItem) {
|
2011-02-04 19:13:10 -05:00
|
|
|
if (summaryItem.actor.hover)
|
|
|
|
this._setExpandedSummaryItem(summaryItem);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setExpandedSummaryItem: function(summaryItem) {
|
|
|
|
if (summaryItem == this._expandedSummaryItem)
|
|
|
|
return;
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
// We can't just animate individual summary items as the
|
|
|
|
// pointer moves in and out of them, because if they don't
|
|
|
|
// move in sync you get weird-looking wobbling. So whenever
|
|
|
|
// there's a change, we have to re-tween the entire summary
|
|
|
|
// area.
|
|
|
|
|
2011-02-04 19:13:10 -05:00
|
|
|
// Turn off ellipsization for the previously expanded item that is
|
|
|
|
// collapsing and for the item that is expanding because it looks
|
|
|
|
// better that way.
|
2011-03-21 21:22:02 -04:00
|
|
|
if (this._expandedSummaryItem) {
|
|
|
|
// Ideally, we would remove 'expanded' pseudo class when the item
|
|
|
|
// is done collapsing, but we don't track when that happens.
|
|
|
|
this._expandedSummaryItem.actor.remove_style_pseudo_class('expanded');
|
2011-02-04 19:13:10 -05:00
|
|
|
this._expandedSummaryItem.setEllipsization(Pango.EllipsizeMode.NONE);
|
2011-03-21 21:22:02 -04:00
|
|
|
}
|
2010-09-24 16:04:56 -04:00
|
|
|
|
2011-02-04 19:13:10 -05:00
|
|
|
this._expandedSummaryItem = summaryItem;
|
2011-03-21 21:22:02 -04:00
|
|
|
if (this._expandedSummaryItem) {
|
|
|
|
this._expandedSummaryItem.actor.add_style_pseudo_class('expanded');
|
2011-02-04 19:13:10 -05:00
|
|
|
this._expandedSummaryItem.setEllipsization(Pango.EllipsizeMode.NONE);
|
2011-03-21 21:22:02 -04:00
|
|
|
}
|
2010-09-24 16:04:56 -04:00
|
|
|
|
|
|
|
// We tween on a "_expandedSummaryItemTitleWidth" pseudo-property
|
|
|
|
// that represents the current title width of the
|
|
|
|
// expanded/expanding item, or the width of the imaginary
|
|
|
|
// invisible item if we're collapsing everything.
|
|
|
|
Tweener.addTween(this,
|
|
|
|
{ _expandedSummaryItemTitleWidth: this._summaryItemTitleWidth,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: this._expandSummaryItemCompleted,
|
|
|
|
onCompleteScope: this });
|
|
|
|
},
|
|
|
|
|
|
|
|
get _expandedSummaryItemTitleWidth() {
|
|
|
|
if (this._expandedSummaryItem)
|
|
|
|
return this._expandedSummaryItem.getTitleWidth();
|
|
|
|
else
|
|
|
|
return this._imaginarySummaryItemTitleWidth;
|
|
|
|
},
|
|
|
|
|
|
|
|
set _expandedSummaryItemTitleWidth(expansion) {
|
2011-03-07 14:04:03 -05:00
|
|
|
expansion = Math.round(expansion);
|
|
|
|
|
2010-09-24 16:04:56 -04:00
|
|
|
// Expand the expanding item to its new width
|
|
|
|
if (this._expandedSummaryItem)
|
|
|
|
this._expandedSummaryItem.setTitleWidth(expansion);
|
2010-06-23 15:20:39 -04:00
|
|
|
else
|
2010-09-24 16:04:56 -04:00
|
|
|
this._imaginarySummaryItemTitleWidth = expansion;
|
|
|
|
|
|
|
|
// Figure out how much space the other items are currently
|
|
|
|
// using, and how much they need to be shrunk to keep the
|
|
|
|
// total width (including the width of the imaginary item)
|
|
|
|
// constant.
|
|
|
|
let excess = this._summaryItemTitleWidth - expansion;
|
|
|
|
let oldExcess = 0, shrinkage;
|
|
|
|
if (excess) {
|
|
|
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
|
|
|
if (this._summaryItems[i] != this._expandedSummaryItem)
|
|
|
|
oldExcess += this._summaryItems[i].getTitleWidth();
|
|
|
|
}
|
|
|
|
if (this._expandedSummaryItem)
|
|
|
|
oldExcess += this._imaginarySummaryItemTitleWidth;
|
|
|
|
}
|
|
|
|
if (excess && oldExcess)
|
|
|
|
shrinkage = excess / oldExcess;
|
|
|
|
else
|
|
|
|
shrinkage = 0;
|
|
|
|
|
|
|
|
// Now shrink each one proportionately
|
|
|
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
|
|
|
if (this._summaryItems[i] == this._expandedSummaryItem)
|
|
|
|
continue;
|
|
|
|
|
2011-03-07 14:04:03 -05:00
|
|
|
let oldWidth = this._summaryItems[i].getTitleWidth();
|
|
|
|
let newWidth = Math.floor(oldWidth * shrinkage);
|
|
|
|
excess -= newWidth;
|
|
|
|
this._summaryItems[i].setTitleWidth(newWidth);
|
|
|
|
}
|
|
|
|
if (this._expandedSummaryItem) {
|
|
|
|
let oldWidth = this._imaginarySummaryItemTitleWidth;
|
|
|
|
let newWidth = Math.floor(oldWidth * shrinkage);
|
|
|
|
excess -= newWidth;
|
|
|
|
this._imaginarySummaryItemTitleWidth = newWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the tray as a whole is fully-expanded, make sure the
|
|
|
|
// left edge doesn't wobble during animation due to rounding.
|
|
|
|
if (this._imaginarySummaryItemTitleWidth == 0 && excess != 0) {
|
|
|
|
for (let i = 0; i < this._summaryItems.length; i++) {
|
|
|
|
if (this._summaryItems[i] == this._expandedSummaryItem)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let oldWidth = this._summaryItems[i].getTitleWidth();
|
|
|
|
if (oldWidth != 0) {
|
|
|
|
this._summaryItems[i].setTitleWidth (oldWidth + excess);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 16:04:56 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_expandSummaryItemCompleted: function() {
|
|
|
|
if (this._expandedSummaryItem)
|
|
|
|
this._expandedSummaryItem.setEllipsization(Pango.EllipsizeMode.END);
|
2010-02-25 14:42:18 -05:00
|
|
|
},
|
|
|
|
|
2011-01-13 15:04:37 -05:00
|
|
|
_onSummaryItemClicked: function(summaryItem, button) {
|
|
|
|
if (summaryItem.source.handleSummaryClick())
|
|
|
|
this._unsetClickedSummaryItem();
|
|
|
|
else if (!this._clickedSummaryItem ||
|
|
|
|
this._clickedSummaryItem != summaryItem ||
|
|
|
|
this._clickedSummaryItemMouseButton != button) {
|
2010-06-24 08:14:27 -04:00
|
|
|
this._clickedSummaryItem = summaryItem;
|
2011-01-13 15:04:37 -05:00
|
|
|
this._clickedSummaryItemMouseButton = button;
|
2011-05-27 05:08:32 -04:00
|
|
|
|
|
|
|
summaryItem.source.emit('summary-item-clicked', button);
|
2011-02-11 14:43:01 -05:00
|
|
|
} else {
|
2010-10-19 15:17:36 -04:00
|
|
|
this._unsetClickedSummaryItem();
|
2011-02-11 14:43:01 -05:00
|
|
|
}
|
2010-02-25 14:42:18 -05:00
|
|
|
|
2010-06-23 15:20:39 -04:00
|
|
|
this._updateState();
|
2010-02-25 14:42:18 -05:00
|
|
|
},
|
|
|
|
|
2010-03-15 12:20:10 -04:00
|
|
|
_onSummaryHoverChanged: function() {
|
|
|
|
this._pointerInSummary = this._summary.hover;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._updateState();
|
|
|
|
},
|
2010-01-28 13:39:00 -05:00
|
|
|
|
2010-03-15 12:20:10 -04:00
|
|
|
_onTrayHoverChanged: function() {
|
|
|
|
if (this.actor.hover) {
|
2010-08-31 15:50:18 -04:00
|
|
|
// Don't do anything if the one pixel area at the bottom is hovered over while the tray is hidden.
|
|
|
|
if (this._trayState == State.HIDDEN)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Don't do anything if this._useLongerTrayLeftTimeout is true, meaning the notification originally
|
|
|
|
// popped up under the pointer, but this._trayLeftTimeoutId is 0, meaning the pointer didn't leave
|
|
|
|
// the tray yet. We need to check for this case because sometimes _onTrayHoverChanged() gets called
|
|
|
|
// multiple times while this.actor.hover is true.
|
|
|
|
if (this._useLongerTrayLeftTimeout && !this._trayLeftTimeoutId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._useLongerTrayLeftTimeout = false;
|
2010-03-15 12:20:10 -04:00
|
|
|
if (this._trayLeftTimeoutId) {
|
|
|
|
Mainloop.source_remove(this._trayLeftTimeoutId);
|
|
|
|
this._trayLeftTimeoutId = 0;
|
2010-10-30 15:54:43 -04:00
|
|
|
this._trayLeftMouseX = -1;
|
|
|
|
this._trayLeftMouseY = -1;
|
2010-03-15 12:20:10 -04:00
|
|
|
return;
|
|
|
|
}
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-08-31 15:50:18 -04:00
|
|
|
if (this._showNotificationMouseX >= 0) {
|
|
|
|
let actorAtShowNotificationPosition =
|
|
|
|
global.stage.get_actor_at_pos(Clutter.PickMode.ALL, this._showNotificationMouseX, this._showNotificationMouseY);
|
|
|
|
this._showNotificationMouseX = -1;
|
|
|
|
this._showNotificationMouseY = -1;
|
|
|
|
// Don't set this._pointerInTray to true if the pointer was initially in the area where the notification
|
|
|
|
// popped up. That way we will not be expanding notifications that happen to pop up over the pointer
|
|
|
|
// automatically. Instead, the user is able to expand the notification by mousing away from it and then
|
|
|
|
// mousing back in. Because this is an expected action, we set the boolean flag that indicates that a longer
|
|
|
|
// timeout should be used before popping down the notification.
|
|
|
|
if (this._notificationBin.contains(actorAtShowNotificationPosition)) {
|
|
|
|
this._useLongerTrayLeftTimeout = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-03-15 12:20:10 -04:00
|
|
|
this._pointerInTray = true;
|
|
|
|
this._updateState();
|
|
|
|
} else {
|
2010-10-30 15:54:43 -04:00
|
|
|
// We record the position of the mouse the moment it leaves the tray. These coordinates are used in
|
|
|
|
// this._onTrayLeftTimeout() to determine if the mouse has moved far enough during the initial timeout for us
|
|
|
|
// to consider that the user intended to leave the tray and therefore hide the tray. If the mouse is still
|
|
|
|
// close to its previous position, we extend the timeout once.
|
|
|
|
let [x, y, mods] = global.get_pointer();
|
|
|
|
this._trayLeftMouseX = x;
|
|
|
|
this._trayLeftMouseY = y;
|
|
|
|
|
2010-08-31 15:50:18 -04:00
|
|
|
// We wait just a little before hiding the message tray in case the user quickly moves the mouse back into it.
|
|
|
|
// We wait for a longer period if the notification popped up where the mouse pointer was already positioned.
|
|
|
|
// That gives the user more time to mouse away from the notification and mouse back in in order to expand it.
|
|
|
|
let timeout = this._useLongerHideTimeout ? LONGER_HIDE_TIMEOUT * 1000 : HIDE_TIMEOUT * 1000;
|
2010-03-15 12:20:10 -04:00
|
|
|
this._trayLeftTimeoutId = Mainloop.timeout_add(timeout, Lang.bind(this, this._onTrayLeftTimeout));
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
}
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2011-09-09 10:56:51 -04:00
|
|
|
_onKeyboardHoverChanged: function(keyboard) {
|
|
|
|
this._pointerInKeyboard = keyboard.hover;
|
|
|
|
|
|
|
|
if (!keyboard.hover) {
|
|
|
|
let event = Clutter.get_current_event();
|
|
|
|
if (event && event.type() == Clutter.EventType.LEAVE) {
|
|
|
|
let into = event.get_related();
|
|
|
|
if (into && this.actor.contains(into)) {
|
|
|
|
// Don't call _updateState, because pointerInTray is
|
|
|
|
// still false
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._updateState();
|
|
|
|
},
|
|
|
|
|
2011-02-19 10:49:56 -05:00
|
|
|
_onStatusChanged: function(presence, status) {
|
|
|
|
this._backFromAway = (this._userStatus == GnomeSession.PresenceStatus.IDLE && this._userStatus != status);
|
|
|
|
this._userStatus = status;
|
|
|
|
|
|
|
|
if (status == GnomeSession.PresenceStatus.BUSY) {
|
|
|
|
// remove notification and allow the summary to be closed now
|
|
|
|
this._updateNotificationTimeout(0);
|
|
|
|
if (this._summaryTimeoutId) {
|
|
|
|
Mainloop.source_remove(this._summaryTimeoutId);
|
|
|
|
this._summaryTimeoutId = 0;
|
|
|
|
}
|
|
|
|
this._busy = true;
|
|
|
|
} else if (status != GnomeSession.PresenceStatus.IDLE) {
|
|
|
|
// We preserve the previous value of this._busy if the status turns to IDLE
|
|
|
|
// so that we don't start showing notifications queued during the BUSY state
|
|
|
|
// as the screensaver gets activated.
|
|
|
|
this._busy = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._updateState();
|
|
|
|
},
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
_onTrayLeftTimeout: function() {
|
2010-10-30 15:54:43 -04:00
|
|
|
let [x, y, mods] = global.get_pointer();
|
|
|
|
// We extend the timeout once if the mouse moved no further than MOUSE_LEFT_ACTOR_THRESHOLD to either side or up.
|
|
|
|
// We don't check how far down the mouse moved because any point above the tray, but below the exit coordinate,
|
|
|
|
// is close to the tray.
|
|
|
|
if (this._trayLeftMouseX > -1 &&
|
|
|
|
y > this._trayLeftMouseY - MOUSE_LEFT_ACTOR_THRESHOLD &&
|
|
|
|
x < this._trayLeftMouseX + MOUSE_LEFT_ACTOR_THRESHOLD &&
|
|
|
|
x > this._trayLeftMouseX - MOUSE_LEFT_ACTOR_THRESHOLD) {
|
|
|
|
this._trayLeftMouseX = -1;
|
|
|
|
this._trayLeftTimeoutId = Mainloop.timeout_add(LONGER_HIDE_TIMEOUT * 1000,
|
|
|
|
Lang.bind(this, this._onTrayLeftTimeout));
|
|
|
|
} else {
|
|
|
|
this._trayLeftTimeoutId = 0;
|
|
|
|
this._useLongerTrayLeftTimeout = false;
|
|
|
|
this._pointerInTray = false;
|
|
|
|
this._pointerInSummary = false;
|
|
|
|
this._updateNotificationTimeout(0);
|
|
|
|
this._updateState();
|
|
|
|
}
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
return false;
|
|
|
|
},
|
2010-01-28 13:39:00 -05:00
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
_escapeTray: function() {
|
|
|
|
this._unlock();
|
2010-07-21 01:26:25 -04:00
|
|
|
this._pointerInTray = false;
|
|
|
|
this._pointerInSummary = false;
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updateNotificationTimeout(0);
|
2010-07-21 01:26:25 -04:00
|
|
|
this._updateState();
|
|
|
|
},
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
// All of the logic for what happens when occurs here; the various
|
|
|
|
// event handlers merely update variables such as
|
2010-05-13 15:46:04 -04:00
|
|
|
// 'this._pointerInTray', 'this._summaryState', etc, and
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
// _updateState() figures out what (if anything) needs to be done
|
|
|
|
// at the present time.
|
|
|
|
_updateState: function() {
|
|
|
|
// Notifications
|
2011-02-28 05:09:40 -05:00
|
|
|
let notificationUrgent = this._notificationQueue.length > 0 && this._notificationQueue[0].urgency == Urgency.CRITICAL;
|
|
|
|
let notificationsPending = this._notificationQueue.length > 0 && (!this._busy || notificationUrgent);
|
2010-02-22 17:19:32 -05:00
|
|
|
let notificationPinned = this._pointerInTray && !this._pointerInSummary && !this._notificationRemoved;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
let notificationExpanded = this._notificationBin.y < 0;
|
2011-09-09 10:56:51 -04:00
|
|
|
let notificationExpired = (this._notificationTimeoutId == 0 && !(this._notification && this._notification.urgency == Urgency.CRITICAL) && !this._pointerInTray && !this._locked && !(this._pointerInKeyboard && notificationExpanded)) || this._notificationRemoved;
|
2011-02-28 05:09:40 -05:00
|
|
|
let canShowNotification = notificationsPending && this._summaryState == State.HIDDEN;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
|
|
|
|
if (this._notificationState == State.HIDDEN) {
|
2011-02-28 05:09:40 -05:00
|
|
|
if (canShowNotification)
|
2010-01-28 13:39:00 -05:00
|
|
|
this._showNotification();
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
} else if (this._notificationState == State.SHOWN) {
|
|
|
|
if (notificationExpired)
|
2010-01-28 13:39:00 -05:00
|
|
|
this._hideNotification();
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
else if (notificationPinned && !notificationExpanded)
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._expandNotification(false);
|
2010-07-21 01:19:25 -04:00
|
|
|
else if (notificationPinned)
|
|
|
|
this._ensureNotificationFocused();
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Summary
|
2011-08-29 11:11:22 -04:00
|
|
|
let summarySummoned = this._pointerInSummary || this._overviewVisible || this._traySummoned;
|
2010-07-21 00:42:37 -04:00
|
|
|
let summaryPinned = this._summaryTimeoutId != 0 || this._pointerInTray || summarySummoned || this._locked;
|
2011-02-04 19:13:10 -05:00
|
|
|
let summaryHovered = this._pointerInTray || this._pointerInSummary;
|
|
|
|
let summaryVisibleWithNoHover = (this._overviewVisible || this._locked) && !summaryHovered;
|
|
|
|
let summaryNotificationIsForExpandedSummaryItem = (this._clickedSummaryItem == this._expandedSummaryItem);
|
2010-02-22 17:19:32 -05:00
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
let notificationsVisible = (this._notificationState == State.SHOWING ||
|
|
|
|
this._notificationState == State.SHOWN);
|
|
|
|
let notificationsDone = !notificationsVisible && !notificationsPending;
|
|
|
|
|
2011-02-28 05:09:40 -05:00
|
|
|
let summaryOptionalInOverview = this._overviewVisible && !this._locked && !summaryHovered;
|
|
|
|
let mustHideSummary = (notificationsPending && (notificationUrgent || summaryOptionalInOverview))
|
|
|
|
|| notificationsVisible;
|
|
|
|
|
|
|
|
if (this._summaryState == State.HIDDEN && !mustHideSummary) {
|
2011-02-19 10:49:56 -05:00
|
|
|
if (this._backFromAway) {
|
|
|
|
// Immediately set this to false, so that we don't schedule a timeout later
|
|
|
|
this._backFromAway = false;
|
|
|
|
if (!this._busy)
|
|
|
|
this._showSummary(LONGER_SUMMARY_TIMEOUT);
|
|
|
|
} else if (notificationsDone && this._newSummaryItems.length > 0 && !this._busy) {
|
|
|
|
this._showSummary(SUMMARY_TIMEOUT);
|
|
|
|
} else if (summarySummoned) {
|
|
|
|
this._showSummary(0);
|
|
|
|
}
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
} else if (this._summaryState == State.SHOWN) {
|
2011-02-28 05:09:40 -05:00
|
|
|
if (!summaryPinned || mustHideSummary)
|
2010-01-28 13:39:00 -05:00
|
|
|
this._hideSummary();
|
2011-02-04 19:13:10 -05:00
|
|
|
else if (summaryVisibleWithNoHover && !summaryNotificationIsForExpandedSummaryItem)
|
|
|
|
// If we are hiding the summary, we'll collapse the expanded summary item when we are done
|
|
|
|
// so that there is no animation. However, we should collapse the expanded summary item
|
|
|
|
// if the summary is visible, but not hovered over, and the summary notification for the
|
|
|
|
// expanded summary item is not being shown.
|
|
|
|
this._setExpandedSummaryItem(null);
|
2010-01-28 13:39:00 -05:00
|
|
|
}
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-02-25 14:42:18 -05:00
|
|
|
// Summary notification
|
2011-02-11 14:43:01 -05:00
|
|
|
let haveClickedSummaryItem = this._clickedSummaryItem != null;
|
2011-03-07 14:03:14 -05:00
|
|
|
let summarySourceIsMainNotificationSource = (haveClickedSummaryItem && this._notification &&
|
|
|
|
this._clickedSummaryItem.source == this._notification.source);
|
2011-02-11 14:43:01 -05:00
|
|
|
let canShowSummaryBoxPointer = this._summaryState == State.SHOWN;
|
2011-03-21 17:43:34 -04:00
|
|
|
// We only have sources with empty notification stacks for legacy tray icons. Currently, we never attempt
|
|
|
|
// to show notifications for legacy tray icons, but this would be necessary if we did.
|
|
|
|
let requestedNotificationStackIsEmpty = (this._clickedSummaryItemMouseButton == 1 && this._clickedSummaryItem.source.notifications.length == 0);
|
|
|
|
let wrongSummaryNotificationStack = (this._clickedSummaryItemMouseButton == 1 &&
|
2011-03-22 03:40:53 -04:00
|
|
|
this._summaryBoxPointer.bin.child != this._clickedSummaryItem.notificationStackView);
|
2011-02-11 14:43:01 -05:00
|
|
|
let wrongSummaryRightClickMenu = (this._clickedSummaryItemMouseButton == 3 &&
|
|
|
|
this._summaryBoxPointer.bin.child != this._clickedSummaryItem.rightClickMenu);
|
|
|
|
let wrongSummaryBoxPointer = (haveClickedSummaryItem &&
|
2011-03-21 17:43:34 -04:00
|
|
|
(wrongSummaryNotificationStack || wrongSummaryRightClickMenu));
|
2011-02-11 14:43:01 -05:00
|
|
|
|
|
|
|
if (this._summaryBoxPointerState == State.HIDDEN) {
|
2011-03-21 17:43:34 -04:00
|
|
|
if (haveClickedSummaryItem && !summarySourceIsMainNotificationSource && canShowSummaryBoxPointer && !requestedNotificationStackIsEmpty)
|
2011-02-11 14:43:01 -05:00
|
|
|
this._showSummaryBoxPointer();
|
|
|
|
} else if (this._summaryBoxPointerState == State.SHOWN) {
|
2011-02-28 05:09:40 -05:00
|
|
|
if (!haveClickedSummaryItem || !canShowSummaryBoxPointer || wrongSummaryBoxPointer || mustHideSummary)
|
2011-02-11 14:43:01 -05:00
|
|
|
this._hideSummaryBoxPointer();
|
2010-02-25 14:42:18 -05:00
|
|
|
}
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
// Tray itself
|
|
|
|
let trayIsVisible = (this._trayState == State.SHOWING ||
|
|
|
|
this._trayState == State.SHOWN);
|
|
|
|
let trayShouldBeVisible = (!notificationsDone ||
|
|
|
|
this._summaryState == State.SHOWING ||
|
|
|
|
this._summaryState == State.SHOWN);
|
|
|
|
if (!trayIsVisible && trayShouldBeVisible)
|
|
|
|
this._showTray();
|
|
|
|
else if (trayIsVisible && !trayShouldBeVisible)
|
|
|
|
this._hideTray();
|
|
|
|
},
|
|
|
|
|
|
|
|
_tween: function(actor, statevar, value, params) {
|
|
|
|
let onComplete = params.onComplete;
|
|
|
|
let onCompleteScope = params.onCompleteScope;
|
|
|
|
let onCompleteParams = params.onCompleteParams;
|
|
|
|
|
|
|
|
params.onComplete = this._tweenComplete;
|
|
|
|
params.onCompleteScope = this;
|
|
|
|
params.onCompleteParams = [statevar, value, onComplete, onCompleteScope, onCompleteParams];
|
|
|
|
|
|
|
|
Tweener.addTween(actor, params);
|
|
|
|
|
|
|
|
let valuing = (value == State.SHOWN) ? State.SHOWING : State.HIDING;
|
|
|
|
this[statevar] = valuing;
|
|
|
|
},
|
|
|
|
|
|
|
|
_tweenComplete: function(statevar, value, onComplete, onCompleteScope, onCompleteParams) {
|
|
|
|
this[statevar] = value;
|
|
|
|
if (onComplete)
|
|
|
|
onComplete.apply(onCompleteScope, onCompleteParams);
|
|
|
|
this._updateState();
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2010-01-28 13:39:00 -05:00
|
|
|
_showTray: function() {
|
2010-05-13 15:46:04 -04:00
|
|
|
this._tween(this.actor, '_trayState', State.SHOWN,
|
2011-07-25 14:25:51 -04:00
|
|
|
{ y: -this.actor.height,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad'
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
});
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2010-01-28 13:39:00 -05:00
|
|
|
_hideTray: function() {
|
2010-05-13 15:46:04 -04:00
|
|
|
this._tween(this.actor, '_trayState', State.HIDDEN,
|
2011-07-25 14:25:51 -04:00
|
|
|
{ y: -1,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad'
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
});
|
2010-01-13 15:05:20 -05:00
|
|
|
},
|
|
|
|
|
2010-01-28 13:39:00 -05:00
|
|
|
_showNotification: function() {
|
2010-02-01 15:23:49 -05:00
|
|
|
this._notification = this._notificationQueue.shift();
|
2010-12-16 15:49:47 -05:00
|
|
|
this._notificationClickedId = this._notification.connect('done-displaying',
|
2011-02-09 22:45:50 -05:00
|
|
|
Lang.bind(this, this._escapeTray));
|
2010-02-01 15:23:49 -05:00
|
|
|
this._notificationBin.child = this._notification.actor;
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-01-28 12:04:26 -05:00
|
|
|
this._notificationBin.opacity = 0;
|
|
|
|
this._notificationBin.y = this.actor.height;
|
|
|
|
this._notificationBin.show();
|
2010-01-13 15:05:20 -05:00
|
|
|
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updateShowingNotification();
|
2010-04-29 15:06:51 -04:00
|
|
|
|
|
|
|
let [x, y, mods] = global.get_pointer();
|
2010-08-31 15:50:18 -04:00
|
|
|
// We save the position of the mouse at the time when we started showing the notification
|
|
|
|
// in order to determine if the notification popped up under it. We make that check if
|
|
|
|
// the user starts moving the mouse and _onTrayHoverChanged() gets called. We don't
|
|
|
|
// expand the notification if it just happened to pop up under the mouse unless the user
|
|
|
|
// explicitly mouses away from it and then mouses back in.
|
|
|
|
this._showNotificationMouseX = x;
|
|
|
|
this._showNotificationMouseY = y;
|
|
|
|
// We save the y coordinate of the mouse at the time when we started showing the notification
|
|
|
|
// and then we update it in _notifiationTimeout() if the mouse is moving towards the
|
|
|
|
// notification. We don't pop down the notification if the mouse is moving towards it.
|
2010-04-29 15:06:51 -04:00
|
|
|
this._lastSeenMouseY = y;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
},
|
|
|
|
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
_updateShowingNotification: function() {
|
|
|
|
Tweener.removeTweens(this._notificationBin);
|
|
|
|
|
2011-01-04 04:34:57 -05:00
|
|
|
// We auto-expand notifications with CRITICAL urgency.
|
2011-01-12 20:05:36 -05:00
|
|
|
// We use Tweener.removeTweens() to remove a tween that was hiding the notification we are
|
|
|
|
// updating, in case that notification was in the process of being hidden. However,
|
|
|
|
// Tweener.removeTweens() would also remove a tween that was updating the position of the
|
|
|
|
// notification we are updating, in case that notification was already expanded and its height
|
|
|
|
// changed. Therefore we need to call this._expandNotification() for expanded notifications
|
|
|
|
// to make sure their position is updated.
|
2011-01-04 04:34:57 -05:00
|
|
|
if (this._notification.urgency == Urgency.CRITICAL || this._notification.expanded)
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._expandNotification(true);
|
2011-01-12 20:05:36 -05:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// We tween any notification showing in the banner mode to banner height (this._notificationBin.y = 0).
|
|
|
|
// This ensures that both new notifications and notifications in the banner mode that might
|
|
|
|
// have been in the process of hiding are shown with the banner height.
|
|
|
|
//
|
|
|
|
// We use this._showNotificationCompleted() onComplete callback to extend the time the updated
|
|
|
|
// notification is being shown.
|
|
|
|
//
|
|
|
|
// We don't set the y parameter for the tween for expanded notifications because
|
|
|
|
// this._expandNotification() will result in getting this._notificationBin.y set to the appropriate
|
|
|
|
// fully expanded value.
|
|
|
|
let tweenParams = { opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: this._showNotificationCompleted,
|
|
|
|
onCompleteScope: this
|
|
|
|
};
|
|
|
|
if (!this._notification.expanded)
|
|
|
|
tweenParams.y = 0;
|
|
|
|
|
|
|
|
this._tween(this._notificationBin, '_notificationState', State.SHOWN, tweenParams);
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
},
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
_showNotificationCompleted: function() {
|
2011-01-11 16:33:03 -05:00
|
|
|
if (this._notification.urgency != Urgency.CRITICAL)
|
|
|
|
this._updateNotificationTimeout(NOTIFICATION_TIMEOUT * 1000);
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_updateNotificationTimeout: function(timeout) {
|
|
|
|
if (this._notificationTimeoutId) {
|
|
|
|
Mainloop.source_remove(this._notificationTimeoutId);
|
|
|
|
this._notificationTimeoutId = 0;
|
|
|
|
}
|
|
|
|
if (timeout > 0)
|
|
|
|
this._notificationTimeoutId =
|
|
|
|
Mainloop.timeout_add(timeout,
|
|
|
|
Lang.bind(this, this._notificationTimeout));
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_notificationTimeout: function() {
|
2010-04-29 15:06:51 -04:00
|
|
|
let [x, y, mods] = global.get_pointer();
|
2011-07-25 14:25:51 -04:00
|
|
|
if (y > this._lastSeenMouseY + 10 && !this.actor.hover) {
|
2010-04-29 15:06:51 -04:00
|
|
|
// The mouse is moving towards the notification, so don't
|
|
|
|
// hide it yet. (We just create a new timeout (and destroy
|
|
|
|
// the old one) each time because the bookkeeping is
|
|
|
|
// simpler.)
|
|
|
|
this._lastSeenMouseY = y;
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._updateNotificationTimeout(1000);
|
2010-04-29 15:06:51 -04:00
|
|
|
} else {
|
|
|
|
this._notificationTimeoutId = 0;
|
|
|
|
this._updateState();
|
|
|
|
}
|
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
return false;
|
2010-01-28 13:39:00 -05:00
|
|
|
},
|
2010-01-13 15:05:20 -05:00
|
|
|
|
2010-01-28 13:39:00 -05:00
|
|
|
_hideNotification: function() {
|
2011-02-09 22:45:50 -05:00
|
|
|
this._focusGrabber.ungrabFocus();
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
if (this._notificationExpandedId) {
|
|
|
|
this._notification.disconnect(this._notificationExpandedId);
|
|
|
|
this._notificationExpandedId = 0;
|
2010-02-22 14:23:36 -05:00
|
|
|
}
|
|
|
|
|
2010-05-13 15:46:04 -04:00
|
|
|
this._tween(this._notificationBin, '_notificationState', State.HIDDEN,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
{ y: this.actor.height,
|
|
|
|
opacity: 0,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad',
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
onComplete: this._hideNotificationCompleted,
|
|
|
|
onCompleteScope: this
|
|
|
|
});
|
2010-01-28 13:39:00 -05:00
|
|
|
},
|
2010-01-13 15:05:20 -05:00
|
|
|
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
_hideNotificationCompleted: function() {
|
2010-02-25 16:19:11 -05:00
|
|
|
this._notificationRemoved = false;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._notificationBin.hide();
|
|
|
|
this._notificationBin.child = null;
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
this._notification.collapseCompleted();
|
2010-12-16 15:49:47 -05:00
|
|
|
this._notification.disconnect(this._notificationClickedId);
|
|
|
|
this._notificationClickedId = 0;
|
2010-12-15 16:30:50 -05:00
|
|
|
let notification = this._notification;
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._notification = null;
|
2010-12-15 16:30:50 -05:00
|
|
|
if (notification.isTransient)
|
2011-01-27 18:26:53 -05:00
|
|
|
notification.destroy(NotificationDestroyedReason.EXPIRED);
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
},
|
|
|
|
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
_expandNotification: function(autoExpanding) {
|
|
|
|
// Don't grab focus in notifications that are auto-expanded.
|
|
|
|
if (!autoExpanding)
|
2011-02-09 22:45:50 -05:00
|
|
|
this._focusGrabber.grabFocus(this._notification.actor);
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
|
|
|
|
if (!this._notificationExpandedId)
|
|
|
|
this._notificationExpandedId =
|
|
|
|
this._notification.connect('expanded',
|
|
|
|
Lang.bind(this, this._onNotificationExpanded));
|
|
|
|
// Don't animate changes in notifications that are auto-expanding.
|
|
|
|
this._notification.expand(!autoExpanding);
|
|
|
|
},
|
|
|
|
|
2011-05-23 17:15:08 -04:00
|
|
|
_onNotificationExpanded: function() {
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
let expandedY = this.actor.height - this._notificationBin.height;
|
2011-05-23 17:15:08 -04:00
|
|
|
|
|
|
|
// Don't animate the notification to its new position if it has shrunk:
|
|
|
|
// there will be a very visible "gap" that breaks the illusion.
|
|
|
|
|
|
|
|
if (this._notificationBin.y < expandedY)
|
|
|
|
this._notificationBin.y = expandedY;
|
|
|
|
else if (this._notification.y != expandedY)
|
2010-05-13 15:46:04 -04:00
|
|
|
this._tween(this._notificationBin, '_notificationState', State.SHOWN,
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
{ y: expandedY,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad'
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
});
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
},
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
|
2010-07-21 01:19:25 -04:00
|
|
|
// We use this function to grab focus when the user moves the pointer
|
2011-01-04 04:34:57 -05:00
|
|
|
// to a notification with CRITICAL urgency that was already auto-expanded.
|
2010-07-21 01:19:25 -04:00
|
|
|
_ensureNotificationFocused: function() {
|
2011-02-09 22:45:50 -05:00
|
|
|
this._focusGrabber.grabFocus(this._notification.actor);
|
2010-07-21 01:19:25 -04:00
|
|
|
},
|
|
|
|
|
2011-02-19 10:49:56 -05:00
|
|
|
_showSummary: function(timeout) {
|
2010-01-28 13:39:00 -05:00
|
|
|
this._summaryBin.opacity = 0;
|
|
|
|
this._summaryBin.y = this.actor.height;
|
2010-05-13 15:46:04 -04:00
|
|
|
this._tween(this._summaryBin, '_summaryState', State.SHOWN,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
{ y: 0,
|
|
|
|
opacity: 255,
|
|
|
|
time: ANIMATION_TIME,
|
2010-05-13 15:46:04 -04:00
|
|
|
transition: 'easeOutQuad',
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
onComplete: this._showSummaryCompleted,
|
|
|
|
onCompleteScope: this,
|
2011-02-19 10:49:56 -05:00
|
|
|
onCompleteParams: [timeout]
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-02-19 10:49:56 -05:00
|
|
|
_showSummaryCompleted: function(timeout) {
|
2010-09-30 17:02:16 -04:00
|
|
|
this._newSummaryItems = [];
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
|
2011-02-19 10:49:56 -05:00
|
|
|
if (timeout != 0) {
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
this._summaryTimeoutId =
|
2011-02-19 10:49:56 -05:00
|
|
|
Mainloop.timeout_add(timeout * 1000,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
Lang.bind(this, this._summaryTimeout));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_summaryTimeout: function() {
|
|
|
|
this._summaryTimeoutId = 0;
|
|
|
|
this._updateState();
|
|
|
|
return false;
|
2010-01-28 13:39:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_hideSummary: function() {
|
2010-05-13 15:46:04 -04:00
|
|
|
this._tween(this._summaryBin, '_summaryState', State.HIDDEN,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
{ opacity: 0,
|
|
|
|
time: ANIMATION_TIME,
|
2011-02-04 19:13:10 -05:00
|
|
|
transition: 'easeOutQuad',
|
|
|
|
onComplete: this._hideSummaryCompleted,
|
|
|
|
onCompleteScope: this,
|
[MessageTray] reimplement the state machine
Previously, every time _updateState was called, it would make some
change, and so it was necessary to very carefully set up all the calls
to it, to ensure it was always called at exactly the right time. Now,
instead, we keep a bunch of state variables like "_notificationState"
and "_pointerInSummary", and potentially multiple timeouts, and
_updateState looks at all of them and figure out what, if anything,
needs to be changed.
By making the rules about what causes changes more explicit, it will
be easier to change those rules in the future as we add new
functionality.
Also, update the rules a bit, so that notifications can appear while
the summary is visible, and the summary only shows after a
notification if the summary has changed.
https://bugzilla.gnome.org/show_bug.cgi?id=609765
2010-02-11 15:31:12 -05:00
|
|
|
});
|
2010-09-30 17:02:16 -04:00
|
|
|
this._newSummaryItems = [];
|
2010-02-25 14:42:18 -05:00
|
|
|
},
|
|
|
|
|
2011-02-04 19:13:10 -05:00
|
|
|
_hideSummaryCompleted: function() {
|
2011-02-28 05:09:40 -05:00
|
|
|
this._setExpandedSummaryItem(null);
|
2011-02-04 19:13:10 -05:00
|
|
|
},
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
_showSummaryBoxPointer: function() {
|
2011-03-21 17:43:34 -04:00
|
|
|
this._summaryBoxPointerItem = this._clickedSummaryItem;
|
|
|
|
this._summaryBoxPointerContentUpdatedId = this._summaryBoxPointerItem.connect('content-updated',
|
2011-09-08 01:15:09 -04:00
|
|
|
Lang.bind(this, this._onSummaryBoxPointerContentUpdated));
|
2011-03-21 17:43:34 -04:00
|
|
|
this._summaryBoxPointerDoneDisplayingId = this._summaryBoxPointerItem.connect('done-displaying-content',
|
|
|
|
Lang.bind(this, this._escapeTray));
|
2011-02-11 14:43:01 -05:00
|
|
|
if (this._clickedSummaryItemMouseButton == 1) {
|
2011-03-21 17:43:34 -04:00
|
|
|
this._notificationQueue = this._notificationQueue.filter( Lang.bind(this,
|
|
|
|
function(notification) {
|
|
|
|
return this._summaryBoxPointerItem.source != notification.source;
|
|
|
|
}));
|
|
|
|
this._summaryBoxPointerItem.prepareNotificationStackForShowing();
|
2011-03-22 03:40:53 -04:00
|
|
|
this._summaryBoxPointer.bin.child = this._summaryBoxPointerItem.notificationStackView;
|
|
|
|
this._summaryBoxPointerItem.scrollTo(St.Side.BOTTOM);
|
2011-02-11 14:43:01 -05:00
|
|
|
} else if (this._clickedSummaryItemMouseButton == 3) {
|
|
|
|
this._summaryBoxPointer.bin.child = this._clickedSummaryItem.rightClickMenu;
|
|
|
|
}
|
2010-02-25 14:42:18 -05:00
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
this._focusGrabber.grabFocus(this._summaryBoxPointer.bin.child);
|
2010-02-25 14:42:18 -05:00
|
|
|
|
2010-10-19 15:17:36 -04:00
|
|
|
this._clickedSummaryItemAllocationChangedId =
|
|
|
|
this._clickedSummaryItem.actor.connect('allocation-changed',
|
2011-02-11 14:43:01 -05:00
|
|
|
Lang.bind(this, this._adjustSummaryBoxPointerPosition));
|
2011-03-21 17:43:34 -04:00
|
|
|
// _clickedSummaryItem.actor can change absolute position without changing allocation
|
2010-10-19 15:17:36 -04:00
|
|
|
this._summaryMotionId = this._summary.connect('allocation-changed',
|
2011-02-11 14:43:01 -05:00
|
|
|
Lang.bind(this, this._adjustSummaryBoxPointerPosition));
|
2011-09-09 09:45:39 -04:00
|
|
|
this._trayMotionId = Main.layoutManager.trayBox.connect('notify::anchor-y',
|
|
|
|
Lang.bind(this, this._adjustSummaryBoxPointerPosition));
|
2010-10-19 15:17:36 -04:00
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointer.actor.opacity = 0;
|
|
|
|
this._summaryBoxPointer.actor.show();
|
|
|
|
this._adjustSummaryBoxPointerPosition();
|
2010-10-19 15:17:36 -04:00
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointerState = State.SHOWING;
|
2011-03-21 21:22:02 -04:00
|
|
|
this._clickedSummaryItem.actor.add_style_pseudo_class('selected');
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointer.show(true, Lang.bind(this, function() {
|
|
|
|
this._summaryBoxPointerState = State.SHOWN;
|
2010-10-19 15:17:36 -04:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2011-09-08 01:15:09 -04:00
|
|
|
_onSummaryBoxPointerContentUpdated: function() {
|
|
|
|
if (this._summaryBoxPointerItem.notificationStack.get_children().length == 0)
|
|
|
|
this._hideSummaryBoxPointer();
|
|
|
|
this._adjustSummaryBoxPointerPosition();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
_adjustSummaryBoxPointerPosition: function() {
|
2010-10-19 15:17:36 -04:00
|
|
|
// The position of the arrow origin should be the same as center of this._clickedSummaryItem.actor
|
|
|
|
if (!this._clickedSummaryItem)
|
|
|
|
return;
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointer.setPosition(this._clickedSummaryItem.actor, 0, 0.5);
|
2010-10-19 15:17:36 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_unsetClickedSummaryItem: function() {
|
|
|
|
if (this._clickedSummaryItemAllocationChangedId) {
|
|
|
|
this._clickedSummaryItem.actor.disconnect(this._clickedSummaryItemAllocationChangedId);
|
|
|
|
this._summary.disconnect(this._summaryMotionId);
|
2011-09-09 09:45:39 -04:00
|
|
|
Main.layoutManager.trayBox.disconnect(this._trayMotionId);
|
2010-10-19 15:17:36 -04:00
|
|
|
this._clickedSummaryItemAllocationChangedId = 0;
|
|
|
|
this._summaryMotionId = 0;
|
2011-09-09 09:45:39 -04:00
|
|
|
this._trayMotionId = 0;
|
2010-10-19 15:17:36 -04:00
|
|
|
}
|
|
|
|
|
2011-03-21 21:22:02 -04:00
|
|
|
if (this._clickedSummaryItem)
|
|
|
|
this._clickedSummaryItem.actor.remove_style_pseudo_class('selected');
|
2010-10-19 15:17:36 -04:00
|
|
|
this._clickedSummaryItem = null;
|
2011-02-11 14:43:01 -05:00
|
|
|
this._clickedSummaryItemMouseButton = -1;
|
2010-04-07 12:53:52 -04:00
|
|
|
},
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
_hideSummaryBoxPointer: function() {
|
2011-09-08 01:15:09 -04:00
|
|
|
// We should be sure to hide the box pointer if all notifications in it are destroyed while
|
|
|
|
// it is hiding, so that we don't show an an animation of an empty blob being hidden.
|
|
|
|
if (this._summaryBoxPointerState == State.HIDING &&
|
|
|
|
this._summaryBoxPointerItem.notificationStack.get_children().length == 0) {
|
|
|
|
this._summaryBoxPointer.actor.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-26 03:25:25 -04:00
|
|
|
this._summaryBoxPointerState = State.HIDING;
|
2011-09-22 23:37:11 -04:00
|
|
|
// Unset this._clickedSummaryItem if we are no longer showing the summary or if
|
|
|
|
// this._clickedSummaryItem is still the item associated with the currently showing box pointer
|
|
|
|
if (this._summaryState != State.SHOWN || this._summaryBoxPointerItem == this._clickedSummaryItem)
|
2010-10-19 15:17:36 -04:00
|
|
|
this._unsetClickedSummaryItem();
|
2010-02-25 14:42:18 -05:00
|
|
|
|
2011-02-09 22:45:50 -05:00
|
|
|
this._focusGrabber.ungrabFocus();
|
2011-03-26 03:25:25 -04:00
|
|
|
if (this._summaryBoxPointerItem.source.notifications.length == 0) {
|
|
|
|
this._summaryBoxPointer.actor.hide();
|
|
|
|
this._hideSummaryBoxPointerCompleted();
|
|
|
|
} else {
|
|
|
|
this._summaryBoxPointer.hide(true, Lang.bind(this, this._hideSummaryBoxPointerCompleted));
|
|
|
|
}
|
2011-02-11 14:43:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
_hideSummaryBoxPointerCompleted: function() {
|
2011-03-22 03:40:53 -04:00
|
|
|
let doneShowingNotificationStack = (this._summaryBoxPointer.bin.child == this._summaryBoxPointerItem.notificationStackView);
|
2011-03-21 17:43:34 -04:00
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
this._summaryBoxPointerState = State.HIDDEN;
|
|
|
|
this._summaryBoxPointer.bin.child = null;
|
2011-03-21 17:43:34 -04:00
|
|
|
this._summaryBoxPointerItem.disconnect(this._summaryBoxPointerContentUpdatedId);
|
|
|
|
this._summaryBoxPointerContentUpdatedId = 0;
|
|
|
|
this._summaryBoxPointerItem.disconnect(this._summaryBoxPointerDoneDisplayingId);
|
|
|
|
this._summaryBoxPointerDoneDisplayingId = 0;
|
|
|
|
|
|
|
|
let sourceNotificationStackDoneShowing = null;
|
|
|
|
if (doneShowingNotificationStack) {
|
|
|
|
this._summaryBoxPointerItem.doneShowingNotificationStack();
|
|
|
|
sourceNotificationStackDoneShowing = this._summaryBoxPointerItem.source;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._summaryBoxPointerItem = null;
|
|
|
|
|
|
|
|
if (sourceNotificationStackDoneShowing) {
|
|
|
|
if (sourceNotificationStackDoneShowing.isTransient && !this._reNotifyAfterHideNotification)
|
|
|
|
sourceNotificationStackDoneShowing.destroy(NotificationDestroyedReason.EXPIRED);
|
|
|
|
if (this._reNotifyAfterHideNotification) {
|
|
|
|
this._onNotify(this._reNotifyAfterHideNotification.source, this._reNotifyAfterHideNotification);
|
|
|
|
this._reNotifyAfterHideNotification = null;
|
2011-02-11 14:43:01 -05:00
|
|
|
}
|
Fix various details of how notifications are shown
This patch ensures the following notifications behavior:
- Urgent notifications that have long title or banner text are auto-expanded
correctly.
- Single-line notifications that have _expandNotification() called (e.g.
because the user mouses over to them), are treated as expanded, which means
they get fully expanded if they are updated with more content and the user
can escape them.
- The position of expanded notifications is updated when they are updated.
- Notification banner is shown again on the first line if it can fully fit
there after a notification is updated, even if it was previously hidden
because the notification was expanded and the old banner did not fully fit.
- New notifications are immediately hidden if the user mouses away from them.
- If a new notification is updated while it is shown, we extend the time it
will be shown.
- If a new notification is updated while it is hiding, we stop hiding it and
show it again.
- If a summary notification is updated while it is hiding, we let it finish
hiding and show a new notification with the updated information.
Implementation details:
- Single-line notifications now have 4px bottom padding instead of 8px, which
means that their height matches the tray height, they are fully shown in the
banner mode, and don't pop out by 4px when the notification is expanded.
- Notification keeps a flag that indicates whether it is expanded, updates
its expanded look when it is updated, and emits an 'expanded' signal
indicating that its layout has possibly changed. The message tray connects
to this 'expanded' signal when it is showing a notification in the expanded
state and updates the position of the notification accordingly when this
signal is received so that the notification is fully shown. This is better
than connecting to 'notify::height' signal on the notification bin, since
it results in fewer callbacks.
https://bugzilla.gnome.org/show_bug.cgi?id=617209
2010-09-10 15:47:12 -04:00
|
|
|
}
|
2011-03-21 17:43:34 -04:00
|
|
|
|
2011-02-15 18:37:33 -05:00
|
|
|
if (this._clickedSummaryItem)
|
|
|
|
this._updateState();
|
2010-01-28 13:39:00 -05:00
|
|
|
}
|
2010-01-13 15:05:20 -05:00
|
|
|
};
|
2010-11-30 10:47:28 -05:00
|
|
|
|
|
|
|
function SystemNotificationSource() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemNotificationSource.prototype = {
|
|
|
|
__proto__: Source.prototype,
|
|
|
|
|
|
|
|
_init: function() {
|
|
|
|
Source.prototype._init.call(this, _("System Information"));
|
|
|
|
|
|
|
|
this._setSummaryIcon(this.createNotificationIcon());
|
|
|
|
},
|
|
|
|
|
|
|
|
createNotificationIcon: function() {
|
|
|
|
return new St.Icon({ icon_name: 'dialog-information',
|
|
|
|
icon_type: St.IconType.SYMBOLIC,
|
|
|
|
icon_size: this.ICON_SIZE });
|
|
|
|
},
|
|
|
|
|
2011-02-11 14:43:01 -05:00
|
|
|
open: function() {
|
2010-11-30 10:47:28 -05:00
|
|
|
this.destroy();
|
|
|
|
}
|
|
|
|
};
|