diff options
author | Victor Kareh <[email protected]> | 2023-03-03 13:00:14 -0500 |
---|---|---|
committer | lukefromdc <[email protected]> | 2024-06-18 17:04:23 -0400 |
commit | cb83a91ed03c9e5ab2a1d8b932ffac3ba49e9fbb (patch) | |
tree | f5382877cd3acfec00676e9a7bd35b41eb51ed5e /src/core | |
parent | b7bf18ee00c1eb780f2f9c3732bfe07eefb726a8 (diff) | |
download | marco-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/core')
-rw-r--r-- | src/core/iconcache.c | 68 | ||||
-rw-r--r-- | src/core/iconcache.h | 6 | ||||
-rw-r--r-- | src/core/window.c | 2 |
3 files changed, 54 insertions, 22 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, |