2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2010-02-22 13:53:41 -05:00
|
|
|
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const MessageTray = imports.ui.messageTray;
|
|
|
|
|
2011-11-20 12:56:27 -05:00
|
|
|
const WindowAttentionHandler = new Lang.Class({
|
|
|
|
Name: 'WindowAttentionHandler',
|
2010-02-22 13:53:41 -05:00
|
|
|
|
|
|
|
_init : function() {
|
2011-03-03 12:10:32 -05:00
|
|
|
this._tracker = Shell.WindowTracker.get_default();
|
2011-07-13 12:34:31 -04:00
|
|
|
global.display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention));
|
2010-02-22 13:53:41 -05:00
|
|
|
},
|
|
|
|
|
2012-02-28 17:12:20 -05:00
|
|
|
_getTitleAndBanner: function(app, window) {
|
|
|
|
let title = app.get_name();
|
2014-01-17 16:30:49 -05:00
|
|
|
let banner = _("“%s” is ready").format(window.get_title());
|
2012-02-28 17:12:20 -05:00
|
|
|
return [title, banner]
|
|
|
|
},
|
|
|
|
|
2010-02-22 13:53:41 -05:00
|
|
|
_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;
|
|
|
|
|
2011-03-03 12:10:32 -05:00
|
|
|
let app = this._tracker.get_window_app(window);
|
|
|
|
let source = new Source(app, window);
|
|
|
|
Main.messageTray.add(source);
|
2010-02-22 13:53:41 -05:00
|
|
|
|
2012-02-28 17:12:20 -05:00
|
|
|
let [title, banner] = this._getTitleAndBanner(app, window);
|
2011-09-27 21:03:53 -04:00
|
|
|
|
|
|
|
let notification = new MessageTray.Notification(source, title, banner);
|
2013-10-13 23:20:50 -04:00
|
|
|
notification.connect('clicked', function() {
|
|
|
|
source.open();
|
|
|
|
});
|
2012-11-02 13:06:40 -04:00
|
|
|
notification.setForFeedback(true);
|
|
|
|
|
2010-02-22 13:53:41 -05:00
|
|
|
source.notify(notification);
|
|
|
|
|
2012-02-28 17:12:20 -05:00
|
|
|
source.signalIDs.push(window.connect('notify::title', Lang.bind(this, function() {
|
|
|
|
let [title, banner] = this._getTitleAndBanner(app, window);
|
|
|
|
notification.update(title, banner);
|
|
|
|
})));
|
2010-02-22 13:53:41 -05:00
|
|
|
}
|
2011-11-20 12:56:27 -05:00
|
|
|
});
|
2010-02-22 13:53:41 -05:00
|
|
|
|
2011-11-20 10:12:02 -05:00
|
|
|
const Source = new Lang.Class({
|
|
|
|
Name: 'WindowAttentionSource',
|
|
|
|
Extends: MessageTray.Source,
|
2010-02-22 13:53:41 -05:00
|
|
|
|
2010-08-09 13:18:15 -04:00
|
|
|
_init: function(app, window) {
|
2010-02-22 13:53:41 -05:00
|
|
|
this._window = window;
|
|
|
|
this._app = app;
|
2011-10-08 18:00:32 -04:00
|
|
|
|
|
|
|
this.parent(app.get_name());
|
2011-03-03 12:10:32 -05:00
|
|
|
|
|
|
|
this.signalIDs = [];
|
|
|
|
this.signalIDs.push(this._window.connect('notify::demands-attention', Lang.bind(this, function() { this.destroy(); })));
|
|
|
|
this.signalIDs.push(this._window.connect('focus', Lang.bind(this, function() { this.destroy(); })));
|
|
|
|
this.signalIDs.push(this._window.connect('unmanaged', Lang.bind(this, function() { this.destroy(); })));
|
|
|
|
|
|
|
|
this.connect('destroy', Lang.bind(this, this._onDestroy));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onDestroy : function() {
|
|
|
|
for(let i = 0; i < this.signalIDs.length; i++) {
|
|
|
|
this._window.disconnect(this.signalIDs[i]);
|
|
|
|
}
|
|
|
|
this.signalIDs = [];
|
2010-02-22 13:53:41 -05:00
|
|
|
},
|
|
|
|
|
2012-07-19 09:05:17 -04:00
|
|
|
createIcon : function(size) {
|
|
|
|
return this._app.create_icon_texture(size);
|
2010-02-22 13:53:41 -05:00
|
|
|
},
|
|
|
|
|
2013-10-13 23:20:50 -04:00
|
|
|
open: function() {
|
2010-02-22 13:53:41 -05:00
|
|
|
Main.activateWindow(this._window);
|
MessageTray: untangle click notifications
Previously, when you clicked on a notification, it would call
this.source.clicked(), which would emit a 'clicked' signal on the
source, and then various other stuff would happen from there. This
used to make a little bit of sense, when clicking on a notification
was supposed to do the same thing as clicking on its source, but makes
less sense now, when clicking on the source itself *doesn't* call
source.clicked()...
Change it so that when you click on a notification, the notification
emits 'clicked' itself, and the source notices that and calls its
notificationClicked() method, and the various source subclasses do
what they need to do with that, and Source no longer has a clicked
method/signal.
https://bugzilla.gnome.org/show_bug.cgi?id=631042
2010-09-30 16:41:38 -04:00
|
|
|
this.destroy();
|
2010-02-22 13:53:41 -05:00
|
|
|
}
|
2011-11-20 10:12:02 -05:00
|
|
|
});
|