Skip to content

Commit 1e60352

Browse files
committed
Always compute the icon_id
1 parent d0f8976 commit 1e60352

File tree

7 files changed

+56
-27
lines changed

7 files changed

+56
-27
lines changed

src/draw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void load_icon_themes(void)
4747
char *theme = settings.icon_theme[i];
4848
int theme_index = load_icon_theme(theme);
4949
if (theme_index >= 0) {
50-
LOG_I("Adding theme %s", theme);
50+
LOG_I("Adding icon theme %s", theme);
5151
add_default_theme(theme_index);
5252
loaded_theme = true;
5353
}

src/icon.c

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,36 @@ static GdkPixbuf *icon_pixbuf_scale_to_size(GdkPixbuf *pixbuf, double dpi_scale,
183183
return pixbuf;
184184
}
185185

186-
GdkPixbuf *get_pixbuf_from_file(const char *filename, int min_size, int max_size, double scale)
186+
static char *get_id_from_data(const uint8_t *data_pb, size_t width, size_t height, size_t pixelstride, size_t rowstride)
187+
{
188+
/* To calculate a checksum of the current image, we have to remove
189+
* all excess spacers, so that our checksummed memory only contains
190+
* real data. */
191+
192+
size_t data_chk_len = pixelstride * width * height;
193+
unsigned char *data_chk = g_malloc(data_chk_len);
194+
size_t rowstride_short = pixelstride * width;
195+
196+
for (int i = 0; i < height; i++) {
197+
memcpy(data_chk + (i*rowstride_short),
198+
data_pb + (i*rowstride),
199+
rowstride_short);
200+
}
201+
202+
char *id = g_compute_checksum_for_data(G_CHECKSUM_MD5, data_chk, data_chk_len);
203+
g_free(data_chk);
204+
205+
return id;
206+
}
207+
208+
GdkPixbuf *get_pixbuf_from_file(const char *filename, char **id, int min_size, int max_size, double scale)
187209
{
188210
GError *error = NULL;
189211
gint w, h;
190212

213+
ASSERT_OR_RET(filename, NULL);
214+
ASSERT_OR_RET(id, NULL);
215+
191216
if (!gdk_pixbuf_get_file_info (filename, &w, &h)) {
192217
LOG_W("Failed to load image info for %s", STR_NN(filename));
193218
return NULL;
@@ -206,6 +231,13 @@ GdkPixbuf *get_pixbuf_from_file(const char *filename, int min_size, int max_size
206231
g_error_free(error);
207232
}
208233

234+
const uint8_t *data = gdk_pixbuf_get_pixels(pixbuf);
235+
size_t rowstride = gdk_pixbuf_get_rowstride(pixbuf);
236+
size_t n_channels = gdk_pixbuf_get_n_channels(pixbuf);
237+
size_t bits_per_sample = gdk_pixbuf_get_bits_per_sample(pixbuf);
238+
size_t pixelstride = (n_channels * bits_per_sample + 7)/8;
239+
240+
*id = get_id_from_data(data, w, h, pixelstride, rowstride);
209241
return pixbuf;
210242
}
211243

@@ -366,22 +398,9 @@ GdkPixbuf *icon_get_for_data(GVariant *data, char **id, double dpi_scale, int mi
366398
return NULL;
367399
}
368400

369-
/* To calculate a checksum of the current image, we have to remove
370-
* all excess spacers, so that our checksummed memory only contains
371-
* real data. */
372-
size_t data_chk_len = pixelstride * width * height;
373-
unsigned char *data_chk = g_malloc(data_chk_len);
374-
size_t rowstride_short = pixelstride * width;
375-
376-
for (int i = 0; i < height; i++) {
377-
memcpy(data_chk + (i*rowstride_short),
378-
data_pb + (i*rowstride),
379-
rowstride_short);
380-
}
381401

382-
*id = g_compute_checksum_for_data(G_CHECKSUM_MD5, data_chk, data_chk_len);
402+
*id = get_id_from_data(data_pb, width, height, pixelstride, rowstride);
383403

384-
g_free(data_chk);
385404
g_variant_unref(data_variant);
386405

387406
pixbuf = icon_pixbuf_scale_to_size(pixbuf, dpi_scale, min_size, max_size);

src/icon.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ cairo_surface_t *gdk_pixbuf_to_cairo_surface(GdkPixbuf *pixbuf);
1111
/** Retrieve an icon by its full filepath, scaled according to settings.
1212
*
1313
* @param filename A string representing a readable file path
14+
* @param id (necessary) A unique identifier of the returned pixbuf.
15+
* Only filled, if the return value is non-NULL.
1416
* @param min_size An iteger representing the desired minimum unscaled icon size.
1517
* @param max_size An iteger representing the desired maximum unscaled icon size.
1618
* @param scale An integer representing the output dpi scaling.
1719
*
1820
* @return an instance of `GdkPixbuf`
1921
* @retval NULL: file does not exist, not readable, etc..
2022
*/
21-
GdkPixbuf *get_pixbuf_from_file(const char *filename, int min_size, int max_size, double scale);
23+
GdkPixbuf *get_pixbuf_from_file(const char *filename, char **id, int min_size, int max_size, double scale);
2224

2325

2426
/**

src/notification.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void notification_print(const struct notification *n)
6060
printf("\traw_icon set: %s\n", (n->icon_id && !STR_EQ(n->iconname, n->icon_id)) ? "true" : "false");
6161
printf("\ticon_id: '%s'\n", STR_NN(n->icon_id));
6262
printf("\tdesktop_entry: '%s'\n", n->desktop_entry ? n->desktop_entry : "");
63-
printf("\tcategory: %s\n", STR_NN(n->category));
63+
printf("\tcategory: '%s'\n", STR_NN(n->category));
6464
printf("\ttimeout: %"G_GINT64_FORMAT"\n", n->timeout/1000);
6565
printf("\tstart: %"G_GINT64_FORMAT"\n", n->start);
6666
printf("\ttimestamp: %"G_GINT64_FORMAT"\n", n->timestamp);
@@ -77,17 +77,19 @@ void notification_print(const struct notification *n)
7777
g_free(grad);
7878

7979
printf("\tfullscreen: %s\n", enum_to_string_fullscreen(n->fullscreen));
80-
printf("\tformat: %s\n", STR_NN(n->format));
80+
printf("\tformat: '%s'\n", STR_NN(n->format));
8181
printf("\tprogress: %d\n", n->progress);
82-
printf("\tstack_tag: %s\n", (n->stack_tag ? n->stack_tag : ""));
82+
printf("\tstack_tag: '%s'\n", (n->stack_tag ? n->stack_tag : ""));
8383
printf("\tid: %d\n", n->id);
8484
if (n->urls) {
8585
char *urls = string_replace_all("\n", "\t\t\n", g_strdup(n->urls));
8686
printf("\turls:\n");
8787
printf("\t{\n");
88-
printf("\t\t%s\n", STR_NN(urls));
88+
printf("\t\t'%s'\n", STR_NN(urls));
8989
printf("\t}\n");
9090
g_free(urls);
91+
} else {
92+
printf("\turls: {}\n");
9193
}
9294
if (g_hash_table_size(n->actions) == 0) {
9395
printf("\tactions: {}\n");
@@ -337,8 +339,12 @@ void notification_unref(struct notification *n)
337339

338340
void notification_transfer_icon(struct notification *from, struct notification *to)
339341
{
340-
if (from->iconname && to->iconname
341-
&& strcmp(from->iconname, to->iconname) == 0){
342+
if (from->iconname && to->iconname && STR_EQ(from->iconname, to->iconname)) {
343+
344+
// If possible check the icon id
345+
if (from->icon_id && to->icon_id && !STR_EQ(from->icon_id, to->icon_id))
346+
return;
347+
342348
// Icons are the same. Transfer icon surface
343349
to->icon = from->icon;
344350

@@ -368,7 +374,7 @@ void notification_icon_replace_path(struct notification *n, const char *new_icon
368374
g_free(n->icon_path);
369375
n->icon_path = get_path_from_icon_name(new_icon, n->min_icon_size);
370376
if (n->icon_path) {
371-
GdkPixbuf *pixbuf = get_pixbuf_from_file(n->icon_path,
377+
GdkPixbuf *pixbuf = get_pixbuf_from_file(n->icon_path, &n->icon_id,
372378
n->min_icon_size, n->max_icon_size,
373379
draw_get_scale());
374380
if (pixbuf) {

src/queues.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ int queues_notification_insert(struct notification *n)
193193
if (!inserted && STR_FULL(n->stack_tag) && queues_stack_by_tag(n))
194194
inserted = true;
195195

196-
if (!inserted && settings.stack_duplicates && queues_stack_duplicate(n)){
197-
if(settings.sort == SORT_TYPE_UPDATE){
196+
if (!inserted && settings.stack_duplicates && queues_stack_duplicate(n)) {
197+
if (settings.sort == SORT_TYPE_UPDATE) {
198198
g_queue_sort(displayed, notification_cmp_data, NULL);
199199
}
200200
inserted = true;
@@ -203,6 +203,7 @@ int queues_notification_insert(struct notification *n)
203203
if (!inserted)
204204
g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL);
205205

206+
// The icon is loaded lazily
206207
if (!n->icon) {
207208
notification_icon_replace_path(n, n->iconname);
208209
}

src/x11/x.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void x_win_show(window winptr)
766766
*/
767767
void x_win_hide(window winptr)
768768
{
769-
LOG_I("X11: Hiding window");
769+
LOG_I("Hiding X11 window");
770770
struct window_x11 *win = (struct window_x11*)winptr;
771771
ASSERT_OR_RET(win->visible,);
772772

test/notification.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static struct notification *notification_load_icon_with_scaling(int min_icon_siz
156156
n->min_icon_size = min_icon_size;
157157
n->max_icon_size = max_icon_size;
158158
notification_icon_replace_data(n, raw_icon);
159+
assert(n->icon_id);
159160

160161
g_variant_unref(raw_icon);
161162
g_free(path);

0 commit comments

Comments
 (0)