[gnome-shell] shell/app: Add new get_icon() method
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] shell/app: Add new get_icon() method
- Date: Wed, 1 Jul 2020 16:52:52 +0000 (UTC)
commit 86b5a43008aa5afad6bfefe5542f048de226e575
Author: Florian Müllner <fmuellner gnome org>
Date: Tue Jun 30 16:53:50 2020 +0200
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
src/shell-app.c | 54 ++++++++++++++++++++++++++++++++++++------------------
src/shell-app.h | 1 +
2 files changed, 37 insertions(+), 18 deletions(-)
---
diff --git a/src/shell-app.c b/src/shell-app.c
index 7937dacdd6..044f280302 100644
--- a/src/shell-app.c
+++ b/src/shell-app.c
@@ -78,6 +78,7 @@ struct _ShellApp
* want (e.g. it will be of TYPE_NORMAL from
* the way shell-window-tracker.c works).
*/
+ GIcon *fallback_icon;
ShellAppRunningState *running_state;
@@ -180,11 +181,26 @@ window_backed_app_get_window (ShellApp *app)
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;
+ 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
* window-backend apps, it's possible we get a request for the icon.
* Avoid asserting here and just return a fallback icon
@@ -194,10 +210,18 @@ window_backed_app_get_icon (ShellApp *app)
if (window &&
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),
- "icon");
- return g_themed_icon_new ("application-x-executable");
+ {
+ app->fallback_icon =
+ st_texture_cache_bind_cairo_surface_property (st_texture_cache_get_default (),
+ 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,
int size)
{
- g_autoptr (GIcon) icon = NULL;
+ GIcon *icon;
ClutterActor *ret;
ret = st_icon_new ();
st_icon_set_icon_size (ST_ICON (ret), size);
st_icon_set_fallback_icon_name (ST_ICON (ret), "application-x-executable");
- if (app->info == NULL)
- {
- 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);
- }
-
+ icon = shell_app_get_icon (app);
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;
}
@@ -1541,6 +1558,7 @@ shell_app_dispose (GObject *object)
ShellApp *app = SHELL_APP (object);
g_clear_object (&app->info);
+ g_clear_object (&app->fallback_icon);
while (app->running_state)
_shell_app_remove_window (app, app->running_state->windows->data);
diff --git a/src/shell-app.h b/src/shell-app.h
index a6b55c3359..bf6f45ecb2 100644
--- a/src/shell-app.h
+++ b/src/shell-app.h
@@ -29,6 +29,7 @@ const char *shell_app_get_id (ShellApp *app);
GDesktopAppInfo *shell_app_get_app_info (ShellApp *app);
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_description (ShellApp *app);
gboolean shell_app_is_window_backed (ShellApp *app);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]