From 2e8881b77cf1f054fbefb164040b538e15b29225 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 8 Apr 2012 22:39:59 -0300 Subject: [PATCH] notificationDaemon: Match app based on WM_CLASS Most tray applets won't have an associated window in the same PID. We need to fall back to the WM_CLASS in this case. https://bugzilla.gnome.org/show_bug.cgi?id=673761 --- js/ui/notificationDaemon.js | 18 ++++++++++- src/shell-app-system.c | 36 +++++++++++++++++++++ src/shell-app-system.h | 3 +- src/shell-window-tracker.c | 64 +++---------------------------------- 4 files changed, 60 insertions(+), 61 deletions(-) diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js index f474fbefd..5a20e7c7b 100644 --- a/js/ui/notificationDaemon.js +++ b/js/ui/notificationDaemon.js @@ -578,11 +578,27 @@ const Source = new Lang.Class({ return true; }, + _getApp: function() { + let app; + + app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid); + if (app != null) + return app; + + if (this.trayIcon) { + app = Shell.AppSystem.get_default().lookup_wmclass(this.trayIcon.wmclass); + if (app != null) + return app; + } + + return null; + }, + _setApp: function() { if (this.app) return; - this.app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid); + this.app = this._getApp(); if (!this.app) return; diff --git a/src/shell-app-system.c b/src/shell-app-system.c index 2528e9f67..a7d144156 100644 --- a/src/shell-app-system.c +++ b/src/shell-app-system.c @@ -608,6 +608,42 @@ shell_app_system_lookup_heuristic_basename (ShellAppSystem *system, return NULL; } +/** + * shell_app_system_lookup_wmclass: + * @system: a #ShellAppSystem + * @wmclass: A WM_CLASS value + * + * Find a valid application corresponding to a WM_CLASS value. + * + * Returns: (transfer none): A #ShellApp for @wmclass + */ +ShellApp * +shell_app_system_lookup_wmclass (ShellAppSystem *system, + const char *wmclass) +{ + char *canonicalized; + char *desktop_file; + ShellApp *app; + + if (wmclass == NULL) + return NULL; + + canonicalized = g_ascii_strdown (wmclass, -1); + + /* This handles "Fedora Eclipse", probably others. + * Note g_strdelimit is modify-in-place. */ + g_strdelimit (canonicalized, " ", '-'); + + desktop_file = g_strconcat (canonicalized, ".desktop", NULL); + + app = shell_app_system_lookup_heuristic_basename (system, desktop_file); + + g_free (canonicalized); + g_free (desktop_file); + + return app; +} + /** * shell_app_system_get_all: * @system: diff --git a/src/shell-app-system.h b/src/shell-app-system.h index c26b72859..b76c6425f 100644 --- a/src/shell-app-system.h +++ b/src/shell-app-system.h @@ -49,7 +49,8 @@ ShellApp *shell_app_system_lookup_app_for_path (ShellAppSystem * const char *desktop_path); ShellApp *shell_app_system_lookup_heuristic_basename (ShellAppSystem *system, const char *id); - +ShellApp *shell_app_system_lookup_wmclass (ShellAppSystem *system, + const char *wmclass); GSList *shell_app_system_get_all (ShellAppSystem *system); diff --git a/src/shell-window-tracker.c b/src/shell-window-tracker.c index cc16fe083..2e2ca481e 100644 --- a/src/shell-window-tracker.c +++ b/src/shell-window-tracker.c @@ -126,30 +126,6 @@ shell_window_tracker_class_init (ShellWindowTrackerClass *klass) G_TYPE_NONE, 0); } -/** - * get_appid_from_window: - * - * Turn the WM_CLASS property into our best guess at a .desktop file id. - */ -static char * -get_appid_from_window (MetaWindow *window) -{ - const char *wmclass; - char *appid_guess; - - wmclass = meta_window_get_wm_class (window); - if (!wmclass) - return NULL; - - appid_guess = g_ascii_strdown (wmclass, -1); - - /* This handles "Fedora Eclipse", probably others. - * Note g_strdelimit is modify-in-place. */ - g_strdelimit (appid_guess, " ", '-'); - - return appid_guess; -} - /** * shell_window_tracker_is_window_interesting: * @@ -201,40 +177,6 @@ shell_window_tracker_is_window_interesting (MetaWindow *window) return TRUE; } -/** - * get_app_from_window_wmclass: - * - * Looks only at the given window, and attempts to determine - * an application based on WM_CLASS. If one can't be determined, - * return %NULL. - * - * Return value: (transfer full): A newly-referenced #ShellApp, or %NULL - */ -static ShellApp * -get_app_from_window_wmclass (MetaWindow *window) -{ - ShellApp *app; - ShellAppSystem *appsys; - char *wmclass; - char *with_desktop; - - appsys = shell_app_system_get_default (); - wmclass = get_appid_from_window (window); - - if (!wmclass) - return NULL; - - with_desktop = g_strjoin (NULL, wmclass, ".desktop", NULL); - g_free (wmclass); - - app = shell_app_system_lookup_heuristic_basename (appsys, with_desktop); - if (app != NULL) - g_object_ref (app); - g_free (with_desktop); - - return app; -} - /** * get_app_from_window_group: * @monitor: a #ShellWindowTracker @@ -328,9 +270,12 @@ static ShellApp * get_app_for_window (ShellWindowTracker *tracker, MetaWindow *window) { + ShellAppSystem *app_system; ShellApp *result = NULL; const char *startup_id; + app_system = shell_app_system_get_default (); + /* First, we check whether we already know about this window, * if so, just return that. */ @@ -351,7 +296,8 @@ get_app_for_window (ShellWindowTracker *tracker, /* Check if the app's WM_CLASS specifies an app; this is * canonical if it does. */ - result = get_app_from_window_wmclass (window); + result = shell_app_system_lookup_wmclass (app_system, + meta_window_get_wm_class (window)); if (result != NULL) return result;