2011-09-28 13:16:26 +00:00
|
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
|
/* exported NotificationPolicy, NotificationGenericPolicy,
|
|
|
|
|
NotificationApplicationPolicy, Source, SourceActor, SourceActorWithLabel,
|
|
|
|
|
SystemNotificationSource, MessageTray */
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2019-02-09 03:21:36 +00:00
|
|
|
|
const { Clutter, Gio, GLib, GObject, Meta, Shell, St } = imports.gi;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2015-02-17 00:13:48 +00:00
|
|
|
|
const Calendar = imports.ui.calendar;
|
2011-02-19 15:49:56 +00:00
|
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
2015-02-25 16:43:54 +00:00
|
|
|
|
const Layout = imports.ui.layout;
|
2011-02-19 15:49:56 +00:00
|
|
|
|
const Main = imports.ui.main;
|
2010-08-18 20:01:33 +00:00
|
|
|
|
const Params = imports.misc.params;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2012-07-14 11:07:24 +00:00
|
|
|
|
const SHELL_KEYBINDINGS_SCHEMA = 'org.gnome.shell.keybindings';
|
|
|
|
|
|
2019-08-01 23:13:10 +00:00
|
|
|
|
var ANIMATION_TIME = 200;
|
|
|
|
|
var NOTIFICATION_TIMEOUT = 4000;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2019-08-01 23:13:10 +00:00
|
|
|
|
var HIDE_TIMEOUT = 200;
|
|
|
|
|
var LONGER_HIDE_TIMEOUT = 600;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
|
var MAX_NOTIFICATIONS_IN_QUEUE = 3;
|
|
|
|
|
var MAX_NOTIFICATIONS_PER_SOURCE = 3;
|
|
|
|
|
var MAX_NOTIFICATION_BUTTONS = 3;
|
2015-02-14 02:18:52 +00:00
|
|
|
|
|
2010-10-30 19:54:43 +00: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.
|
2017-07-18 17:47:27 +00:00
|
|
|
|
var MOUSE_LEFT_ACTOR_THRESHOLD = 20;
|
2010-10-30 19:54:43 +00:00
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
|
var IDLE_TIME = 1000;
|
2012-08-10 21:54:33 +00:00
|
|
|
|
|
2017-07-18 17:47:27 +00:00
|
|
|
|
var State = {
|
[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 20:31:12 +00:00
|
|
|
|
HIDDEN: 0,
|
|
|
|
|
SHOWING: 1,
|
|
|
|
|
SHOWN: 2,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
HIDING: 3,
|
2010-01-28 18:39:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-01-27 23:26:53 +00:00
|
|
|
|
// These reasons are useful when we destroy the notifications received through
|
2015-02-13 23:06:11 +00:00
|
|
|
|
// the notification daemon. We use EXPIRED for notifications that we dismiss
|
|
|
|
|
// and the user did not interact with, DISMISSED for all other notifications
|
2018-10-11 01:26:31 +00:00
|
|
|
|
// that were destroyed as a result of a user action, SOURCE_CLOSED for the
|
|
|
|
|
// notifications that were requested to be destroyed by the associated source,
|
|
|
|
|
// and REPLACED for notifications that were destroyed as a consequence of a
|
|
|
|
|
// newer version having replaced them.
|
2017-07-18 17:47:27 +00:00
|
|
|
|
var NotificationDestroyedReason = {
|
2011-01-27 23:26:53 +00:00
|
|
|
|
EXPIRED: 1,
|
|
|
|
|
DISMISSED: 2,
|
2018-10-11 01:26:31 +00:00
|
|
|
|
SOURCE_CLOSED: 3,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
REPLACED: 4,
|
2011-01-27 23:26:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-01-04 09:34:57 +00: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.
|
2017-07-18 17:47:27 +00:00
|
|
|
|
var Urgency = {
|
2011-01-04 09:34:57 +00:00
|
|
|
|
LOW: 0,
|
|
|
|
|
NORMAL: 1,
|
|
|
|
|
HIGH: 2,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
CRITICAL: 3,
|
2013-12-04 16:22:25 +00:00
|
|
|
|
};
|
2011-01-04 09:34:57 +00:00
|
|
|
|
|
2018-11-01 20:56:25 +00:00
|
|
|
|
// The privacy of the details of a notification. USER is for notifications which
|
|
|
|
|
// contain private information to the originating user account (for example,
|
|
|
|
|
// details of an e-mail they’ve received). SYSTEM is for notifications which
|
|
|
|
|
// contain information private to the physical system (for example, battery
|
|
|
|
|
// status) and hence the same for every user. This affects whether the content
|
|
|
|
|
// of a notification is shown on the lock screen.
|
|
|
|
|
var PrivacyScope = {
|
|
|
|
|
USER: 0,
|
|
|
|
|
SYSTEM: 1,
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
|
var FocusGrabber = class FocusGrabber {
|
|
|
|
|
constructor(actor) {
|
2013-05-23 21:11:40 +00:00
|
|
|
|
this._actor = actor;
|
|
|
|
|
this._prevKeyFocusActor = null;
|
|
|
|
|
this._focusActorChangedId = 0;
|
|
|
|
|
this._focused = false;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-05-23 21:11:40 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
grabFocus() {
|
2013-05-23 21:11:40 +00:00
|
|
|
|
if (this._focused)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this._prevKeyFocusActor = global.stage.get_key_focus();
|
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._focusActorChangedId = global.stage.connect('notify::key-focus', this._focusActorChanged.bind(this));
|
2013-05-23 21:11:40 +00:00
|
|
|
|
|
2018-11-27 12:58:25 +00:00
|
|
|
|
if (!this._actor.navigate_focus(null, St.DirectionType.TAB_FORWARD, false))
|
2013-05-23 21:11:40 +00:00
|
|
|
|
this._actor.grab_key_focus();
|
|
|
|
|
|
|
|
|
|
this._focused = true;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-05-23 21:11:40 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_focusUngrabbed() {
|
2013-05-23 21:11:40 +00:00
|
|
|
|
if (!this._focused)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (this._focusActorChangedId > 0) {
|
|
|
|
|
global.stage.disconnect(this._focusActorChangedId);
|
|
|
|
|
this._focusActorChangedId = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._focused = false;
|
|
|
|
|
return true;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-05-23 21:11:40 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_focusActorChanged() {
|
2013-05-23 21:11:40 +00:00
|
|
|
|
let focusedActor = global.stage.get_key_focus();
|
|
|
|
|
if (!focusedActor || !this._actor.contains(focusedActor))
|
|
|
|
|
this._focusUngrabbed();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-05-23 21:11:40 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
ungrabFocus() {
|
2013-05-23 21:11:40 +00:00
|
|
|
|
if (!this._focusUngrabbed())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (this._prevKeyFocusActor) {
|
|
|
|
|
global.stage.set_key_focus(this._prevKeyFocusActor);
|
|
|
|
|
this._prevKeyFocusActor = null;
|
|
|
|
|
} else {
|
|
|
|
|
let focusedActor = global.stage.get_key_focus();
|
|
|
|
|
if (focusedActor && this._actor.contains(focusedActor))
|
|
|
|
|
global.stage.set_key_focus(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
};
|
2013-05-23 21:11:40 +00:00
|
|
|
|
|
2012-10-16 15:08:54 +00:00
|
|
|
|
// NotificationPolicy:
|
|
|
|
|
// An object that holds all bits of configurable policy related to a notification
|
|
|
|
|
// source, such as whether to play sound or honour the critical bit.
|
|
|
|
|
//
|
|
|
|
|
// A notification without a policy object will inherit the default one.
|
2019-05-13 21:32:31 +00:00
|
|
|
|
var NotificationPolicy = GObject.registerClass({
|
|
|
|
|
Properties: {
|
|
|
|
|
'enable': GObject.ParamSpec.boolean(
|
|
|
|
|
'enable', 'enable', 'enable',
|
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
|
true),
|
|
|
|
|
'enable-sound': GObject.ParamSpec.boolean(
|
|
|
|
|
'enable-sound', 'enable-sound', 'enable-sound',
|
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
|
true),
|
|
|
|
|
'show-banners': GObject.ParamSpec.boolean(
|
|
|
|
|
'show-banners', 'show-banners', 'show-banners',
|
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
|
true),
|
|
|
|
|
'force-expanded': GObject.ParamSpec.boolean(
|
|
|
|
|
'force-expanded', 'force-expanded', 'force-expanded',
|
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
|
false),
|
|
|
|
|
'show-in-lock-screen': GObject.ParamSpec.boolean(
|
|
|
|
|
'show-in-lock-screen', 'show-in-lock-screen', 'show-in-lock-screen',
|
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
|
false),
|
|
|
|
|
'details-in-lock-screen': GObject.ParamSpec.boolean(
|
|
|
|
|
'details-in-lock-screen', 'details-in-lock-screen', 'details-in-lock-screen',
|
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
|
false),
|
2019-08-20 21:43:54 +00:00
|
|
|
|
},
|
2019-05-13 21:32:31 +00:00
|
|
|
|
}, class NotificationPolicy extends GObject.Object {
|
2012-10-16 15:08:54 +00:00
|
|
|
|
// Do nothing for the default policy. These methods are only useful for the
|
|
|
|
|
// GSettings policy.
|
2017-10-31 01:19:44 +00:00
|
|
|
|
store() { }
|
2019-08-19 19:08:38 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
destroy() {
|
|
|
|
|
this.run_dispose();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-12-11 10:17:30 +00:00
|
|
|
|
|
|
|
|
|
get enableSound() {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
return this.enable_sound;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-12-11 10:17:30 +00:00
|
|
|
|
|
|
|
|
|
get showBanners() {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
return this.show_banners;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-12-11 10:17:30 +00:00
|
|
|
|
|
|
|
|
|
get forceExpanded() {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
return this.force_expanded;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-12-11 10:17:30 +00:00
|
|
|
|
|
|
|
|
|
get showInLockScreen() {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
return this.show_in_lock_screen;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2018-12-11 10:17:30 +00:00
|
|
|
|
|
|
|
|
|
get detailsInLockScreen() {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
return this.details_in_lock_screen;
|
2018-12-11 10:17:30 +00:00
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2012-10-16 15:08:54 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
var NotificationGenericPolicy = GObject.registerClass({
|
|
|
|
|
}, class NotificationGenericPolicy extends NotificationPolicy {
|
|
|
|
|
_init() {
|
|
|
|
|
super._init();
|
2013-10-13 20:01:56 +00:00
|
|
|
|
this.id = 'generic';
|
|
|
|
|
|
2014-06-24 19:17:09 +00:00
|
|
|
|
this._masterSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.notifications' });
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._masterSettings.connect('changed', this._changed.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
destroy() {
|
2013-10-13 20:01:56 +00:00
|
|
|
|
this._masterSettings.run_dispose();
|
2019-05-13 21:32:31 +00:00
|
|
|
|
|
|
|
|
|
super.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_changed(settings, key) {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
if (this.constructor.find_property(key))
|
|
|
|
|
this.notify(key);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get showBanners() {
|
|
|
|
|
return this._masterSettings.get_boolean('show-banners');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get showInLockScreen() {
|
|
|
|
|
return this._masterSettings.get_boolean('show-in-lock-screen');
|
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
var NotificationApplicationPolicy = GObject.registerClass({
|
|
|
|
|
}, class NotificationApplicationPolicy extends NotificationPolicy {
|
|
|
|
|
_init(id) {
|
|
|
|
|
super._init();
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
this.id = id;
|
|
|
|
|
this._canonicalId = this._canonicalizeId(id);
|
|
|
|
|
|
2014-06-24 19:17:09 +00:00
|
|
|
|
this._masterSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.notifications' });
|
|
|
|
|
this._settings = new Gio.Settings({ schema_id: 'org.gnome.desktop.notifications.application',
|
2019-01-30 00:18:24 +00:00
|
|
|
|
path: `/org/gnome/desktop/notifications/application/${this._canonicalId}/` });
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._masterSettings.connect('changed', this._changed.bind(this));
|
|
|
|
|
this._settings.connect('changed', this._changed.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
store() {
|
2019-01-30 00:18:24 +00:00
|
|
|
|
this._settings.set_string('application-id', `${this.id}.desktop`);
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
let apps = this._masterSettings.get_strv('application-children');
|
2018-07-14 20:56:22 +00:00
|
|
|
|
if (!apps.includes(this._canonicalId)) {
|
2013-10-13 20:01:56 +00:00
|
|
|
|
apps.push(this._canonicalId);
|
|
|
|
|
this._masterSettings.set_strv('application-children', apps);
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
destroy() {
|
2013-10-13 20:01:56 +00:00
|
|
|
|
this._masterSettings.run_dispose();
|
|
|
|
|
this._settings.run_dispose();
|
2019-05-13 21:32:31 +00:00
|
|
|
|
|
|
|
|
|
super.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_changed(settings, key) {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
if (this.constructor.find_property(key))
|
|
|
|
|
this.notify(key);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_canonicalizeId(id) {
|
2013-10-13 20:01:56 +00:00
|
|
|
|
// Keys are restricted to lowercase alphanumeric characters and dash,
|
|
|
|
|
// and two dashes cannot be in succession
|
2019-01-29 22:44:38 +00:00
|
|
|
|
return id.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/--+/g, '-');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get enable() {
|
|
|
|
|
return this._settings.get_boolean('enable');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get enableSound() {
|
|
|
|
|
return this._settings.get_boolean('enable-sound-alerts');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get showBanners() {
|
|
|
|
|
return this._masterSettings.get_boolean('show-banners') &&
|
|
|
|
|
this._settings.get_boolean('show-banners');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get forceExpanded() {
|
|
|
|
|
return this._settings.get_boolean('force-expanded');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get showInLockScreen() {
|
|
|
|
|
return this._masterSettings.get_boolean('show-in-lock-screen') &&
|
|
|
|
|
this._settings.get_boolean('show-in-lock-screen');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
|
|
|
|
get detailsInLockScreen() {
|
|
|
|
|
return this._settings.get_boolean('details-in-lock-screen');
|
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2013-10-13 20:01:56 +00:00
|
|
|
|
|
2010-02-01 17:10:38 +00:00
|
|
|
|
// Notification:
|
|
|
|
|
// @source: the notification's Source
|
|
|
|
|
// @title: the title
|
|
|
|
|
// @banner: the banner text
|
2010-08-18 20:01:33 +00:00
|
|
|
|
// @params: optional additional params
|
2010-02-01 17:10:38 +00:00
|
|
|
|
//
|
2010-08-30 20:03:08 +00: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 16:25:10 +00:00
|
|
|
|
//
|
2010-08-30 20:03:08 +00: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 17:09:27 +00:00
|
|
|
|
//
|
2010-08-30 20:03:08 +00:00
|
|
|
|
// Additional notification content can be added with addActor() and
|
|
|
|
|
// addBody() methods. The notification content is put inside a
|
2010-02-22 19:23:36 +00:00
|
|
|
|
// scrollview, so if it gets too tall, the notification will scroll
|
2010-08-30 20:03:08 +00: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.
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
2012-09-14 14:33:52 +00:00
|
|
|
|
// By default, the icon shown is the same as the source's.
|
|
|
|
|
// However, if @params contains a 'gicon' parameter, the passed in gicon
|
|
|
|
|
// will be used.
|
|
|
|
|
//
|
|
|
|
|
// You can add a secondary icon to the banner with 'secondaryGIcon'. There
|
|
|
|
|
// is no fallback for this icon.
|
2010-08-30 20:03:08 +00:00
|
|
|
|
//
|
2018-05-21 19:07:09 +00:00
|
|
|
|
// If @params contains 'bannerMarkup', with the value %true, a subset (<b>,
|
|
|
|
|
// <i> and <u>) of the markup in [1] will be interpreted within @banner. If
|
|
|
|
|
// the parameter is not present, then anything that looks like markup
|
|
|
|
|
// in @banner will appear literally in the output.
|
2010-11-23 23:31:55 +00:00
|
|
|
|
//
|
2010-08-30 20:03:08 +00: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.
|
2012-11-05 17:10:24 +00:00
|
|
|
|
//
|
|
|
|
|
// If @params contains 'soundName' or 'soundFile', the corresponding
|
|
|
|
|
// event sound is played when the notification is shown (if the policy for
|
|
|
|
|
// @source allows playing sounds).
|
2018-05-21 19:07:09 +00:00
|
|
|
|
//
|
2019-09-12 15:26:08 +00:00
|
|
|
|
// [1] https://developer.gnome.org/notification-spec/#markup
|
2019-05-13 21:32:31 +00:00
|
|
|
|
var Notification = GObject.registerClass({
|
|
|
|
|
Properties: {
|
|
|
|
|
'acknowledged': GObject.ParamSpec.boolean(
|
|
|
|
|
'acknowledged', 'acknowledged', 'acknowledged',
|
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
|
false),
|
|
|
|
|
},
|
|
|
|
|
Signals: {
|
|
|
|
|
'activated': {},
|
|
|
|
|
'destroy': { param_types: [GObject.TYPE_UINT] },
|
|
|
|
|
'updated': { param_types: [GObject.TYPE_BOOLEAN] },
|
2019-08-20 21:43:54 +00:00
|
|
|
|
},
|
2019-05-13 21:32:31 +00:00
|
|
|
|
}, class Notification extends GObject.Object {
|
|
|
|
|
_init(source, title, banner, params) {
|
|
|
|
|
super._init();
|
|
|
|
|
|
2010-01-28 18:39:00 +00:00
|
|
|
|
this.source = source;
|
2011-09-21 20:46:08 +00:00
|
|
|
|
this.title = title;
|
2011-01-04 09:34:57 +00:00
|
|
|
|
this.urgency = Urgency.NORMAL;
|
2010-12-15 21:30:50 +00:00
|
|
|
|
// 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
|
|
|
|
|
this.isTransient = false;
|
2018-11-01 20:56:25 +00:00
|
|
|
|
this.privacyScope = PrivacyScope.USER;
|
2012-11-02 17:06:40 +00:00
|
|
|
|
this.forFeedback = false;
|
2015-02-14 01:33:54 +00:00
|
|
|
|
this._acknowledged = false;
|
2013-01-30 18:47:55 +00:00
|
|
|
|
this.bannerBodyText = null;
|
|
|
|
|
this.bannerBodyMarkup = false;
|
2012-11-05 17:10:24 +00:00
|
|
|
|
this._soundName = null;
|
|
|
|
|
this._soundFile = null;
|
|
|
|
|
this._soundPlayed = false;
|
2015-02-19 12:45:31 +00:00
|
|
|
|
this.actions = [];
|
2019-05-14 01:58:58 +00:00
|
|
|
|
this.setResident(false);
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2013-10-12 16:50:49 +00:00
|
|
|
|
// If called with only one argument we assume the caller
|
|
|
|
|
// will call .update() later on. This is the case of
|
|
|
|
|
// NotificationDaemon, which wants to use the same code
|
|
|
|
|
// for new and updated notifications
|
|
|
|
|
if (arguments.length != 1)
|
|
|
|
|
this.update(title, banner, params);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2010-02-09 16:25:10 +00:00
|
|
|
|
// update:
|
|
|
|
|
// @title: the new title
|
|
|
|
|
// @banner: the new banner
|
2010-08-18 20:01:33 +00:00
|
|
|
|
// @params: as in the Notification constructor
|
2010-02-09 16:25:10 +00:00
|
|
|
|
//
|
|
|
|
|
// Updates the notification by regenerating its icon and updating
|
2010-08-18 20:01:33 +00:00
|
|
|
|
// the title/banner. If @params.clear is %true, it will also
|
|
|
|
|
// remove any additional actors/action buttons previously added.
|
2017-10-31 00:03:21 +00:00
|
|
|
|
update(title, banner, params) {
|
2015-02-11 19:20:03 +00:00
|
|
|
|
params = Params.parse(params, { gicon: null,
|
2012-09-14 14:33:52 +00:00
|
|
|
|
secondaryGIcon: null,
|
2010-11-23 23:31:55 +00:00
|
|
|
|
bannerMarkup: false,
|
2012-11-05 17:10:24 +00:00
|
|
|
|
clear: false,
|
2017-02-26 23:14:09 +00:00
|
|
|
|
datetime: null,
|
2012-11-05 17:10:24 +00:00
|
|
|
|
soundName: null,
|
|
|
|
|
soundFile: null });
|
2010-08-18 20:01:33 +00:00
|
|
|
|
|
2011-09-21 20:46:08 +00:00
|
|
|
|
this.title = title;
|
2015-02-11 19:20:03 +00:00
|
|
|
|
this.bannerBodyText = banner;
|
2013-01-30 18:47:55 +00:00
|
|
|
|
this.bannerBodyMarkup = params.bannerMarkup;
|
2010-02-09 16:25:10 +00:00
|
|
|
|
|
2017-02-26 23:14:09 +00:00
|
|
|
|
if (params.datetime)
|
|
|
|
|
this.datetime = params.datetime;
|
|
|
|
|
else
|
|
|
|
|
this.datetime = GLib.DateTime.new_now_local();
|
|
|
|
|
|
2015-02-11 19:20:03 +00:00
|
|
|
|
if (params.gicon || params.clear)
|
|
|
|
|
this.gicon = params.gicon;
|
2010-11-23 23:27:47 +00:00
|
|
|
|
|
2015-02-11 19:20:03 +00:00
|
|
|
|
if (params.secondaryGIcon || params.clear)
|
|
|
|
|
this.secondaryGIcon = params.secondaryGIcon;
|
2010-04-29 14:54:05 +00:00
|
|
|
|
|
2015-02-11 19:20:03 +00:00
|
|
|
|
if (params.clear)
|
|
|
|
|
this.actions = [];
|
2010-08-30 20:03:08 +00:00
|
|
|
|
|
2012-11-05 17:10:24 +00:00
|
|
|
|
if (this._soundName != params.soundName ||
|
|
|
|
|
this._soundFile != params.soundFile) {
|
|
|
|
|
this._soundName = params.soundName;
|
|
|
|
|
this._soundFile = params.soundFile;
|
|
|
|
|
this._soundPlayed = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-19 18:23:14 +00:00
|
|
|
|
this.emit('updated', params.clear);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-02-01 17:10:38 +00:00
|
|
|
|
|
2013-10-14 03:08:16 +00:00
|
|
|
|
// addAction:
|
|
|
|
|
// @label: the label for the action's button
|
2013-10-14 03:06:09 +00:00
|
|
|
|
// @callback: the callback for the action
|
2017-10-31 00:03:21 +00:00
|
|
|
|
addAction(label, callback) {
|
2019-08-19 19:06:04 +00:00
|
|
|
|
this.actions.push({ label, callback });
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-05-17 19:05:36 +00:00
|
|
|
|
|
2015-02-14 01:33:54 +00:00
|
|
|
|
get acknowledged() {
|
|
|
|
|
return this._acknowledged;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-14 01:33:54 +00:00
|
|
|
|
|
|
|
|
|
set acknowledged(v) {
|
|
|
|
|
if (this._acknowledged == v)
|
|
|
|
|
return;
|
|
|
|
|
this._acknowledged = v;
|
2019-05-13 21:32:31 +00:00
|
|
|
|
this.notify('acknowledged');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-14 01:33:54 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
setUrgency(urgency) {
|
2011-01-04 09:34:57 +00:00
|
|
|
|
this.urgency = urgency;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-04-28 19:34:27 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
setResident(resident) {
|
2010-12-16 20:49:47 +00:00
|
|
|
|
this.resident = resident;
|
2019-05-14 01:58:58 +00:00
|
|
|
|
|
|
|
|
|
if (this.resident) {
|
|
|
|
|
if (this._activatedId) {
|
|
|
|
|
this.disconnect(this._activatedId);
|
|
|
|
|
this._activatedId = 0;
|
|
|
|
|
}
|
|
|
|
|
} else if (!this._activatedId) {
|
|
|
|
|
this._activatedId = this.connect_after('activated', () => this.destroy());
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-12-16 20:49:47 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
setTransient(isTransient) {
|
2010-12-15 21:30:50 +00:00
|
|
|
|
this.isTransient = isTransient;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-12-15 21:30:50 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
setForFeedback(forFeedback) {
|
2012-11-02 17:06:40 +00:00
|
|
|
|
this.forFeedback = forFeedback;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-11-02 17:06:40 +00:00
|
|
|
|
|
2018-11-01 20:56:25 +00:00
|
|
|
|
setPrivacyScope(privacyScope) {
|
|
|
|
|
this.privacyScope = privacyScope;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
playSound() {
|
2012-11-05 17:10:24 +00:00
|
|
|
|
if (this._soundPlayed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!this.source.policy.enableSound) {
|
|
|
|
|
this._soundPlayed = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-13 19:32:16 +00:00
|
|
|
|
let player = global.display.get_sound_player();
|
|
|
|
|
if (this._soundName)
|
|
|
|
|
player.play_from_theme(this._soundName, this.title, null);
|
|
|
|
|
else if (this._soundFile)
|
|
|
|
|
player.play_from_file(this._soundFile, this.title, null);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-11-05 17:10:24 +00:00
|
|
|
|
|
2015-02-17 02:27:11 +00:00
|
|
|
|
// Allow customizing the banner UI:
|
|
|
|
|
// the default implementation defers the creation to
|
|
|
|
|
// the source (which will create a NotificationBanner),
|
|
|
|
|
// so customization can be done by subclassing either
|
|
|
|
|
// Notification or Source
|
2017-10-31 00:03:21 +00:00
|
|
|
|
createBanner() {
|
2015-02-17 02:27:11 +00:00
|
|
|
|
return this.source.createBanner(this);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 02:27:11 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
activate() {
|
2015-02-18 23:00:25 +00:00
|
|
|
|
this.emit('activated');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-12-16 20:49:47 +00:00
|
|
|
|
|
2019-07-11 23:31:38 +00:00
|
|
|
|
destroy(reason = NotificationDestroyedReason.DISMISSED) {
|
2019-05-14 01:58:58 +00:00
|
|
|
|
if (this._activatedId) {
|
|
|
|
|
this.disconnect(this._activatedId);
|
|
|
|
|
delete this._activatedId;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 19:20:03 +00:00
|
|
|
|
this.emit('destroy', reason);
|
2019-05-14 01:58:58 +00:00
|
|
|
|
this.run_dispose();
|
2010-01-13 20:05:20 +00:00
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
|
var NotificationBanner = GObject.registerClass({
|
|
|
|
|
Signals: {
|
|
|
|
|
'done-displaying': {},
|
|
|
|
|
'unfocused': {},
|
2019-08-20 21:43:54 +00:00
|
|
|
|
},
|
2019-07-16 09:24:13 +00:00
|
|
|
|
}, class NotificationBanner extends Calendar.NotificationMessage {
|
|
|
|
|
_init(notification) {
|
|
|
|
|
super._init(notification);
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this.can_focus = false;
|
|
|
|
|
this.add_style_class_name('notification-banner');
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
|
|
|
|
this._buttonBox = null;
|
|
|
|
|
|
|
|
|
|
this._addActions();
|
|
|
|
|
this._addSecondaryIcon();
|
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this._activatedId = this.notification.connect('activated', () => {
|
|
|
|
|
// 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');
|
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2019-01-29 14:30:40 +00:00
|
|
|
|
_disconnectNotificationSignals() {
|
|
|
|
|
super._disconnectNotificationSignals();
|
|
|
|
|
|
|
|
|
|
if (this._activatedId)
|
|
|
|
|
this.notification.disconnect(this._activatedId);
|
|
|
|
|
this._activatedId = 0;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onUpdated(n, clear) {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
super._onUpdated(n, clear);
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
|
|
|
|
if (clear) {
|
|
|
|
|
this.setSecondaryActor(null);
|
|
|
|
|
this.setActionArea(null);
|
|
|
|
|
this._buttonBox = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._addActions();
|
|
|
|
|
this._addSecondaryIcon();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_addActions() {
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this.notification.actions.forEach(action => {
|
|
|
|
|
this.addAction(action.label, action.callback);
|
|
|
|
|
});
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_addSecondaryIcon() {
|
2015-02-17 00:13:48 +00:00
|
|
|
|
if (this.notification.secondaryGIcon) {
|
2017-02-26 02:33:26 +00:00
|
|
|
|
let icon = new St.Icon({ gicon: this.notification.secondaryGIcon,
|
|
|
|
|
x_align: Clutter.ActorAlign.END });
|
2015-02-17 00:13:48 +00:00
|
|
|
|
this.setSecondaryActor(icon);
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
addButton(button, callback) {
|
2015-02-17 00:13:48 +00:00
|
|
|
|
if (!this._buttonBox) {
|
|
|
|
|
this._buttonBox = new St.BoxLayout({ style_class: 'notification-actions',
|
|
|
|
|
x_expand: true });
|
|
|
|
|
this.setActionArea(this._buttonBox);
|
|
|
|
|
global.focus_manager.add_group(this._buttonBox);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 02:53:00 +00:00
|
|
|
|
if (this._buttonBox.get_n_children() >= MAX_NOTIFICATION_BUTTONS)
|
|
|
|
|
return null;
|
|
|
|
|
|
2015-02-17 00:13:48 +00:00
|
|
|
|
this._buttonBox.add(button);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
button.connect('clicked', () => {
|
2015-02-17 00:13:48 +00:00
|
|
|
|
callback();
|
|
|
|
|
|
|
|
|
|
if (!this.notification.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.notification.destroy();
|
|
|
|
|
}
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
|
|
|
|
return button;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
addAction(label, callback) {
|
2015-02-17 00:13:48 +00:00
|
|
|
|
let button = new St.Button({ style_class: 'notification-button',
|
2019-08-19 19:06:04 +00:00
|
|
|
|
label,
|
2015-02-17 00:13:48 +00:00
|
|
|
|
x_expand: true,
|
|
|
|
|
can_focus: true });
|
|
|
|
|
|
|
|
|
|
return this.addButton(button, callback);
|
|
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
|
});
|
2015-02-17 00:13:48 +00:00
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
|
var SourceActor = GObject.registerClass(
|
|
|
|
|
class SourceActor extends St.Widget {
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_init(source, size) {
|
2017-10-31 01:23:39 +00:00
|
|
|
|
super._init();
|
2018-07-06 08:55:23 +00:00
|
|
|
|
|
2012-07-19 13:05:17 +00:00
|
|
|
|
this._source = source;
|
2012-07-23 04:07:51 +00:00
|
|
|
|
this._size = size;
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
2018-07-06 08:55:23 +00:00
|
|
|
|
this.connect('destroy', () => {
|
2014-10-09 18:31:04 +00:00
|
|
|
|
this._source.disconnect(this._iconUpdatedId);
|
2012-07-19 13:05:17 +00:00
|
|
|
|
this._actorDestroyed = true;
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2011-07-12 23:18:58 +00:00
|
|
|
|
this._actorDestroyed = false;
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
2019-01-31 13:43:52 +00:00
|
|
|
|
let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor;
|
2019-10-17 21:40:24 +00:00
|
|
|
|
this._iconBin = new St.Bin({ x_expand: true,
|
2019-01-31 13:43:52 +00:00
|
|
|
|
height: size * scaleFactor,
|
|
|
|
|
width: size * scaleFactor });
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
2018-07-06 08:55:23 +00:00
|
|
|
|
this.add_actor(this._iconBin);
|
2012-07-23 04:07:51 +00:00
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._iconUpdatedId = this._source.connect('icon-updated', this._updateIcon.bind(this));
|
2012-07-23 04:07:51 +00:00
|
|
|
|
this._updateIcon();
|
2017-10-31 01:23:39 +00:00
|
|
|
|
}
|
2011-10-07 22:31:26 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
setIcon(icon) {
|
2012-07-19 13:05:17 +00:00
|
|
|
|
this._iconBin.child = icon;
|
2012-07-23 04:07:51 +00:00
|
|
|
|
this._iconSet = true;
|
2017-10-31 01:23:39 +00:00
|
|
|
|
}
|
2010-12-15 21:30:50 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_updateIcon() {
|
2014-02-14 17:39:32 +00:00
|
|
|
|
if (this._actorDestroyed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!this._iconSet)
|
|
|
|
|
this._iconBin.child = this._source.createIcon(this._size);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-31 01:23:39 +00:00
|
|
|
|
var SourceActorWithLabel = GObject.registerClass(
|
|
|
|
|
class SourceActorWithLabel extends SourceActor {
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_init(source, size) {
|
2017-10-31 01:23:39 +00:00
|
|
|
|
super._init(source, size);
|
2014-02-14 17:39:32 +00:00
|
|
|
|
|
|
|
|
|
this._counterLabel = new St.Label({ x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
|
x_expand: true,
|
|
|
|
|
y_align: Clutter.ActorAlign.CENTER,
|
|
|
|
|
y_expand: true });
|
|
|
|
|
|
|
|
|
|
this._counterBin = new St.Bin({ style_class: 'summary-source-counter',
|
|
|
|
|
child: this._counterLabel,
|
|
|
|
|
layout_manager: new Clutter.BinLayout() });
|
|
|
|
|
this._counterBin.hide();
|
|
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this._counterBin.connect('style-changed', () => {
|
2014-02-14 17:39:32 +00:00
|
|
|
|
let themeNode = this._counterBin.get_theme_node();
|
|
|
|
|
this._counterBin.translation_x = themeNode.get_length('-shell-counter-overlap-x');
|
|
|
|
|
this._counterBin.translation_y = themeNode.get_length('-shell-counter-overlap-y');
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2014-02-14 17:39:32 +00:00
|
|
|
|
|
2018-07-06 08:55:23 +00:00
|
|
|
|
this.add_actor(this._counterBin);
|
2014-02-14 17:39:32 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
this._countUpdatedId = this._source.connect('notify::count', this._updateCount.bind(this));
|
2014-02-14 17:39:32 +00:00
|
|
|
|
this._updateCount();
|
2014-10-09 18:31:04 +00:00
|
|
|
|
|
2018-07-06 08:55:23 +00:00
|
|
|
|
this.connect('destroy', () => {
|
2014-10-09 18:31:04 +00:00
|
|
|
|
this._source.disconnect(this._countUpdatedId);
|
|
|
|
|
});
|
2017-10-31 01:23:39 +00:00
|
|
|
|
}
|
2014-02-14 17:39:32 +00:00
|
|
|
|
|
2018-07-06 08:55:23 +00:00
|
|
|
|
vfunc_allocate(box, flags) {
|
2017-10-31 01:23:39 +00:00
|
|
|
|
super.vfunc_allocate(box, flags);
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
|
|
|
|
let childBox = new Clutter.ActorBox();
|
|
|
|
|
|
2019-02-01 13:41:55 +00:00
|
|
|
|
let [, , naturalWidth, naturalHeight] = this._counterBin.get_preferred_size();
|
2018-07-06 08:55:23 +00:00
|
|
|
|
let direction = this.get_text_direction();
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
2012-02-14 01:37:28 +00:00
|
|
|
|
if (direction == Clutter.TextDirection.LTR) {
|
2011-06-24 19:46:55 +00:00
|
|
|
|
// 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);
|
2017-10-31 01:23:39 +00:00
|
|
|
|
}
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_updateCount() {
|
2012-07-19 13:05:17 +00:00
|
|
|
|
if (this._actorDestroyed)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this._counterBin.visible = this._source.countVisible;
|
2012-09-10 15:41:30 +00:00
|
|
|
|
|
|
|
|
|
let text;
|
|
|
|
|
if (this._source.count < 100)
|
|
|
|
|
text = this._source.count.toString();
|
|
|
|
|
else
|
|
|
|
|
text = String.fromCharCode(0x22EF); // midline horizontal ellipsis
|
|
|
|
|
|
|
|
|
|
this._counterLabel.set_text(text);
|
2012-07-23 04:07:51 +00:00
|
|
|
|
}
|
2012-07-19 13:05:17 +00:00
|
|
|
|
});
|
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
var Source = GObject.registerClass({
|
|
|
|
|
Properties: {
|
|
|
|
|
'count': GObject.ParamSpec.int(
|
|
|
|
|
'count', 'count', 'count',
|
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
|
0, GLib.MAXINT32, 0),
|
|
|
|
|
'policy': GObject.ParamSpec.object(
|
|
|
|
|
'policy', 'policy', 'policy',
|
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
|
NotificationPolicy.$gtype),
|
|
|
|
|
'title': GObject.ParamSpec.string(
|
|
|
|
|
'title', 'title', 'title',
|
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
|
null),
|
|
|
|
|
},
|
|
|
|
|
Signals: {
|
|
|
|
|
'destroy': { param_types: [GObject.TYPE_UINT] },
|
|
|
|
|
'icon-updated': {},
|
|
|
|
|
'notification-added': { param_types: [Notification.$gtype] },
|
|
|
|
|
'notification-show': { param_types: [Notification.$gtype] },
|
2019-08-20 21:43:54 +00:00
|
|
|
|
},
|
2019-05-13 21:32:31 +00:00
|
|
|
|
}, class Source extends GObject.Object {
|
|
|
|
|
_init(title, iconName) {
|
2019-08-19 19:06:04 +00:00
|
|
|
|
super._init({ title });
|
2019-05-13 21:32:31 +00:00
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
|
this.SOURCE_ICON_SIZE = 48;
|
2012-07-19 13:05:17 +00:00
|
|
|
|
|
|
|
|
|
this.iconName = iconName;
|
|
|
|
|
|
|
|
|
|
this.isChat = false;
|
|
|
|
|
|
|
|
|
|
this.notifications = [];
|
2012-10-16 15:08:54 +00:00
|
|
|
|
|
2017-11-01 18:21:31 +00:00
|
|
|
|
this._policy = null;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2017-11-01 18:21:31 +00:00
|
|
|
|
|
|
|
|
|
get policy() {
|
|
|
|
|
if (!this._policy)
|
|
|
|
|
this._policy = this._createPolicy();
|
|
|
|
|
return this._policy;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-07-19 13:05:17 +00:00
|
|
|
|
|
2019-03-02 19:53:33 +00:00
|
|
|
|
set policy(policy) {
|
|
|
|
|
if (this._policy)
|
|
|
|
|
this._policy.destroy();
|
|
|
|
|
this._policy = policy;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-06 15:28:55 +00:00
|
|
|
|
get count() {
|
|
|
|
|
return this.notifications.length;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
2012-08-06 15:28:55 +00:00
|
|
|
|
get unseenCount() {
|
2017-10-31 00:38:18 +00:00
|
|
|
|
return this.notifications.filter(n => !n.acknowledged).length;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-06-24 19:46:55 +00:00
|
|
|
|
|
2012-08-06 15:28:55 +00:00
|
|
|
|
get countVisible() {
|
|
|
|
|
return this.count > 1;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-08-06 15:28:55 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
countUpdated() {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
super.notify('count');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-06-24 19:47:24 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_createPolicy() {
|
2012-10-16 15:08:54 +00:00
|
|
|
|
return new NotificationPolicy();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-10-16 15:08:54 +00:00
|
|
|
|
|
2018-11-01 20:56:25 +00:00
|
|
|
|
get narrowestPrivacyScope() {
|
2019-08-19 19:33:15 +00:00
|
|
|
|
return this.notifications.every(n => n.privacyScope == PrivacyScope.SYSTEM)
|
|
|
|
|
? PrivacyScope.SYSTEM
|
|
|
|
|
: PrivacyScope.USER;
|
2018-11-01 20:56:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
setTitle(newTitle) {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
if (this.title == newTitle)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-06-08 06:27:57 +00:00
|
|
|
|
this.title = newTitle;
|
2019-05-13 21:32:31 +00:00
|
|
|
|
this.notify('title');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-06-08 06:27:57 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
createBanner(notification) {
|
2015-02-17 02:27:11 +00:00
|
|
|
|
return new NotificationBanner(notification);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-17 02:27:11 +00:00
|
|
|
|
|
2012-07-19 13:05:17 +00:00
|
|
|
|
// Called to create a new icon actor.
|
2011-10-07 22:31:26 +00:00
|
|
|
|
// Provides a sane default implementation, override if you need
|
|
|
|
|
// something more fancy.
|
2017-10-31 00:03:21 +00:00
|
|
|
|
createIcon(size) {
|
2012-09-15 06:10:15 +00:00
|
|
|
|
return new St.Icon({ gicon: this.getIcon(),
|
2012-07-19 13:05:17 +00:00
|
|
|
|
icon_size: size });
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
getIcon() {
|
2012-09-15 06:10:15 +00:00
|
|
|
|
return new Gio.ThemedIcon({ name: this.iconName });
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-09-15 06:10:15 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onNotificationDestroy(notification) {
|
2013-10-14 01:52:44 +00:00
|
|
|
|
let index = this.notifications.indexOf(notification);
|
|
|
|
|
if (index < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.notifications.splice(index, 1);
|
2019-05-14 02:03:51 +00:00
|
|
|
|
this.countUpdated();
|
|
|
|
|
|
2013-10-14 01:52:44 +00:00
|
|
|
|
if (this.notifications.length == 0)
|
2015-02-15 19:19:03 +00:00
|
|
|
|
this.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2013-10-14 01:52:44 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
pushNotification(notification) {
|
2018-07-14 20:56:22 +00:00
|
|
|
|
if (this.notifications.includes(notification))
|
2013-10-14 01:51:30 +00:00
|
|
|
|
return;
|
2010-02-25 19:42:18 +00:00
|
|
|
|
|
2015-02-13 23:06:11 +00:00
|
|
|
|
while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE)
|
|
|
|
|
this.notifications.shift().destroy(NotificationDestroyedReason.EXPIRED);
|
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
|
notification.connect('destroy', this._onNotificationDestroy.bind(this));
|
2019-05-13 21:32:31 +00:00
|
|
|
|
notification.connect('notify::acknowledged', this.countUpdated.bind(this));
|
2013-10-14 01:51:30 +00:00
|
|
|
|
this.notifications.push(notification);
|
|
|
|
|
this.emit('notification-added', notification);
|
|
|
|
|
|
2012-08-06 15:28:55 +00:00
|
|
|
|
this.countUpdated();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-02-25 19:42:18 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
showNotification(notification) {
|
2012-08-06 15:28:55 +00:00
|
|
|
|
notification.acknowledged = false;
|
2011-02-28 18:13:32 +00:00
|
|
|
|
this.pushNotification(notification);
|
2012-10-16 15:08:54 +00:00
|
|
|
|
|
2019-08-20 00:51:42 +00:00
|
|
|
|
if (this.policy.showBanners || notification.urgency == Urgency.CRITICAL)
|
2019-05-13 21:32:31 +00:00
|
|
|
|
this.emit('notification-show', notification);
|
2019-08-20 00:51:42 +00:00
|
|
|
|
else
|
2015-02-17 02:49:24 +00:00
|
|
|
|
notification.playSound();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
notify(propName) {
|
|
|
|
|
if (propName instanceof Notification) {
|
|
|
|
|
try {
|
|
|
|
|
throw new Error('Source.notify() has been moved to Source.showNotification()' +
|
|
|
|
|
'this code will break in the future');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
logError(e);
|
|
|
|
|
this.showNotification(propName);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.notify(propName);
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
destroy(reason) {
|
2012-10-16 15:08:54 +00:00
|
|
|
|
this.policy.destroy();
|
2012-10-25 16:30:27 +00:00
|
|
|
|
|
|
|
|
|
let notifications = this.notifications;
|
|
|
|
|
this.notifications = [];
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < notifications.length; i++)
|
|
|
|
|
notifications[i].destroy(reason);
|
|
|
|
|
|
2011-03-21 21:43:34 +00:00
|
|
|
|
this.emit('destroy', reason);
|
2019-05-14 02:03:51 +00:00
|
|
|
|
|
|
|
|
|
this.run_dispose();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-08-05 17:09:27 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
iconUpdated() {
|
2012-07-23 04:07:51 +00:00
|
|
|
|
this.emit('icon-updated');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-07-23 04:07:51 +00:00
|
|
|
|
|
2013-08-02 04:08:33 +00:00
|
|
|
|
// To be overridden by subclasses
|
2017-10-31 00:03:21 +00:00
|
|
|
|
open() {
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-12-16 20:49:47 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
destroyNonResidentNotifications() {
|
2019-08-20 00:51:42 +00:00
|
|
|
|
for (let i = this.notifications.length - 1; i >= 0; i--) {
|
2011-03-21 21:43:34 +00:00
|
|
|
|
if (!this.notifications[i].resident)
|
|
|
|
|
this.notifications[i].destroy();
|
2019-08-20 00:51:42 +00:00
|
|
|
|
}
|
2015-02-11 16:01:11 +00:00
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
|
var MessageTray = GObject.registerClass({
|
|
|
|
|
Signals: {
|
|
|
|
|
'queue-changed': {},
|
|
|
|
|
'source-added': { param_types: [Source.$gtype] },
|
|
|
|
|
'source-removed': { param_types: [Source.$gtype] },
|
2019-08-20 21:43:54 +00:00
|
|
|
|
},
|
2019-07-16 09:24:13 +00:00
|
|
|
|
}, class MessageTray extends St.Widget {
|
|
|
|
|
_init() {
|
|
|
|
|
super._init({
|
|
|
|
|
visible: false,
|
|
|
|
|
clip_to_allocation: true,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
layout_manager: new Clutter.BinLayout(),
|
2019-07-16 09:24:13 +00:00
|
|
|
|
});
|
|
|
|
|
|
2019-01-31 14:08:10 +00:00
|
|
|
|
this._presence = new GnomeSession.Presence((proxy, _error) => {
|
2011-08-16 12:24:39 +00:00
|
|
|
|
this._onStatusChanged(proxy.status);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2011-02-19 15:49:56 +00:00
|
|
|
|
this._busy = false;
|
2015-02-13 22:53:18 +00:00
|
|
|
|
this._bannerBlocked = false;
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this._presence.connectSignal('StatusChanged', (proxy, senderName, [status]) => {
|
2011-08-16 12:24:39 +00:00
|
|
|
|
this._onStatusChanged(status);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
global.stage.connect('enter-event', (a, ev) => {
|
|
|
|
|
// HACK: St uses ClutterInputDevice for hover tracking, which
|
|
|
|
|
// misses relevant X11 events when untracked actors are
|
|
|
|
|
// involved (read: the notification banner in normal mode),
|
|
|
|
|
// so fix up Clutter's view of the pointer position in
|
|
|
|
|
// that case.
|
|
|
|
|
let related = ev.get_related();
|
2019-07-16 09:24:13 +00:00
|
|
|
|
if (!related || this.contains(related))
|
2017-10-31 00:38:18 +00:00
|
|
|
|
global.sync_pointer();
|
|
|
|
|
});
|
2015-02-13 20:12:53 +00:00
|
|
|
|
|
2015-02-25 16:43:54 +00:00
|
|
|
|
let constraint = new Layout.MonitorConstraint({ primary: true });
|
|
|
|
|
Main.layoutManager.panelBox.bind_property('visible',
|
|
|
|
|
constraint, 'work-area',
|
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this.add_constraint(constraint);
|
2015-02-25 16:43:54 +00:00
|
|
|
|
|
|
|
|
|
this._bannerBin = new St.Widget({ name: 'notification-container',
|
|
|
|
|
reactive: true,
|
|
|
|
|
track_hover: true,
|
|
|
|
|
y_align: Clutter.ActorAlign.START,
|
|
|
|
|
x_align: Clutter.ActorAlign.CENTER,
|
|
|
|
|
y_expand: true,
|
|
|
|
|
x_expand: true,
|
|
|
|
|
layout_manager: new Clutter.BinLayout() });
|
|
|
|
|
this._bannerBin.connect('key-release-event',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onNotificationKeyRelease.bind(this));
|
2015-02-25 16:43:54 +00:00
|
|
|
|
this._bannerBin.connect('notify::hover',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onNotificationHoverChanged.bind(this));
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this.add_actor(this._bannerBin);
|
2015-02-25 16:43:54 +00:00
|
|
|
|
|
|
|
|
|
this._notificationFocusGrabber = new FocusGrabber(this._bannerBin);
|
2010-01-13 20:05:20 +00:00
|
|
|
|
this._notificationQueue = [];
|
2010-02-01 20:23:49 +00:00
|
|
|
|
this._notification = null;
|
2015-02-17 02:13:56 +00:00
|
|
|
|
this._banner = null;
|
|
|
|
|
this._bannerClickedId = 0;
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2012-07-30 23:14:49 +00:00
|
|
|
|
this._userActiveWhileNotificationShown = false;
|
2012-03-15 02:50:58 +00:00
|
|
|
|
|
2013-08-14 13:47:27 +00:00
|
|
|
|
this.idleMonitor = Meta.IdleMonitor.get_core();
|
2012-03-15 02:50:58 +00:00
|
|
|
|
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._useLongerNotificationLeftTimeout = false;
|
2013-03-11 19:36:56 +00:00
|
|
|
|
|
2013-03-13 20:14:53 +00:00
|
|
|
|
// pointerInNotification is sort of a misnomer -- it tracks whether
|
2013-03-11 19:36:56 +00:00
|
|
|
|
// a message tray notification should expand. The value is
|
2013-03-13 20:14:53 +00:00
|
|
|
|
// partially driven by the hover state of the notification, but has
|
2013-03-11 19:36:56 +00:00
|
|
|
|
// a lot of complex state related to timeouts and the current
|
|
|
|
|
// state of the pointer when a notification pops up.
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._pointerInNotification = false;
|
2013-03-11 19:36:56 +00:00
|
|
|
|
|
2015-02-25 16:43:54 +00:00
|
|
|
|
// This tracks this._bannerBin.hover and is used to fizzle
|
2013-03-13 20:14:53 +00:00
|
|
|
|
// out non-changing hover notifications in onNotificationHoverChanged.
|
|
|
|
|
this._notificationHovered = false;
|
2013-03-11 19:36:56 +00: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 20:31:12 +00:00
|
|
|
|
this._notificationState = State.HIDDEN;
|
|
|
|
|
this._notificationTimeoutId = 0;
|
2010-02-22 22:19:32 +00:00
|
|
|
|
this._notificationRemoved = false;
|
2010-02-09 18:31:39 +00:00
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
|
Main.layoutManager.addChrome(this, { affectsInputRegion: false });
|
2015-02-25 16:43:54 +00:00
|
|
|
|
Main.layoutManager.trackChrome(this._bannerBin, { affectsInputRegion: true });
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2018-01-03 07:55:38 +00:00
|
|
|
|
global.display.connect('in-fullscreen-changed', this._updateState.bind(this));
|
2010-02-12 17:33:00 +00:00
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2012-05-22 22:02:00 +00:00
|
|
|
|
|
2015-02-21 08:05:58 +00:00
|
|
|
|
Main.overview.connect('window-drag-begin',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragBegin.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
Main.overview.connect('window-drag-cancelled',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragEnd.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
Main.overview.connect('window-drag-end',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragEnd.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
|
|
|
|
|
Main.overview.connect('item-drag-begin',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragBegin.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
Main.overview.connect('item-drag-cancelled',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragEnd.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
Main.overview.connect('item-drag-end',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragEnd.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
|
|
|
|
|
Main.xdndHandler.connect('drag-begin',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragBegin.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
Main.xdndHandler.connect('drag-end',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onDragEnd.bind(this));
|
2015-02-21 08:05:58 +00:00
|
|
|
|
|
2012-08-20 20:16:21 +00:00
|
|
|
|
Main.wm.addKeybinding('focus-active-notification',
|
2014-06-24 19:17:09 +00:00
|
|
|
|
new Gio.Settings({ schema_id: SHELL_KEYBINDINGS_SCHEMA }),
|
2012-08-20 20:16:21 +00:00
|
|
|
|
Meta.KeyBindingFlags.NONE,
|
2014-12-11 14:35:40 +00:00
|
|
|
|
Shell.ActionMode.NORMAL |
|
|
|
|
|
Shell.ActionMode.OVERVIEW,
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._expandActiveNotification.bind(this));
|
2012-07-14 11:07:24 +00:00
|
|
|
|
|
2014-01-14 22:49:47 +00:00
|
|
|
|
this._sources = new Map();
|
2012-08-17 20:07:42 +00:00
|
|
|
|
|
2012-10-10 20:17:39 +00:00
|
|
|
|
this._sessionUpdated();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-10-10 20:17:39 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_sessionUpdated() {
|
2012-10-10 20:17:39 +00:00
|
|
|
|
this._updateState();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-08-17 20:07:42 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onDragBegin() {
|
2019-07-16 09:24:13 +00:00
|
|
|
|
Shell.util_set_hidden_from_pick(this, true);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-21 08:05:58 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onDragEnd() {
|
2019-07-16 09:24:13 +00:00
|
|
|
|
Shell.util_set_hidden_from_pick(this, false);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-21 08:05:58 +00:00
|
|
|
|
|
2015-04-23 10:43:03 +00:00
|
|
|
|
get bannerAlignment() {
|
|
|
|
|
return this._bannerBin.get_x_align();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-04-23 10:43:03 +00:00
|
|
|
|
|
|
|
|
|
set bannerAlignment(align) {
|
|
|
|
|
this._bannerBin.set_x_align(align);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-04-23 10:43:03 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onNotificationKeyRelease(actor, event) {
|
2012-12-23 03:21:47 +00:00
|
|
|
|
if (event.get_key_symbol() == Clutter.KEY_Escape && event.get_state() == 0) {
|
2014-02-26 13:44:53 +00:00
|
|
|
|
this._expireNotification();
|
2013-11-29 18:17:34 +00:00
|
|
|
|
return Clutter.EVENT_STOP;
|
2012-11-08 14:38:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 18:17:34 +00:00
|
|
|
|
return Clutter.EVENT_PROPAGATE;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-11-08 14:38:57 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_expireNotification() {
|
2014-02-26 13:44:53 +00:00
|
|
|
|
this._notificationExpired = true;
|
|
|
|
|
this._updateState();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2014-02-26 13:44:53 +00:00
|
|
|
|
|
2015-02-14 02:17:16 +00:00
|
|
|
|
get queueCount() {
|
|
|
|
|
return this._notificationQueue.length;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-14 02:17:16 +00:00
|
|
|
|
|
2015-02-13 22:53:18 +00:00
|
|
|
|
set bannerBlocked(v) {
|
|
|
|
|
if (this._bannerBlocked == v)
|
|
|
|
|
return;
|
|
|
|
|
this._bannerBlocked = v;
|
|
|
|
|
this._updateState();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2015-02-13 22:53:18 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
contains(source) {
|
2012-11-04 17:49:14 +00:00
|
|
|
|
return this._sources.has(source);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
add(source) {
|
2010-01-13 20:05:20 +00:00
|
|
|
|
if (this.contains(source)) {
|
2019-01-30 00:18:24 +00:00
|
|
|
|
log(`Trying to re-add source ${source.title}`);
|
2010-01-13 20:05:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-16 15:08:54 +00:00
|
|
|
|
// Register that we got a notification for this source
|
|
|
|
|
source.policy.store();
|
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
source.policy.connect('notify::enable', () => {
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onSourceEnableChanged(source.policy, source);
|
|
|
|
|
});
|
2019-05-13 21:32:31 +00:00
|
|
|
|
source.policy.connect('notify', this._updateState.bind(this));
|
2012-10-16 15:08:54 +00:00
|
|
|
|
this._onSourceEnableChanged(source.policy, source);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-11-04 17:49:14 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_addSource(source) {
|
2012-11-04 17:49:14 +00:00
|
|
|
|
let obj = {
|
2019-05-13 21:32:31 +00:00
|
|
|
|
showId: 0,
|
2012-11-04 17:49:14 +00:00
|
|
|
|
destroyId: 0,
|
|
|
|
|
};
|
2010-06-23 19:20:39 +00:00
|
|
|
|
|
2012-11-04 17:49:14 +00:00
|
|
|
|
this._sources.set(source, obj);
|
2010-01-28 18:12:03 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
obj.showId = source.connect('notification-show', this._onNotificationShow.bind(this));
|
2017-12-02 00:27:35 +00:00
|
|
|
|
obj.destroyId = source.connect('destroy', this._onSourceDestroy.bind(this));
|
2011-11-03 14:48:09 +00:00
|
|
|
|
|
2013-01-30 18:47:55 +00:00
|
|
|
|
this.emit('source-added', source);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-05-22 22:02:00 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_removeSource(source) {
|
2014-01-14 22:49:47 +00:00
|
|
|
|
let obj = this._sources.get(source);
|
|
|
|
|
this._sources.delete(source);
|
2010-12-30 21:09:56 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
source.disconnect(obj.showId);
|
2012-11-04 17:49:14 +00:00
|
|
|
|
source.disconnect(obj.destroyId);
|
|
|
|
|
|
2013-02-05 18:06:19 +00:00
|
|
|
|
this.emit('source-removed', source);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
getSources() {
|
2017-07-18 17:20:42 +00:00
|
|
|
|
return [...this._sources.keys()];
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-11-04 17:49:14 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onSourceEnableChanged(policy, source) {
|
2012-10-16 15:08:54 +00:00
|
|
|
|
let wasEnabled = this.contains(source);
|
|
|
|
|
let shouldBeEnabled = policy.enable;
|
|
|
|
|
|
|
|
|
|
if (wasEnabled != shouldBeEnabled) {
|
|
|
|
|
if (shouldBeEnabled)
|
|
|
|
|
this._addSource(source);
|
|
|
|
|
else
|
|
|
|
|
this._removeSource(source);
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-10-16 15:08:54 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onSourceDestroy(source) {
|
2012-11-04 17:49:14 +00:00
|
|
|
|
this._removeSource(source);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-11-04 17:49:14 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onNotificationDestroy(notification) {
|
2010-02-22 22:19:32 +00: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 19:47:12 +00:00
|
|
|
|
this._updateNotificationTimeout(0);
|
2010-02-22 22:19:32 +00:00
|
|
|
|
this._notificationRemoved = true;
|
|
|
|
|
this._updateState();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let index = this._notificationQueue.indexOf(notification);
|
2015-02-21 08:59:24 +00:00
|
|
|
|
if (index != -1) {
|
2010-02-22 22:19:32 +00:00
|
|
|
|
this._notificationQueue.splice(index, 1);
|
2015-02-21 08:59:24 +00:00
|
|
|
|
this.emit('queue-changed');
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-02-22 22:19:32 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
_onNotificationShow(_source, 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 19:47:12 +00: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();
|
2018-07-14 20:56:22 +00:00
|
|
|
|
} else if (!this._notificationQueue.includes(notification)) {
|
2015-02-14 02:18:52 +00:00
|
|
|
|
// If the queue is "full", we skip banner mode and just show a small
|
|
|
|
|
// indicator in the panel; however do make an exception for CRITICAL
|
|
|
|
|
// notifications, as only banner mode allows expansion.
|
|
|
|
|
let bannerCount = this._notification ? 1 : 0;
|
2019-08-19 19:38:51 +00:00
|
|
|
|
let full = this.queueCount + bannerCount >= MAX_NOTIFICATIONS_IN_QUEUE;
|
2015-02-14 02:18:52 +00:00
|
|
|
|
if (!full || notification.urgency == Urgency.CRITICAL) {
|
|
|
|
|
notification.connect('destroy',
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this._onNotificationDestroy.bind(this));
|
2015-02-14 02:18:52 +00:00
|
|
|
|
this._notificationQueue.push(notification);
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this._notificationQueue.sort(
|
|
|
|
|
(n1, n2) => n2.urgency - n1.urgency
|
|
|
|
|
);
|
2015-02-21 08:59:24 +00:00
|
|
|
|
this.emit('queue-changed');
|
2015-02-14 02:18:52 +00:00
|
|
|
|
}
|
2010-02-22 22:19:32 +00: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 20:31:12 +00:00
|
|
|
|
this._updateState();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-28 18:12:03 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_resetNotificationLeftTimeout() {
|
2014-05-28 19:18:00 +00:00
|
|
|
|
this._useLongerNotificationLeftTimeout = false;
|
|
|
|
|
if (this._notificationLeftTimeoutId) {
|
2019-08-19 18:50:33 +00:00
|
|
|
|
GLib.source_remove(this._notificationLeftTimeoutId);
|
2014-05-28 19:18:00 +00:00
|
|
|
|
this._notificationLeftTimeoutId = 0;
|
|
|
|
|
this._notificationLeftMouseX = -1;
|
|
|
|
|
this._notificationLeftMouseY = -1;
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2014-05-28 19:18:00 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onNotificationHoverChanged() {
|
2015-02-25 16:43:54 +00:00
|
|
|
|
if (this._bannerBin.hover == this._notificationHovered)
|
2013-03-11 19:36:56 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-02-25 16:43:54 +00:00
|
|
|
|
this._notificationHovered = this._bannerBin.hover;
|
2013-03-13 20:14:53 +00:00
|
|
|
|
if (this._notificationHovered) {
|
2014-05-28 19:18:00 +00:00
|
|
|
|
this._resetNotificationLeftTimeout();
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2010-08-31 19:50:18 +00: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;
|
2013-03-13 20:14:53 +00:00
|
|
|
|
// Don't set this._pointerInNotification to true if the pointer was initially in the area where the notification
|
2010-08-31 19:50:18 +00:00
|
|
|
|
// 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.
|
2015-02-25 16:43:54 +00:00
|
|
|
|
if (this._bannerBin.contains(actorAtShowNotificationPosition)) {
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._useLongerNotificationLeftTimeout = true;
|
2010-08-31 19:50:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-28 19:02:40 +00:00
|
|
|
|
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._pointerInNotification = true;
|
2010-03-15 16:20:10 +00:00
|
|
|
|
this._updateState();
|
|
|
|
|
} else {
|
2010-10-30 19:54:43 +00:00
|
|
|
|
// We record the position of the mouse the moment it leaves the tray. These coordinates are used in
|
2013-03-13 20:14:53 +00:00
|
|
|
|
// this._onNotificationLeftTimeout() to determine if the mouse has moved far enough during the initial timeout for us
|
2010-10-30 19:54:43 +00:00
|
|
|
|
// 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.
|
2019-02-01 13:41:55 +00:00
|
|
|
|
let [x, y] = global.get_pointer();
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._notificationLeftMouseX = x;
|
|
|
|
|
this._notificationLeftMouseY = y;
|
2010-10-30 19:54:43 +00:00
|
|
|
|
|
2010-08-31 19:50:18 +00: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.
|
2019-08-01 23:13:10 +00:00
|
|
|
|
let timeout = this._useLongerNotificationLeftTimeout ? LONGER_HIDE_TIMEOUT : HIDE_TIMEOUT;
|
2019-08-19 18:50:33 +00:00
|
|
|
|
this._notificationLeftTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, timeout, this._onNotificationLeftTimeout.bind(this));
|
2014-04-10 17:26:52 +00:00
|
|
|
|
GLib.Source.set_name_by_id(this._notificationLeftTimeoutId, '[gnome-shell] this._onNotificationLeftTimeout');
|
[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 20:31:12 +00:00
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onStatusChanged(status) {
|
2011-02-19 15:49:56 +00:00
|
|
|
|
if (status == GnomeSession.PresenceStatus.BUSY) {
|
|
|
|
|
// remove notification and allow the summary to be closed now
|
|
|
|
|
this._updateNotificationTimeout(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();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2011-02-19 15:49:56 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onNotificationLeftTimeout() {
|
2019-02-01 13:41:55 +00:00
|
|
|
|
let [x, y] = global.get_pointer();
|
2015-02-19 10:08:39 +00:00
|
|
|
|
// We extend the timeout once if the mouse moved no further than MOUSE_LEFT_ACTOR_THRESHOLD to either side.
|
2013-03-13 20:14:53 +00:00
|
|
|
|
if (this._notificationLeftMouseX > -1 &&
|
2015-02-19 10:08:39 +00:00
|
|
|
|
y < this._notificationLeftMouseY + MOUSE_LEFT_ACTOR_THRESHOLD &&
|
2013-03-13 20:14:53 +00:00
|
|
|
|
y > this._notificationLeftMouseY - MOUSE_LEFT_ACTOR_THRESHOLD &&
|
|
|
|
|
x < this._notificationLeftMouseX + MOUSE_LEFT_ACTOR_THRESHOLD &&
|
|
|
|
|
x > this._notificationLeftMouseX - MOUSE_LEFT_ACTOR_THRESHOLD) {
|
|
|
|
|
this._notificationLeftMouseX = -1;
|
2019-08-19 18:50:33 +00:00
|
|
|
|
this._notificationLeftTimeoutId = GLib.timeout_add(
|
|
|
|
|
GLib.PRIORITY_DEFAULT,
|
|
|
|
|
LONGER_HIDE_TIMEOUT,
|
|
|
|
|
this._onNotificationLeftTimeout.bind(this));
|
2014-04-10 17:26:52 +00:00
|
|
|
|
GLib.Source.set_name_by_id(this._notificationLeftTimeoutId, '[gnome-shell] this._onNotificationLeftTimeout');
|
2010-10-30 19:54:43 +00:00
|
|
|
|
} else {
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._notificationLeftTimeoutId = 0;
|
|
|
|
|
this._useLongerNotificationLeftTimeout = false;
|
|
|
|
|
this._pointerInNotification = false;
|
2010-10-30 19:54:43 +00:00
|
|
|
|
this._updateNotificationTimeout(0);
|
|
|
|
|
this._updateState();
|
|
|
|
|
}
|
2013-11-29 00:45:39 +00:00
|
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-28 18:39:00 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_escapeTray() {
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._pointerInNotification = 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 19:47:12 +00:00
|
|
|
|
this._updateNotificationTimeout(0);
|
2010-07-21 05:26:25 +00:00
|
|
|
|
this._updateState();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-07-21 05:26:25 +00: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 20:31:12 +00:00
|
|
|
|
// All of the logic for what happens when occurs here; the various
|
|
|
|
|
// event handlers merely update variables such as
|
2013-03-13 20:14:53 +00:00
|
|
|
|
// 'this._pointerInNotification', 'this._traySummoned', 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 20:31:12 +00:00
|
|
|
|
// _updateState() figures out what (if anything) needs to be done
|
|
|
|
|
// at the present time.
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_updateState() {
|
2017-09-26 10:03:33 +00:00
|
|
|
|
let hasMonitor = Main.layoutManager.primaryMonitor != null;
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this.visible = !this._bannerBlocked && hasMonitor && this._banner != null;
|
2017-09-26 10:03:33 +00:00
|
|
|
|
if (this._bannerBlocked || !hasMonitor)
|
2015-02-13 22:53:18 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2013-11-15 15:34:04 +00:00
|
|
|
|
// If our state changes caused _updateState to be called,
|
|
|
|
|
// just exit now to prevent reentrancy issues.
|
|
|
|
|
if (this._updatingState)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this._updatingState = true;
|
|
|
|
|
|
2013-08-02 03:07:59 +00:00
|
|
|
|
// Filter out acknowledged notifications.
|
2015-02-21 08:59:24 +00:00
|
|
|
|
let changed = false;
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this._notificationQueue = this._notificationQueue.filter(n => {
|
2015-02-21 08:59:24 +00:00
|
|
|
|
changed = changed || n.acknowledged;
|
2013-05-12 17:52:58 +00:00
|
|
|
|
return !n.acknowledged;
|
|
|
|
|
});
|
2013-05-20 17:54:48 +00:00
|
|
|
|
|
2015-02-21 08:59:24 +00:00
|
|
|
|
if (changed)
|
|
|
|
|
this.emit('queue-changed');
|
|
|
|
|
|
2013-08-02 03:07:59 +00:00
|
|
|
|
let hasNotifications = Main.sessionMode.hasNotifications;
|
[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 20:31:12 +00:00
|
|
|
|
|
|
|
|
|
if (this._notificationState == State.HIDDEN) {
|
2013-08-02 03:07:59 +00:00
|
|
|
|
let nextNotification = this._notificationQueue[0] || null;
|
2015-02-11 16:29:23 +00:00
|
|
|
|
if (hasNotifications && nextNotification) {
|
2017-03-09 14:42:36 +00:00
|
|
|
|
let limited = this._busy || Main.layoutManager.primaryMonitor.inFullscreen;
|
2019-08-19 19:38:51 +00:00
|
|
|
|
let showNextNotification = !limited || nextNotification.forFeedback || nextNotification.urgency == Urgency.CRITICAL;
|
2015-02-14 02:19:49 +00:00
|
|
|
|
if (showNextNotification)
|
|
|
|
|
this._showNotification();
|
2013-08-02 03:07:59 +00: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 20:31:12 +00:00
|
|
|
|
} else if (this._notificationState == State.SHOWN) {
|
2013-08-02 03:07:59 +00:00
|
|
|
|
let expired = (this._userActiveWhileNotificationShown &&
|
|
|
|
|
this._notificationTimeoutId == 0 &&
|
2013-12-04 16:22:48 +00:00
|
|
|
|
this._notification.urgency != Urgency.CRITICAL &&
|
2015-02-17 02:13:56 +00:00
|
|
|
|
!this._banner.focused &&
|
2014-02-26 13:44:53 +00:00
|
|
|
|
!this._pointerInNotification) || this._notificationExpired;
|
2019-08-19 19:38:51 +00:00
|
|
|
|
let mustClose = this._notificationRemoved || !hasNotifications || expired;
|
2013-08-02 03:07:59 +00:00
|
|
|
|
|
|
|
|
|
if (mustClose) {
|
|
|
|
|
let animate = hasNotifications && !this._notificationRemoved;
|
2013-08-02 02:53:21 +00:00
|
|
|
|
this._hideNotification(animate);
|
2015-02-17 02:13:56 +00:00
|
|
|
|
} else if (this._pointerInNotification && !this._banner.expanded) {
|
|
|
|
|
this._expandBanner(false);
|
2013-11-04 19:16:28 +00:00
|
|
|
|
} else if (this._pointerInNotification) {
|
2015-02-17 02:13:56 +00:00
|
|
|
|
this._ensureBannerFocused();
|
2013-08-02 02:53:21 +00: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 20:31:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 15:34:04 +00:00
|
|
|
|
this._updatingState = false;
|
2014-02-26 13:44:53 +00:00
|
|
|
|
|
|
|
|
|
// Clean transient variables that are used to communicate actions
|
|
|
|
|
// to updateState()
|
|
|
|
|
this._notificationExpired = false;
|
2017-10-31 01:19:44 +00: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 20:31:12 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_onIdleMonitorBecameActive() {
|
2012-07-30 23:14:49 +00:00
|
|
|
|
this._userActiveWhileNotificationShown = true;
|
2012-08-20 04:06:50 +00:00
|
|
|
|
this._updateNotificationTimeout(2000);
|
2012-07-30 23:14:49 +00:00
|
|
|
|
this._updateState();
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-03-15 02:50:58 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_showNotification() {
|
2012-08-27 12:42:22 +00:00
|
|
|
|
this._notification = this._notificationQueue.shift();
|
2015-02-21 08:59:24 +00:00
|
|
|
|
this.emit('queue-changed');
|
2012-08-20 04:06:50 +00:00
|
|
|
|
|
2013-03-11 21:29:41 +00:00
|
|
|
|
this._userActiveWhileNotificationShown = this.idleMonitor.get_idletime() <= IDLE_TIME;
|
2013-01-18 05:24:32 +00:00
|
|
|
|
if (!this._userActiveWhileNotificationShown) {
|
|
|
|
|
// If the user isn't active, set up a watch to let us know
|
|
|
|
|
// when the user becomes active.
|
2017-12-02 00:27:35 +00:00
|
|
|
|
this.idleMonitor.add_user_active_watch(this._onIdleMonitorBecameActive.bind(this));
|
2012-08-20 04:06:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-21 20:41:18 +00:00
|
|
|
|
this._banner = this._notification.createBanner();
|
2018-11-22 17:18:34 +00:00
|
|
|
|
this._bannerClickedId = this._banner.connect('done-displaying',
|
|
|
|
|
this._escapeTray.bind(this));
|
2017-10-31 00:38:18 +00:00
|
|
|
|
this._bannerUnfocusedId = this._banner.connect('unfocused', () => {
|
2012-09-05 16:59:50 +00:00
|
|
|
|
this._updateState();
|
2017-10-31 00:38:18 +00:00
|
|
|
|
});
|
2015-02-17 02:13:56 +00:00
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this._bannerBin.add_actor(this._banner);
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2015-02-25 16:43:54 +00:00
|
|
|
|
this._bannerBin.opacity = 0;
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this._bannerBin.y = -this._banner.height;
|
|
|
|
|
this.show();
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2018-08-12 23:25:13 +00:00
|
|
|
|
Meta.disable_unredirect_for_display(global.display);
|
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 19:47:12 +00:00
|
|
|
|
this._updateShowingNotification();
|
2010-04-29 19:06:51 +00:00
|
|
|
|
|
2019-02-01 13:41:55 +00:00
|
|
|
|
let [x, y] = global.get_pointer();
|
2010-08-31 19:50:18 +00: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
|
2013-03-13 20:14:53 +00:00
|
|
|
|
// the user starts moving the mouse and _onNotificationHoverChanged() gets called. We don't
|
2010-08-31 19:50:18 +00:00
|
|
|
|
// 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;
|
2012-09-03 16:29:39 +00:00
|
|
|
|
// We save the coordinates of the mouse at the time when we started showing the notification
|
|
|
|
|
// and then we update it in _notificationTimeout(). We don't pop down the notification if
|
|
|
|
|
// the mouse is moving towards it or within it.
|
|
|
|
|
this._lastSeenMouseX = x;
|
2010-04-29 19:06:51 +00:00
|
|
|
|
this._lastSeenMouseY = y;
|
2014-06-02 17:28:18 +00:00
|
|
|
|
|
|
|
|
|
this._resetNotificationLeftTimeout();
|
2017-10-31 01:19:44 +00: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 20:31:12 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_updateShowingNotification() {
|
2012-08-06 15:28:55 +00:00
|
|
|
|
this._notification.acknowledged = true;
|
2012-11-05 17:10:24 +00:00
|
|
|
|
this._notification.playSound();
|
2012-08-06 15:28:55 +00:00
|
|
|
|
|
2012-10-16 15:08:54 +00:00
|
|
|
|
// We auto-expand notifications with CRITICAL urgency, or for which the relevant setting
|
|
|
|
|
// is on in the control center.
|
|
|
|
|
if (this._notification.urgency == Urgency.CRITICAL ||
|
|
|
|
|
this._notification.source.policy.forceExpanded)
|
2015-02-17 02:13:56 +00:00
|
|
|
|
this._expandBanner(true);
|
2011-01-13 01:05:36 +00: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.
|
|
|
|
|
//
|
2012-11-30 15:05:38 +00:00
|
|
|
|
// We tween any notification showing in the banner mode to the appropriate height
|
|
|
|
|
// (which is banner height or expanded height, depending on the notification state)
|
2011-01-13 01:05:36 +00:00
|
|
|
|
// This ensures that both new notifications and notifications in the banner mode that might
|
2012-11-30 15:05:38 +00:00
|
|
|
|
// have been in the process of hiding are shown with the correct height.
|
2011-01-13 01:05:36 +00:00
|
|
|
|
//
|
|
|
|
|
// We use this._showNotificationCompleted() onComplete callback to extend the time the updated
|
|
|
|
|
// notification is being shown.
|
2012-11-30 15:05:38 +00:00
|
|
|
|
|
2018-07-20 19:46:19 +00:00
|
|
|
|
this._notificationState = State.SHOWING;
|
2018-07-20 19:46:19 +00:00
|
|
|
|
this._bannerBin.remove_all_transitions();
|
|
|
|
|
this._bannerBin.ease({
|
2018-07-20 19:46:19 +00:00
|
|
|
|
opacity: 255,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
duration: ANIMATION_TIME,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
mode: Clutter.AnimationMode.LINEAR,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
});
|
2018-07-20 19:46:19 +00:00
|
|
|
|
this._bannerBin.ease({
|
2018-07-20 19:46:19 +00:00
|
|
|
|
y: 0,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
duration: ANIMATION_TIME,
|
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_BACK,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
onComplete: () => {
|
|
|
|
|
this._notificationState = State.SHOWN;
|
|
|
|
|
this._showNotificationCompleted();
|
|
|
|
|
this._updateState();
|
2019-08-20 21:43:54 +00:00
|
|
|
|
},
|
2018-07-20 19:46:19 +00:00
|
|
|
|
});
|
2017-10-31 01:19:44 +00: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 19:47:12 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_showNotificationCompleted() {
|
2011-01-11 21:33:03 +00:00
|
|
|
|
if (this._notification.urgency != Urgency.CRITICAL)
|
2019-08-01 23:13:10 +00:00
|
|
|
|
this._updateNotificationTimeout(NOTIFICATION_TIMEOUT);
|
2017-10-31 01:19:44 +00: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 19:47:12 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_updateNotificationTimeout(timeout) {
|
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 19:47:12 +00:00
|
|
|
|
if (this._notificationTimeoutId) {
|
2019-08-19 18:50:33 +00:00
|
|
|
|
GLib.source_remove(this._notificationTimeoutId);
|
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 19:47:12 +00:00
|
|
|
|
this._notificationTimeoutId = 0;
|
|
|
|
|
}
|
2014-04-10 17:26:52 +00:00
|
|
|
|
if (timeout > 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 19:47:12 +00:00
|
|
|
|
this._notificationTimeoutId =
|
2019-08-19 18:50:33 +00:00
|
|
|
|
GLib.timeout_add(GLib.PRIORITY_DEFAULT, timeout,
|
|
|
|
|
this._notificationTimeout.bind(this));
|
2014-04-10 17:26:52 +00:00
|
|
|
|
GLib.Source.set_name_by_id(this._notificationTimeoutId, '[gnome-shell] this._notificationTimeout');
|
|
|
|
|
}
|
2017-10-31 01:19:44 +00: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 20:31:12 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_notificationTimeout() {
|
2019-02-01 13:41:55 +00:00
|
|
|
|
let [x, y] = global.get_pointer();
|
2015-02-19 10:08:39 +00:00
|
|
|
|
if (y < this._lastSeenMouseY - 10 && !this._notificationHovered) {
|
2010-04-29 19:06:51 +00: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.)
|
2012-09-03 16:29:39 +00:00
|
|
|
|
this._updateNotificationTimeout(1000);
|
2013-03-13 20:14:53 +00:00
|
|
|
|
} else if (this._useLongerNotificationLeftTimeout && !this._notificationLeftTimeoutId &&
|
2012-09-03 16:29:39 +00:00
|
|
|
|
(x != this._lastSeenMouseX || y != this._lastSeenMouseY)) {
|
|
|
|
|
// Refresh the timeout if the notification originally
|
|
|
|
|
// popped up under the pointer, and the pointer is hovering
|
|
|
|
|
// inside it.
|
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 19:47:12 +00:00
|
|
|
|
this._updateNotificationTimeout(1000);
|
2010-04-29 19:06:51 +00:00
|
|
|
|
} else {
|
|
|
|
|
this._notificationTimeoutId = 0;
|
|
|
|
|
this._updateState();
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-03 16:29:39 +00:00
|
|
|
|
this._lastSeenMouseX = x;
|
|
|
|
|
this._lastSeenMouseY = y;
|
2013-11-29 00:45:39 +00:00
|
|
|
|
return GLib.SOURCE_REMOVE;
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_hideNotification(animate) {
|
2013-05-23 21:11:40 +00:00
|
|
|
|
this._notificationFocusGrabber.ungrabFocus();
|
2012-02-28 20:04:00 +00:00
|
|
|
|
|
2015-02-17 02:13:56 +00:00
|
|
|
|
if (this._bannerClickedId) {
|
|
|
|
|
this._banner.disconnect(this._bannerClickedId);
|
|
|
|
|
this._bannerClickedId = 0;
|
2013-01-28 11:09:17 +00:00
|
|
|
|
}
|
2015-02-17 02:13:56 +00:00
|
|
|
|
if (this._bannerUnfocusedId) {
|
|
|
|
|
this._banner.disconnect(this._bannerUnfocusedId);
|
|
|
|
|
this._bannerUnfocusedId = 0;
|
2013-01-28 11:09:17 +00:00
|
|
|
|
}
|
2010-02-22 19:23:36 +00:00
|
|
|
|
|
2014-05-28 19:18:00 +00:00
|
|
|
|
this._resetNotificationLeftTimeout();
|
2018-07-20 19:46:19 +00:00
|
|
|
|
this._bannerBin.remove_all_transitions();
|
2013-03-06 08:30:17 +00:00
|
|
|
|
|
2013-08-02 02:53:21 +00:00
|
|
|
|
if (animate) {
|
2018-07-20 19:46:19 +00:00
|
|
|
|
this._notificationState = State.HIDING;
|
2018-07-20 19:46:19 +00:00
|
|
|
|
this._bannerBin.ease({
|
2018-07-20 19:46:19 +00:00
|
|
|
|
opacity: 0,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
duration: ANIMATION_TIME,
|
2019-08-20 21:43:54 +00:00
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_BACK,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
});
|
2018-07-20 19:46:19 +00:00
|
|
|
|
this._bannerBin.ease({
|
2018-07-20 19:46:19 +00:00
|
|
|
|
y: -this._bannerBin.height,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
duration: ANIMATION_TIME,
|
|
|
|
|
mode: Clutter.AnimationMode.EASE_OUT_BACK,
|
2018-07-20 19:46:19 +00:00
|
|
|
|
onComplete: () => {
|
|
|
|
|
this._notificationState = State.HIDDEN;
|
|
|
|
|
this._hideNotificationCompleted();
|
|
|
|
|
this._updateState();
|
2019-08-20 21:43:54 +00:00
|
|
|
|
},
|
2018-07-20 19:46:19 +00:00
|
|
|
|
});
|
2013-08-02 02:53:21 +00:00
|
|
|
|
} else {
|
2015-02-25 16:43:54 +00:00
|
|
|
|
this._bannerBin.y = -this._bannerBin.height;
|
|
|
|
|
this._bannerBin.opacity = 0;
|
2013-08-02 02:53:21 +00:00
|
|
|
|
this._notificationState = State.HIDDEN;
|
|
|
|
|
this._hideNotificationCompleted();
|
2012-08-19 22:21:50 +00:00
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-01-13 20:05:20 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_hideNotificationCompleted() {
|
2010-12-15 21:30:50 +00: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 20:31:12 +00:00
|
|
|
|
this._notification = null;
|
2019-05-14 01:58:58 +00:00
|
|
|
|
if (!this._notificationRemoved && notification.isTransient)
|
2011-01-27 23:26:53 +00:00
|
|
|
|
notification.destroy(NotificationDestroyedReason.EXPIRED);
|
2012-12-22 15:02:19 +00:00
|
|
|
|
|
2013-03-13 20:14:53 +00:00
|
|
|
|
this._pointerInNotification = false;
|
|
|
|
|
this._notificationRemoved = false;
|
2018-11-22 17:18:34 +00:00
|
|
|
|
Meta.enable_unredirect_for_display(global.display);
|
2015-02-17 02:13:56 +00:00
|
|
|
|
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this._banner.destroy();
|
2015-02-17 02:13:56 +00:00
|
|
|
|
this._banner = null;
|
2019-07-16 09:24:13 +00:00
|
|
|
|
this.hide();
|
2017-10-31 01:19:44 +00: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 20:31:12 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_expandActiveNotification() {
|
2015-02-17 02:13:56 +00:00
|
|
|
|
if (!this._banner)
|
2012-11-08 14:24:40 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-02-17 02:13:56 +00:00
|
|
|
|
this._expandBanner(false);
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2012-11-08 14:24:40 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_expandBanner(autoExpanding) {
|
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 19:47:12 +00:00
|
|
|
|
// Don't animate changes in notifications that are auto-expanding.
|
2015-02-17 02:13:56 +00:00
|
|
|
|
this._banner.expand(!autoExpanding);
|
2013-06-21 19:24:50 +00:00
|
|
|
|
|
|
|
|
|
// Don't focus notifications that are auto-expanding.
|
|
|
|
|
if (!autoExpanding)
|
2015-02-17 02:13:56 +00:00
|
|
|
|
this._ensureBannerFocused();
|
2017-10-31 01:19:44 +00: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 19:47:12 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
_ensureBannerFocused() {
|
2013-05-23 21:11:40 +00:00
|
|
|
|
this._notificationFocusGrabber.grabFocus();
|
2010-01-28 18:39:00 +00:00
|
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
|
});
|
2010-11-30 15:47:28 +00:00
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
|
var SystemNotificationSource = GObject.registerClass(
|
|
|
|
|
class SystemNotificationSource extends Source {
|
|
|
|
|
_init() {
|
|
|
|
|
super._init(_("System Information"), 'dialog-information-symbolic');
|
2017-10-31 01:19:44 +00:00
|
|
|
|
}
|
2010-11-30 15:47:28 +00:00
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
|
open() {
|
2010-11-30 15:47:28 +00:00
|
|
|
|
this.destroy();
|
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
|
});
|