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 WindowAttentionHandler */
|
2010-02-22 18:53:41 +00:00
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
const { GObject, Shell } = imports.gi;
|
2010-02-22 18:53:41 +00:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
|
2017-10-31 01:19:44 +00:00
|
|
|
var WindowAttentionHandler = class {
|
|
|
|
constructor() {
|
2011-03-03 17:10:32 +00:00
|
|
|
this._tracker = Shell.WindowTracker.get_default();
|
2015-07-01 17:02:36 +00:00
|
|
|
this._windowDemandsAttentionId = global.display.connect('window-demands-attention',
|
2017-12-02 00:27:35 +00:00
|
|
|
this._onWindowDemandsAttention.bind(this));
|
2018-07-13 17:16:14 +00:00
|
|
|
this._windowMarkedUrgentId = global.display.connect('window-marked-urgent',
|
2019-01-29 19:36:54 +00:00
|
|
|
this._onWindowDemandsAttention.bind(this));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-02-22 18:53:41 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_getTitleAndBanner(app, window) {
|
2012-02-28 22:12:20 +00:00
|
|
|
let title = app.get_name();
|
2014-01-17 21:30:49 +00:00
|
|
|
let banner = _("“%s” is ready").format(window.get_title());
|
2019-01-29 01:18:52 +00:00
|
|
|
return [title, banner];
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2012-02-28 22:12:20 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_onWindowDemandsAttention(display, window) {
|
2010-02-22 18:53:41 +00:00
|
|
|
// We don't want to show the notification when the window is already focused,
|
|
|
|
// because this is rather pointless.
|
|
|
|
// Some apps (like GIMP) do things like setting the urgency hint on the
|
|
|
|
// toolbar windows which would result into a notification even though GIMP itself is
|
|
|
|
// focused.
|
|
|
|
// We are just ignoring the hint on skip_taskbar windows for now.
|
|
|
|
// (Which is the same behaviour as with metacity + panel)
|
|
|
|
|
|
|
|
if (!window || window.has_focus() || window.is_skip_taskbar())
|
|
|
|
return;
|
|
|
|
|
2011-03-03 17:10:32 +00:00
|
|
|
let app = this._tracker.get_window_app(window);
|
2019-05-13 21:32:31 +00:00
|
|
|
let source = new WindowAttentionSource(app, window);
|
2011-03-03 17:10:32 +00:00
|
|
|
Main.messageTray.add(source);
|
2010-02-22 18:53:41 +00:00
|
|
|
|
2012-02-28 22:12:20 +00:00
|
|
|
let [title, banner] = this._getTitleAndBanner(app, window);
|
2011-09-28 01:03:53 +00:00
|
|
|
|
|
|
|
let notification = new MessageTray.Notification(source, title, banner);
|
2017-10-31 00:38:18 +00:00
|
|
|
notification.connect('activated', () => {
|
2013-10-14 03:20:50 +00:00
|
|
|
source.open();
|
|
|
|
});
|
2012-11-02 17:06:40 +00:00
|
|
|
notification.setForFeedback(true);
|
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
source.showNotification(notification);
|
2010-02-22 18:53:41 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
source.signalIDs.push(window.connect('notify::title', () => {
|
2019-08-20 00:20:08 +00:00
|
|
|
[title, banner] = this._getTitleAndBanner(app, window);
|
2012-02-28 22:12:20 +00:00
|
|
|
notification.update(title, banner);
|
2017-10-31 00:38:18 +00:00
|
|
|
}));
|
2010-02-22 18:53:41 +00:00
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
};
|
2010-02-22 18:53:41 +00:00
|
|
|
|
2019-05-13 21:32:31 +00:00
|
|
|
var WindowAttentionSource = GObject.registerClass(
|
|
|
|
class WindowAttentionSource extends MessageTray.Source {
|
|
|
|
_init(app, window) {
|
|
|
|
super._init(app.get_name());
|
2010-02-22 18:53:41 +00:00
|
|
|
|
|
|
|
this._window = window;
|
|
|
|
this._app = app;
|
2011-10-08 22:00:32 +00:00
|
|
|
|
2011-03-03 17:10:32 +00:00
|
|
|
this.signalIDs = [];
|
2017-10-31 00:38:18 +00:00
|
|
|
this.signalIDs.push(this._window.connect('notify::demands-attention',
|
2018-11-14 18:38:33 +00:00
|
|
|
this._sync.bind(this)));
|
2018-07-13 17:16:14 +00:00
|
|
|
this.signalIDs.push(this._window.connect('notify::urgent',
|
2018-11-14 18:38:33 +00:00
|
|
|
this._sync.bind(this)));
|
2017-10-31 00:38:18 +00:00
|
|
|
this.signalIDs.push(this._window.connect('focus',
|
2019-01-28 00:42:00 +00:00
|
|
|
() => this.destroy()));
|
2017-10-31 00:38:18 +00:00
|
|
|
this.signalIDs.push(this._window.connect('unmanaged',
|
2019-01-28 00:42:00 +00:00
|
|
|
() => this.destroy()));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-03-03 17:10:32 +00:00
|
|
|
|
2018-07-13 17:16:14 +00:00
|
|
|
_sync() {
|
|
|
|
if (this._window.demands_attention || this._window.urgent)
|
|
|
|
return;
|
|
|
|
this.destroy();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2018-07-13 17:16:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createPolicy() {
|
2017-10-23 08:06:18 +00:00
|
|
|
if (this._app && this._app.get_app_info()) {
|
2019-01-29 01:27:05 +00:00
|
|
|
let id = this._app.get_id().replace(/\.desktop$/, '');
|
2017-10-23 08:06:18 +00:00
|
|
|
return new MessageTray.NotificationApplicationPolicy(id);
|
|
|
|
} else {
|
|
|
|
return new MessageTray.NotificationGenericPolicy();
|
|
|
|
}
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-10-23 08:06:18 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
createIcon(size) {
|
2012-07-19 13:05:17 +00:00
|
|
|
return this._app.create_icon_texture(size);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2010-02-22 18:53:41 +00:00
|
|
|
|
2019-05-26 15:31:07 +00:00
|
|
|
destroy(params) {
|
|
|
|
for (let i = 0; i < this.signalIDs.length; i++)
|
|
|
|
this._window.disconnect(this.signalIDs[i]);
|
|
|
|
this.signalIDs = [];
|
|
|
|
|
|
|
|
super.destroy(params);
|
|
|
|
}
|
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
open() {
|
2010-02-22 18:53:41 +00:00
|
|
|
Main.activateWindow(this._window);
|
|
|
|
}
|
2019-05-13 21:32:31 +00:00
|
|
|
});
|