revert-notificationdaemon-group-based-on-pid-and-titles.patch 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. From 7e654ab3ca6e8ac75ba5e45c2a411eb1c2904b26 Mon Sep 17 00:00:00 2001
  2. From: Marina Zhurakhinskaya <marinaz@redhat.com>
  3. Date: Tue, 20 Dec 2011 05:51:35 +0000
  4. Subject: notificationDaemon: group sources based on a combination of pid and title
  5. That way different system notifications, such as the ones about battery power
  6. and the ones about software updates, are shown with separate message tray
  7. sources.
  8. https://bugzilla.gnome.org/show_bug.cgi?id=664138
  9. ---
  10. diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
  11. index f40205d..c691efe 100644
  12. --- a/js/ui/notificationDaemon.js
  13. +++ b/js/ui/notificationDaemon.js
  14. @@ -92,7 +92,7 @@ NotificationDaemon.prototype = {
  15. _init: function() {
  16. DBus.session.exportObject('/org/freedesktop/Notifications', this);
  17. - this._sources = {};
  18. + this._sources = [];
  19. this._senderToPid = {};
  20. this._notifications = {};
  21. this._busProxy = new Bus();
  22. @@ -150,14 +150,30 @@ NotificationDaemon.prototype = {
  23. }
  24. },
  25. + _lookupSource: function(title, pid, trayIcon) {
  26. + for (let i = 0; i < this._sources.length; i++) {
  27. + let source = this._sources[i];
  28. + if (source.pid == pid &&
  29. + (source.initialTitle == title || source.trayIcon || trayIcon))
  30. + return source;
  31. + }
  32. + return null;
  33. + },
  34. +
  35. // Returns the source associated with ndata.notification if it is set.
  36. - // Otherwise, returns the source associated with the pid if one is
  37. - // stored in this._sources and the notification is not transient.
  38. - // Otherwise, creates a new source as long as pid is provided.
  39. + // Otherwise, returns the source associated with the title and pid if
  40. + // such source is stored in this._sources and the notification is not
  41. + // transient. If the existing or requested source is associated with
  42. + // a tray icon and passed in pid matches a pid of an existing source,
  43. + // the title match is ignored to enable representing a tray icon and
  44. + // notifications from the same application with a single source.
  45. + //
  46. + // If no existing source is found, a new source is created as long as
  47. + // pid is provided.
  48. //
  49. // Either a pid or ndata.notification is needed to retrieve or
  50. // create a source.
  51. - _getSource: function(title, pid, ndata, sender) {
  52. + _getSource: function(title, pid, ndata, sender, trayIcon) {
  53. if (!pid && !(ndata && ndata.notification))
  54. return null;
  55. @@ -174,20 +190,24 @@ NotificationDaemon.prototype = {
  56. // with a transient one from the same sender, so we
  57. // always create a new source object for new transient notifications
  58. // and never add it to this._sources .
  59. - if (!isForTransientNotification && this._sources[pid]) {
  60. - let source = this._sources[pid];
  61. - source.setTitle(title);
  62. - return source;
  63. + if (!isForTransientNotification) {
  64. + let source = this._lookupSource(title, pid, trayIcon);
  65. + if (source) {
  66. + source.setTitle(title);
  67. + return source;
  68. + }
  69. }
  70. - let source = new Source(title, pid, sender);
  71. + let source = new Source(title, pid, sender, trayIcon);
  72. source.setTransient(isForTransientNotification);
  73. if (!isForTransientNotification) {
  74. - this._sources[pid] = source;
  75. + this._sources.push(source);
  76. source.connect('destroy', Lang.bind(this,
  77. function() {
  78. - delete this._sources[pid];
  79. + let index = this._sources.indexOf(source);
  80. + if (index >= 0)
  81. + this._sources.splice(index, 1);
  82. }));
  83. }
  84. @@ -261,7 +281,7 @@ NotificationDaemon.prototype = {
  85. let sender = DBus.getCurrentMessageContext().sender;
  86. let pid = this._senderToPid[sender];
  87. - let source = this._getSource(appName, pid, ndata, sender);
  88. + let source = this._getSource(appName, pid, ndata, sender, null);
  89. if (source) {
  90. this._notifyForSource(source, ndata);
  91. @@ -282,7 +302,7 @@ NotificationDaemon.prototype = {
  92. if (!ndata)
  93. return;
  94. - source = this._getSource(appName, pid, ndata, sender);
  95. + source = this._getSource(appName, pid, ndata, sender, null);
  96. // We only store sender-pid entries for persistent sources.
  97. // Removing the entries once the source is destroyed
  98. @@ -432,8 +452,8 @@ NotificationDaemon.prototype = {
  99. if (!tracker.focus_app)
  100. return;
  101. - for (let id in this._sources) {
  102. - let source = this._sources[id];
  103. + for (let i = 0; i < this._sources.length; i++) {
  104. + let source = this._sources[i];
  105. if (source.app == tracker.focus_app) {
  106. source.destroyNonResidentNotifications();
  107. return;
  108. @@ -456,12 +476,11 @@ NotificationDaemon.prototype = {
  109. },
  110. _onTrayIconAdded: function(o, icon) {
  111. - let source = this._getSource(icon.title || icon.wm_class || _("Unknown"), icon.pid, null, null);
  112. - source.setTrayIcon(icon);
  113. + let source = this._getSource(icon.title || icon.wm_class || _("Unknown"), icon.pid, null, null, icon);
  114. },
  115. _onTrayIconRemoved: function(o, icon) {
  116. - let source = this._sources[icon.pid];
  117. + let source = this._lookupSource(icon.pid, null, true);
  118. if (source)
  119. source.destroy();
  120. }
  121. @@ -476,10 +495,12 @@ function Source(title, pid, sender) {
  122. Source.prototype = {
  123. __proto__: MessageTray.Source.prototype,
  124. - _init: function(title, pid, sender) {
  125. + _init: function(title, pid, sender, trayIcon) {
  126. MessageTray.Source.prototype._init.call(this, title);
  127. - this._pid = pid;
  128. + this.initialTitle = title;
  129. +
  130. + this.pid = pid;
  131. if (sender)
  132. // TODO: dbus-glib implementation of watch_name() doesn’t return an id to be used for
  133. // unwatch_name() or implement unwatch_name(), however when we move to using GDBus implementation,
  134. @@ -496,7 +517,12 @@ Source.prototype = {
  135. this.title = this.app.get_name();
  136. else
  137. this.useNotificationIcon = true;
  138. - this._trayIcon = null;
  139. +
  140. + this.trayIcon = trayIcon;
  141. + if (this.trayIcon) {
  142. + this._setSummaryIcon(this.trayIcon);
  143. + this.useNotificationIcon = false;
  144. + }
  145. },
  146. _onNameVanished: function() {
  147. @@ -523,7 +549,7 @@ Source.prototype = {
  148. },
  149. handleSummaryClick: function() {
  150. - if (!this._trayIcon)
  151. + if (!this.trayIcon)
  152. return false;
  153. let event = Clutter.get_current_event();
  154. @@ -544,11 +570,11 @@ Source.prototype = {
  155. let id = global.connect('notify::stage-input-mode', Lang.bind(this,
  156. function () {
  157. global.disconnect(id);
  158. - this._trayIcon.click(event);
  159. + this.trayIcon.click(event);
  160. }));
  161. Main.overview.hide();
  162. } else {
  163. - this._trayIcon.click(event);
  164. + this.trayIcon.click(event);
  165. }
  166. return true;
  167. },
  168. @@ -557,31 +583,25 @@ Source.prototype = {
  169. if (this.app)
  170. return;
  171. - this.app = Shell.WindowTracker.get_default().get_app_from_pid(this._pid);
  172. + this.app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid);
  173. if (!this.app)
  174. return;
  175. // Only override the icon if we were previously using
  176. // notification-based icons (ie, not a trayicon) or if it was unset before
  177. - if (!this._trayIcon) {
  178. + if (!this.trayIcon) {
  179. this.useNotificationIcon = false;
  180. this._setSummaryIcon(this.app.create_icon_texture (this.ICON_SIZE));
  181. }
  182. },
  183. - setTrayIcon: function(icon) {
  184. - this._setSummaryIcon(icon);
  185. - this.useNotificationIcon = false;
  186. - this._trayIcon = icon;
  187. - },
  188. -
  189. open: function(notification) {
  190. this.destroyNonResidentNotifications();
  191. this.openApp();
  192. },
  193. _lastNotificationRemoved: function() {
  194. - if (!this._trayIcon)
  195. + if (!this.trayIcon)
  196. this.destroy();
  197. },
  198. --
  199. cgit v0.9.0.2