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
This commit is contained in:
Jasper St. Pierre 2012-04-08 22:39:59 -03:00
parent 64aa729edd
commit 2e8881b77c
4 changed files with 60 additions and 61 deletions

View File

@ -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;

View File

@ -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:

View File

@ -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);

View File

@ -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;