From 4dc5bac72fe20ad8ea786b18485aff272921a02a Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Sun, 4 Nov 2012 01:53:43 +0100 Subject: [PATCH] NotificationDaemon: improve associating sources with applications Try harder to find a ShellApp for a notification source, by looking at the PID, tray icon wm_class and desktop-entry libnotify hint. https://bugzilla.gnome.org/show_bug.cgi?id=685926 --- js/ui/notificationDaemon.js | 42 +++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index fa1d7157b..e353d8d15 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -213,7 +213,7 @@ const NotificationDaemon = new Lang.Class({ } } - let source = new Source(title, pid, sender, trayIcon); + let source = new Source(title, pid, sender, trayIcon, ndata ? ndata.hints['desktop-entry'] : null); source.setTransient(isForTransientNotification); if (!isForTransientNotification) { @@ -515,12 +515,22 @@ const Source = new Lang.Class({ Name: 'NotificationDaemonSource', Extends: MessageTray.Source, - _init: function(title, pid, sender, trayIcon) { + _init: function(title, pid, sender, trayIcon, appId) { + // Need to set the app before chaining up, so + // methods called from the parent constructor can find it + this.trayIcon = trayIcon; + this.pid = pid; + this.app = this._getApp(appId); + this.parent(title); this.initialTitle = title; - this.pid = pid; + if (this.app) + this.title = this.app.get_name(); + else + this.useNotificationIcon = true; + if (sender) this._nameWatcherId = Gio.DBus.session.watch_name(sender, Gio.BusNameWatcherFlags.NONE, @@ -529,16 +539,10 @@ const Source = new Lang.Class({ else this._nameWatcherId = 0; - this._setApp(); - if (this.app) - this.title = this.app.get_name(); - else - this.useNotificationIcon = true; - - this.trayIcon = trayIcon; if (this.trayIcon) { - this._setSummaryIcon(this.trayIcon); - this.useNotificationIcon = false; + // Try again finding the app, using the WM_CLASS from the tray icon + this._setSummaryIcon(this.trayIcon); + this.useNotificationIcon = false; } }, @@ -588,7 +592,7 @@ const Source = new Lang.Class({ return true; }, - _getApp: function() { + _getApp: function(appId) { let app; app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid); @@ -596,7 +600,13 @@ const Source = new Lang.Class({ return app; if (this.trayIcon) { - app = Shell.AppSystem.get_default().lookup_wmclass(this.trayIcon.wmclass); + app = Shell.AppSystem.get_default().lookup_wmclass(this.trayIcon.wm_class); + if (app != null) + return app; + } + + if (appId) { + app = Shell.AppSystem.get_default().lookup_app(appId + '.desktop'); if (app != null) return app; } @@ -604,11 +614,11 @@ const Source = new Lang.Class({ return null; }, - _setApp: function() { + _setApp: function(appId) { if (this.app) return; - this.app = this._getApp(); + this.app = this._getApp(appId); if (!this.app) return;