Merge pull request #423 from bebehei/optimize_icons

Optimize icons
This commit is contained in:
Nikos Tsipinakis 2017-11-02 07:54:41 +02:00 committed by GitHub
commit 76857b6e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 19 deletions

View File

@ -267,13 +267,12 @@ static void on_notify(GDBusConnection *connection,
n->category = category; n->category = category;
n->dbus_client = g_strdup(sender); n->dbus_client = g_strdup(sender);
n->transient = transient; n->transient = transient;
if (actions->count > 0) {
n->actions = actions; if (actions->count < 1) {
} else { actions_free(actions);
n->actions = NULL; actions = NULL;
g_strfreev(actions->actions);
g_free(actions);
} }
n->actions = actions;
for (int i = 0; i < ColLast; i++) { for (int i = 0; i < ColLast; i++) {
n->color_strings[i] = NULL; n->color_strings[i] = NULL;

View File

@ -163,6 +163,33 @@ int notification_is_duplicate(const notification *a, const notification *b)
&& a->urgency == b->urgency; && a->urgency == b->urgency;
} }
/*
* Free the actions element
* @a: (nullable): Pointer to #Actions
*/
void actions_free(Actions *a)
{
if (!a)
return;
g_strfreev(a->actions);
g_free(a->dmenu_str);
g_free(a);
}
/*
* Free a #RawImage
* @i: (nullable): pointer to #RawImage
*/
void rawimage_free(RawImage *i)
{
if (!i)
return;
g_free(i->data);
g_free(i);
}
/* /*
* Free the memory used by the given notification. * Free the memory used by the given notification.
*/ */
@ -179,16 +206,8 @@ void notification_free(notification *n)
g_free(n->text_to_render); g_free(n->text_to_render);
g_free(n->urls); g_free(n->urls);
if (n->actions) { actions_free(n->actions);
g_strfreev(n->actions->actions); rawimage_free(n->raw_icon);
g_free(n->actions->dmenu_str);
}
if (n->raw_icon) {
if (n->raw_icon->data)
g_free(n->raw_icon->data);
g_free(n->raw_icon);
}
g_free(n); g_free(n);
} }

View File

@ -33,7 +33,6 @@ typedef struct _notification {
char *appname; char *appname;
char *summary; char *summary;
char *body; char *body;
bool icon_overridden;
char *icon; char *icon;
RawImage *raw_icon; RawImage *raw_icon;
char *msg; /* formatted message */ char *msg; /* formatted message */
@ -63,6 +62,8 @@ typedef struct _notification {
notification *notification_create(void); notification *notification_create(void);
void notification_init(notification *n); void notification_init(notification *n);
void actions_free(Actions *a);
void rawimage_free(RawImage *i);
void notification_free(notification *n); void notification_free(notification *n);
int notification_cmp(const void *a, const void *b); int notification_cmp(const void *a, const void *b);
int notification_cmp_data(const void *a, const void *b, void *data); int notification_cmp_data(const void *a, const void *b, void *data);

View File

@ -25,7 +25,8 @@ void rule_apply(rule_t *r, notification *n)
if (r->new_icon) { if (r->new_icon) {
g_free(n->icon); g_free(n->icon);
n->icon = g_strdup(r->new_icon); n->icon = g_strdup(r->new_icon);
n->icon_overridden = true; rawimage_free(n->raw_icon);
n->raw_icon = NULL;
} }
if (r->fg) if (r->fg)
n->color_strings[ColFG] = r->fg; n->color_strings[ColFG] = r->fg;

View File

@ -425,7 +425,7 @@ static colored_layout *r_init_shared(cairo_t *c, notification *n)
GdkPixbuf *pixbuf = NULL; GdkPixbuf *pixbuf = NULL;
if (n->raw_icon && !n->icon_overridden && if (n->raw_icon &&
settings.icon_position != icons_off) { settings.icon_position != icons_off) {
pixbuf = get_pixbuf_from_raw_image(n->raw_icon); pixbuf = get_pixbuf_from_raw_image(n->raw_icon);