Switch to the corresponding app when the notification icon is clicked
This adds some meaningful functionality to the notification icons in the tray and in the notification pop-up and allows to switch to the application that sent the notification. We get the application from the notification context and set it on the source for the notification.
This commit is contained in:
parent
a6df234528
commit
60046aaa4f
@ -85,12 +85,18 @@ Notification.prototype = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let icon = this.source.createIcon(ICON_SIZE);
|
let icon = this.source.createIcon(ICON_SIZE);
|
||||||
|
icon.reactive = true;
|
||||||
this.actor.add(icon, { row: 0,
|
this.actor.add(icon, { row: 0,
|
||||||
col: 0,
|
col: 0,
|
||||||
x_expand: false,
|
x_expand: false,
|
||||||
y_expand: false,
|
y_expand: false,
|
||||||
y_fill: false });
|
y_fill: false });
|
||||||
|
|
||||||
|
icon.connect('button-release-event', Lang.bind(this,
|
||||||
|
function () {
|
||||||
|
this.source.clicked();
|
||||||
|
}));
|
||||||
|
|
||||||
// The first line should have the title, followed by the
|
// The first line should have the title, followed by the
|
||||||
// banner text, but ellipsized if they won't both fit. We can't
|
// banner text, but ellipsized if they won't both fit. We can't
|
||||||
// make St.Table or St.BoxLayout do this the way we want (don't
|
// make St.Table or St.BoxLayout do this the way we want (don't
|
||||||
|
@ -12,6 +12,26 @@ const Params = imports.misc.params;
|
|||||||
|
|
||||||
let nextNotificationId = 1;
|
let nextNotificationId = 1;
|
||||||
|
|
||||||
|
// Should really be defined in dbus.js
|
||||||
|
const BusIface = {
|
||||||
|
name: 'org.freedesktop.DBus',
|
||||||
|
methods: [{ name: 'GetConnectionUnixProcessID',
|
||||||
|
inSignature: 's',
|
||||||
|
outSignature: 'i' }]
|
||||||
|
}
|
||||||
|
|
||||||
|
const Bus = function () {
|
||||||
|
this._init();
|
||||||
|
}
|
||||||
|
|
||||||
|
Bus.prototype = {
|
||||||
|
_init: function() {
|
||||||
|
DBus.session.proxifyObject(this, 'org.freedesktop.DBus', '/org/freedesktop/DBus');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DBus.proxifyPrototype(Bus.prototype, BusIface);
|
||||||
|
|
||||||
const NotificationDaemonIface = {
|
const NotificationDaemonIface = {
|
||||||
name: 'org.freedesktop.Notifications',
|
name: 'org.freedesktop.Notifications',
|
||||||
methods: [{ name: 'Notify',
|
methods: [{ name: 'Notify',
|
||||||
@ -119,6 +139,13 @@ NotificationDaemon.prototype = {
|
|||||||
source.destroy();
|
source.destroy();
|
||||||
this._emitNotificationClosed(id, NotificationClosedReason.DISMISSED);
|
this._emitNotificationClosed(id, NotificationClosedReason.DISMISSED);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
let sender = DBus.getCurrentMessageContext().sender;
|
||||||
|
let busProxy = new Bus();
|
||||||
|
busProxy.GetConnectionUnixProcessIDRemote(sender, function (result, excp) {
|
||||||
|
let app = Shell.WindowTracker.get_default().get_app_from_pid(result);
|
||||||
|
source.setApp(app);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
summary = GLib.markup_escape_text(summary, -1);
|
summary = GLib.markup_escape_text(summary, -1);
|
||||||
@ -200,6 +227,9 @@ Source.prototype = {
|
|||||||
this._icon = icon;
|
this._icon = icon;
|
||||||
this._iconData = hints.icon_data;
|
this._iconData = hints.icon_data;
|
||||||
this._urgency = hints.urgency;
|
this._urgency = hints.urgency;
|
||||||
|
|
||||||
|
this.app = null;
|
||||||
|
this._openAppRequested = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
createIcon: function(size) {
|
createIcon: function(size) {
|
||||||
@ -231,5 +261,29 @@ Source.prototype = {
|
|||||||
}
|
}
|
||||||
return textureCache.load_icon_name(stockIcon, size);
|
return textureCache.load_icon_name(stockIcon, size);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
clicked: function() {
|
||||||
|
this.openApp();
|
||||||
|
MessageTray.Source.prototype.clicked.call(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
setApp: function(app) {
|
||||||
|
this.app = app;
|
||||||
|
if (this._openAppRequested)
|
||||||
|
this.openApp();
|
||||||
|
},
|
||||||
|
|
||||||
|
openApp: function() {
|
||||||
|
if (this.app == null) {
|
||||||
|
this._openAppRequested = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let windows = this.app.get_windows();
|
||||||
|
if (windows.length > 0) {
|
||||||
|
let mostRecentWindow = windows[0];
|
||||||
|
Main.activateWindow(mostRecentWindow);
|
||||||
|
}
|
||||||
|
this._openAppRequested = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user