shell/app: Add new get_icon() method
Now that we can always associate a GIcon with the app, add a method to access it. While create_icon_texture() is still likely to be more convenient in most cases, exposing the icon can still be useful, for example to add it to a different kind of actor or to compare it with other GIcons. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1342
This commit is contained in:
parent
d7cb2eeebc
commit
86b5a43008
@ -78,6 +78,7 @@ struct _ShellApp
|
|||||||
* want (e.g. it will be of TYPE_NORMAL from
|
* want (e.g. it will be of TYPE_NORMAL from
|
||||||
* the way shell-window-tracker.c works).
|
* the way shell-window-tracker.c works).
|
||||||
*/
|
*/
|
||||||
|
GIcon *fallback_icon;
|
||||||
|
|
||||||
ShellAppRunningState *running_state;
|
ShellAppRunningState *running_state;
|
||||||
|
|
||||||
@ -180,11 +181,26 @@ window_backed_app_get_window (ShellApp *app)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GIcon *
|
/**
|
||||||
window_backed_app_get_icon (ShellApp *app)
|
* shell_app_get_icon:
|
||||||
|
*
|
||||||
|
* Look up the icon for this application
|
||||||
|
*
|
||||||
|
* Return value: (transfer none): A #GIcon
|
||||||
|
*/
|
||||||
|
GIcon *
|
||||||
|
shell_app_get_icon (ShellApp *app)
|
||||||
{
|
{
|
||||||
MetaWindow *window = NULL;
|
MetaWindow *window = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (SHELL_IS_APP (app), NULL);
|
||||||
|
|
||||||
|
if (app->info)
|
||||||
|
return g_app_info_get_icon (G_APP_INFO (app->info));
|
||||||
|
|
||||||
|
if (app->fallback_icon)
|
||||||
|
return app->fallback_icon;
|
||||||
|
|
||||||
/* During a state transition from running to not-running for
|
/* During a state transition from running to not-running for
|
||||||
* window-backend apps, it's possible we get a request for the icon.
|
* window-backend apps, it's possible we get a request for the icon.
|
||||||
* Avoid asserting here and just return a fallback icon
|
* Avoid asserting here and just return a fallback icon
|
||||||
@ -194,10 +210,18 @@ window_backed_app_get_icon (ShellApp *app)
|
|||||||
|
|
||||||
if (window &&
|
if (window &&
|
||||||
meta_window_get_client_type (window) == META_WINDOW_CLIENT_TYPE_X11)
|
meta_window_get_client_type (window) == META_WINDOW_CLIENT_TYPE_X11)
|
||||||
return st_texture_cache_bind_cairo_surface_property (st_texture_cache_get_default (),
|
{
|
||||||
G_OBJECT (window),
|
app->fallback_icon =
|
||||||
"icon");
|
st_texture_cache_bind_cairo_surface_property (st_texture_cache_get_default (),
|
||||||
return g_themed_icon_new ("application-x-executable");
|
G_OBJECT (window),
|
||||||
|
"icon");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app->fallback_icon = g_themed_icon_new ("application-x-executable");
|
||||||
|
}
|
||||||
|
|
||||||
|
return app->fallback_icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -212,26 +236,19 @@ ClutterActor *
|
|||||||
shell_app_create_icon_texture (ShellApp *app,
|
shell_app_create_icon_texture (ShellApp *app,
|
||||||
int size)
|
int size)
|
||||||
{
|
{
|
||||||
g_autoptr (GIcon) icon = NULL;
|
GIcon *icon;
|
||||||
ClutterActor *ret;
|
ClutterActor *ret;
|
||||||
|
|
||||||
ret = st_icon_new ();
|
ret = st_icon_new ();
|
||||||
st_icon_set_icon_size (ST_ICON (ret), size);
|
st_icon_set_icon_size (ST_ICON (ret), size);
|
||||||
st_icon_set_fallback_icon_name (ST_ICON (ret), "application-x-executable");
|
st_icon_set_fallback_icon_name (ST_ICON (ret), "application-x-executable");
|
||||||
|
|
||||||
if (app->info == NULL)
|
icon = shell_app_get_icon (app);
|
||||||
{
|
|
||||||
icon = window_backed_app_get_icon (app);
|
|
||||||
st_widget_add_style_class_name (ST_WIDGET (ret), "fallback-app-icon");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
icon = g_app_info_get_icon (G_APP_INFO (app->info));
|
|
||||||
g_object_ref (icon);
|
|
||||||
}
|
|
||||||
|
|
||||||
st_icon_set_gicon (ST_ICON (ret), icon);
|
st_icon_set_gicon (ST_ICON (ret), icon);
|
||||||
|
|
||||||
|
if (shell_app_is_window_backed (app))
|
||||||
|
st_widget_add_style_class_name (ST_WIDGET (ret), "fallback-app-icon");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1541,6 +1558,7 @@ shell_app_dispose (GObject *object)
|
|||||||
ShellApp *app = SHELL_APP (object);
|
ShellApp *app = SHELL_APP (object);
|
||||||
|
|
||||||
g_clear_object (&app->info);
|
g_clear_object (&app->info);
|
||||||
|
g_clear_object (&app->fallback_icon);
|
||||||
|
|
||||||
while (app->running_state)
|
while (app->running_state)
|
||||||
_shell_app_remove_window (app, app->running_state->windows->data);
|
_shell_app_remove_window (app, app->running_state->windows->data);
|
||||||
|
@ -29,6 +29,7 @@ const char *shell_app_get_id (ShellApp *app);
|
|||||||
GDesktopAppInfo *shell_app_get_app_info (ShellApp *app);
|
GDesktopAppInfo *shell_app_get_app_info (ShellApp *app);
|
||||||
|
|
||||||
ClutterActor *shell_app_create_icon_texture (ShellApp *app, int size);
|
ClutterActor *shell_app_create_icon_texture (ShellApp *app, int size);
|
||||||
|
GIcon *shell_app_get_icon (ShellApp *app);
|
||||||
const char *shell_app_get_name (ShellApp *app);
|
const char *shell_app_get_name (ShellApp *app);
|
||||||
const char *shell_app_get_description (ShellApp *app);
|
const char *shell_app_get_description (ShellApp *app);
|
||||||
gboolean shell_app_is_window_backed (ShellApp *app);
|
gboolean shell_app_is_window_backed (ShellApp *app);
|
||||||
|
Loading…
Reference in New Issue
Block a user