Use StartupWMClass to associate window and applications
Some applications (such as most Java apps, as well as Chrome Web apps) ship with desktop files that have the wrong name, but whose StartupWMClass field contains the right value. Therefore first check that key, against both the class and instance part of WM_CLASS, and only use the filename if nothing else works. https://bugzilla.gnome.org/show_bug.cgi?id=673657
This commit is contained in:
@ -177,6 +177,82 @@ 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 *appid;
|
||||
const char *wm_class;
|
||||
const char *wm_instance;
|
||||
char *with_desktop;
|
||||
|
||||
appsys = shell_app_system_get_default ();
|
||||
|
||||
/* Notes on the heuristics used here:
|
||||
much of the complexity here comes from the desire to support
|
||||
Chrome apps.
|
||||
|
||||
From https://bugzilla.gnome.org/show_bug.cgi?id=673657#c13
|
||||
|
||||
Currently chrome sets WM_CLASS as follows (the first string is the 'instance',
|
||||
the second one is the 'class':
|
||||
|
||||
For the normal browser:
|
||||
WM_CLASS(STRING) = "chromium", "Chromium"
|
||||
|
||||
For a bookmarked page (through 'Tools -> Create application shortcuts')
|
||||
WM_CLASS(STRING) = "wiki.gnome.org__GnomeShell_ApplicationBased", "Chromium"
|
||||
|
||||
For an application from the chrome store (with a .desktop file created through
|
||||
right click, "Create shortcuts" from Chrome's apps overview)
|
||||
WM_CLASS(STRING) = "crx_blpcfgokakmgnkcojhhkbfbldkacnbeo", "Chromium"
|
||||
|
||||
The .desktop file has a matching StartupWMClass, but the name differs, e.g. for
|
||||
the store app (youtube) there is
|
||||
|
||||
.local/share/applications/chrome-blpcfgokakmgnkcojhhkbfbldkacnbeo-Default.desktop
|
||||
|
||||
with
|
||||
|
||||
StartupWMClass=crx_blpcfgokakmgnkcojhhkbfbldkacnbeo
|
||||
*/
|
||||
|
||||
/* first try a match from WM_CLASS to StartupWMClass */
|
||||
wm_class = meta_window_get_wm_class (window);
|
||||
app = shell_app_system_lookup_startup_wmclass (appsys, wm_class);
|
||||
if (app != NULL)
|
||||
return g_object_ref (app);
|
||||
|
||||
/* then try a match from WM_CLASS (instance part) to StartupWMClass */
|
||||
wm_instance = meta_window_get_wm_class_instance (window);
|
||||
app = shell_app_system_lookup_startup_wmclass (appsys, wm_instance);
|
||||
if (app != NULL)
|
||||
return g_object_ref (app);
|
||||
|
||||
/* then try a match from WM_CLASS to .desktop */
|
||||
app = shell_app_system_lookup_desktop_wmclass (appsys, wm_class);
|
||||
if (app != NULL)
|
||||
return g_object_ref (app);
|
||||
|
||||
/* finally, try a match from WM_CLASS (instance part) to .desktop
|
||||
(unlikely to find anything at this point, but still worth a try) */
|
||||
app = shell_app_system_lookup_desktop_wmclass (appsys, wm_instance);
|
||||
if (app != NULL)
|
||||
return g_object_ref (app);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_app_from_window_group:
|
||||
* @monitor: a #ShellWindowTracker
|
||||
@ -296,8 +372,7 @@ get_app_for_window (ShellWindowTracker *tracker,
|
||||
/* Check if the app's WM_CLASS specifies an app; this is
|
||||
* canonical if it does.
|
||||
*/
|
||||
result = shell_app_system_lookup_wmclass (app_system,
|
||||
meta_window_get_wm_class (window));
|
||||
result = get_app_from_window_wmclass (window);
|
||||
if (result != NULL)
|
||||
return g_object_ref (result);
|
||||
|
||||
|
Reference in New Issue
Block a user