Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iconcache: Use desktop_id to lookup GDesktopAppInfo #776

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/atomnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ item(_MARCO_SET_KEYBINDINGS_MESSAGE)
item(_MARCO_TOGGLE_VERBOSE)
item(_GTK_THEME_VARIANT)
item(_GTK_FRAME_EXTENTS)
item(_GTK_APPLICATION_ID)
item(_GTK_SHOW_WINDOW_MENU)
item(_GTK_WORKAREAS)
item(_MATE_PANEL_ACTION)
Expand All @@ -76,6 +77,11 @@ item(TIMESTAMP)
item(VERSION)
item(ATOM_PAIR)

/* This is only used if BAMF is installed and the daemon is running.
* Otherwise it's a no-op
*/
item(_BAMF_DESKTOP_FILE)

/* Oddities: These are used, and we need atoms for them,
* but when we need all _NET_WM hints (i.e. when we're making
* lists of which _NET_WM hints we support in order to advertise
Expand Down
68 changes: 49 additions & 19 deletions src/core/iconcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -691,7 +702,7 @@ scaled_from_pixdata (guchar *pixdata,
gboolean
meta_read_icons (MetaScreen *screen,
Window xwindow,
char *res_name,
char *desktop_id,
MetaIconCache *icon_cache,
Pixmap wm_hints_pixmap,
Pixmap wm_hints_mask,
Expand Down Expand Up @@ -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 &&
desktop_id != NULL)
{
icon_cache->g_desktop_app_icon_dirty = FALSE;

*iconp = meta_ui_get_window_icon_from_desktop_id (screen->ui, desktop_id);
*mini_iconp = meta_ui_get_mini_icon_from_desktop_id (screen->ui, desktop_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)

Expand Down Expand Up @@ -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 &&
Expand Down
6 changes: 4 additions & 2 deletions src/core/iconcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 *desktop_id,
MetaIconCache *icon_cache,
Pixmap wm_hints_pixmap,
Pixmap wm_hints_mask,
Expand Down
2 changes: 2 additions & 0 deletions src/core/window-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ struct _MetaWindow
char *wm_client_machine;
char *startup_id;
char *gtk_theme_variant;
char *gtk_application_id;
char *bamf_desktop_file;

int net_wm_pid;

Expand Down
49 changes: 49 additions & 0 deletions src/core/window-props.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,53 @@ reload_gtk_theme_variant (MetaWindow *window,
meta_ui_update_frame_style (window->screen->ui, window->frame->xwindow);
}
}

static void
reload_gtk_application_id (MetaWindow *window,
MetaPropValue *value,
gboolean initial)
{
char *requested = NULL;
char *current = window->gtk_application_id;

if (value->type != META_PROP_VALUE_INVALID)
{
requested = value->v.str;
meta_verbose ("Requested \"%s\" gtk-application-id for window %s.\n",
requested, window->desc);
}

if (g_strcmp0 (requested, current) != 0)
{
g_free (current);

window->gtk_application_id = g_strdup (requested);
}
}

static void
reload_bamf_desktop_file (MetaWindow *window,
MetaPropValue *value,
gboolean initial)
{
char *requested = NULL;
char *current = window->bamf_desktop_file;

if (value->type != META_PROP_VALUE_INVALID)
{
requested = value->v.str;
meta_verbose ("Requested _BAMF_DESKTOP_FILE \"%s\" for window %s.\n",
requested, window->desc);
}

if (g_strcmp0 (requested, current) != 0)
{
g_free (current);

window->bamf_desktop_file = g_strdup (requested);
}
}

/**
* Initialises the property hooks system. Each row in the table named "hooks"
* represents an action to take when a property is found on a newly-created
Expand Down Expand Up @@ -1652,6 +1699,8 @@ meta_display_init_window_prop_hooks (MetaDisplay *display)
{ display->atom__NET_WM_USER_TIME_WINDOW, META_PROP_VALUE_WINDOW, reload_net_wm_user_time_window },
{ display->atom__GTK_THEME_VARIANT, META_PROP_VALUE_UTF8, reload_gtk_theme_variant, },
{ display->atom__GTK_FRAME_EXTENTS, META_PROP_VALUE_CARDINAL_LIST, reload_gtk_frame_extents },
{ display->atom__GTK_APPLICATION_ID, META_PROP_VALUE_UTF8, reload_gtk_application_id },
{ display->atom__BAMF_DESKTOP_FILE, META_PROP_VALUE_STRING, reload_bamf_desktop_file },
{ 0 },
};

Expand Down
40 changes: 38 additions & 2 deletions src/core/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ meta_window_new_with_attrs (MetaDisplay *display,
gulong existing_wm_state;
gulong event_mask;
MetaMoveResizeFlags flags;
#define N_INITIAL_PROPS 20
#define N_INITIAL_PROPS 22
Atom initial_props[N_INITIAL_PROPS];
int i;
gboolean has_shape;
Expand Down Expand Up @@ -563,6 +563,8 @@ meta_window_new_with_attrs (MetaDisplay *display,
window->wm_client_machine = NULL;
window->startup_id = NULL;
window->gtk_theme_variant = NULL;
window->gtk_application_id = NULL;
window->bamf_desktop_file = NULL;

window->net_wm_pid = -1;

Expand Down Expand Up @@ -621,6 +623,8 @@ meta_window_new_with_attrs (MetaDisplay *display,
initial_props[i++] = display->atom__NET_WM_USER_TIME_WINDOW;
initial_props[i++] = display->atom__NET_WM_FULLSCREEN_MONITORS;
initial_props[i++] = display->atom__GTK_THEME_VARIANT;
initial_props[i++] = display->atom__GTK_APPLICATION_ID;
initial_props[i++] = display->atom__BAMF_DESKTOP_FILE;
g_assert (N_INITIAL_PROPS == i);

meta_window_reload_properties (window, initial_props, N_INITIAL_PROPS, TRUE);
Expand Down Expand Up @@ -6107,6 +6111,33 @@ redraw_icon (MetaWindow *window)
meta_ui_queue_frame_draw (window->screen->ui, window->frame->xwindow);
}

static gchar*
meta_window_get_desktop_id (MetaWindow *window)
{
gchar* desktop_id = NULL;

if (window->gtk_application_id != NULL)
{
meta_verbose ("Request desktop ID from _GTK_APPLICATION_ID '%s'\n", window->gtk_application_id);

/* Generate a desktop extension to the application ID (e.g. org.mate.Caja.desktop). */
desktop_id = g_strconcat(window->gtk_application_id, ".desktop", NULL);
}
else if (window->bamf_desktop_file != NULL)
{
meta_verbose ("Request desktop ID from _BAMF_DESKTOP_FILE '%s'\n", window->bamf_desktop_file);

/* Remove any paths to separate the application ID */
gchar **path_parts = g_strsplit (window->bamf_desktop_file, "/", -1);
/* Generate a desktop ID the application ID (e.g. org.mate.Caja.desktop). */
if (g_strv_length(path_parts) > 0)
desktop_id = g_strdup (path_parts[g_strv_length(path_parts)-1]);
g_strfreev (path_parts);
}

