1
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
3
const Clutter = imports.gi.Clutter;
4
const GLib = imports.gi.GLib;
5
const Gio = imports.gi.Gio;
6
const Gtk = imports.gi.Gtk;
7
const Atk = imports.gi.Atk;
8
const Lang = imports.lang;
9
const Mainloop = imports.mainloop;
10
const Meta = imports.gi.Meta;
11
const Pango = imports.gi.Pango;
12
const Shell = imports.gi.Shell;
13
const Signals = imports.signals;
14
const St = imports.gi.St;
16
const BoxPointer = imports.ui.boxpointer;
17
const CtrlAltTab = imports.ui.ctrlAltTab;
18
const GnomeSession = imports.misc.gnomeSession;
19
const GrabHelper = imports.ui.grabHelper;
20
const Lightbox = imports.ui.lightbox;
21
const Main = imports.ui.main;
22
const PointerWatcher = imports.ui.pointerWatcher;
23
const PopupMenu = imports.ui.popupMenu;
24
const Params = imports.misc.params;
25
const Tweener = imports.ui.tweener;
26
const Util = imports.misc.util;
28
const SHELL_KEYBINDINGS_SCHEMA = 'org.gnome.shell.keybindings';
30
const ANIMATION_TIME = 0.2;
31
const NOTIFICATION_TIMEOUT = 4;
32
const SUMMARY_TIMEOUT = 1;
33
const LONGER_SUMMARY_TIMEOUT = 4;
35
const HIDE_TIMEOUT = 0.2;
36
const LONGER_HIDE_TIMEOUT = 0.6;
38
const NOTIFICATION_ICON_SIZE = 24;
40
// We delay hiding of the tray if the mouse is within MOUSE_LEFT_ACTOR_THRESHOLD
41
// range from the point where it left the tray.
42
const MOUSE_LEFT_ACTOR_THRESHOLD = 20;
44
// Time the user needs to leave the mouse on the bottom pixel row to open the tray
45
const TRAY_DWELL_TIME = 1000; // ms
46
// Time resolution when tracking the mouse to catch the open tray dwell
47
const TRAY_DWELL_CHECK_INTERVAL = 100; // ms
49
const IDLE_TIME = 1000;
58
// These reasons are useful when we destroy the notifications received through
59
// the notification daemon. We use EXPIRED for transient notifications that the
60
// user did not interact with, DISMISSED for all other notifications that were
61
// destroyed as a result of a user action, and SOURCE_CLOSED for the notifications
62
// that were requested to be destroyed by the associated source.
63
const NotificationDestroyedReason = {
69
// Message tray has its custom Urgency enumeration. LOW, NORMAL and CRITICAL
70
// urgency values map to the corresponding values for the notifications received
71
// through the notification daemon. HIGH urgency value is used for chats received
72
// through the Telepathy client.
80
function _fixMarkup(text, allowMarkup) {
82
// Support &, ", ', < and >, escape all other
83
// occurrences of '&'.
84
let _text = text.replace(/&(?!amp;|quot;|apos;|lt;|gt;)/g, '&');
86
// Support <b>, <i>, and <u>, escape anything else
87
// so it displays as raw markup.
88
_text = _text.replace(/<(?!\/?[biu]>)/g, '<');
91
Pango.parse_markup(_text, -1, '');
96
// !allowMarkup, or invalid markup
97
return GLib.markup_escape_text(text, -1);
100
const URLHighlighter = new Lang.Class({
101
Name: 'URLHighlighter',
103
_init: function(text, lineWrap, allowMarkup) {
106
this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter' });
107
this._linkColor = '#ccccff';
108
this.actor.connect('style-changed', Lang.bind(this, function() {
109
let [hasColor, color] = this.actor.get_theme_node().lookup_color('link-color', false);
111
let linkColor = color.to_string().substr(0, 7);
112
if (linkColor != this._linkColor) {
113
this._linkColor = linkColor;
114
this._highlightUrls();
119
this.actor.clutter_text.line_wrap = true;
120
this.actor.clutter_text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
121
this.actor.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
124
this.setMarkup(text, allowMarkup);
125
this.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
126
// Don't try to URL highlight when invisible.
127
// The MessageTray doesn't actually hide us, so
128
// we need to check for paint opacities as well.
129
if (!actor.visible || actor.get_paint_opacity() == 0)
132
// Keep Notification.actor from seeing this and taking
133
// a pointer grab, which would block our button-release-event
134
// handler, if an URL is clicked
135
return this._findUrlAtPos(event) != -1;
137
this.actor.connect('button-release-event', Lang.bind(this, function (actor, event) {
138
if (!actor.visible || actor.get_paint_opacity() == 0)
141
let urlId = this._findUrlAtPos(event);
143
let url = this._urls[urlId].url;
144
if (url.indexOf(':') == -1)
145
url = 'http://' + url;
147
Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context());
150
// TODO: remove this after gnome 3 release
151
Util.spawn(['gvfs-open', url]);
157
this.actor.connect('motion-event', Lang.bind(this, function(actor, event) {
158
if (!actor.visible || actor.get_paint_opacity() == 0)
161
let urlId = this._findUrlAtPos(event);
162
if (urlId != -1 && !this._cursorChanged) {
163
global.set_cursor(Shell.Cursor.POINTING_HAND);
164
this._cursorChanged = true;
165
} else if (urlId == -1) {
166
global.unset_cursor();
167
this._cursorChanged = false;
171
this.actor.connect('leave-event', Lang.bind(this, function() {
172
if (!this.actor.visible || this.actor.get_paint_opacity() == 0)
175
if (this._cursorChanged) {
176
this._cursorChanged = false;
177
global.unset_cursor();
182
setMarkup: function(text, allowMarkup) {
183
text = text ? _fixMarkup(text, allowMarkup) : '';
186
this.actor.clutter_text.set_markup(text);
187
/* clutter_text.text contain text without markup */
188
this._urls = Util.findUrls(this.actor.clutter_text.text);
189
this._highlightUrls();
192
_highlightUrls: function() {
193
// text here contain markup
194
let urls = Util.findUrls(this._text);
197
for (let i = 0; i < urls.length; i++) {
199
let str = this._text.substr(pos, url.pos - pos);
200
markup += str + '<span foreground="' + this._linkColor + '"><u>' + url.url + '</u></span>';
201
pos = url.pos + url.url.length;
203
markup += this._text.substr(pos);
204
this.actor.clutter_text.set_markup(markup);
207
_findUrlAtPos: function(event) {
209
let [x, y] = event.get_coords();
210
[success, x, y] = this.actor.transform_stage_point(x, y);
212
for (let i = 0; i < this.actor.clutter_text.text.length; i++) {
213
let [success, px, py, line_height] = this.actor.clutter_text.position_to_coords(i);
214
if (py > y || py + line_height < y || x < px)
218
if (find_pos != -1) {
219
for (let i = 0; i < this._urls.length; i++)
220
if (find_pos >= this._urls[i].pos &&
221
this._urls[i].pos + this._urls[i].url.length > find_pos)
228
function makeCloseButton() {
229
let closeButton = new St.Button({ style_class: 'notification-close'});
231
// This is a bit tricky. St.Bin has its own x-align/y-align properties
232
// that compete with Clutter's properties. This should be fixed for
233
// Clutter 2.0. Since St.Bin doesn't define its own setters, the
234
// setters are a workaround to get Clutter's version.
235
closeButton.set_x_align(Clutter.ActorAlign.END);
236
closeButton.set_y_align(Clutter.ActorAlign.START);
238
// XXX Clutter 2.0 workaround: ClutterBinLayout needs expand
239
// to respect the alignments.
240
closeButton.set_x_expand(true);
241
closeButton.set_y_expand(true);
243
closeButton.connect('style-changed', function() {
244
let themeNode = closeButton.get_theme_node();
246
// libcroco doesn't support negative units
247
let direction = closeButton.get_text_direction() == Clutter.TextDirection.RTL ? -1 : 1;
248
closeButton.translation_x = direction * themeNode.get_length('-shell-close-overlap-x');
250
// libcroco doesn't support negative units
251
closeButton.translation_y = -themeNode.get_length('-shell-close-overlap-y');
258
// @source: the notification's Source
260
// @banner: the banner text
261
// @params: optional additional params
263
// Creates a notification. In the banner mode, the notification
264
// will show an icon, @title (in bold) and @banner, all on a single
265
// line (with @banner ellipsized if necessary).
267
// The notification will be expandable if either it has additional
268
// elements that were added to it or if the @banner text did not
269
// fit fully in the banner mode. When the notification is expanded,
270
// the @banner text from the top line is always removed. The complete
271
// @banner text is added as the first element in the content section,
272
// unless 'customContent' parameter with the value 'true' is specified
275
// Additional notification content can be added with addActor() and
276
// addBody() methods. The notification content is put inside a
277
// scrollview, so if it gets too tall, the notification will scroll
278
// rather than continue to grow. In addition to this main content
279
// area, there is also a single-row action area, which is not
280
// scrolled and can contain a single actor. The action area can
281
// be set by calling setActionArea() method. There is also a
282
// convenience method addButton() for adding a button to the action
285
// @params can contain values for 'customContent', 'body', 'icon',
286
// 'titleMarkup', 'bannerMarkup', 'bodyMarkup', and 'clear'
289
// If @params contains a 'customContent' parameter with the value %true,
290
// then @banner will not be shown in the body of the notification when the
291
// notification is expanded and calls to update() will not clear the content
292
// unless 'clear' parameter with value %true is explicitly specified.
294
// If @params contains a 'body' parameter, then that text will be added to
295
// the content area (as with addBody()).
297
// By default, the icon shown is created by calling
298
// source.createIcon(). However, if @params contains an 'icon'
299
// parameter, the passed in icon will be used.
301
// If @params contains a 'titleMarkup', 'bannerMarkup', or
302
// 'bodyMarkup' parameter with the value %true, then the corresponding
303
// element is assumed to use pango markup. If the parameter is not
304
// present for an element, then anything that looks like markup in
305
// that element will appear literally in the output.
307
// If @params contains a 'clear' parameter with the value %true, then
308
// the content and the action area of the notification will be cleared.
309
// The content area is also always cleared if 'customContent' is false
310
// because it might contain the @banner that didn't fit in the banner mode.
311
const Notification = new Lang.Class({
312
Name: 'Notification',
316
_init: function(source, title, banner, params) {
317
this.source = source;
319
this.urgency = Urgency.NORMAL;
320
this.resident = false;
321
// 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
322
this.isTransient = false;
323
this.expanded = false;
324
this.focused = false;
325
this.acknowledged = false;
326
this._destroyed = false;
327
this._useActionIcons = false;
328
this._customContent = false;
329
this._bannerBodyText = null;
330
this._bannerBodyMarkup = false;
331
this._titleFitsInBannerMode = true;
332
this._titleDirection = Clutter.TextDirection.DEFAULT;
334
this._scrollPolicy = Gtk.PolicyType.AUTOMATIC;
335
this._imageBin = null;
337
source.connect('destroy', Lang.bind(this,
338
function (source, reason) {
339
this.destroy(reason);
342
this.actor = new St.Button({ accessible_role: Atk.Role.NOTIFICATION });
343
this.actor.add_style_class_name('notification-unexpanded');
344
this.actor._delegate = this;
345
this.actor.connect('clicked', Lang.bind(this, this._onClicked));
346
this.actor.connect('destroy', Lang.bind(this, this._onDestroy));
348
this._table = new St.Table({ style_class: 'notification',
350
this._table.connect('style-changed', Lang.bind(this, this._styleChanged));
351
this.actor.set_child(this._table);
353
// The first line should have the title, followed by the
354
// banner text, but ellipsized if they won't both fit. We can't
355
// make St.Table or St.BoxLayout do this the way we want (don't
356
// show banner at all if title needs to be ellipsized), so we
357
// use Shell.GenericContainer.
358
this._bannerBox = new Shell.GenericContainer();
359
this._bannerBox.connect('get-preferred-width', Lang.bind(this, this._bannerBoxGetPreferredWidth));
360
this._bannerBox.connect('get-preferred-height', Lang.bind(this, this._bannerBoxGetPreferredHeight));
361
this._bannerBox.connect('allocate', Lang.bind(this, this._bannerBoxAllocate));
362
this._table.add(this._bannerBox, { row: 0,
369
// This is an empty cell that overlaps with this._bannerBox cell to ensure
370
// that this._bannerBox cell expands horizontally, while not forcing the
371
// this._imageBin that is also in col: 2 to expand horizontally.
372
this._table.add(new St.Bin(), { row: 0,
377
this._titleLabel = new St.Label();
378
this._bannerBox.add_actor(this._titleLabel);
379
this._bannerUrlHighlighter = new URLHighlighter();
380
this._bannerLabel = this._bannerUrlHighlighter.actor;
381
this._bannerBox.add_actor(this._bannerLabel);
383
this.update(title, banner, params);
387
// @title: the new title
388
// @banner: the new banner
389
// @params: as in the Notification constructor
391
// Updates the notification by regenerating its icon and updating
392
// the title/banner. If @params.clear is %true, it will also
393
// remove any additional actors/action buttons previously added.
394
update: function(title, banner, params) {
395
params = Params.parse(params, { customContent: false,
404
this._customContent = params.customContent;
406
let oldFocus = global.stage.key_focus;
408
if (this._icon && (params.icon || params.clear)) {
409
this._icon.destroy();
413
if (this._secondaryIcon && (params.secondaryIcon || params.clear)) {
414
this._secondaryIcon.destroy();
415
this._secondaryIcon = null;
418
// We always clear the content area if we don't have custom
419
// content because it might contain the @banner that didn't
420
// fit in the banner mode.
421
if (this._scrollArea && (!this._customContent || params.clear)) {
422
if (oldFocus && this._scrollArea.contains(oldFocus))
423
this.actor.grab_key_focus();
425
this._scrollArea.destroy();
426
this._scrollArea = null;
427
this._contentArea = null;
429
if (this._actionArea && params.clear) {
430
if (oldFocus && this._actionArea.contains(oldFocus))
431
this.actor.grab_key_focus();
433
this._actionArea.destroy();
434
this._actionArea = null;
435
this._buttonBox = null;
437
if (this._imageBin && params.clear)
440
if (!this._scrollArea && !this._actionArea && !this._imageBin)
441
this._table.remove_style_class_name('multi-line-notification');
444
this._icon = params.icon || this.source.createIcon(NOTIFICATION_ICON_SIZE);
445
this._table.add(this._icon, { row: 0,
450
y_align: St.Align.START });
453
if (!this._secondaryIcon) {
454
this._secondaryIcon = params.secondaryIcon;
456
if (this._secondaryIcon)
457
this._bannerBox.add_actor(this._secondaryIcon);
461
title = title ? _fixMarkup(title.replace(/\n/g, ' '), params.titleMarkup) : '';
462
this._titleLabel.clutter_text.set_markup('<b>' + title + '</b>');
464
if (Pango.find_base_dir(title, -1) == Pango.Direction.RTL)
465
this._titleDirection = Clutter.TextDirection.RTL;
467
this._titleDirection = Clutter.TextDirection.LTR;
469
// Let the title's text direction control the overall direction
470
// of the notification - in case where different scripts are used
471
// in the notification, this is the right thing for the icon, and
472
// arguably for action buttons as well. Labels other than the title
473
// will be allocated at the available width, so that their alignment
474
// is done correctly automatically.
475
this._table.set_text_direction(this._titleDirection);
477
// Unless the notification has custom content, we save this._bannerBodyText
478
// to add it to the content of the notification if the notification is
479
// expandable due to other elements in its content area or due to the banner
480
// not fitting fully in the single-line mode.
481
this._bannerBodyText = this._customContent ? null : banner;
482
this._bannerBodyMarkup = params.bannerMarkup;
484
banner = banner ? banner.replace(/\n/g, ' ') : '';
486
this._bannerUrlHighlighter.setMarkup(banner, params.bannerMarkup);
487
this._bannerLabel.queue_relayout();
489
// Add the bannerBody now if we know for sure we'll need it
490
if (this._bannerBodyText && this._bannerBodyText.indexOf('\n') > -1)
491
this._addBannerBody();
494
this.addBody(params.body, params.bodyMarkup);
498
setIconVisible: function(visible) {
499
this._icon.visible = visible;
502
enableScrolling: function(enableScrolling) {
503
this._scrollPolicy = enableScrolling ? Gtk.PolicyType.AUTOMATIC : Gtk.PolicyType.NEVER;
504
if (this._scrollArea) {
505
this._scrollArea.vscrollbar_policy = this._scrollPolicy;
506
this._scrollArea.enable_mouse_scrolling = enableScrolling;
510
_createScrollArea: function() {
511
this._table.add_style_class_name('multi-line-notification');
512
this._scrollArea = new St.ScrollView({ style_class: 'notification-scrollview',
513
vscrollbar_policy: this._scrollPolicy,
514
hscrollbar_policy: Gtk.PolicyType.NEVER });
515
this._table.add(this._scrollArea, { row: 1,
517
this._updateLastColumnSettings();
518
this._contentArea = new St.BoxLayout({ style_class: 'notification-body',
520
this._scrollArea.add_actor(this._contentArea);
521
// If we know the notification will be expandable, we need to add
522
// the banner text to the body as the first element.
523
this._addBannerBody();
527
// @actor: actor to add to the body of the notification
529
// Appends @actor to the notification's body
530
addActor: function(actor, style) {
531
if (!this._scrollArea) {
532
this._createScrollArea();
535
this._contentArea.add(actor, style ? style : {});
541
// @markup: %true if @text contains pango markup
542
// @style: style to use when adding the actor containing the text
544
// Adds a multi-line label containing @text to the notification.
546
// Return value: the newly-added label
547
addBody: function(text, markup, style) {
548
let label = new URLHighlighter(text, true, markup);
550
this.addActor(label.actor, style);
554
_addBannerBody: function() {
555
if (this._bannerBodyText) {
556
let text = this._bannerBodyText;
557
this._bannerBodyText = null;
558
this.addBody(text, this._bannerBodyMarkup);
563
// @side: St.Side.TOP or St.Side.BOTTOM
565
// Scrolls the content area (if scrollable) to the indicated edge
566
scrollTo: function(side) {
567
let adjustment = this._scrollArea.vscroll.adjustment;
568
if (side == St.Side.TOP)
569
adjustment.value = adjustment.lower;
570
else if (side == St.Side.BOTTOM)
571
adjustment.value = adjustment.upper;
576
// @props: (option) St.Table child properties
578
// Puts @actor into the action area of the notification, replacing
579
// the previous contents
580
setActionArea: function(actor, props) {
581
if (this._actionArea) {
582
this._actionArea.destroy();
583
this._actionArea = null;
585
this._buttonBox = null;
587
this._addBannerBody();
589
this._actionArea = actor;
596
this._table.add_style_class_name('multi-line-notification');
597
this._table.add(this._actionArea, props);
598
this._updateLastColumnSettings();
602
_updateLastColumnSettings: function() {
603
if (this._scrollArea)
604
this._table.child_set(this._scrollArea, { col: this._imageBin ? 2 : 1,
605
col_span: this._imageBin ? 1 : 2 });
606
if (this._actionArea)
607
this._table.child_set(this._actionArea, { col: this._imageBin ? 2 : 1,
608
col_span: this._imageBin ? 1 : 2 });
611
setImage: function(image) {
614
this._imageBin = new St.Bin();
615
this._imageBin.child = image;
616
this._imageBin.opacity = 230;
617
this._table.add_style_class_name('multi-line-notification');
618
this._table.add_style_class_name('notification-with-image');
619
this._addBannerBody();
620
this._updateLastColumnSettings();
621
this._table.add(this._imageBin, { row: 1,
630
unsetImage: function() {
631
if (this._imageBin) {
632
this._table.remove_style_class_name('notification-with-image');
633
this._table.remove_actor(this._imageBin);
634
this._imageBin = null;
635
this._updateLastColumnSettings();
636
if (!this._scrollArea && !this._actionArea)
637
this._table.remove_style_class_name('multi-line-notification');
642
// @id: the action ID
643
// @label: the label for the action's button
645
// Adds a button with the given @label to the notification. All
646
// action buttons will appear in a single row at the bottom of
649
// If the button is clicked, the notification will emit the
650
// %action-invoked signal with @id as a parameter
651
addButton: function(id, label) {
652
if (!this._buttonBox) {
654
let box = new St.BoxLayout({ style_class: 'notification-actions' });
655
this.setActionArea(box, { x_expand: false,
659
x_align: St.Align.END });
660
this._buttonBox = box;
663
let button = new St.Button({ can_focus: true });
664
button._actionId = id;
666
if (this._useActionIcons && Gtk.IconTheme.get_default().has_icon(id)) {
667
button.add_style_class_name('notification-icon-button');
668
button.child = new St.Icon({ icon_name: id });
670
button.add_style_class_name('notification-button');
671
button.label = label;
674
if (this._buttonBox.get_n_children() > 0)
675
global.focus_manager.remove_group(this._buttonBox);
677
this._buttonBox.add(button);
678
global.focus_manager.add_group(this._buttonBox);
679
button.connect('clicked', Lang.bind(this, this._onActionInvoked, id));
684
// setButtonSensitive:
685
// @id: the action ID
686
// @sensitive: whether the button should be sensitive
688
// If the notification contains a button with action ID @id,
689
// its sensitivity will be set to @sensitive. Insensitive
690
// buttons cannot be clicked.
691
setButtonSensitive: function(id, sensitive) {
692
if (!this._buttonBox)
695
let button = this._buttonBox.get_children().filter(function(b) {
696
return b._actionId == id;
699
if (!button || button.reactive == sensitive)
702
button.reactive = sensitive;
705
setUrgency: function(urgency) {
706
this.urgency = urgency;
709
setResident: function(resident) {
710
this.resident = resident;
713
setTransient: function(isTransient) {
714
this.isTransient = isTransient;
717
setUseActionIcons: function(useIcons) {
718
this._useActionIcons = useIcons;
721
_styleChanged: function() {
722
this._spacing = this._table.get_theme_node().get_length('spacing-columns');
725
_bannerBoxGetPreferredWidth: function(actor, forHeight, alloc) {
726
let [titleMin, titleNat] = this._titleLabel.get_preferred_width(forHeight);
727
let [bannerMin, bannerNat] = this._bannerLabel.get_preferred_width(forHeight);
729
if (this._secondaryIcon) {
730
let [secondaryIconMin, secondaryIconNat] = this._secondaryIcon.get_preferred_width(forHeight);
732
alloc.min_size = secondaryIconMin + this._spacing + titleMin;
733
alloc.natural_size = secondaryIconNat + this._spacing + titleNat + this._spacing + bannerNat;
735
alloc.min_size = titleMin;
736
alloc.natural_size = titleNat + this._spacing + bannerNat;
740
_bannerBoxGetPreferredHeight: function(actor, forWidth, alloc) {
741
[alloc.min_size, alloc.natural_size] =
742
this._titleLabel.get_preferred_height(forWidth);
745
_bannerBoxAllocate: function(actor, box, flags) {
746
let availWidth = box.x2 - box.x1;
748
let [titleMinW, titleNatW] = this._titleLabel.get_preferred_width(-1);
749
let [titleMinH, titleNatH] = this._titleLabel.get_preferred_height(availWidth);
750
let [bannerMinW, bannerNatW] = this._bannerLabel.get_preferred_width(availWidth);
752
let rtl = (this._titleDirection == Clutter.TextDirection.RTL);
753
let x = rtl ? availWidth : 0;
755
if (this._secondaryIcon) {
756
let [iconMinW, iconNatW] = this._secondaryIcon.get_preferred_width(-1);
757
let [iconMinH, iconNatH] = this._secondaryIcon.get_preferred_height(availWidth);
759
let secondaryIconBox = new Clutter.ActorBox();
760
let secondaryIconBoxW = Math.min(iconNatW, availWidth);
762
// allocate secondary icon box
764
secondaryIconBox.x1 = x - secondaryIconBoxW;
765
secondaryIconBox.x2 = x;
766
x = x - (secondaryIconBoxW + this._spacing);
768
secondaryIconBox.x1 = x;
769
secondaryIconBox.x2 = x + secondaryIconBoxW;
770
x = x + secondaryIconBoxW + this._spacing;
772
secondaryIconBox.y1 = 0;
773
// Using titleNatH ensures that the secondary icon is centered vertically
774
secondaryIconBox.y2 = titleNatH;
776
availWidth = availWidth - (secondaryIconBoxW + this._spacing);
777
this._secondaryIcon.allocate(secondaryIconBox, flags);
780
let titleBox = new Clutter.ActorBox();
781
let titleBoxW = Math.min(titleNatW, availWidth);
783
titleBox.x1 = availWidth - titleBoxW;
784
titleBox.x2 = availWidth;
787
titleBox.x2 = titleBox.x1 + titleBoxW;
790
titleBox.y2 = titleNatH;
791
this._titleLabel.allocate(titleBox, flags);
792
this._titleFitsInBannerMode = (titleNatW <= availWidth);
794
let bannerFits = true;
795
if (titleBoxW + this._spacing > availWidth) {
796
this._bannerLabel.opacity = 0;
799
let bannerBox = new Clutter.ActorBox();
803
bannerBox.x2 = titleBox.x1 - this._spacing;
805
bannerFits = (bannerBox.x2 - bannerNatW >= 0);
807
bannerBox.x1 = titleBox.x2 + this._spacing;
808
bannerBox.x2 = availWidth;
810
bannerFits = (bannerBox.x1 + bannerNatW <= availWidth);
813
bannerBox.y2 = titleNatH;
814
this._bannerLabel.allocate(bannerBox, flags);
816
// Make _bannerLabel visible if the entire notification
817
// fits on one line, or if the notification is currently
818
// unexpanded and only showing one line anyway.
819
if (!this.expanded || (bannerFits && this._table.row_count == 1))
820
this._bannerLabel.opacity = 255;
823
// If the banner doesn't fully fit in the banner box, we possibly need to add the
824
// banner to the body. We can't do that from here though since that will force a
825
// relayout, so we add it to the main loop.
826
if (!bannerFits && this._canExpandContent())
827
Meta.later_add(Meta.LaterType.BEFORE_REDRAW,
830
if (this._canExpandContent()) {
831
this._addBannerBody();
832
this._table.add_style_class_name('multi-line-notification');
839
_canExpandContent: function() {
840
return this._bannerBodyText ||
841
(!this._titleFitsInBannerMode && !this._table.has_style_class_name('multi-line-notification'));
844
updated: function() {
849
expand: function(animate) {
850
this.expanded = true;
851
this.actor.remove_style_class_name('notification-unexpanded');
853
// The banner is never shown when the title did not fit, so this
854
// can be an if-else statement.
855
if (!this._titleFitsInBannerMode) {
856
// Remove ellipsization from the title label and make it wrap so that
857
// we show the full title when the notification is expanded.
858
this._titleLabel.clutter_text.line_wrap = true;
859
this._titleLabel.clutter_text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
860
this._titleLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
861
} else if (this._table.row_count > 1 && this._bannerLabel.opacity != 0) {
862
// We always hide the banner if the notification has additional content.
864
// We don't need to wrap the banner that doesn't fit the way we wrap the
865
// title that doesn't fit because we won't have a notification with
866
// row_count=1 that has a banner that doesn't fully fit. We'll either add
867
// that banner to the content of the notification in _bannerBoxAllocate()
868
// or the notification will have custom content.
870
Tweener.addTween(this._bannerLabel,
872
time: ANIMATION_TIME,
873
transition: 'easeOutQuad' });
875
this._bannerLabel.opacity = 0;
877
this.emit('expanded');
880
collapseCompleted: function() {
883
this.expanded = false;
884
// Make sure we don't line wrap the title, and ellipsize it instead.
885
this._titleLabel.clutter_text.line_wrap = false;
886
this._titleLabel.clutter_text.ellipsize = Pango.EllipsizeMode.END;
887
// Restore banner opacity in case the notification is shown in the
888
// banner mode again on update.
889
this._bannerLabel.opacity = 255;
890
// Restore height requisition
891
this.actor.add_style_class_name('notification-unexpanded');
892
this.emit('collapsed');
895
_onActionInvoked: function(actor, mouseButtonClicked, id) {
896
this.emit('action-invoked', id);
897
if (!this.resident) {
898
// We don't hide a resident notification when the user invokes one of its actions,
899
// because it is common for such notifications to update themselves with new
900
// information based on the action. We'd like to display the updated information
901
// in place, rather than pop-up a new notification.
902
this.emit('done-displaying');
907
_onClicked: function() {
908
this.emit('clicked');
909
// We hide all types of notifications once the user clicks on them because the common
910
// outcome of clicking should be the relevant window being brought forward and the user's
911
// attention switching to the window.
912
this.emit('done-displaying');
917
_onDestroy: function() {
920
this._destroyed = true;
921
if (!this._destroyedReason)
922
this._destroyedReason = NotificationDestroyedReason.DISMISSED;
923
this.emit('destroy', this._destroyedReason);
926
destroy: function(reason) {
927
this._destroyedReason = reason;
928
this.actor.destroy();
929
this.actor._delegate = null;
932
Signals.addSignalMethods(Notification.prototype);
934
const SourceActor = new Lang.Class({
937
_init: function(source, size) {
938
this._source = source;
941
this.actor = new Shell.GenericContainer();
942
this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
943
this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
944
this.actor.connect('allocate', Lang.bind(this, this._allocate));
945
this.actor.connect('destroy', Lang.bind(this, function() {
946
this._actorDestroyed = true;
948
this._actorDestroyed = false;
950
this._counterLabel = new St.Label( {x_align: Clutter.ActorAlign.CENTER,
952
y_align: Clutter.ActorAlign.CENTER,
955
this._counterBin = new St.Bin({ style_class: 'summary-source-counter',
956
child: this._counterLabel,
957
layout_manager: new Clutter.BinLayout() });
958
this._counterBin.hide();
960
this._counterBin.connect('style-changed', Lang.bind(this, function() {
961
let themeNode = this._counterBin.get_theme_node();
962
this._counterBin.translation_x = themeNode.get_length('-shell-counter-overlap-x');
963
this._counterBin.translation_y = themeNode.get_length('-shell-counter-overlap-y');
966
this._iconBin = new St.Bin({ width: size,
971
this.actor.add_actor(this._iconBin);
972
this.actor.add_actor(this._counterBin);
974
this._source.connect('count-updated', Lang.bind(this, this._updateCount));
977
this._source.connect('icon-updated', Lang.bind(this, this._updateIcon));
981
setIcon: function(icon) {
982
this._iconBin.child = icon;
983
this._iconSet = true;
986
_getPreferredWidth: function (actor, forHeight, alloc) {
987
let [min, nat] = this._iconBin.get_preferred_width(forHeight);
988
alloc.min_size = min; alloc.nat_size = nat;
991
_getPreferredHeight: function (actor, forWidth, alloc) {
992
let [min, nat] = this._iconBin.get_preferred_height(forWidth);
993
alloc.min_size = min; alloc.nat_size = nat;
996
_allocate: function(actor, box, flags) {
997
// the iconBin should fill our entire box
998
this._iconBin.allocate(box, flags);
1000
let childBox = new Clutter.ActorBox();
1002
let [minWidth, minHeight, naturalWidth, naturalHeight] = this._counterBin.get_preferred_size();
1003
let direction = this.actor.get_text_direction();
1005
if (direction == Clutter.TextDirection.LTR) {
1006
// allocate on the right in LTR
1007
childBox.x1 = box.x2 - naturalWidth;
1008
childBox.x2 = box.x2;
1010
// allocate on the left in RTL
1012
childBox.x2 = naturalWidth;
1015
childBox.y1 = box.y2 - naturalHeight;
1016
childBox.y2 = box.y2;
1018
this._counterBin.allocate(childBox, flags);
1021
_updateIcon: function() {
1022
if (this._actorDestroyed)
1026
this._iconBin.child = this._source.createIcon(this._size);
1029
_updateCount: function() {
1030
if (this._actorDestroyed)
1033
this._counterBin.visible = this._source.countVisible;
1036
if (this._source.count < 100)
1037
text = this._source.count.toString();
1039
text = String.fromCharCode(0x22EF); // midline horizontal ellipsis
1041
this._counterLabel.set_text(text);
1045
const Source = new Lang.Class({
1046
Name: 'MessageTraySource',
1048
SOURCE_ICON_SIZE: 48,
1050
_init: function(title, iconName) {
1052
this.iconName = iconName;
1054
this.isTransient = false;
1055
this.isChat = false;
1056
this.isMuted = false;
1057
this.showInLockScreen = true;
1058
this.keepTrayOnSummaryClick = false;
1060
this.notifications = [];
1064
return this.notifications.length;
1068
return this.notifications.filter(function(n) { return !n.acknowledged; }).length;
1071
get countVisible() {
1072
return this.count > 1;
1075
countUpdated: function() {
1076
this.emit('count-updated');
1079
buildRightClickMenu: function() {
1081
let rightClickMenu = new St.BoxLayout({ name: 'summary-right-click-menu',
1084
item = new PopupMenu.PopupMenuItem(_("Open"));
1085
item.connect('activate', Lang.bind(this, function() {
1087
this.emit('done-displaying-content');
1089
rightClickMenu.add(item.actor);
1091
item = new PopupMenu.PopupMenuItem(_("Remove"));
1092
item.connect('activate', Lang.bind(this, function() {
1094
this.emit('done-displaying-content');
1096
rightClickMenu.add(item.actor);
1097
return rightClickMenu;
1100
setTransient: function(isTransient) {
1101
this.isTransient = isTransient;
1104
setTitle: function(newTitle) {
1105
this.title = newTitle;
1106
this.emit('title-changed');
1109
setMuted: function(muted) {
1110
if (!this.isChat || this.isMuted == muted)
1112
this.isMuted = muted;
1113
this.emit('muted-changed');
1116
// Called to create a new icon actor.
1117
// Provides a sane default implementation, override if you need
1118
// something more fancy.
1119
createIcon: function(size) {
1120
return new St.Icon({ icon_name: this.iconName,
1124
_ensureMainIcon: function() {
1128
this._mainIcon = new SourceActor(this, this.SOURCE_ICON_SIZE);
1131
// Unlike createIcon, this always returns the same actor;
1132
// there is only one summary icon actor for a Source.
1133
getSummaryIcon: function() {
1134
this._ensureMainIcon();
1135
return this._mainIcon.actor;
1138
pushNotification: function(notification) {
1139
if (this.notifications.indexOf(notification) < 0) {
1140
this.notifications.push(notification);
1141
this.emit('notification-added', notification);
1144
notification.connect('clicked', Lang.bind(this, this.open));
1145
notification.connect('destroy', Lang.bind(this,
1147
let index = this.notifications.indexOf(notification);
1151
this.notifications.splice(index, 1);
1152
if (this.notifications.length == 0)
1153
this._lastNotificationRemoved();
1155
this.countUpdated();
1158
this.countUpdated();
1161
notify: function(notification) {
1162
notification.acknowledged = false;
1163
this.pushNotification(notification);
1165
this.emit('notify', notification);
1168
destroy: function(reason) {
1169
this.emit('destroy', reason);
1172
// A subclass can redefine this to "steal" clicks from the
1173
// summaryitem; Use Clutter.get_current_event() to get the
1174
// details, return true to prevent the default handling from
1176
handleSummaryClick: function() {
1180
iconUpdated: function() {
1181
this.emit('icon-updated');
1184
//// Protected methods ////
1185
_setSummaryIcon: function(icon) {
1186
this._ensureMainIcon();
1187
this._mainIcon.setIcon(icon);
1191
open: function(notification) {
1192
this.emit('opened', notification);
1195
destroyNonResidentNotifications: function() {
1196
for (let i = this.notifications.length - 1; i >= 0; i--)
1197
if (!this.notifications[i].resident)
1198
this.notifications[i].destroy();
1200
this.countUpdated();
1203
// Default implementation is to destroy this source, but subclasses can override
1204
_lastNotificationRemoved: function() {
1208
hasResidentNotification: function() {
1209
return this.notifications.some(function(n) { return n.resident; });
1212
Signals.addSignalMethods(Source.prototype);
1214
const SummaryItem = new Lang.Class({
1215
Name: 'SummaryItem',
1217
_init: function(source) {
1218
this.source = source;
1219
this.source.connect('notification-added', Lang.bind(this, this._notificationAddedToSource));
1221
this.actor = new St.Button({ style_class: 'summary-source-button',
1224
button_mask: St.ButtonMask.ONE | St.ButtonMask.TWO | St.ButtonMask.THREE,
1226
track_hover: true });
1227
this.actor.label_actor = new St.Label({ text: source.title });
1228
this.actor.connect('key-press-event', Lang.bind(this, this._onKeyPress));
1229
this._sourceBox = new St.BoxLayout({ style_class: 'summary-source' });
1231
this._sourceIcon = source.getSummaryIcon();
1232
this._sourceBox.add(this._sourceIcon, { y_fill: false });
1233
this.actor.child = this._sourceBox;
1235
this.notificationStackWidget = new St.Widget({ layout_manager: new Clutter.BinLayout() });
1237
this.notificationStackView = new St.ScrollView({ style_class: source.isChat ? '' : 'summary-notification-stack-scrollview',
1238
vscrollbar_policy: source.isChat ? Gtk.PolicyType.NEVER : Gtk.PolicyType.AUTOMATIC,
1239
hscrollbar_policy: Gtk.PolicyType.NEVER });
1240
this.notificationStackView.add_style_class_name('vfade');
1241
this.notificationStack = new St.BoxLayout({ style_class: 'summary-notification-stack',
1243
this.notificationStackView.add_actor(this.notificationStack);
1244
this.notificationStackWidget.add_actor(this.notificationStackView);
1246
this.closeButton = makeCloseButton();
1247
this.notificationStackWidget.add_actor(this.closeButton);
1248
this._stackedNotifications = [];
1250
this._oldMaxScrollAdjustment = 0;
1252
this.notificationStackView.vscroll.adjustment.connect('changed', Lang.bind(this, function(adjustment) {
1253
let currentValue = adjustment.value + adjustment.page_size;
1254
if (currentValue == this._oldMaxScrollAdjustment)
1255
this.scrollTo(St.Side.BOTTOM);
1256
this._oldMaxScrollAdjustment = adjustment.upper;
1259
this.rightClickMenu = source.buildRightClickMenu();
1260
if (this.rightClickMenu)
1261
global.focus_manager.add_group(this.rightClickMenu);
1264
_onKeyPress: function(actor, event) {
1265
if (event.get_key_symbol() == Clutter.KEY_Up) {
1266
actor.emit('clicked', 1);
1272
prepareNotificationStackForShowing: function() {
1273
if (this.notificationStack.get_n_children() > 0)
1276
for (let i = 0; i < this.source.notifications.length; i++) {
1277
this._appendNotificationToStack(this.source.notifications[i]);
1280
this.scrollTo(St.Side.BOTTOM);
1283
doneShowingNotificationStack: function() {
1284
for (let i = 0; i < this._stackedNotifications.length; i++) {
1285
let stackedNotification = this._stackedNotifications[i];
1286
let notification = stackedNotification.notification;
1287
notification.collapseCompleted();
1288
notification.disconnect(stackedNotification.notificationExpandedId);
1289
notification.disconnect(stackedNotification.notificationDoneDisplayingId);
1290
notification.disconnect(stackedNotification.notificationDestroyedId);
1291
if (notification.actor.get_parent() == this.notificationStack)
1292
this.notificationStack.remove_actor(notification.actor);
1293
notification.setIconVisible(true);
1294
notification.enableScrolling(true);
1296
this._stackedNotifications = [];
1299
_notificationAddedToSource: function(source, notification) {
1300
if (this.notificationStack.mapped)
1301
this._appendNotificationToStack(notification);
1304
_appendNotificationToStack: function(notification) {
1305
let stackedNotification = {};
1306
stackedNotification.notification = notification;
1307
stackedNotification.notificationExpandedId = notification.connect('expanded', Lang.bind(this, this._contentUpdated));
1308
stackedNotification.notificationDoneDisplayingId = notification.connect('done-displaying', Lang.bind(this, this._notificationDoneDisplaying));
1309
stackedNotification.notificationDestroyedId = notification.connect('destroy', Lang.bind(this, this._notificationDestroyed));
1310
this._stackedNotifications.push(stackedNotification);
1311
if (!this.source.isChat)
1312
notification.enableScrolling(false);
1313
if (this.notificationStack.get_n_children() > 0)
1314
notification.setIconVisible(false);
1315
this.notificationStack.add(notification.actor);
1316
notification.expand(false);
1320
// @side: St.Side.TOP or St.Side.BOTTOM
1322
// Scrolls the notifiction stack to the indicated edge
1323
scrollTo: function(side) {
1324
let adjustment = this.notificationStackView.vscroll.adjustment;
1325
if (side == St.Side.TOP)
1326
adjustment.value = adjustment.lower;
1327
else if (side == St.Side.BOTTOM)
1328
adjustment.value = adjustment.upper;
1331
_contentUpdated: function() {
1332
this.emit('content-updated');
1335
_notificationDoneDisplaying: function() {
1336
this.source.emit('done-displaying-content');
1339
_notificationDestroyed: function(notification) {
1340
for (let i = 0; i < this._stackedNotifications.length; i++) {
1341
if (this._stackedNotifications[i].notification == notification) {
1342
let stackedNotification = this._stackedNotifications[i];
1343
notification.disconnect(stackedNotification.notificationExpandedId);
1344
notification.disconnect(stackedNotification.notificationDoneDisplayingId);
1345
notification.disconnect(stackedNotification.notificationDestroyedId);
1346
this._stackedNotifications.splice(i, 1);
1347
if (notification.actor.get_parent() == this.notificationStack)
1348
this.notificationStack.remove_actor(notification.actor);
1349
this._contentUpdated();
1354
let firstNotification = this._stackedNotifications[0];
1355
if (firstNotification)
1356
firstNotification.notification.setIconVisible(true);
1359
Signals.addSignalMethods(SummaryItem.prototype);
1361
const MessageTray = new Lang.Class({
1362
Name: 'MessageTray',
1365
this._presence = new GnomeSession.Presence(Lang.bind(this, function(proxy, error) {
1366
this._onStatusChanged(proxy.status);
1369
this._presence.connectSignal('StatusChanged', Lang.bind(this, function(proxy, senderName, [status]) {
1370
this._onStatusChanged(status);
1373
this.actor = new St.Widget({ name: 'message-tray',
1376
layout_manager: new Clutter.BinLayout(),
1379
y_align: Clutter.ActorAlign.START,
1381
this.actor.connect('notify::hover', Lang.bind(this, this._onTrayHoverChanged));
1383
this._notificationWidget = new St.Widget({ name: 'notification-container',
1384
y_align: Clutter.ActorAlign.START,
1385
x_align: Clutter.ActorAlign.CENTER,
1388
layout_manager: new Clutter.BinLayout() });
1389
this.actor.add_actor(this._notificationWidget);
1391
this._notificationBin = new St.Bin({ y_expand: true });
1392
this._notificationBin.set_y_align(Clutter.ActorAlign.START);
1393
this._notificationWidget.add_actor(this._notificationBin);
1394
this._notificationWidget.hide();
1395
this._notificationQueue = [];
1396
this._notification = null;
1397
this._notificationClickedId = 0;
1399
this.actor.connect('button-release-event', Lang.bind(this, function(actor, event) {
1400
this._setClickedSummaryItem(null);
1401
this._updateState();
1402
actor.grab_key_focus();
1404
global.focus_manager.add_group(this.actor);
1405
this._summary = new St.BoxLayout({ name: 'summary-mode',
1408
x_align: Clutter.ActorAlign.END,
1410
y_align: Clutter.ActorAlign.CENTER,
1412
this._summary.connect('notify::hover', Lang.bind(this, this._onSummaryHoverChanged));
1413
this.actor.add_actor(this._summary);
1414
this._summary.opacity = 0;
1416
this._summaryMotionId = 0;
1417
this._trayMotionId = 0;
1419
this._summaryBoxPointer = new BoxPointer.BoxPointer(St.Side.BOTTOM,
1421
track_hover: true });
1422
this._summaryBoxPointer.actor.connect('key-press-event',
1423
Lang.bind(this, this._onSummaryBoxPointerKeyPress));
1424
this._summaryBoxPointer.actor.style_class = 'summary-boxpointer';
1425
this._summaryBoxPointer.actor.hide();
1426
Main.layoutManager.addChrome(this._summaryBoxPointer.actor);
1428
this._summaryBoxPointerItem = null;
1429
this._summaryBoxPointerContentUpdatedId = 0;
1430
this._summaryBoxPointerDoneDisplayingId = 0;
1431
this._clickedSummaryItem = null;
1432
this._clickedSummaryItemMouseButton = -1;
1433
this._clickedSummaryItemAllocationChangedId = 0;
1434
this._pointerBarrier = 0;
1436
this._closeButton = makeCloseButton();
1437
this._closeButton.hide();
1438
this._closeButton.connect('clicked', Lang.bind(this, this._onCloseClicked));
1439
this._notificationWidget.add_actor(this._closeButton);
1441
this._idleMonitorWatchId = 0;
1442
this._userActiveWhileNotificationShown = false;
1444
this.idleMonitor = Shell.IdleMonitor.get();
1446
this._grabHelper = new GrabHelper.GrabHelper(this.actor);
1447
this._grabHelper.addActor(this._summaryBoxPointer.actor);
1448
this._grabHelper.addActor(this.actor);
1449
if (Main.panel.statusArea.activities)
1450
this._grabHelper.addActor(Main.panel.statusArea.activities.hotCorner.actor);
1452
Main.layoutManager.keyboardBox.connect('notify::hover', Lang.bind(this, this._onKeyboardHoverChanged));
1453
Main.layoutManager.connect('keyboard-visible-changed', Lang.bind(this, this._onKeyboardVisibleChanged));
1455
this._trayState = State.HIDDEN;
1456
this._locked = false;
1457
this._traySummoned = false;
1458
this._useLongerTrayLeftTimeout = false;
1459
this._trayLeftTimeoutId = 0;
1460
this._pointerInTray = false;
1461
this._pointerInKeyboard = false;
1462
this._keyboardVisible = false;
1463
this._summaryState = State.HIDDEN;
1464
this._pointerInSummary = false;
1465
this._notificationClosed = false;
1466
this._notificationState = State.HIDDEN;
1467
this._notificationTimeoutId = 0;
1468
this._notificationExpandedId = 0;
1469
this._summaryBoxPointerState = State.HIDDEN;
1470
this._summaryBoxPointerTimeoutId = 0;
1471
this._desktopCloneState = State.HIDDEN;
1472
this._overviewVisible = Main.overview.visible;
1473
this._notificationRemoved = false;
1474
this._reNotifyAfterHideNotification = null;
1475
this._inFullscreen = false;
1476
this._desktopClone = null;
1478
this._lightbox = new Lightbox.Lightbox(global.window_group,
1479
{ inhibitEvents: true,
1480
fadeInTime: ANIMATION_TIME,
1481
fadeOutTime: ANIMATION_TIME,
1485
Main.layoutManager.trayBox.add_actor(this.actor);
1487
Main.layoutManager.trackChrome(this.actor);
1488
Main.layoutManager.trackChrome(this._notificationWidget);
1489
Main.layoutManager.trackChrome(this._closeButton);
1491
Main.layoutManager.connect('primary-fullscreen-changed', Lang.bind(this, this._onFullscreenChanged));
1493
Main.overview.connect('showing', Lang.bind(this,
1495
this._overviewVisible = true;
1496
this._grabHelper.ungrab(); // drop modal grab if necessary
1497
this.actor.add_style_pseudo_class('overview');
1498
this._updateState();
1500
Main.overview.connect('hiding', Lang.bind(this,
1502
this._overviewVisible = false;
1504
this.actor.remove_style_pseudo_class('overview');
1505
this._updateState();
1508
Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
1510
global.display.add_keybinding('toggle-message-tray',
1511
new Gio.Settings({ schema: SHELL_KEYBINDINGS_SCHEMA }),
1512
Meta.KeyBindingFlags.NONE,
1513
Lang.bind(this, this.toggleAndNavigate));
1515
this._summaryItems = [];
1516
this._chatSummaryItemsCount = 0;
1518
let pointerWatcher = PointerWatcher.getPointerWatcher();
1519
pointerWatcher.addWatch(TRAY_DWELL_CHECK_INTERVAL, Lang.bind(this, this._checkTrayDwell));
1520
this._trayDwellTimeoutId = 0;
1521
this._trayDwelling = false;
1522
this._trayDwellUserTime = 0;
1524
this._sessionUpdated();
1527
_sessionUpdated: function() {
1528
if (Main.sessionMode.isLocked || Main.sessionMode.isGreeter)
1529
Main.ctrlAltTabManager.removeGroup(this._summary);
1531
Main.ctrlAltTabManager.addGroup(this._summary, _("Message Tray"), 'start-here-symbolic',
1532
{ focusCallback: Lang.bind(this, this.toggleAndNavigate),
1533
sortGroup: CtrlAltTab.SortGroup.BOTTOM });
1534
this._updateState();
1537
_checkTrayDwell: function(x, y) {
1538
let monitor = Main.layoutManager.bottomMonitor;
1539
let shouldDwell = (x >= monitor.x && x <= monitor.x + monitor.width &&
1540
y == monitor.y + monitor.height - 1);
1542
// We only set up dwell timeout when the user is not hovering over the tray
1543
// (!this.actor.hover). This avoids bringing up the message tray after the
1544
// user clicks on a notification with the pointer on the bottom pixel
1545
// of the monitor. The _trayDwelling variable is used so that we only try to
1546
// fire off one tray dwell - if it fails (because, say, the user has the mouse down),
1547
// we don't try again until the user moves the mouse up and down again.
1548
if (!this._trayDwelling && !this.actor.hover && this._trayDwellTimeoutId == 0) {
1549
// Save the interaction timestamp so we can detect user input
1550
let focusWindow = global.display.focus_window;
1551
this._trayDwellUserTime = focusWindow ? focusWindow.user_time : 0;
1553
this._trayDwellTimeoutId = Mainloop.timeout_add(TRAY_DWELL_TIME,
1554
Lang.bind(this, this._trayDwellTimeout));
1556
this._trayDwelling = true;
1558
this._cancelTrayDwell();
1559
this._trayDwelling = false;
1563
_cancelTrayDwell: function() {
1564
if (this._trayDwellTimeoutId != 0) {
1565
Mainloop.source_remove(this._trayDwellTimeoutId);
1566
this._trayDwellTimeoutId = 0;
1570
_trayDwellTimeout: function() {
1571
if (Main.modalCount > 0)
1574
// If the user interacted with the focus window since we started the tray
1575
// dwell (by clicking or typing), don't activate the message tray
1576
let focusWindow = global.display.focus_window;
1577
let currentUserTime = focusWindow ? focusWindow.user_time : 0;
1578
if (currentUserTime != this._trayDwellUserTime)
1581
this._trayDwellTimeoutId = 0;
1583
this._traySummoned = true;
1584
this._updateState();
1589
_onCloseClicked: function() {
1590
if (this._notificationState == State.SHOWN) {
1591
this._closeButton.hide();
1592
this._notificationClosed = true;
1593
this._updateState();
1594
this._notificationClosed = false;
1598
contains: function(source) {
1599
return this._getIndexOfSummaryItemForSource(source) >= 0;
1602
_getIndexOfSummaryItemForSource: function(source) {
1603
for (let i = 0; i < this._summaryItems.length; i++) {
1604
if (this._summaryItems[i].source == source)
1610
add: function(source) {
1611
if (this.contains(source)) {
1612
log('Trying to re-add source ' + source.title);
1616
let summaryItem = new SummaryItem(source);
1618
if (source.isChat) {
1619
this._summary.insert_child_at_index(summaryItem.actor, 0);
1620
this._chatSummaryItemsCount++;
1622
this._summary.insert_child_at_index(summaryItem.actor, this._chatSummaryItemsCount);
1625
this._summaryItems.push(summaryItem);
1627
source.connect('notify', Lang.bind(this, this._onNotify));
1629
source.connect('muted-changed', Lang.bind(this,
1632
this._notificationQueue = this._notificationQueue.filter(function(notification) {
1633
return source != notification.source;
1637
summaryItem.actor.connect('clicked', Lang.bind(this,
1638
function(actor, button) {
1639
actor.grab_key_focus();
1640
this._onSummaryItemClicked(summaryItem, button);
1642
summaryItem.actor.connect('popup-menu', Lang.bind(this,
1643
function(actor, button) {
1644
actor.grab_key_focus();
1645
this._onSummaryItemClicked(summaryItem, 3);
1648
source.connect('destroy', Lang.bind(this, this._onSourceDestroy));
1650
// We need to display the newly-added summary item, but if the
1651
// caller is about to post a notification, we want to show that
1652
// *first* and not show the summary item until after it hides.
1653
// So postpone calling _updateState() a tiny bit.
1654
Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() { this._updateState(); return false; }));
1656
this.emit('summary-item-added', summaryItem);
1659
getSummaryItems: function() {
1660
return this._summaryItems;
1663
_onSourceDestroy: function(source) {
1664
let index = this._getIndexOfSummaryItemForSource(source);
1668
let summaryItemToRemove = this._summaryItems[index];
1670
this._summaryItems.splice(index, 1);
1673
this._chatSummaryItemsCount--;
1675
let needUpdate = false;
1677
if (this._notification && this._notification.source == source) {
1678
this._updateNotificationTimeout(0);
1679
this._notificationRemoved = true;
1682
if (this._clickedSummaryItem == summaryItemToRemove) {
1683
this._setClickedSummaryItem(null);
1687
summaryItemToRemove.actor.destroy();
1690
this._updateState();
1693
_onNotificationDestroy: function(notification) {
1694
if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) {
1695
this._updateNotificationTimeout(0);
1696
this._notificationRemoved = true;
1697
this._updateState();
1701
let index = this._notificationQueue.indexOf(notification);
1702
notification.destroy();
1704
this._notificationQueue.splice(index, 1);
1708
this._locked = true;
1711
_unlock: function() {
1714
this._locked = false;
1715
this._pointerInTray = this.actor.hover;
1716
this._updateState();
1719
toggle: function() {
1720
this._traySummoned = !this._traySummoned;
1721
this._updateState();
1724
toggleAndNavigate: function() {
1726
this._summary.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
1730
this._traySummoned = false;
1731
this.actor.set_hover(false);
1732
this._summary.set_hover(false);
1733
this._updateState();
1736
_onNotify: function(source, notification) {
1737
if (this._summaryBoxPointerItem && this._summaryBoxPointerItem.source == source) {
1738
if (this._summaryBoxPointerState == State.HIDING) {
1739
// We are in the process of hiding the summary box pointer.
1740
// If there is an update for one of the notifications or
1741
// a new notification to be added to the notification stack
1742
// while it is in the process of being hidden, we show it as
1743
// a new notification. However, we first wait till the hide
1744
// is complete. This is especially important if one of the
1745
// notifications in the stack was updated because we will
1746
// need to be able to re-parent its actor to a different
1747
// part of the stage.
1748
this._reNotifyAfterHideNotification = notification;
1750
// The summary box pointer is showing or shown (otherwise,
1751
// this._summaryBoxPointerItem would be null)
1752
// Immediately mark the notification as acknowledged, as it's
1753
// not going into the queue
1754
notification.acknowledged = true;
1760
if (this._notification == notification) {
1761
// If a notification that is being shown is updated, we update
1762
// how it is shown and extend the time until it auto-hides.
1763
// If a new notification is updated while it is being hidden,
1764
// we stop hiding it and show it again.
1765
this._updateShowingNotification();
1766
} else if (this._notificationQueue.indexOf(notification) < 0) {
1767
notification.connect('destroy',
1768
Lang.bind(this, this._onNotificationDestroy));
1769
this._notificationQueue.push(notification);
1770
this._notificationQueue.sort(function(notification1, notification2) {
1771
return (notification2.urgency - notification1.urgency);
1774
this._updateState();
1777
_onSummaryItemClicked: function(summaryItem, button) {
1778
if (summaryItem.source.handleSummaryClick()) {
1779
if (summaryItem.source.keepTrayOnSummaryClick)
1780
this._setClickedSummaryItem(null);
1784
if (!this._setClickedSummaryItem(summaryItem, button))
1785
this._setClickedSummaryItem(null);
1788
this._updateState();
1791
_onSummaryHoverChanged: function() {
1792
this._pointerInSummary = this._summary.hover;
1793
this._updateState();
1796
_onTrayHoverChanged: function() {
1797
if (this.actor.hover) {
1798
// No dwell inside notifications at the bottom of the screen
1799
this._cancelTrayDwell();
1801
// Don't do anything if the one pixel area at the bottom is hovered over while the tray is hidden.
1802
if (this._trayState == State.HIDDEN && this._notificationState == State.HIDDEN)
1805
// Don't do anything if this._useLongerTrayLeftTimeout is true, meaning the notification originally
1806
// popped up under the pointer, but this._trayLeftTimeoutId is 0, meaning the pointer didn't leave
1807
// the tray yet. We need to check for this case because sometimes _onTrayHoverChanged() gets called
1808
// multiple times while this.actor.hover is true.
1809
if (this._useLongerTrayLeftTimeout && !this._trayLeftTimeoutId)
1812
this._useLongerTrayLeftTimeout = false;
1813
if (this._trayLeftTimeoutId) {
1814
Mainloop.source_remove(this._trayLeftTimeoutId);
1815
this._trayLeftTimeoutId = 0;
1816
this._trayLeftMouseX = -1;
1817
this._trayLeftMouseY = -1;
1821
if (this._showNotificationMouseX >= 0) {
1822
let actorAtShowNotificationPosition =
1823
global.stage.get_actor_at_pos(Clutter.PickMode.ALL, this._showNotificationMouseX, this._showNotificationMouseY);
1824
this._showNotificationMouseX = -1;
1825
this._showNotificationMouseY = -1;
1826
// Don't set this._pointerInTray to true if the pointer was initially in the area where the notification
1827
// popped up. That way we will not be expanding notifications that happen to pop up over the pointer
1828
// automatically. Instead, the user is able to expand the notification by mousing away from it and then
1829
// mousing back in. Because this is an expected action, we set the boolean flag that indicates that a longer
1830
// timeout should be used before popping down the notification.
1831
if (this.actor.contains(actorAtShowNotificationPosition)) {
1832
this._useLongerTrayLeftTimeout = true;
1836
this._pointerInTray = true;
1837
this._updateState();
1839
// We record the position of the mouse the moment it leaves the tray. These coordinates are used in
1840
// this._onTrayLeftTimeout() to determine if the mouse has moved far enough during the initial timeout for us
1841
// to consider that the user intended to leave the tray and therefore hide the tray. If the mouse is still
1842
// close to its previous position, we extend the timeout once.
1843
let [x, y, mods] = global.get_pointer();
1844
this._trayLeftMouseX = x;
1845
this._trayLeftMouseY = y;
1847
// We wait just a little before hiding the message tray in case the user quickly moves the mouse back into it.
1848
// We wait for a longer period if the notification popped up where the mouse pointer was already positioned.
1849
// That gives the user more time to mouse away from the notification and mouse back in in order to expand it.
1850
let timeout = this._useLongerTrayLeftTimeout ? LONGER_HIDE_TIMEOUT * 1000 : HIDE_TIMEOUT * 1000;
1851
this._trayLeftTimeoutId = Mainloop.timeout_add(timeout, Lang.bind(this, this._onTrayLeftTimeout));
1855
_onKeyboardHoverChanged: function(keyboard) {
1856
this._pointerInKeyboard = keyboard.hover;
1858
if (!keyboard.hover) {
1859
let event = Clutter.get_current_event();
1860
if (event && event.type() == Clutter.EventType.LEAVE) {
1861
let into = event.get_related();
1862
if (into && this.actor.contains(into)) {
1863
// Don't call _updateState, because pointerInTray is
1870
this._updateState();
1873
_onKeyboardVisibleChanged: function(layoutManager, keyboardVisible) {
1874
if (this._keyboardVisible == keyboardVisible)
1877
this._keyboardVisible = keyboardVisible;
1879
if (keyboardVisible)
1880
this.actor.add_style_pseudo_class('keyboard');
1882
this.actor.remove_style_pseudo_class('keyboard');
1884
this._updateState();
1887
_onFullscreenChanged: function(obj, state) {
1888
this._inFullscreen = state;
1889
this._updateState();
1892
_onStatusChanged: function(status) {
1893
if (status == GnomeSession.PresenceStatus.BUSY) {
1894
// remove notification and allow the summary to be closed now
1895
this._updateNotificationTimeout(0);
1897
} else if (status != GnomeSession.PresenceStatus.IDLE) {
1898
// We preserve the previous value of this._busy if the status turns to IDLE
1899
// so that we don't start showing notifications queued during the BUSY state
1900
// as the screensaver gets activated.
1904
this._updateState();
1907
_onTrayLeftTimeout: function() {
1908
let [x, y, mods] = global.get_pointer();
1909
// We extend the timeout once if the mouse moved no further than MOUSE_LEFT_ACTOR_THRESHOLD to either side or up.
1910
// We don't check how far down the mouse moved because any point above the tray, but below the exit coordinate,
1911
// is close to the tray.
1912
if (this._trayLeftMouseX > -1 &&
1913
y > this._trayLeftMouseY - MOUSE_LEFT_ACTOR_THRESHOLD &&
1914
x < this._trayLeftMouseX + MOUSE_LEFT_ACTOR_THRESHOLD &&
1915
x > this._trayLeftMouseX - MOUSE_LEFT_ACTOR_THRESHOLD) {
1916
this._trayLeftMouseX = -1;
1917
this._trayLeftTimeoutId = Mainloop.timeout_add(LONGER_HIDE_TIMEOUT * 1000,
1918
Lang.bind(this, this._onTrayLeftTimeout));
1920
this._trayLeftTimeoutId = 0;
1921
this._useLongerTrayLeftTimeout = false;
1922
this._pointerInTray = false;
1923
this._pointerInSummary = false;
1924
this._updateNotificationTimeout(0);
1925
this._updateState();
1930
_escapeTray: function() {
1932
this._pointerInTray = false;
1933
this._pointerInSummary = false;
1934
this._traySummoned = false;
1935
this._setClickedSummaryItem(null);
1936
this._updateNotificationTimeout(0);
1937
this._updateState();
1940
// All of the logic for what happens when occurs here; the various
1941
// event handlers merely update variables such as
1942
// 'this._pointerInTray', 'this._summaryState', etc, and
1943
// _updateState() figures out what (if anything) needs to be done
1944
// at the present time.
1945
_updateState: function() {
1947
let notificationQueue = this._notificationQueue;
1948
let notificationUrgent = notificationQueue.length > 0 && notificationQueue[0].urgency == Urgency.CRITICAL;
1949
let notificationsLimited = this._busy || this._inFullscreen;
1950
let notificationsPending = notificationQueue.length > 0 && (!notificationsLimited || notificationUrgent) && Main.sessionMode.hasNotifications;
1951
let nextNotification = notificationQueue.length > 0 ? notificationQueue[0] : null;
1952
let notificationPinned = this._pointerInTray && !this._pointerInSummary && !this._notificationRemoved;
1953
let notificationExpanded = this._notification && this._notification.expanded;
1954
let notificationExpired = this._notificationTimeoutId == 0 &&
1955
!(this._notification && this._notification.urgency == Urgency.CRITICAL) &&
1956
!(this._notification && this._notification.focused) &&
1957
!this._pointerInTray &&
1959
!(this._pointerInKeyboard && notificationExpanded);
1960
let notificationLockedOut = !Main.sessionMode.hasNotifications && this._notification;
1961
let notificationMustClose = this._notificationRemoved || notificationLockedOut || (notificationExpired && this._userActiveWhileNotificationShown) || this._notificationClosed;
1962
let canShowNotification = notificationsPending && this._summaryState == State.HIDDEN;
1964
if (this._notificationState == State.HIDDEN) {
1965
if (canShowNotification) {
1966
this._showNotification();
1968
} else if (this._notificationState == State.SHOWN) {
1969
if (notificationMustClose)
1970
this._hideNotification();
1971
else if (notificationPinned && !notificationExpanded)
1972
this._expandNotification(false);
1973
else if (notificationPinned)
1974
this._ensureNotificationFocused();
1978
let summarySummoned = this._pointerInSummary || this._overviewVisible || this._traySummoned;
1979
let summaryPinned = this._pointerInTray || summarySummoned || this._locked;
1980
let summaryHovered = this._pointerInTray || this._pointerInSummary;
1982
let notificationsVisible = (this._notificationState == State.SHOWING ||
1983
this._notificationState == State.SHOWN);
1984
let notificationsDone = !notificationsVisible && !notificationsPending;
1986
let summaryOptionalInOverview = this._overviewVisible && !this._locked && !summaryHovered;
1987
let mustHideSummary = (notificationsPending && (notificationUrgent || summaryOptionalInOverview))
1988
|| notificationsVisible || !Main.sessionMode.hasNotifications;
1990
if (this._summaryState == State.HIDDEN && !mustHideSummary && summarySummoned)
1991
this._showSummary();
1992
else if (this._summaryState == State.SHOWN && (!summaryPinned || mustHideSummary))
1993
this._hideSummary();
1995
// Summary notification
1996
let haveClickedSummaryItem = this._clickedSummaryItem != null;
1997
let summarySourceIsMainNotificationSource = (haveClickedSummaryItem && this._notification &&
1998
this._clickedSummaryItem.source == this._notification.source);
1999
let canShowSummaryBoxPointer = this._summaryState == State.SHOWN;
2000
// We only have sources with empty notification stacks for legacy tray icons. Currently, we never attempt
2001
// to show notifications for legacy tray icons, but this would be necessary if we did.
2002
let requestedNotificationStackIsEmpty = (this._clickedSummaryItemMouseButton == 1 && this._clickedSummaryItem.source.notifications.length == 0);
2003
let wrongSummaryNotificationStack = (this._clickedSummaryItemMouseButton == 1 &&
2004
this._summaryBoxPointer.bin.child != this._clickedSummaryItem.notificationStackWidget);
2005
let wrongSummaryRightClickMenu = (this._clickedSummaryItemMouseButton == 3 &&
2006
this._summaryBoxPointer.bin.child != this._clickedSummaryItem.rightClickMenu);
2007
let wrongSummaryBoxPointer = (haveClickedSummaryItem &&
2008
(wrongSummaryNotificationStack || wrongSummaryRightClickMenu));
2010
if (this._summaryBoxPointerState == State.HIDDEN) {
2011
if (haveClickedSummaryItem && !summarySourceIsMainNotificationSource && canShowSummaryBoxPointer && !requestedNotificationStackIsEmpty)
2012
this._showSummaryBoxPointer();
2013
} else if (this._summaryBoxPointerState == State.SHOWN) {
2014
if (!haveClickedSummaryItem || !canShowSummaryBoxPointer || wrongSummaryBoxPointer || mustHideSummary) {
2015
this._hideSummaryBoxPointer();
2016
if (wrongSummaryBoxPointer)
2017
this._showSummaryBoxPointer();
2022
let trayIsVisible = (this._trayState == State.SHOWING ||
2023
this._trayState == State.SHOWN);
2024
let trayShouldBeVisible = (this._summaryState == State.SHOWING ||
2025
this._summaryState == State.SHOWN);
2026
if (!trayIsVisible && trayShouldBeVisible)
2027
trayShouldBeVisible = this._showTray();
2028
else if (trayIsVisible && !trayShouldBeVisible)
2032
let desktopCloneIsVisible = (this._desktopCloneState == State.SHOWING ||
2033
this._desktopCloneState == State.SHOWN);
2034
let desktopCloneShouldBeVisible = (trayShouldBeVisible &&
2035
!this._overviewVisible &&
2036
!this._keyboardVisible);
2038
if (!desktopCloneIsVisible && desktopCloneShouldBeVisible) {
2039
this._showDesktopClone();
2040
} else if (desktopCloneIsVisible && !desktopCloneShouldBeVisible) {
2041
this._hideDesktopClone (this._keyboardVisible);
2045
_tween: function(actor, statevar, value, params) {
2046
let onComplete = params.onComplete;
2047
let onCompleteScope = params.onCompleteScope;
2048
let onCompleteParams = params.onCompleteParams;
2050
params.onComplete = this._tweenComplete;
2051
params.onCompleteScope = this;
2052
params.onCompleteParams = [statevar, value, onComplete, onCompleteScope, onCompleteParams];
2054
// Remove other tweens that could mess with the state machine
2055
Tweener.removeTweens(actor);
2056
Tweener.addTween(actor, params);
2058
let valuing = (value == State.SHOWN) ? State.SHOWING : State.HIDING;
2059
this[statevar] = valuing;
2062
_tweenComplete: function(statevar, value, onComplete, onCompleteScope, onCompleteParams) {
2063
this[statevar] = value;
2065
onComplete.apply(onCompleteScope, onCompleteParams);
2066
this._updateState();
2069
_showTray: function() {
2070
// Don't actually take a modal grab in the overview.
2071
// Just add something to the grab stack that we can
2073
let modal = !this._overviewVisible;
2075
if (!this._grabHelper.grab({ actor: this.actor,
2077
onUngrab: Lang.bind(this, this._escapeTray) })) {
2078
this._traySummoned = false;
2082
this._tween(this.actor, '_trayState', State.SHOWN,
2083
{ y: -this.actor.height,
2084
time: ANIMATION_TIME,
2085
transition: 'easeOutQuad'
2088
if (!this._overviewVisible)
2089
this._lightbox.show();
2094
_updateDesktopCloneClip: function() {
2095
let geometry = this._bottomMonitorGeometry;
2096
let progress = -Math.round(this._desktopClone.y);
2097
this._desktopClone.set_clip(geometry.x,
2098
geometry.y + progress,
2100
geometry.height - progress);
2103
_showDesktopClone: function() {
2104
let bottomMonitor = Main.layoutManager.bottomMonitor;
2105
this._bottomMonitorGeometry = { x: bottomMonitor.x,
2107
width: bottomMonitor.width,
2108
height: bottomMonitor.height };
2110
if (this._desktopClone)
2111
this._desktopClone.destroy();
2112
this._desktopClone = new Clutter.Clone({ source: global.window_group, clip: new Clutter.Geometry(this._bottomMonitorGeometry) });
2113
Main.uiGroup.insert_child_above(this._desktopClone, global.window_group);
2114
this._desktopClone.x = 0;
2115
this._desktopClone.y = 0;
2116
this._desktopClone.show();
2118
this._tween(this._desktopClone, '_desktopCloneState', State.SHOWN,
2119
{ y: -this.actor.height,
2120
time: ANIMATION_TIME,
2121
transition: 'easeOutQuad',
2122
onUpdate: Lang.bind(this, this._updateDesktopCloneClip)
2126
_hideTray: function() {
2127
// Having the summary item animate out while sliding down the tray
2128
// is distracting, so hide it immediately in case it was visible.
2129
this._summaryBoxPointer.actor.hide();
2131
this._tween(this.actor, '_trayState', State.HIDDEN,
2133
time: ANIMATION_TIME,
2134
transition: 'easeOutQuad'
2137
// Note that we might have entered here without a grab,
2138
// which would happen if GrabHelper ungrabbed for us.
2139
// This is a no-op in that case.
2140
this._grabHelper.ungrab({ actor: this.actor });
2141
this._lightbox.hide();
2144
_hideDesktopClone: function(now) {
2145
this._tween(this._desktopClone, '_desktopCloneState', State.HIDDEN,
2147
time: now ? 0 : ANIMATION_TIME,
2148
transition: 'easeOutQuad',
2149
onComplete: Lang.bind(this, function() {
2150
this._desktopClone.destroy();
2151
this._desktopClone = null;
2152
this._bottomMonitorGeometry = null;
2154
onUpdate: Lang.bind(this, this._updateDesktopCloneClip)
2158
_onIdleMonitorWatch: function(monitor, id, userBecameIdle) {
2159
this.idleMonitor.remove_watch(this._idleMonitorWatchId);
2160
this._idleMonitorWatchId = 0;
2161
if (!userBecameIdle)
2162
this._updateNotificationTimeout(2000);
2163
this._userActiveWhileNotificationShown = true;
2164
this._updateState();
2167
_showNotification: function() {
2168
this._notification = this._notificationQueue.shift();
2169
this._userActiveWhileNotificationShown = this.idleMonitor.get_idletime() <= IDLE_TIME;
2170
this._idleMonitorWatchId = this.idleMonitor.add_watch(IDLE_TIME,
2171
Lang.bind(this, this._onIdleMonitorWatch));
2172
this._notificationClickedId = this._notification.connect('done-displaying',
2173
Lang.bind(this, this._escapeTray));
2174
this._notification.connect('unfocused', Lang.bind(this, function() {
2175
this._updateState();
2177
this._notificationBin.child = this._notification.actor;
2179
this._notificationWidget.opacity = 0;
2180
this._notificationWidget.y = 0;
2181
this._notificationWidget.show();
2183
this._updateShowingNotification();
2185
let [x, y, mods] = global.get_pointer();
2186
// We save the position of the mouse at the time when we started showing the notification
2187
// in order to determine if the notification popped up under it. We make that check if
2188
// the user starts moving the mouse and _onTrayHoverChanged() gets called. We don't
2189
// expand the notification if it just happened to pop up under the mouse unless the user
2190
// explicitly mouses away from it and then mouses back in.
2191
this._showNotificationMouseX = x;
2192
this._showNotificationMouseY = y;
2193
// We save the coordinates of the mouse at the time when we started showing the notification
2194
// and then we update it in _notificationTimeout(). We don't pop down the notification if
2195
// the mouse is moving towards it or within it.
2196
this._lastSeenMouseX = x;
2197
this._lastSeenMouseY = y;
2200
_updateShowingNotification: function() {
2201
this._notification.acknowledged = true;
2203
// We auto-expand notifications with CRITICAL urgency.
2204
if (this._notification.urgency == Urgency.CRITICAL)
2205
this._expandNotification(true);
2207
// We tween all notifications to full opacity. This ensures that both new notifications and
2208
// notifications that might have been in the process of hiding get full opacity.
2210
// We tween any notification showing in the banner mode to the appropriate height
2211
// (which is banner height or expanded height, depending on the notification state)
2212
// This ensures that both new notifications and notifications in the banner mode that might
2213
// have been in the process of hiding are shown with the correct height.
2215
// We use this._showNotificationCompleted() onComplete callback to extend the time the updated
2216
// notification is being shown.
2218
let tweenParams = { opacity: 255,
2219
y: -this._notificationWidget.height,
2220
time: ANIMATION_TIME,
2221
transition: 'easeOutQuad',
2222
onComplete: this._showNotificationCompleted,
2223
onCompleteScope: this
2226
this._tween(this._notificationWidget, '_notificationState', State.SHOWN, tweenParams);
2229
_showNotificationCompleted: function() {
2230
if (this._notification.urgency != Urgency.CRITICAL)
2231
this._updateNotificationTimeout(NOTIFICATION_TIMEOUT * 1000);
2234
_updateNotificationTimeout: function(timeout) {
2235
if (this._notificationTimeoutId) {
2236
Mainloop.source_remove(this._notificationTimeoutId);
2237
this._notificationTimeoutId = 0;
2240
this._notificationTimeoutId =
2241
Mainloop.timeout_add(timeout,
2242
Lang.bind(this, this._notificationTimeout));
2245
_notificationTimeout: function() {
2246
let [x, y, mods] = global.get_pointer();
2247
if (y > this._lastSeenMouseY + 10 && !this.actor.hover) {
2248
// The mouse is moving towards the notification, so don't
2249
// hide it yet. (We just create a new timeout (and destroy
2250
// the old one) each time because the bookkeeping is
2252
this._updateNotificationTimeout(1000);
2253
} else if (this._useLongerTrayLeftTimeout && !this._trayLeftTimeoutId &&
2254
(x != this._lastSeenMouseX || y != this._lastSeenMouseY)) {
2255
// Refresh the timeout if the notification originally
2256
// popped up under the pointer, and the pointer is hovering
2258
this._updateNotificationTimeout(1000);
2260
this._notificationTimeoutId = 0;
2261
this._updateState();
2264
this._lastSeenMouseX = x;
2265
this._lastSeenMouseY = y;
2269
_hideNotification: function() {
2270
this._grabHelper.ungrab({ actor: this._notification.actor });
2272
if (this._notificationExpandedId) {
2273
this._notification.disconnect(this._notificationExpandedId);
2274
this._notificationExpandedId = 0;
2277
if (this._notificationRemoved) {
2278
this._notificationWidget.y = this.actor.height;
2279
this._notificationWidget.opacity = 0;
2280
this._notificationState = State.HIDDEN;
2281
this._hideNotificationCompleted();
2283
this._tween(this._notificationWidget, '_notificationState', State.HIDDEN,
2284
{ y: this.actor.height,
2286
time: ANIMATION_TIME,
2287
transition: 'easeOutQuad',
2288
onComplete: this._hideNotificationCompleted,
2289
onCompleteScope: this
2295
_hideNotificationCompleted: function() {
2296
this._notificationRemoved = false;
2297
this._notificationWidget.hide();
2298
this._closeButton.hide();
2299
this._pointerInTray = false;
2300
this.actor.hover = false; // Clutter doesn't emit notify::hover when actors move
2301
this._notificationBin.child = null;
2302
this._notification.collapseCompleted();
2303
this._notification.disconnect(this._notificationClickedId);
2304
this._notificationClickedId = 0;
2305
let notification = this._notification;
2306
this._notification = null;
2307
if (notification.isTransient)
2308
notification.destroy(NotificationDestroyedReason.EXPIRED);
2311
_expandNotification: function(autoExpanding) {
2312
// Don't grab focus in notifications that are auto-expanded.
2314
this._grabHelper.grab({ actor: this._notification.actor,
2317
if (!this._notificationExpandedId)
2318
this._notificationExpandedId =
2319
this._notification.connect('expanded',
2320
Lang.bind(this, this._onNotificationExpanded));
2321
// Don't animate changes in notifications that are auto-expanding.
2322
this._notification.expand(!autoExpanding);
2325
_onNotificationExpanded: function() {
2326
let expandedY = - this._notificationWidget.height;
2327
this._closeButton.show();
2329
// Don't animate the notification to its new position if it has shrunk:
2330
// there will be a very visible "gap" that breaks the illusion.
2331
if (this._notificationWidget.y < expandedY) {
2332
this._notificationWidget.y = expandedY;
2333
} else if (this._notification.y != expandedY) {
2334
// Tween also opacity here, to override a possible tween that's
2335
// currently hiding the notification. This will ensure that the
2336
// notification is not removed when the onComplete handler for this
2338
this._tween(this._notificationWidget, '_notificationState', State.SHOWN,
2341
time: ANIMATION_TIME,
2342
transition: 'easeOutQuad'
2347
// We use this function to grab focus when the user moves the pointer
2348
// to a notification with CRITICAL urgency that was already auto-expanded.
2349
_ensureNotificationFocused: function() {
2350
this._grabHelper.grab({ actor: this._notification.actor,
2354
_showSummary: function() {
2355
this._summary.opacity = 0;
2356
this._tween(this._summary, '_summaryState', State.SHOWN,
2358
time: ANIMATION_TIME,
2359
transition: 'easeOutQuad',
2363
_hideSummary: function() {
2364
this._tween(this._summary, '_summaryState', State.HIDDEN,
2366
time: ANIMATION_TIME,
2367
transition: 'easeOutQuad',
2371
_showSummaryBoxPointer: function() {
2372
this._summaryBoxPointerItem = this._clickedSummaryItem;
2373
this._summaryBoxPointerContentUpdatedId = this._summaryBoxPointerItem.connect('content-updated',
2374
Lang.bind(this, this._onSummaryBoxPointerContentUpdated));
2375
this._sourceDoneDisplayingId = this._summaryBoxPointerItem.source.connect('done-displaying-content',
2376
Lang.bind(this, this._escapeTray));
2378
let hasRightClickMenu = this._summaryBoxPointerItem.rightClickMenu != null;
2379
if (this._clickedSummaryItemMouseButton == 1 || !hasRightClickMenu) {
2381
for (let i = 0; i < this._notificationQueue.length; i++) {
2382
let notification = this._notificationQueue[i];
2383
let sameSource = this._summaryBoxPointerItem.source == notification.source;
2385
notification.acknowledged = true;
2387
newQueue.push(notification);
2389
this._notificationQueue = newQueue;
2391
this._summaryBoxPointer.bin.child = this._summaryBoxPointerItem.notificationStackWidget;
2393
let closeButton = this._summaryBoxPointerItem.closeButton;
2395
this._summaryBoxPointerCloseClickedId = closeButton.connect('clicked', Lang.bind(this, this._hideSummaryBoxPointer));
2396
this._summaryBoxPointerItem.prepareNotificationStackForShowing();
2397
} else if (this._clickedSummaryItemMouseButton == 3) {
2398
this._summaryBoxPointer.bin.child = this._clickedSummaryItem.rightClickMenu;
2401
this._grabHelper.grab({ actor: this._summaryBoxPointer.bin.child,
2403
onUngrab: Lang.bind(this, this._onSummaryBoxPointerUngrabbed) });
2406
this._summaryBoxPointer.actor.opacity = 0;
2407
this._summaryBoxPointer.actor.show();
2408
this._adjustSummaryBoxPointerPosition();
2410
this._summaryBoxPointerState = State.SHOWING;
2411
this._clickedSummaryItem.actor.add_style_pseudo_class('selected');
2412
this._summaryBoxPointer.show(BoxPointer.PopupAnimation.FULL, Lang.bind(this, function() {
2413
this._summaryBoxPointerState = State.SHOWN;
2417
_onSummaryBoxPointerContentUpdated: function() {
2418
if (this._summaryBoxPointerItem.notificationStack.get_n_children() == 0)
2419
this._hideSummaryBoxPointer();
2420
this._adjustSummaryBoxPointerPosition();
2423
_adjustSummaryBoxPointerPosition: function() {
2424
if (!this._clickedSummaryItem)
2427
this._summaryBoxPointer.setPosition(this._clickedSummaryItem.actor, 0);
2430
_setClickedSummaryItem: function(item, button) {
2431
if (item == this._clickedSummaryItem &&
2432
button == this._clickedSummaryItemMouseButton)
2435
if (this._clickedSummaryItem) {
2436
this._clickedSummaryItem.actor.remove_style_pseudo_class('selected');
2437
this._clickedSummaryItem.actor.disconnect(this._clickedSummaryItemAllocationChangedId);
2438
this._summary.disconnect(this._summaryMotionId);
2439
Main.layoutManager.trayBox.disconnect(this._trayMotionId);
2440
this._clickedSummaryItemAllocationChangedId = 0;
2441
this._summaryMotionId = 0;
2442
this._trayMotionId = 0;
2445
this._clickedSummaryItem = item;
2446
this._clickedSummaryItemMouseButton = button;
2448
if (this._clickedSummaryItem) {
2449
this._clickedSummaryItem.source.emit('summary-item-clicked', button);
2450
this._clickedSummaryItem.actor.add_style_pseudo_class('selected');
2451
this._clickedSummaryItemAllocationChangedId =
2452
this._clickedSummaryItem.actor.connect('allocation-changed',
2453
Lang.bind(this, this._adjustSummaryBoxPointerPosition));
2454
// _clickedSummaryItem.actor can change absolute position without changing allocation
2455
this._summaryMotionId = this._summary.connect('allocation-changed',
2456
Lang.bind(this, this._adjustSummaryBoxPointerPosition));
2457
this._trayMotionId = Main.layoutManager.trayBox.connect('notify::anchor-y',
2458
Lang.bind(this, this._adjustSummaryBoxPointerPosition));
2464
_onSummaryBoxPointerKeyPress: function(actor, event) {
2465
switch (event.get_key_symbol()) {
2466
case Clutter.KEY_Down:
2467
case Clutter.KEY_Escape:
2468
this._setClickedSummaryItem(null);
2469
this._updateState();
2471
case Clutter.KEY_Delete:
2472
this._clickedSummaryItem.source.destroy();
2479
_onSummaryBoxPointerUngrabbed: function() {
2480
this._summaryBoxPointerState = State.HIDING;
2483
if (this._summaryBoxPointerItem.source.notifications.length == 0) {
2484
this._summaryBoxPointer.actor.hide();
2485
this._hideSummaryBoxPointerCompleted();
2487
if (global.stage.key_focus &&
2488
!this.actor.contains(global.stage.key_focus))
2489
this._setClickedSummaryItem(null);
2490
this._summaryBoxPointer.hide(BoxPointer.PopupAnimation.FULL, Lang.bind(this, this._hideSummaryBoxPointerCompleted));
2494
_hideSummaryBoxPointer: function() {
2495
this._grabHelper.ungrab({ actor: this._summaryBoxPointer.bin.child });
2498
_hideSummaryBoxPointerCompleted: function() {
2499
let doneShowingNotificationStack = (this._summaryBoxPointer.bin.child == this._summaryBoxPointerItem.notificationStackWidget);
2501
this._summaryBoxPointerState = State.HIDDEN;
2502
this._summaryBoxPointer.bin.child = null;
2503
this._summaryBoxPointerItem.disconnect(this._summaryBoxPointerContentUpdatedId);
2504
this._summaryBoxPointerContentUpdatedId = 0;
2505
this._summaryBoxPointerItem.closeButton.disconnect(this._summaryBoxPointerCloseClickedId);
2506
this._summaryBoxPointerCloseClickedId = 0;
2507
this._summaryBoxPointerItem.source.disconnect(this._sourceDoneDisplayingId);
2508
this._summaryBoxPointerDoneDisplayingId = 0;
2510
let sourceNotificationStackDoneShowing = null;
2511
if (doneShowingNotificationStack) {
2512
this._summaryBoxPointerItem.doneShowingNotificationStack();
2513
sourceNotificationStackDoneShowing = this._summaryBoxPointerItem.source;
2516
this._summaryBoxPointerItem = null;
2518
if (sourceNotificationStackDoneShowing) {
2519
if (sourceNotificationStackDoneShowing.isTransient && !this._reNotifyAfterHideNotification)
2520
sourceNotificationStackDoneShowing.destroy(NotificationDestroyedReason.EXPIRED);
2521
if (this._reNotifyAfterHideNotification) {
2522
this._onNotify(this._reNotifyAfterHideNotification.source, this._reNotifyAfterHideNotification);
2523
this._reNotifyAfterHideNotification = null;
2527
if (this._clickedSummaryItem)
2528
this._updateState();
2531
Signals.addSignalMethods(MessageTray.prototype);
2533
const SystemNotificationSource = new Lang.Class({
2534
Name: 'SystemNotificationSource',
2538
this.parent(_("System Information"), 'dialog-information-symbolic');
2539
this.setTransient(true);