2010-02-22 13:53:41 -05:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
const Gettext = imports.gettext.domain('gnome-shell');
|
|
|
|
const _ = Gettext.gettext;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
|
|
|
|
function WindowAttentionHandler() {
|
|
|
|
this._init();
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowAttentionHandler.prototype = {
|
|
|
|
_init : function() {
|
2010-08-09 13:18:15 -04:00
|
|
|
this._startupIds = {};
|
|
|
|
this._sources = {};
|
|
|
|
|
2010-02-22 13:53:41 -05:00
|
|
|
let display = global.screen.get_display();
|
|
|
|
display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention));
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
tracker.connect('startup-sequence-changed', Lang.bind(this, this._onStartupSequenceChanged));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onStartupSequenceChanged : function(tracker) {
|
|
|
|
let sequences = tracker.get_startup_sequences();
|
|
|
|
this._startupIds = {};
|
|
|
|
for(let i = 0; i < sequences.length; i++) {
|
|
|
|
this._startupIds[sequences[i].get_id()] = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_getTitle : function(app, window) {
|
|
|
|
if (this._startupIds[window.get_startup_id()])
|
|
|
|
return app.get_name();
|
|
|
|
else
|
|
|
|
return window.title;
|
|
|
|
},
|
|
|
|
|
|
|
|
_getBanner : function(app, window) {
|
|
|
|
if (this._startupIds[window.get_startup_id()])
|
|
|
|
return _("%s has finished starting").format(app.get_name());
|
|
|
|
else
|
|
|
|
return _("'%s' is ready").format(window.title);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onWindowDemandsAttention : function(display, window) {
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
let tracker = Shell.WindowTracker.get_default();
|
|
|
|
let app = tracker.get_window_app(window);
|
2010-08-09 13:18:15 -04:00
|
|
|
let appId = app.get_id();
|
2010-02-22 13:53:41 -05:00
|
|
|
|
2010-08-09 13:18:15 -04:00
|
|
|
let source = this._sources[appId];
|
2010-02-22 13:53:41 -05:00
|
|
|
if (source == null) {
|
2010-08-09 13:18:15 -04:00
|
|
|
source = new Source(app, window);
|
|
|
|
this._sources[appId] = source;
|
2010-02-22 13:53:41 -05:00
|
|
|
Main.messageTray.add(source);
|
|
|
|
source.connect('clicked', Lang.bind(this, function() { source.destroy(); }));
|
2010-08-09 13:18:15 -04:00
|
|
|
source.connect('destroy', Lang.bind(this, function() { delete this._sources[appId]; }));
|
2010-02-22 13:53:41 -05:00
|
|
|
}
|
|
|
|
|
2010-08-30 16:03:08 -04:00
|
|
|
let notification = new MessageTray.Notification(source, this._getTitle(app, window), this._getBanner(app, window));
|
2010-02-22 13:53:41 -05:00
|
|
|
source.notify(notification);
|
|
|
|
|
|
|
|
window.connect('notify::title', Lang.bind(this, function(win) {
|
2010-08-18 16:01:33 -04:00
|
|
|
notification.update(this._getTitle(app, win), this._getBanner(app, win));
|
2010-02-22 13:53:41 -05:00
|
|
|
}));
|
2010-03-15 09:50:05 -04:00
|
|
|
window.connect('notify::demands-attention', Lang.bind(this, function() { source.destroy(); }));
|
|
|
|
window.connect('focus', Lang.bind(this, function() { source.destroy(); }));
|
|
|
|
window.connect('unmanaged', Lang.bind(this, function() { source.destroy(); }));
|
2010-02-22 13:53:41 -05:00
|
|
|
|
|
|
|
}
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|
2010-02-22 13:53:41 -05:00
|
|
|
|
2010-08-09 13:18:15 -04:00
|
|
|
function Source(app, window) {
|
|
|
|
this._init(app, window);
|
2010-02-22 13:53:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Source.prototype = {
|
|
|
|
__proto__ : MessageTray.Source.prototype,
|
|
|
|
|
2010-08-09 13:18:15 -04:00
|
|
|
_init: function(app, window) {
|
|
|
|
MessageTray.Source.prototype._init.call(this, app.get_name());
|
2010-02-22 13:53:41 -05:00
|
|
|
this._window = window;
|
|
|
|
this._app = app;
|
2010-08-05 13:09:27 -04:00
|
|
|
this._setSummaryIcon(this.createNotificationIcon());
|
2010-02-22 13:53:41 -05:00
|
|
|
},
|
|
|
|
|
2010-08-05 13:09:27 -04:00
|
|
|
createNotificationIcon : function() {
|
|
|
|
return this._app.create_icon_texture(this.ICON_SIZE);
|
2010-02-22 13:53:41 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
clicked : function() {
|
|
|
|
Main.activateWindow(this._window);
|
|
|
|
MessageTray.Source.prototype.clicked.call(this);
|
|
|
|
}
|
|
|
|
|
2010-03-15 09:50:05 -04:00
|
|
|
};
|