Skip to content

Commit cfd5021

Browse files
llandwerlin-intellukefromdc
authored andcommitted
icon-info: hash/store icons using scale factor as well as size
Otherwise we might pick up an icon at an invalid size for a given scale. https://bugzilla.gnome.org/show_bug.cgi?id=776896 origin commit: https://gitlab.gnome.org/GNOME/nautilus/commit/53cee1de
1 parent 47246e2 commit cfd5021

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

libcaja-private/caja-icon-info.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,14 @@ caja_icon_info_new_for_icon_info (GtkIconInfo *icon_info,
186186
typedef struct
187187
{
188188
GIcon *icon;
189+
int scale;
189190
int size;
190191
} LoadableIconKey;
191192

192193
typedef struct
193194
{
194195
char *filename;
196+
int scale;
195197
int size;
196198
} ThemedIconKey;
197199

@@ -290,24 +292,28 @@ caja_icon_info_clear_caches (void)
290292
static guint
291293
loadable_icon_key_hash (LoadableIconKey *key)
292294
{
293-
return g_icon_hash (key->icon) ^ key->size;
295+
return g_icon_hash (key->icon) ^ key->scale ^ key->size;
294296
}
295297

296298
static gboolean
297299
loadable_icon_key_equal (const LoadableIconKey *a,
298300
const LoadableIconKey *b)
299301
{
300302
return a->size == b->size &&
303+
a->scale == b->scale &&
301304
g_icon_equal (a->icon, b->icon);
302305
}
303306

304307
static LoadableIconKey *
305-
loadable_icon_key_new (GIcon *icon, int size)
308+
loadable_icon_key_new (GIcon *icon,
309+
int scale,
310+
int size)
306311
{
307312
LoadableIconKey *key;
308313

309314
key = g_slice_new (LoadableIconKey);
310315
key->icon = g_object_ref (icon);
316+
key->scale = scale;
311317
key->size = size;
312318

313319
return key;
@@ -331,16 +337,20 @@ themed_icon_key_equal (const ThemedIconKey *a,
331337
const ThemedIconKey *b)
332338
{
333339
return a->size == b->size &&
340+
a->scale == b->scale &&
334341
g_str_equal (a->filename, b->filename);
335342
}
336343

337344
static ThemedIconKey *
338-
themed_icon_key_new (const char *filename, int size)
345+
themed_icon_key_new (const char *filename,
346+
int scale,
347+
int size)
339348
{
340349
ThemedIconKey *key;
341350

342351
key = g_slice_new (ThemedIconKey);
343352
key->filename = g_strdup (filename);
353+
key->scale = scale;
344354
key->size = size;
345355

346356
return key;
@@ -377,7 +387,8 @@ caja_icon_info_lookup (GIcon *icon,
377387
}
378388

379389
lookup_key.icon = icon;
380-
lookup_key.size = size;
390+
lookup_key.scale = scale;
391+
lookup_key.size = size * scale;
381392

382393
icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key);
383394
if (icon_info)
@@ -401,7 +412,7 @@ caja_icon_info_lookup (GIcon *icon,
401412

402413
icon_info = caja_icon_info_new_for_pixbuf (pixbuf, scale);
403414

404-
key = loadable_icon_key_new (icon, size);
415+
key = loadable_icon_key_new (icon, scale, size);
405416
g_hash_table_insert (loadable_icon_cache, key, icon_info);
406417

407418
return g_object_ref (icon_info);
@@ -442,6 +453,7 @@ caja_icon_info_lookup (GIcon *icon,
442453
}
443454

444455
lookup_key.filename = (char *)filename;
456+
lookup_key.scale = scale;
445457
lookup_key.size = size;
446458

447459
icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key);
@@ -453,7 +465,7 @@ caja_icon_info_lookup (GIcon *icon,
453465

454466
icon_info = caja_icon_info_new_for_icon_info (gtkicon_info, scale);
455467

456-
key = themed_icon_key_new (filename, size);
468+
key = themed_icon_key_new (filename, scale, size);
457469
g_hash_table_insert (themed_icon_cache, key, icon_info);
458470

459471
g_object_unref (gtkicon_info);

0 commit comments

Comments
 (0)