return desktop_id;
}

void
meta_window_update_icon_now (MetaWindow *window)
{
Expand All @@ -6117,10 +6148,11 @@ meta_window_update_icon_now (MetaWindow *window)
mini_icon = NULL;

int icon_size = meta_prefs_get_icon_size();
gchar* desktop_id = meta_window_get_desktop_id (window);

if (meta_read_icons (window->screen,
window->xwindow,
window->res_name,
desktop_id,
&window->icon_cache,
window->wm_hints_pixmap,
window->wm_hints_mask,
Expand All @@ -6143,6 +6175,8 @@ meta_window_update_icon_now (MetaWindow *window)
redraw_icon (window);
}

g_free (desktop_id);

g_assert (window->icon);
g_assert (window->mini_icon);
}
Expand Down Expand Up @@ -9015,6 +9049,8 @@ meta_window_finalize (GObject *object)
g_clear_pointer (&window->icon_name, g_free);
g_clear_pointer (&window->desc, g_free);
g_clear_pointer (&window->gtk_theme_variant, g_free);
g_clear_pointer (&window->gtk_application_id, g_free);
g_clear_pointer (&window->bamf_desktop_file, g_free);

G_OBJECT_CLASS (meta_window_parent_class)->finalize (object);
}
Expand Down
4 changes: 2 additions & 2 deletions src/include/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_desktop_id (MetaUI *ui, char *desktop_id);
GdkPixbuf* meta_ui_get_mini_icon_from_desktop_id (MetaUI *ui, char *desktop_id);

gboolean meta_ui_window_should_not_cause_focus (Display *xdisplay,
Window xwindow);
Expand Down
Loading