summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVictor Kareh <[email protected]>2023-03-03 13:00:14 -0500
committerlukefromdc <[email protected]>2024-06-18 17:04:23 -0400
commitcb83a91ed03c9e5ab2a1d8b932ffac3ba49e9fbb (patch)
treef5382877cd3acfec00676e9a7bd35b41eb51ed5e /src
parentb7bf18ee00c1eb780f2f9c3732bfe07eefb726a8 (diff)
downloadmarco-cb83a91ed03c9e5ab2a1d8b932ffac3ba49e9fbb.tar.bz2
marco-cb83a91ed03c9e5ab2a1d8b932ffac3ba49e9fbb.tar.xz
iconcache: Add GDesktopAppInfo lookup as an icon caching strategy
Looking up GDesktopAppInfo from the GTK Application ID we can get a much better match for the icon and load it at the appropriate scale. This results in matching icons to straneous windows and better looking icons overall.
Diffstat (limited to 'src')
-rw-r--r--src/core/iconcache.c68
-rw-r--r--src/core/iconcache.h6
-rw-r--r--src/core/window.c2
-rw-r--r--src/include/ui.h4
-rw-r--r--src/ui/ui.c39
5 files changed, 66 insertions, 53 deletions
diff --git a/src/core/iconcache.c b/src/core/iconcache.c
index a45d3d99..32107781 100644
--- a/src/core/iconcache.c
+++ b/src/core/iconcache.c
@@ -31,7 +31,7 @@
/* The icon-reading code is also in libwnck, please sync bugfixes */
-static void
+static gboolean
get_fallback_icons (MetaScreen *screen,
GdkPixbuf **iconp,
int ideal_width,
@@ -45,6 +45,11 @@ get_fallback_icons (MetaScreen *screen,
*/
*iconp = meta_ui_get_default_window_icon (screen->ui);
*mini_iconp = meta_ui_get_default_mini_icon (screen->ui);
+
+ if (*iconp && *mini_iconp)
+ return TRUE;
+
+ return FALSE;
}
static gboolean
@@ -524,6 +529,7 @@ meta_icon_cache_init (MetaIconCache *icon_cache)
icon_cache->wm_hints_dirty = TRUE;
icon_cache->kwm_win_icon_dirty = TRUE;
icon_cache->net_wm_icon_dirty = TRUE;
+ icon_cache->g_desktop_app_icon_dirty = TRUE;
icon_cache->wm_hints_dirty_forced = FALSE;
icon_cache->kwm_win_icon_dirty_forced = FALSE;
@@ -551,6 +557,7 @@ clear_icon_cache (MetaIconCache *icon_cache,
icon_cache->wm_hints_dirty = TRUE;
icon_cache->kwm_win_icon_dirty = TRUE;
icon_cache->net_wm_icon_dirty = TRUE;
+ icon_cache->g_desktop_app_icon_dirty = TRUE;
}
}
@@ -566,6 +573,7 @@ meta_icon_cache_invalidate (MetaIconCache *icon_cache)
icon_cache->wm_hints_dirty = TRUE;
icon_cache->kwm_win_icon_dirty = TRUE;
icon_cache->net_wm_icon_dirty = TRUE;
+ icon_cache->g_desktop_app_icon_dirty = TRUE;
icon_cache->wm_hints_dirty_forced = TRUE;
icon_cache->kwm_win_icon_dirty_forced = TRUE;
@@ -594,6 +602,9 @@ meta_icon_cache_get_icon_invalidated (MetaIconCache *icon_cache)
else if (icon_cache->origin <= USING_WM_HINTS &&
icon_cache->wm_hints_dirty)
return TRUE;
+ else if (icon_cache->origin <= USING_G_DESKTOP_APP &&
+ icon_cache->g_desktop_app_icon_dirty)
+ return TRUE;
else if (icon_cache->origin <= USING_NET_WM_ICON &&
icon_cache->net_wm_icon_dirty)
return TRUE;
@@ -691,7 +702,7 @@ scaled_from_pixdata (guchar *pixdata,
gboolean
meta_read_icons (MetaScreen *screen,
Window xwindow,
- char *res_name,
+ char *app_id,
MetaIconCache *icon_cache,
Pixmap wm_hints_pixmap,
Pixmap wm_hints_mask,
@@ -743,6 +754,31 @@ meta_read_icons (MetaScreen *screen,
* we haven't done that since the last change.
*/
+ if (icon_cache->origin <= USING_G_DESKTOP_APP &&
+ icon_cache->g_desktop_app_icon_dirty &&
+ app_id != NULL)
+ {
+ icon_cache->g_desktop_app_icon_dirty = FALSE;
+
+ *iconp = meta_ui_get_window_icon_from_app (screen->ui, app_id);
+ *mini_iconp = meta_ui_get_mini_icon_from_app (screen->ui, app_id);
+
+ if (*iconp && *mini_iconp)
+ {
+ replace_cache (icon_cache, USING_G_DESKTOP_APP,
+ *iconp, *mini_iconp);
+
+ return TRUE;
+ }
+ else
+ {
+ if (*iconp)
+ g_object_unref (G_OBJECT (*iconp));
+ if (*mini_iconp)
+ g_object_unref (G_OBJECT (*mini_iconp));
+ }
+ }
+
if (icon_cache->origin <= USING_NET_WM_ICON &&
icon_cache->net_wm_icon_dirty)
@@ -849,25 +885,19 @@ meta_read_icons (MetaScreen *screen,
{
icon_cache->fallback_icon_dirty_forced = FALSE;
- if (res_name != NULL)
+ if (get_fallback_icons (screen,
+ iconp,
+ ideal_width,
+ ideal_height,
+ mini_iconp,
+ ideal_mini_width,
+ ideal_mini_height))
{
- *iconp = meta_ui_get_window_icon_from_name (screen->ui, res_name);
- *mini_iconp = meta_ui_get_mini_icon_from_name (screen->ui, res_name);
- }
-
- if (*iconp == NULL || *mini_iconp == NULL)
- get_fallback_icons (screen,
- iconp,
- ideal_width,
- ideal_height,
- mini_iconp,
- ideal_mini_width,
- ideal_mini_height);
+ replace_cache (icon_cache, USING_FALLBACK_ICON,
+ *iconp, *mini_iconp);
- replace_cache (icon_cache, USING_FALLBACK_ICON,
- *iconp, *mini_iconp);
-
- return TRUE;
+ return TRUE;
+ }
}
if (!icon_cache->want_fallback &&
diff --git a/src/core/iconcache.h b/src/core/iconcache.h
index 7e9a1f6d..9aee499b 100644
--- a/src/core/iconcache.h
+++ b/src/core/iconcache.h
@@ -38,7 +38,8 @@ typedef enum
USING_FALLBACK_ICON,
USING_KWM_WIN_ICON,
USING_WM_HINTS,
- USING_NET_WM_ICON
+ USING_NET_WM_ICON,
+ USING_G_DESKTOP_APP
} IconOrigin;
struct _MetaIconCache
@@ -51,6 +52,7 @@ struct _MetaIconCache
guint wm_hints_dirty : 1;
guint kwm_win_icon_dirty : 1;
guint net_wm_icon_dirty : 1;
+ guint g_desktop_app_icon_dirty : 1;
guint wm_hints_dirty_forced : 1;
guint kwm_win_icon_dirty_forced : 1;
@@ -67,7 +69,7 @@ gboolean meta_icon_cache_get_icon_invalidated (MetaIconCache *icon_cache);
gboolean meta_read_icons (MetaScreen *screen,
Window xwindow,
- char *res_name,
+ char *app_id,
MetaIconCache *icon_cache,
Pixmap wm_hints_pixmap,
Pixmap wm_hints_mask,
diff --git a/src/core/window.c b/src/core/window.c
index 658ca957..b58aff2f 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -6122,7 +6122,7 @@ meta_window_update_icon_now (MetaWindow *window)
if (meta_read_icons (window->screen,
window->xwindow,
- window->res_name,
+ window->gtk_application_id,
&window->icon_cache,
window->wm_hints_pixmap,
window->wm_hints_mask,
diff --git a/src/include/ui.h b/src/include/ui.h
index 9d95e37a..f4728e32 100644
--- a/src/include/ui.h
+++ b/src/include/ui.h
@@ -157,8 +157,8 @@ void meta_ui_pop_delay_exposes (MetaUI *ui);
GdkPixbuf* meta_ui_get_default_window_icon (MetaUI *ui);
GdkPixbuf* meta_ui_get_default_mini_icon (MetaUI *ui);
-GdkPixbuf* meta_ui_get_window_icon_from_name (MetaUI *ui, char *name);
-GdkPixbuf* meta_ui_get_mini_icon_from_name (MetaUI *ui, char *name);
+GdkPixbuf* meta_ui_get_window_icon_from_app (MetaUI *ui, char *name);
+GdkPixbuf* meta_ui_get_mini_icon_from_app (MetaUI *ui, char *name);
gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay,
Window xwindow);
diff --git a/src/ui/ui.c b/src/ui/ui.c
index 2b15cc82..3c32c909 100644
--- a/src/ui/ui.c
+++ b/src/ui/ui.c
@@ -650,43 +650,26 @@ meta_ui_get_default_mini_icon (MetaUI *ui)
}
static GdkPixbuf *
-load_window_icon_from_name (char *name, int size, int scale)
+load_window_icon_from_app (char *app_id, int size, int scale)
{
GtkIconTheme *theme = gtk_icon_theme_get_default ();
GdkPixbuf *pixbuf = NULL;
- /* If the res_name window property maps to an icon, use that */
- pixbuf = gtk_icon_theme_load_icon_for_scale (theme, name, size, scale, GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
- if (pixbuf != NULL)
- return pixbuf;
-
- char ***results;
- gchar *desktop_id = NULL;
- gint i, j;
GDesktopAppInfo *info;
GIcon *gicon;
GtkIconInfo *icon_info;
- /* Find a proper desktop file based on the window property name */
- results = g_desktop_app_info_search (name);
-
- for (i = 0; results[i]; i++)
- {
- for (j = 0; results[i][j]; j++)
- {
- /* We are only interested in the top ranking result, so we use that and free up the rest */
- if (desktop_id == NULL)
- desktop_id = g_strdup(results[i][j]);
- }
- g_strfreev (results[i]);
- }
- g_free (results);
+ /* Generate a desktop ID the GTK Application ID name (e.g. org.mate.Caja.desktop). */
+ gchar *desktop_id = g_strconcat(app_id, ".desktop", NULL);
if (desktop_id == NULL)
return NULL;
/* Now that we have the desktop file ID, we extract the icon from it and render it */
info = g_desktop_app_info_new (desktop_id);
+ g_free(desktop_id);
+ if (info == NULL)
+ return NULL;
gicon = g_app_info_get_icon (G_APP_INFO (info));
icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, gicon, size, scale, GTK_ICON_LOOKUP_FORCE_SIZE);
if (icon_info)
@@ -695,13 +678,11 @@ load_window_icon_from_name (char *name, int size, int scale)
g_object_unref (icon_info);
}
- g_free (desktop_id);
-
return pixbuf;
}
GdkPixbuf*
-meta_ui_get_window_icon_from_name (MetaUI *ui, char *name)
+meta_ui_get_window_icon_from_app (MetaUI *ui, char *name)
{
int scale;
int size;
@@ -709,11 +690,11 @@ meta_ui_get_window_icon_from_name (MetaUI *ui, char *name)
scale = gtk_widget_get_scale_factor (GTK_WIDGET (ui->frames));
size = meta_prefs_get_icon_size() / scale;
- return load_window_icon_from_name (name, size, scale);
+ return load_window_icon_from_app (name, size, scale);
}
GdkPixbuf*
-meta_ui_get_mini_icon_from_name (MetaUI *ui, char *name)
+meta_ui_get_mini_icon_from_app (MetaUI *ui, char *name)
{
int scale;
int size;
@@ -721,7 +702,7 @@ meta_ui_get_mini_icon_from_name (MetaUI *ui, char *name)
scale = gtk_widget_get_scale_factor (GTK_WIDGET (ui->frames));
size = META_MINI_ICON_WIDTH / scale;
- return load_window_icon_from_name (name, size, scale);
+ return load_window_icon_from_app (name, size, scale);
}
gboolean