Merge pull request #531 from bebehei/typenames

Refactor typenames
This commit is contained in:
Nikos Tsipinakis 2018-09-24 15:55:28 +03:00 committed by GitHub
commit 09ef1b2b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 266 additions and 264 deletions

View File

@ -1,6 +1,6 @@
/* see example dunstrc for additional explanations about these options */ /* see example dunstrc for additional explanations about these options */
settings_t defaults = { struct settings defaults = {
.font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*", .font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*",
.markup = MARKUP_NO, .markup = MARKUP_NO,
@ -32,12 +32,12 @@ settings_t defaults = {
.indicate_hidden = true, /* show count of hidden messages */ .indicate_hidden = true, /* show count of hidden messages */
.idle_threshold = 0, /* don't timeout notifications when idle for x seconds */ .idle_threshold = 0, /* don't timeout notifications when idle for x seconds */
.show_age_threshold = -1, /* show age of notification, when notification is older than x seconds */ .show_age_threshold = -1, /* show age of notification, when notification is older than x seconds */
.align = left, /* text alignment [left/center/right] */ .align = ALIGN_LEFT, /* text alignment ALIGN_[LEFT|CENTER|RIGHT] */
.sticky_history = true, .sticky_history = true,
.history_length = 20, /* max amount of notifications kept in history */ .history_length = 20, /* max amount of notifications kept in history */
.show_indicators = true, .show_indicators = true,
.word_wrap = false, .word_wrap = false,
.ellipsize = middle, .ellipsize = ELLIPSE_MIDDLE,
.ignore_newline = false, .ignore_newline = false,
.line_height = 0, /* if line height < font height, it will be raised to font height */ .line_height = 0, /* if line height < font height, it will be raised to font height */
.notification_height = 0, /* if notification height < font height and padding, it will be raised */ .notification_height = 0, /* if notification height < font height and padding, it will be raised */
@ -110,7 +110,7 @@ settings_t defaults = {
}; };
rule_t default_rules[] = { struct rule default_rules[] = {
/* name can be any unique string. It is used to identify /* name can be any unique string. It is used to identify
* the rule in dunstrc to override it there * the rule in dunstrc to override it there
*/ */

View File

@ -81,7 +81,7 @@ static void on_get_server_information(GDBusConnection *connection,
const gchar *sender, const gchar *sender,
const GVariant *parameters, const GVariant *parameters,
GDBusMethodInvocation *invocation); GDBusMethodInvocation *invocation);
static RawImage *get_raw_image_from_data_hint(GVariant *icon_data); static struct raw_image *get_raw_image_from_data_hint(GVariant *icon_data);
void handle_method_call(GDBusConnection *connection, void handle_method_call(GDBusConnection *connection,
const gchar *sender, const gchar *sender,
@ -130,12 +130,12 @@ static void on_get_capabilities(GDBusConnection *connection,
g_dbus_connection_flush(connection, NULL, NULL, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL);
} }
static notification *dbus_message_to_notification(const gchar *sender, GVariant *parameters) static struct notification *dbus_message_to_notification(const gchar *sender, GVariant *parameters)
{ {
notification *n = notification_create(); struct notification *n = notification_create();
n->actions = g_malloc0(sizeof(Actions)); n->actions = g_malloc0(sizeof(struct actions));
n->dbus_client = g_strdup(sender); n->dbus_client = g_strdup(sender);
{ {
@ -272,7 +272,7 @@ static void on_notify(GDBusConnection *connection,
GVariant *parameters, GVariant *parameters,
GDBusMethodInvocation *invocation) GDBusMethodInvocation *invocation)
{ {
notification *n = dbus_message_to_notification(sender, parameters); struct notification *n = dbus_message_to_notification(sender, parameters);
int id = queues_notification_insert(n); int id = queues_notification_insert(n);
GVariant *reply = g_variant_new("(u)", id); GVariant *reply = g_variant_new("(u)", id);
@ -314,7 +314,7 @@ static void on_get_server_information(GDBusConnection *connection,
g_dbus_connection_flush(connection, NULL, NULL, NULL); g_dbus_connection_flush(connection, NULL, NULL, NULL);
} }
void signal_notification_closed(notification *n, enum reason reason) void signal_notification_closed(struct notification *n, enum reason reason)
{ {
if (reason < REASON_MIN || REASON_MAX < reason) { if (reason < REASON_MIN || REASON_MAX < reason) {
LOG_W("Closing notification with reason '%d' not supported. " LOG_W("Closing notification with reason '%d' not supported. "
@ -344,7 +344,7 @@ void signal_notification_closed(notification *n, enum reason reason)
} }
void signal_action_invoked(notification *n, const char *identifier) void signal_action_invoked(const struct notification *n, const char *identifier)
{ {
GVariant *body = g_variant_new("(us)", n->id, identifier); GVariant *body = g_variant_new("(us)", n->id, identifier);
GError *err = NULL; GError *err = NULL;
@ -520,9 +520,9 @@ static void on_name_lost(GDBusConnection *connection,
exit(1); exit(1);
} }
static RawImage *get_raw_image_from_data_hint(GVariant *icon_data) static struct raw_image *get_raw_image_from_data_hint(GVariant *icon_data)
{ {
RawImage *image = g_malloc(sizeof(RawImage)); struct raw_image *image = g_malloc(sizeof(struct raw_image));
GVariant *data_variant; GVariant *data_variant;
gsize expected_len; gsize expected_len;

View File

@ -17,8 +17,8 @@ enum reason {
int initdbus(void); int initdbus(void);
void dbus_tear_down(int id); void dbus_tear_down(int id);
void signal_notification_closed(notification *n, enum reason reason); void signal_notification_closed(struct notification *n, enum reason reason);
void signal_action_invoked(notification *n, const char *identifier); void signal_action_invoked(const struct notification *n, const char *identifier);
#endif #endif
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -18,18 +18,18 @@
#include "queues.h" #include "queues.h"
#include "x11/x.h" #include "x11/x.h"
typedef struct { struct colored_layout {
PangoLayout *l; PangoLayout *l;
color_t fg; struct color fg;
color_t bg; struct color bg;
color_t frame; struct color frame;
char *text; char *text;
PangoAttrList *attr; PangoAttrList *attr;
cairo_surface_t *icon; cairo_surface_t *icon;
const notification *n; const struct notification *n;
} colored_layout; };
window_x11 *win; struct window_x11 *win;
PangoFontDescription *pango_fdesc; PangoFontDescription *pango_fdesc;
@ -41,17 +41,17 @@ void draw_setup(void)
pango_fdesc = pango_font_description_from_string(settings.font); pango_fdesc = pango_font_description_from_string(settings.font);
} }
static color_t color_hex_to_double(int hexValue) static struct color hex_to_color(int hexValue)
{ {
color_t color; struct color ret;
color.r = ((hexValue >> 16) & 0xFF) / 255.0; ret.r = ((hexValue >> 16) & 0xFF) / 255.0;
color.g = ((hexValue >> 8) & 0xFF) / 255.0; ret.g = ((hexValue >> 8) & 0xFF) / 255.0;
color.b = ((hexValue) & 0xFF) / 255.0; ret.b = ((hexValue) & 0xFF) / 255.0;
return color; return ret;
} }
static color_t string_to_color(const char *str) static struct color string_to_color(const char *str)
{ {
char *end; char *end;
long int val = strtol(str+1, &end, 16); long int val = strtol(str+1, &end, 16);
@ -59,7 +59,7 @@ static color_t string_to_color(const char *str)
LOG_W("Invalid color string: '%s'", str); LOG_W("Invalid color string: '%s'", str);
} }
return color_hex_to_double(val); return hex_to_color(val);
} }
static double color_apply_delta(double base, double delta) static double color_apply_delta(double base, double delta)
@ -73,24 +73,25 @@ static double color_apply_delta(double base, double delta)
return base; return base;
} }
static color_t calculate_foreground_color(color_t bg) static struct color calculate_foreground_color(struct color bg)
{ {
double c_delta = 0.1; double c_delta = 0.1;
color_t color = bg; struct color fg = bg;
/* do we need to darken or brighten the colors? */ /* do we need to darken or brighten the colors? */
bool darken = (bg.r + bg.g + bg.b) / 3 > 0.5; bool darken = (bg.r + bg.g + bg.b) / 3 > 0.5;
int signedness = darken ? -1 : 1; int signedness = darken ? -1 : 1;
color.r = color_apply_delta(color.r, c_delta * signedness); fg.r = color_apply_delta(fg.r, c_delta * signedness);
color.g = color_apply_delta(color.g, c_delta * signedness); fg.g = color_apply_delta(fg.g, c_delta * signedness);
color.b = color_apply_delta(color.b, c_delta * signedness); fg.b = color_apply_delta(fg.b, c_delta * signedness);
return color; return fg;
} }
static color_t layout_get_sepcolor(colored_layout *cl, colored_layout *cl_next) static struct color layout_get_sepcolor(struct colored_layout *cl,
struct colored_layout *cl_next)
{ {
switch (settings.sep_color) { switch (settings.sep_color) {
case SEP_FRAME: case SEP_FRAME:
@ -119,14 +120,14 @@ static void layout_setup_pango(PangoLayout *layout, int width)
PangoAlignment align; PangoAlignment align;
switch (settings.align) { switch (settings.align) {
case left: case ALIGN_LEFT:
default: default:
align = PANGO_ALIGN_LEFT; align = PANGO_ALIGN_LEFT;
break; break;
case center: case ALIGN_CENTER:
align = PANGO_ALIGN_CENTER; align = PANGO_ALIGN_CENTER;
break; break;
case right: case ALIGN_RIGHT:
align = PANGO_ALIGN_RIGHT; align = PANGO_ALIGN_RIGHT;
break; break;
} }
@ -136,7 +137,7 @@ static void layout_setup_pango(PangoLayout *layout, int width)
static void free_colored_layout(void *data) static void free_colored_layout(void *data)
{ {
colored_layout *cl = data; struct colored_layout *cl = data;
g_object_unref(cl->l); g_object_unref(cl->l);
pango_attr_list_unref(cl->attr); pango_attr_list_unref(cl->attr);
g_free(cl->text); g_free(cl->text);
@ -153,7 +154,7 @@ static struct dimensions calculate_dimensions(GSList *layouts)
{ {
struct dimensions dim = { 0 }; struct dimensions dim = { 0 };
screen_info *scr = get_active_screen(); struct screen_info *scr = get_active_screen();
if (have_dynamic_width()) { if (have_dynamic_width()) {
/* dynamic width */ /* dynamic width */
dim.w = 0; dim.w = 0;
@ -176,7 +177,7 @@ static struct dimensions calculate_dimensions(GSList *layouts)
int text_width = 0, total_width = 0; int text_width = 0, total_width = 0;
for (GSList *iter = layouts; iter; iter = iter->next) { for (GSList *iter = layouts; iter; iter = iter->next) {
colored_layout *cl = iter->data; struct colored_layout *cl = iter->data;
int w=0,h=0; int w=0,h=0;
pango_layout_get_pixel_size(cl->l, &w, &h); pango_layout_get_pixel_size(cl->l, &w, &h);
if (cl->icon) { if (cl->icon) {
@ -233,7 +234,7 @@ static struct dimensions calculate_dimensions(GSList *layouts)
static PangoLayout *layout_create(cairo_t *c) static PangoLayout *layout_create(cairo_t *c)
{ {
screen_info *screen = get_active_screen(); struct screen_info *screen = get_active_screen();
PangoContext *context = pango_cairo_create_context(c); PangoContext *context = pango_cairo_create_context(c);
pango_cairo_context_set_resolution(context, get_dpi_for_screen(screen)); pango_cairo_context_set_resolution(context, get_dpi_for_screen(screen));
@ -245,21 +246,21 @@ static PangoLayout *layout_create(cairo_t *c)
return layout; return layout;
} }
static colored_layout *layout_init_shared(cairo_t *c, const notification *n) static struct colored_layout *layout_init_shared(cairo_t *c, const struct notification *n)
{ {
colored_layout *cl = g_malloc(sizeof(colored_layout)); struct colored_layout *cl = g_malloc(sizeof(struct colored_layout));
cl->l = layout_create(c); cl->l = layout_create(c);
if (!settings.word_wrap) { if (!settings.word_wrap) {
PangoEllipsizeMode ellipsize; PangoEllipsizeMode ellipsize;
switch (settings.ellipsize) { switch (settings.ellipsize) {
case start: case ELLIPSE_START:
ellipsize = PANGO_ELLIPSIZE_START; ellipsize = PANGO_ELLIPSIZE_START;
break; break;
case middle: case ELLIPSE_MIDDLE:
ellipsize = PANGO_ELLIPSIZE_MIDDLE; ellipsize = PANGO_ELLIPSIZE_MIDDLE;
break; break;
case end: case ELLIPSE_END:
ellipsize = PANGO_ELLIPSIZE_END; ellipsize = PANGO_ELLIPSIZE_END;
break; break;
default: default:
@ -269,7 +270,7 @@ static colored_layout *layout_init_shared(cairo_t *c, const notification *n)
pango_layout_set_ellipsize(cl->l, ellipsize); pango_layout_set_ellipsize(cl->l, ellipsize);
} }
if (settings.icon_position != icons_off) { if (settings.icon_position != ICON_OFF) {
cl->icon = icon_get_for_notification(n); cl->icon = icon_get_for_notification(n);
} else { } else {
cl->icon = NULL; cl->icon = NULL;
@ -301,19 +302,19 @@ static colored_layout *layout_init_shared(cairo_t *c, const notification *n)
return cl; return cl;
} }
static colored_layout *layout_derive_xmore(cairo_t *c, const notification *n, int qlen) static struct colored_layout *layout_derive_xmore(cairo_t *c, const struct notification *n, int qlen)
{ {
colored_layout *cl = layout_init_shared(c, n); struct colored_layout *cl = layout_init_shared(c, n);
cl->text = g_strdup_printf("(%d more)", qlen); cl->text = g_strdup_printf("(%d more)", qlen);
cl->attr = NULL; cl->attr = NULL;
pango_layout_set_text(cl->l, cl->text, -1); pango_layout_set_text(cl->l, cl->text, -1);
return cl; return cl;
} }
static colored_layout *layout_from_notification(cairo_t *c, notification *n) static struct colored_layout *layout_from_notification(cairo_t *c, struct notification *n)
{ {
colored_layout *cl = layout_init_shared(c, n); struct colored_layout *cl = layout_init_shared(c, n);
/* markup */ /* markup */
GError *err = NULL; GError *err = NULL;
@ -353,7 +354,7 @@ static GSList *create_layouts(cairo_t *c)
for (const GList *iter = queues_get_displayed(); for (const GList *iter = queues_get_displayed();
iter; iter = iter->next) iter; iter = iter->next)
{ {
notification *n = iter->data; struct notification *n = iter->data;
notification_update_text_to_render(n); notification_update_text_to_render(n);
@ -380,7 +381,7 @@ static void free_layouts(GSList *layouts)
g_slist_free_full(layouts, free_colored_layout); g_slist_free_full(layouts, free_colored_layout);
} }
static int layout_get_height(colored_layout *cl) static int layout_get_height(struct colored_layout *cl)
{ {
int h; int h;
int h_icon = 0; int h_icon = 0;
@ -446,8 +447,8 @@ static void draw_rounded_rect(cairo_t *c, int x, int y, int width, int height, i
} }
static cairo_surface_t *render_background(cairo_surface_t *srf, static cairo_surface_t *render_background(cairo_surface_t *srf,
colored_layout *cl, struct colored_layout *cl,
colored_layout *cl_next, struct colored_layout *cl_next,
int y, int y,
int width, int width,
int height, int height,
@ -492,7 +493,7 @@ static cairo_surface_t *render_background(cairo_surface_t *srf,
if ( settings.sep_color != SEP_FRAME if ( settings.sep_color != SEP_FRAME
&& settings.separator_height > 0 && settings.separator_height > 0
&& !last) { && !last) {
color_t sep_color = layout_get_sepcolor(cl, cl_next); struct color sep_color = layout_get_sepcolor(cl, cl_next);
cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b); cairo_set_source_rgb(c, sep_color.r, sep_color.g, sep_color.b);
cairo_rectangle(c, settings.frame_width, y + height, width, settings.separator_height); cairo_rectangle(c, settings.frame_width, y + height, width, settings.separator_height);
@ -508,16 +509,16 @@ static cairo_surface_t *render_background(cairo_surface_t *srf,
return cairo_surface_create_for_rectangle(srf, x, y, width, height); return cairo_surface_create_for_rectangle(srf, x, y, width, height);
} }
static void render_content(cairo_t *c, colored_layout *cl, int width) static void render_content(cairo_t *c, struct colored_layout *cl, int width)
{ {
const int h = layout_get_height(cl); const int h = layout_get_height(cl);
int h_text; int h_text;
pango_layout_get_pixel_size(cl->l, NULL, &h_text); pango_layout_get_pixel_size(cl->l, NULL, &h_text);
if (cl->icon && settings.icon_position == icons_left) { if (cl->icon && settings.icon_position == ICON_LEFT) {
cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding,
settings.padding + h/2 - h_text/2); settings.padding + h/2 - h_text/2);
} else if (cl->icon && settings.icon_position == icons_right) { } else if (cl->icon && settings.icon_position == ICON_RIGHT) {
cairo_move_to(c, settings.h_padding, settings.padding + h/2 - h_text/2); cairo_move_to(c, settings.h_padding, settings.padding + h/2 - h_text/2);
} else { } else {
cairo_move_to(c, settings.h_padding, settings.padding); cairo_move_to(c, settings.h_padding, settings.padding);
@ -534,9 +535,9 @@ static void render_content(cairo_t *c, colored_layout *cl, int width)
image_x, image_x,
image_y = settings.padding + h/2 - image_height/2; image_y = settings.padding + h/2 - image_height/2;
if (settings.icon_position == icons_left) { if (settings.icon_position == ICON_LEFT) {
image_x = settings.h_padding; image_x = settings.h_padding;
} else if (settings.icon_position == icons_right){ } else if (settings.icon_position == ICON_RIGHT){
image_x = width - settings.h_padding - image_width; image_x = width - settings.h_padding - image_width;
} else { } else {
LOG_E("Tried to draw icon but icon position is not valid. %s:%d", __FILE__, __LINE__); LOG_E("Tried to draw icon but icon position is not valid. %s:%d", __FILE__, __LINE__);
@ -550,8 +551,8 @@ static void render_content(cairo_t *c, colored_layout *cl, int width)
} }
static struct dimensions layout_render(cairo_surface_t *srf, static struct dimensions layout_render(cairo_surface_t *srf,
colored_layout *cl, struct colored_layout *cl,
colored_layout *cl_next, struct colored_layout *cl_next,
struct dimensions dim, struct dimensions dim,
bool first, bool first,
bool last) bool last)
@ -593,7 +594,7 @@ static struct dimensions layout_render(cairo_surface_t *srf,
*/ */
static void calc_window_pos(int width, int height, int *ret_x, int *ret_y) static void calc_window_pos(int width, int height, int *ret_x, int *ret_y)
{ {
screen_info *scr = get_active_screen(); struct screen_info *scr = get_active_screen();
if (ret_x) { if (ret_x) {
if (settings.geometry.negative_x) { if (settings.geometry.negative_x) {
@ -624,8 +625,8 @@ void draw(void)
bool first = true; bool first = true;
for (GSList *iter = layouts; iter; iter = iter->next) { for (GSList *iter = layouts; iter; iter = iter->next) {
colored_layout *cl_this = iter->data; struct colored_layout *cl_this = iter->data;
colored_layout *cl_next = iter->next ? iter->next->data : NULL; struct colored_layout *cl_next = iter->next ? iter->next->data : NULL;
dim = layout_render(image_surface, cl_this, cl_next, dim, first, !cl_next); dim = layout_render(image_surface, cl_this, cl_next, dim, first, !cl_next);

View File

@ -2,7 +2,7 @@
#define DUNST_DRAW_H #define DUNST_DRAW_H
#include "src/x11/x.h" #include "src/x11/x.h"
extern window_x11 *win; // Temporary extern struct window_x11 *win; // Temporary
void draw_setup(void); void draw_setup(void);

View File

@ -161,7 +161,7 @@ int dunst_main(int argc, char *argv[])
guint int_src = g_unix_signal_add(SIGINT, quit_signal, NULL); guint int_src = g_unix_signal_add(SIGINT, quit_signal, NULL);
if (settings.startup_notification) { if (settings.startup_notification) {
notification *n = notification_create(); struct notification *n = notification_create();
n->id = 0; n->id = 0;
n->appname = g_strdup("dunst"); n->appname = g_strdup("dunst");
n->summary = g_strdup("startup"); n->summary = g_strdup("startup");

View File

@ -126,7 +126,7 @@ GdkPixbuf *get_pixbuf_from_icon(const char *iconname)
return pixbuf; return pixbuf;
} }
GdkPixbuf *get_pixbuf_from_raw_image(const RawImage *raw_image) GdkPixbuf *get_pixbuf_from_raw_image(const struct raw_image *raw_image)
{ {
GdkPixbuf *pixbuf = NULL; GdkPixbuf *pixbuf = NULL;
@ -143,7 +143,7 @@ GdkPixbuf *get_pixbuf_from_raw_image(const RawImage *raw_image)
return pixbuf; return pixbuf;
} }
cairo_surface_t *icon_get_for_notification(const notification *n) cairo_surface_t *icon_get_for_notification(const struct notification *n)
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;

View File

@ -26,9 +26,9 @@ GdkPixbuf *get_pixbuf_from_file(const char *filename);
*/ */
GdkPixbuf *get_pixbuf_from_icon(const char *iconname); GdkPixbuf *get_pixbuf_from_icon(const char *iconname);
/** Convert a RawImage to a `GdkPixbuf` /** Convert a struct raw_image to a `GdkPixbuf`
*/ */
GdkPixbuf *get_pixbuf_from_raw_image(const RawImage *raw_image); GdkPixbuf *get_pixbuf_from_raw_image(const struct raw_image *raw_image);
/** /**
* Get a cairo surface with the appropriate icon for the notification, scaled * Get a cairo surface with the appropriate icon for the notification, scaled
@ -36,7 +36,7 @@ GdkPixbuf *get_pixbuf_from_raw_image(const RawImage *raw_image);
* *
* @return a cairo_surface_t pointer or NULL if no icon could be retrieved. * @return a cairo_surface_t pointer or NULL if no icon could be retrieved.
*/ */
cairo_surface_t *icon_get_for_notification(const notification *n); cairo_surface_t *icon_get_for_notification(const struct notification *n);
#endif #endif
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -135,7 +135,7 @@ void open_browser(const char *in)
*/ */
void invoke_action(const char *action) void invoke_action(const char *action)
{ {
notification *invoked = NULL; struct notification *invoked = NULL;
char *action_identifier = NULL; char *action_identifier = NULL;
char *appname_begin = strchr(action, '['); char *appname_begin = strchr(action, '[');
@ -149,7 +149,7 @@ void invoke_action(const char *action)
for (const GList *iter = queues_get_displayed(); iter; for (const GList *iter = queues_get_displayed(); iter;
iter = iter->next) { iter = iter->next) {
notification *n = iter->data; struct notification *n = iter->data;
if (g_str_has_prefix(appname_begin, n->appname) && strlen(n->appname) == appname_len) { if (g_str_has_prefix(appname_begin, n->appname) && strlen(n->appname) == appname_len) {
if (!n->actions) if (!n->actions)
continue; continue;
@ -201,7 +201,7 @@ void context_menu(void)
for (const GList *iter = queues_get_displayed(); iter; for (const GList *iter = queues_get_displayed(); iter;
iter = iter->next) { iter = iter->next) {
notification *n = iter->data; struct notification *n = iter->data;
if (n->urls) if (n->urls)
dmenu_input = string_append(dmenu_input, n->urls, "\n"); dmenu_input = string_append(dmenu_input, n->urls, "\n");

View File

@ -24,9 +24,9 @@
#include "utils.h" #include "utils.h"
#include "x11/x.h" #include "x11/x.h"
static void notification_extract_urls(notification *n); static void notification_extract_urls(struct notification *n);
static void notification_format_message(notification *n); static void notification_format_message(struct notification *n);
static void notification_dmenu_string(notification *n); static void notification_dmenu_string(struct notification *n);
/* see notification.h */ /* see notification.h */
const char *enum_to_string_fullscreen(enum behavior_fullscreen in) const char *enum_to_string_fullscreen(enum behavior_fullscreen in)
@ -43,7 +43,7 @@ const char *enum_to_string_fullscreen(enum behavior_fullscreen in)
} }
/* see notification.h */ /* see notification.h */
void notification_print(notification *n) void notification_print(const struct notification *n)
{ {
//TODO: use logging info for this //TODO: use logging info for this
printf("{\n"); printf("{\n");
@ -87,7 +87,7 @@ void notification_print(notification *n)
} }
/* see notification.h */ /* see notification.h */
void notification_run_script(notification *n) void notification_run_script(struct notification *n)
{ {
if (!n->script || strlen(n->script) < 1) if (!n->script || strlen(n->script) < 1)
return; return;
@ -150,7 +150,7 @@ const char *notification_urgency_to_string(const enum urgency urgency)
} }
/* see notification.h */ /* see notification.h */
int notification_cmp(const notification *a, const notification *b) int notification_cmp(const struct notification *a, const struct notification *b)
{ {
if (a->urgency != b->urgency) { if (a->urgency != b->urgency) {
return b->urgency - a->urgency; return b->urgency - a->urgency;
@ -162,8 +162,8 @@ int notification_cmp(const notification *a, const notification *b)
/* see notification.h */ /* see notification.h */
int notification_cmp_data(const void *va, const void *vb, void *data) int notification_cmp_data(const void *va, const void *vb, void *data)
{ {
notification *a = (notification *) va; struct notification *a = (struct notification *) va;
notification *b = (notification *) vb; struct notification *b = (struct notification *) vb;
if (!settings.sort) if (!settings.sort)
return 1; return 1;
@ -171,22 +171,22 @@ int notification_cmp_data(const void *va, const void *vb, void *data)
return notification_cmp(a, b); return notification_cmp(a, b);
} }
int notification_is_duplicate(const notification *a, const notification *b) int notification_is_duplicate(const struct notification *a, const struct notification *b)
{ {
//Comparing raw icons is not supported, assume they are not identical //Comparing raw icons is not supported, assume they are not identical
if (settings.icon_position != icons_off if (settings.icon_position != ICON_OFF
&& (a->raw_icon || b->raw_icon)) && (a->raw_icon || b->raw_icon))
return false; return false;
return strcmp(a->appname, b->appname) == 0 return strcmp(a->appname, b->appname) == 0
&& strcmp(a->summary, b->summary) == 0 && strcmp(a->summary, b->summary) == 0
&& strcmp(a->body, b->body) == 0 && strcmp(a->body, b->body) == 0
&& (settings.icon_position != icons_off ? strcmp(a->icon, b->icon) == 0 : 1) && (settings.icon_position != ICON_OFF ? strcmp(a->icon, b->icon) == 0 : 1)
&& a->urgency == b->urgency; && a->urgency == b->urgency;
} }
/* see notification.h */ /* see notification.h */
void actions_free(Actions *a) void actions_free(struct actions *a)
{ {
if (!a) if (!a)
return; return;
@ -197,7 +197,7 @@ void actions_free(Actions *a)
} }
/* see notification.h */ /* see notification.h */
void rawimage_free(RawImage *i) void rawimage_free(struct raw_image *i)
{ {
if (!i) if (!i)
return; return;
@ -207,7 +207,7 @@ void rawimage_free(RawImage *i)
} }
/* see notification.h */ /* see notification.h */
void notification_free(notification *n) void notification_free(struct notification *n)
{ {
if (!n) if (!n)
return; return;
@ -256,9 +256,9 @@ void notification_replace_single_field(char **haystack,
} }
/* see notification.h */ /* see notification.h */
notification *notification_create(void) struct notification *notification_create(void)
{ {
notification *n = g_malloc0(sizeof(notification)); struct notification *n = g_malloc0(sizeof(struct notification));
/* Unparameterized default values */ /* Unparameterized default values */
n->first_render = true; n->first_render = true;
@ -281,7 +281,7 @@ notification *notification_create(void)
} }
/* see notification.h */ /* see notification.h */
void notification_init(notification *n) void notification_init(struct notification *n)
{ {
/* default to empty string to avoid further NULL faults */ /* default to empty string to avoid further NULL faults */
n->appname = n->appname ? n->appname : g_strdup("unknown"); n->appname = n->appname ? n->appname : g_strdup("unknown");
@ -326,7 +326,7 @@ void notification_init(notification *n)
notification_format_message(n); notification_format_message(n);
} }
static void notification_format_message(notification *n) static void notification_format_message(struct notification *n)
{ {
g_clear_pointer(&n->msg, g_free); g_clear_pointer(&n->msg, g_free);
@ -431,7 +431,7 @@ static void notification_format_message(notification *n)
} }
} }
static void notification_extract_urls(notification *n) static void notification_extract_urls(struct notification *n)
{ {
g_clear_pointer(&n->urls, g_free); g_clear_pointer(&n->urls, g_free);
@ -455,7 +455,7 @@ static void notification_extract_urls(notification *n)
g_free(urls_text); g_free(urls_text);
} }
static void notification_dmenu_string(notification *n) static void notification_dmenu_string(struct notification *n)
{ {
if (n->actions) { if (n->actions) {
g_clear_pointer(&n->actions->dmenu_str, g_free); g_clear_pointer(&n->actions->dmenu_str, g_free);
@ -473,7 +473,7 @@ static void notification_dmenu_string(notification *n)
} }
} }
void notification_update_text_to_render(notification *n) void notification_update_text_to_render(struct notification *n)
{ {
g_clear_pointer(&n->text_to_render, g_free); g_clear_pointer(&n->text_to_render, g_free);
@ -529,7 +529,7 @@ void notification_update_text_to_render(notification *n)
} }
/* see notification.h */ /* see notification.h */
void notification_do_action(notification *n) void notification_do_action(const struct notification *n)
{ {
if (n->actions) { if (n->actions) {
if (n->actions->count == 2) { if (n->actions->count == 2) {

View File

@ -26,7 +26,7 @@ enum urgency {
URG_MAX = 2, /**< Maximum value, useful for boundary checking */ URG_MAX = 2, /**< Maximum value, useful for boundary checking */
}; };
typedef struct _raw_image { struct raw_image {
int width; int width;
int height; int height;
int rowstride; int rowstride;
@ -34,15 +34,15 @@ typedef struct _raw_image {
int bits_per_sample; int bits_per_sample;
int n_channels; int n_channels;
unsigned char *data; unsigned char *data;
} RawImage; };
typedef struct _actions { struct actions {
char **actions; char **actions;
char *dmenu_str; char *dmenu_str;
gsize count; gsize count;
} Actions; };
typedef struct _notification { struct notification {
int id; int id;
char *dbus_client; char *dbus_client;
@ -53,13 +53,13 @@ typedef struct _notification {
enum urgency urgency; enum urgency urgency;
char *icon; /**< plain icon information (may be a path or just a name) */ char *icon; /**< plain icon information (may be a path or just a name) */
RawImage *raw_icon; /**< passed icon data of notification, takes precedence over icon */ struct raw_image *raw_icon; /**< passed icon data of notification, takes precedence over icon */
gint64 start; /**< begin of current display */ gint64 start; /**< begin of current display */
gint64 timestamp; /**< arrival time */ gint64 timestamp; /**< arrival time */
gint64 timeout; /**< time to display */ gint64 timeout; /**< time to display */
Actions *actions; struct actions *actions;
enum markup_mode markup; enum markup_mode markup;
const char *format; const char *format;
@ -83,7 +83,7 @@ typedef struct _notification {
char *msg; /**< formatted message */ char *msg; /**< formatted message */
char *text_to_render; /**< formatted message (with age and action indicators) */ char *text_to_render; /**< formatted message (with age and action indicators) */
char *urls; /**< urllist delimited by '\\n' */ char *urls; /**< urllist delimited by '\\n' */
} notification; };
/** /**
* Create notification struct and initialise all fields with either * Create notification struct and initialise all fields with either
@ -93,7 +93,7 @@ typedef struct _notification {
* This function is guaranteed to return a valid pointer. * This function is guaranteed to return a valid pointer.
* @returns The generated notification * @returns The generated notification
*/ */
notification *notification_create(void); struct notification *notification_create(void);
/** /**
* Sanitize values of notification, apply all matching rules * Sanitize values of notification, apply all matching rules
@ -101,33 +101,33 @@ notification *notification_create(void);
* *
* @param n: the notification to sanitize * @param n: the notification to sanitize
*/ */
void notification_init(notification *n); void notification_init(struct notification *n);
/** /**
* Free the actions structure * Free the actions structure
* *
* @param a (nullable): Pointer to #Actions * @param a (nullable): Pointer to #actions
*/ */
void actions_free(Actions *a); void actions_free(struct actions *a);
/** /**
* Free a #RawImage * Free a #raw_image
* *
* @param i (nullable): pointer to #RawImage * @param i (nullable): pointer to #raw_image
*/ */
void rawimage_free(RawImage *i); void rawimage_free(struct raw_image *i);
/** /**
* Free the memory used by the given notification. * Free the memory used by the given notification.
* *
* @param n (nullable): pointer to #notification * @param n (nullable): pointer to #notification
*/ */
void notification_free(notification *n); void notification_free(struct notification *n);
/** /**
* Helper function to compare two given notifications. * Helper function to compare two given notifications.
*/ */
int notification_cmp(const notification *a, const notification *b); int notification_cmp(const struct notification *a, const struct notification *b);
/** /**
* Wrapper for notification_cmp to match glib's * Wrapper for notification_cmp to match glib's
@ -135,7 +135,7 @@ int notification_cmp(const notification *a, const notification *b);
*/ */
int notification_cmp_data(const void *va, const void *vb, void *data); int notification_cmp_data(const void *va, const void *vb, void *data);
int notification_is_duplicate(const notification *a, const notification *b); int notification_is_duplicate(const struct notification *a, const struct notification *b);
/** /**
* Run the script associated with the * Run the script associated with the
@ -144,12 +144,12 @@ int notification_is_duplicate(const notification *a, const notification *b);
* If the script of the notification has been executed already and * If the script of the notification has been executed already and
* settings.always_run_script is not set, do nothing. * settings.always_run_script is not set, do nothing.
*/ */
void notification_run_script(notification *n); void notification_run_script(struct notification *n);
/** /**
* print a human readable representation * print a human readable representation
* of the given notification to stdout. * of the given notification to stdout.
*/ */
void notification_print(notification *n); void notification_print(const struct notification *n);
/** /**
* Replace the two chars where **needle points * Replace the two chars where **needle points
@ -162,14 +162,15 @@ void notification_replace_single_field(char **haystack,
char **needle, char **needle,
const char *replacement, const char *replacement,
enum markup_mode markup_mode); enum markup_mode markup_mode);
void notification_update_text_to_render(notification *n);
void notification_update_text_to_render(struct notification *n);
/** /**
* If the notification has exactly one action, or one is marked as default, * If the notification has exactly one action, or one is marked as default,
* invoke it. If there are multiple and no default, open the context menu. If * invoke it. If there are multiple and no default, open the context menu. If
* there are no actions, proceed similarly with urls. * there are no actions, proceed similarly with urls.
*/ */
void notification_do_action(notification *n); void notification_do_action(const struct notification *n);
const char *notification_urgency_to_string(const enum urgency urgency); const char *notification_urgency_to_string(const enum urgency urgency);

View File

@ -12,22 +12,22 @@
#include "log.h" #include "log.h"
#include "utils.h" #include "utils.h"
typedef struct _entry_t { struct entry {
char *key; char *key;
char *value; char *value;
} entry_t; };
typedef struct _section_t { struct section {
char *name; char *name;
int entry_count; int entry_count;
entry_t *entries; struct entry *entries;
} section_t; };
static int section_count = 0; static int section_count = 0;
static section_t *sections; static struct section *sections;
static section_t *new_section(const char *name); static struct section *new_section(const char *name);
static section_t *get_section(const char *name); static struct section *get_section(const char *name);
static void add_entry(const char *section_name, const char *key, const char *value); static void add_entry(const char *section_name, const char *key, const char *value);
static const char *get_value(const char *section, const char *key); static const char *get_value(const char *section, const char *key);
static char *clean_value(const char *value); static char *clean_value(const char *value);
@ -40,7 +40,7 @@ static void cmdline_usage_append(const char *key, const char *type, const char *
static int cmdline_find_option(const char *key); static int cmdline_find_option(const char *key);
section_t *new_section(const char *name) struct section *new_section(const char *name)
{ {
for (int i = 0; i < section_count; i++) { for (int i = 0; i < section_count; i++) {
if (!strcmp(name, sections[i].name)) { if (!strcmp(name, sections[i].name)) {
@ -49,7 +49,7 @@ section_t *new_section(const char *name)
} }
section_count++; section_count++;
sections = g_realloc(sections, sizeof(section_t) * section_count); sections = g_realloc(sections, sizeof(struct section) * section_count);
sections[section_count - 1].name = g_strdup(name); sections[section_count - 1].name = g_strdup(name);
sections[section_count - 1].entries = NULL; sections[section_count - 1].entries = NULL;
sections[section_count - 1].entry_count = 0; sections[section_count - 1].entry_count = 0;
@ -70,7 +70,7 @@ void free_ini(void)
section_count = 0; section_count = 0;
} }
section_t *get_section(const char *name) struct section *get_section(const char *name)
{ {
for (int i = 0; i < section_count; i++) { for (int i = 0; i < section_count; i++) {
if (strcmp(sections[i].name, name) == 0) if (strcmp(sections[i].name, name) == 0)
@ -82,20 +82,20 @@ section_t *get_section(const char *name)
void add_entry(const char *section_name, const char *key, const char *value) void add_entry(const char *section_name, const char *key, const char *value)
{ {
section_t *s = get_section(section_name); struct section *s = get_section(section_name);
if (!s) if (!s)
s = new_section(section_name); s = new_section(section_name);
s->entry_count++; s->entry_count++;
int len = s->entry_count; int len = s->entry_count;
s->entries = g_realloc(s->entries, sizeof(entry_t) * len); s->entries = g_realloc(s->entries, sizeof(struct entry) * len);
s->entries[s->entry_count - 1].key = g_strdup(key); s->entries[s->entry_count - 1].key = g_strdup(key);
s->entries[s->entry_count - 1].value = clean_value(value); s->entries[s->entry_count - 1].value = clean_value(value);
} }
const char *get_value(const char *section, const char *key) const char *get_value(const char *section, const char *key)
{ {
section_t *s = get_section(section); struct section *s = get_section(section);
if (!s) { if (!s) {
return NULL; return NULL;
} }

View File

@ -33,7 +33,7 @@ static GQueue *history = NULL; /**< history of displayed notifications */
int next_notification_id = 1; int next_notification_id = 1;
bool pause_displayed = false; bool pause_displayed = false;
static bool queues_stack_duplicate(notification *n); static bool queues_stack_duplicate(struct notification *n);
/* see queues.h */ /* see queues.h */
void queues_init(void) void queues_init(void)
@ -50,7 +50,7 @@ const GList *queues_get_displayed(void)
} }
/* see queues.h */ /* see queues.h */
const notification *queues_get_head_waiting(void) const struct notification *queues_get_head_waiting(void)
{ {
if (waiting->length == 0) if (waiting->length == 0)
return NULL; return NULL;
@ -91,8 +91,8 @@ static void queues_swap_notifications(GQueue *queueA,
GQueue *queueB, GQueue *queueB,
GList *elemB) GList *elemB)
{ {
notification *toB = elemA->data; struct notification *toB = elemA->data;
notification *toA = elemB->data; struct notification *toA = elemB->data;
g_queue_delete_link(queueA, elemA); g_queue_delete_link(queueA, elemA);
g_queue_delete_link(queueB, elemB); g_queue_delete_link(queueB, elemB);
@ -110,7 +110,7 @@ static void queues_swap_notifications(GQueue *queueA,
* @param fullscreen True if a fullscreen window is currently active * @param fullscreen True if a fullscreen window is currently active
* @param visible True if the notification is currently displayed * @param visible True if the notification is currently displayed
*/ */
static bool queues_notification_is_ready(const notification *n, bool fullscreen, bool visible) static bool queues_notification_is_ready(const struct notification *n, bool fullscreen, bool visible)
{ {
if (fullscreen && visible) if (fullscreen && visible)
return n && n->fullscreen != FS_PUSHBACK; return n && n->fullscreen != FS_PUSHBACK;
@ -121,7 +121,7 @@ static bool queues_notification_is_ready(const notification *n, bool fullscreen,
} }
/* see queues.h */ /* see queues.h */
int queues_notification_insert(notification *n) int queues_notification_insert(struct notification *n)
{ {
/* do not display the message, if the message is empty */ /* do not display the message, if the message is empty */
@ -167,13 +167,13 @@ int queues_notification_insert(notification *n)
* @return true, if notification got stacked * @return true, if notification got stacked
* @return false, if notification did not get stacked * @return false, if notification did not get stacked
*/ */
static bool queues_stack_duplicate(notification *n) static bool queues_stack_duplicate(struct notification *n)
{ {
GQueue *allqueues[] = { displayed, waiting }; GQueue *allqueues[] = { displayed, waiting };
for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) { for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) {
for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter; for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter;
iter = iter->next) { iter = iter->next) {
notification *orig = iter->data; struct notification *orig = iter->data;
if (notification_is_duplicate(orig, n)) { if (notification_is_duplicate(orig, n)) {
/* If the progress differs, probably notify-send was used to update the notification /* If the progress differs, probably notify-send was used to update the notification
* So only count it as a duplicate, if the progress was not the same. * So only count it as a duplicate, if the progress was not the same.
@ -201,14 +201,14 @@ static bool queues_stack_duplicate(notification *n)
} }
/* see queues.h */ /* see queues.h */
bool queues_notification_replace_id(notification *new) bool queues_notification_replace_id(struct notification *new)
{ {
GQueue *allqueues[] = { displayed, waiting }; GQueue *allqueues[] = { displayed, waiting };
for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) { for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) {
for (GList *iter = g_queue_peek_head_link(allqueues[i]); for (GList *iter = g_queue_peek_head_link(allqueues[i]);
iter; iter;
iter = iter->next) { iter = iter->next) {
notification *old = iter->data; struct notification *old = iter->data;
if (old->id == new->id) { if (old->id == new->id) {
iter->data = new; iter->data = new;
new->dup_count = old->dup_count; new->dup_count = old->dup_count;
@ -222,7 +222,6 @@ bool queues_notification_replace_id(notification *new)
return true; return true;
} }
} }
} }
return false; return false;
} }
@ -230,13 +229,13 @@ bool queues_notification_replace_id(notification *new)
/* see queues.h */ /* see queues.h */
void queues_notification_close_id(int id, enum reason reason) void queues_notification_close_id(int id, enum reason reason)
{ {
notification *target = NULL; struct notification *target = NULL;
GQueue *allqueues[] = { displayed, waiting }; GQueue *allqueues[] = { displayed, waiting };
for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) { for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) {
for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter; for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter;
iter = iter->next) { iter = iter->next) {
notification *n = iter->data; struct notification *n = iter->data;
if (n->id == id) { if (n->id == id) {
g_queue_remove(allqueues[i], n); g_queue_remove(allqueues[i], n);
target = n; target = n;
@ -254,7 +253,7 @@ void queues_notification_close_id(int id, enum reason reason)
} }
/* see queues.h */ /* see queues.h */
void queues_notification_close(notification *n, enum reason reason) void queues_notification_close(struct notification *n, enum reason reason)
{ {
assert(n != NULL); assert(n != NULL);
queues_notification_close_id(n->id, reason); queues_notification_close_id(n->id, reason);
@ -266,7 +265,7 @@ void queues_history_pop(void)
if (g_queue_is_empty(history)) if (g_queue_is_empty(history))
return; return;
notification *n = g_queue_pop_tail(history); struct notification *n = g_queue_pop_tail(history);
n->redisplayed = true; n->redisplayed = true;
n->start = 0; n->start = 0;
n->timeout = settings.sticky_history ? 0 : n->timeout; n->timeout = settings.sticky_history ? 0 : n->timeout;
@ -274,11 +273,11 @@ void queues_history_pop(void)
} }
/* see queues.h */ /* see queues.h */
void queues_history_push(notification *n) void queues_history_push(struct notification *n)
{ {
if (!n->history_ignore) { if (!n->history_ignore) {
if (settings.history_length > 0 && history->length >= settings.history_length) { if (settings.history_length > 0 && history->length >= settings.history_length) {
notification *to_free = g_queue_pop_head(history); struct notification *to_free = g_queue_pop_head(history);
notification_free(to_free); notification_free(to_free);
} }
@ -311,7 +310,7 @@ void queues_check_timeouts(bool idle, bool fullscreen)
GList *iter = g_queue_peek_head_link(displayed); GList *iter = g_queue_peek_head_link(displayed);
while (iter) { while (iter) {
notification *n = iter->data; struct notification *n = iter->data;
/* /*
* Update iter to the next item before we either exit the * Update iter to the next item before we either exit the
@ -353,7 +352,7 @@ void queues_update(bool fullscreen)
if (fullscreen) { if (fullscreen) {
GList *iter = g_queue_peek_head_link(displayed); GList *iter = g_queue_peek_head_link(displayed);
while (iter) { while (iter) {
notification *n = iter->data; struct notification *n = iter->data;
GList *nextiter = iter->next; GList *nextiter = iter->next;
if (n->fullscreen == FS_PUSHBACK){ if (n->fullscreen == FS_PUSHBACK){
@ -378,7 +377,7 @@ void queues_update(bool fullscreen)
/* move notifications from queue to displayed */ /* move notifications from queue to displayed */
GList *iter = g_queue_peek_head_link(waiting); GList *iter = g_queue_peek_head_link(waiting);
while (displayed->length < cur_displayed_limit && iter) { while (displayed->length < cur_displayed_limit && iter) {
notification *n = iter->data; struct notification *n = iter->data;
GList *nextiter = iter->next; GList *nextiter = iter->next;
if (!n) if (!n)
@ -400,7 +399,7 @@ void queues_update(bool fullscreen)
/* if necessary, push the overhanging notifications from displayed to waiting again */ /* if necessary, push the overhanging notifications from displayed to waiting again */
while (displayed->length > cur_displayed_limit) { while (displayed->length > cur_displayed_limit) {
notification *n = g_queue_pop_tail(displayed); struct notification *n = g_queue_pop_tail(displayed);
g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL); //TODO: actually it should be on the head if unsorted g_queue_insert_sorted(waiting, n, notification_cmp_data, NULL); //TODO: actually it should be on the head if unsorted
} }
@ -418,7 +417,7 @@ void queues_update(bool fullscreen)
} }
if (i_waiting && notification_cmp(i_displayed->data, i_waiting->data) > 0) { if (i_waiting && notification_cmp(i_displayed->data, i_waiting->data) > 0) {
notification *todisp = i_waiting->data; struct notification *todisp = i_waiting->data;
todisp->start = time_monotonic_now(); todisp->start = time_monotonic_now();
notification_run_script(todisp); notification_run_script(todisp);
@ -438,7 +437,7 @@ gint64 queues_get_next_datachange(gint64 time)
for (GList *iter = g_queue_peek_head_link(displayed); iter; for (GList *iter = g_queue_peek_head_link(displayed); iter;
iter = iter->next) { iter = iter->next) {
notification *n = iter->data; struct notification *n = iter->data;
gint64 ttl = n->timeout - (time - n->start); gint64 ttl = n->timeout - (time - n->start);
if (n->timeout > 0) { if (n->timeout > 0) {
@ -488,7 +487,7 @@ bool queues_pause_status(void)
*/ */
static void teardown_notification(gpointer data) static void teardown_notification(gpointer data)
{ {
notification *n = data; struct notification *n = data;
notification_free(n); notification_free(n);
} }

View File

@ -30,7 +30,7 @@ const GList *queues_get_displayed(void);
* *
* @return a notification or NULL, if waiting is empty * @return a notification or NULL, if waiting is empty
*/ */
const notification *queues_get_head_waiting(void); const struct notification *queues_get_head_waiting(void);
/** /**
* Returns the current amount of notifications, * Returns the current amount of notifications,
@ -63,7 +63,7 @@ unsigned int queues_length_history(void);
* @return `0`, the notification was dismissed and freed * @return `0`, the notification was dismissed and freed
* @return The new value of `n->id` * @return The new value of `n->id`
*/ */
int queues_notification_insert(notification *n); int queues_notification_insert(struct notification *n);
/** /**
* Replace the notification which matches the id field of * Replace the notification which matches the id field of
@ -75,7 +75,7 @@ int queues_notification_insert(notification *n);
* @return true, if a matching notification has been found and is replaced * @return true, if a matching notification has been found and is replaced
* @return false, else * @return false, else
*/ */
bool queues_notification_replace_id(notification *new); bool queues_notification_replace_id(struct notification *new);
/** /**
* Close the notification that has n->id == id * Close the notification that has n->id == id
@ -96,7 +96,7 @@ void queues_notification_close_id(int id, enum reason reason);
* @param n (transfer full) The notification to close * @param n (transfer full) The notification to close
* @param reason The #reason to close * @param reason The #reason to close
* */ * */
void queues_notification_close(notification *n, enum reason reason); void queues_notification_close(struct notification *n, enum reason reason);
/** /**
* Pushes the latest notification of history to the displayed queue * Pushes the latest notification of history to the displayed queue
@ -110,7 +110,7 @@ void queues_history_pop(void);
* *
* @param n (transfer full) The notification to push to history * @param n (transfer full) The notification to push to history
*/ */
void queues_history_push(notification *n); void queues_history_push(struct notification *n);
/** /**
* Push all waiting and displayed notifications to history * Push all waiting and displayed notifications to history

View File

@ -10,7 +10,7 @@
/* /*
* Apply rule to notification. * Apply rule to notification.
*/ */
void rule_apply(rule_t *r, notification *n) void rule_apply(struct rule *r, struct notification *n)
{ {
if (r->timeout != -1) if (r->timeout != -1)
n->timeout = r->timeout; n->timeout = r->timeout;
@ -50,10 +50,10 @@ void rule_apply(rule_t *r, notification *n)
/* /*
* Check all rules if they match n and apply. * Check all rules if they match n and apply.
*/ */
void rule_apply_all(notification *n) void rule_apply_all(struct notification *n)
{ {
for (GSList *iter = rules; iter; iter = iter->next) { for (GSList *iter = rules; iter; iter = iter->next) {
rule_t *r = iter->data; struct rule *r = iter->data;
if (rule_matches_notification(r, n)) { if (rule_matches_notification(r, n)) {
rule_apply(r, n); rule_apply(r, n);
} }
@ -63,7 +63,7 @@ void rule_apply_all(notification *n)
/* /*
* Initialize rule with default values. * Initialize rule with default values.
*/ */
void rule_init(rule_t *r) void rule_init(struct rule *r)
{ {
r->name = NULL; r->name = NULL;
r->appname = NULL; r->appname = NULL;
@ -89,7 +89,7 @@ void rule_init(rule_t *r)
/* /*
* Check whether rule should be applied to n. * Check whether rule should be applied to n.
*/ */
bool rule_matches_notification(rule_t *r, notification *n) bool rule_matches_notification(struct rule *r, struct notification *n)
{ {
return ( (!r->appname || (n->appname && !fnmatch(r->appname, n->appname, 0))) return ( (!r->appname || (n->appname && !fnmatch(r->appname, n->appname, 0)))
&& (!r->summary || (n->summary && !fnmatch(r->summary, n->summary, 0))) && (!r->summary || (n->summary && !fnmatch(r->summary, n->summary, 0)))

View File

@ -8,7 +8,7 @@
#include "notification.h" #include "notification.h"
#include "settings.h" #include "settings.h"
typedef struct _rule_t { struct rule {
char *name; char *name;
/* filters */ /* filters */
char *appname; char *appname;
@ -32,14 +32,14 @@ typedef struct _rule_t {
const char *format; const char *format;
const char *script; const char *script;
enum behavior_fullscreen fullscreen; enum behavior_fullscreen fullscreen;
} rule_t; };
extern GSList *rules; extern GSList *rules;
void rule_init(rule_t *r); void rule_init(struct rule *r);
void rule_apply(rule_t *r, notification *n); void rule_apply(struct rule *r, struct notification *n);
void rule_apply_all(notification *n); void rule_apply_all(struct notification *n);
bool rule_matches_notification(rule_t *r, notification *n); bool rule_matches_notification(struct rule *r, struct notification *n);
#endif #endif
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

View File

@ -19,7 +19,7 @@
#include "utils.h" #include "utils.h"
#include "x11/x.h" #include "x11/x.h"
settings_t settings; struct settings settings;
static void parse_follow_mode(const char *mode) static void parse_follow_mode(const char *mode)
{ {
@ -219,11 +219,11 @@ void load_settings(char *cmdline_config_path)
if (strlen(c) == 0) { if (strlen(c) == 0) {
settings.ellipsize = defaults.ellipsize; settings.ellipsize = defaults.ellipsize;
} else if (strcmp(c, "start") == 0) { } else if (strcmp(c, "start") == 0) {
settings.ellipsize = start; settings.ellipsize = ELLIPSE_START;
} else if (strcmp(c, "middle") == 0) { } else if (strcmp(c, "middle") == 0) {
settings.ellipsize = middle; settings.ellipsize = ELLIPSE_MIDDLE;
} else if (strcmp(c, "end") == 0) { } else if (strcmp(c, "end") == 0) {
settings.ellipsize = end; settings.ellipsize = ELLIPSE_END;
} else { } else {
LOG_W("Unknown ellipsize value: '%s'", c); LOG_W("Unknown ellipsize value: '%s'", c);
settings.ellipsize = defaults.ellipsize; settings.ellipsize = defaults.ellipsize;
@ -320,11 +320,11 @@ void load_settings(char *cmdline_config_path)
if (strlen(c) > 0) { if (strlen(c) > 0) {
if (strcmp(c, "left") == 0) if (strcmp(c, "left") == 0)
settings.align = left; settings.align = ALIGN_LEFT;
else if (strcmp(c, "center") == 0) else if (strcmp(c, "center") == 0)
settings.align = center; settings.align = ALIGN_CENTER;
else if (strcmp(c, "right") == 0) else if (strcmp(c, "right") == 0)
settings.align = right; settings.align = ALIGN_RIGHT;
else else
LOG_W("Unknown alignment value: '%s'", c); LOG_W("Unknown alignment value: '%s'", c);
g_free(c); g_free(c);
@ -457,11 +457,11 @@ void load_settings(char *cmdline_config_path)
if (strlen(c) > 0) { if (strlen(c) > 0) {
if (strcmp(c, "left") == 0) if (strcmp(c, "left") == 0)
settings.icon_position = icons_left; settings.icon_position = ICON_LEFT;
else if (strcmp(c, "right") == 0) else if (strcmp(c, "right") == 0)
settings.icon_position = icons_right; settings.icon_position = ICON_RIGHT;
else if (strcmp(c, "off") == 0) else if (strcmp(c, "off") == 0)
settings.icon_position = icons_off; settings.icon_position = ICON_OFF;
else else
LOG_W("Unknown icon position: '%s'", c); LOG_W("Unknown icon position: '%s'", c);
g_free(c); g_free(c);
@ -727,16 +727,16 @@ void load_settings(char *cmdline_config_path)
continue; continue;
/* check for existing rule with same name */ /* check for existing rule with same name */
rule_t *r = NULL; struct rule *r = NULL;
for (GSList *iter = rules; iter; iter = iter->next) { for (GSList *iter = rules; iter; iter = iter->next) {
rule_t *match = iter->data; struct rule *match = iter->data;
if (match->name && if (match->name &&
strcmp(match->name, cur_section) == 0) strcmp(match->name, cur_section) == 0)
r = match; r = match;
} }
if (!r) { if (!r) {
r = g_malloc(sizeof(rule_t)); r = g_malloc(sizeof(struct rule));
rule_init(r); rule_init(r);
rules = g_slist_insert(rules, r, -1); rules = g_slist_insert(rules, r, -1);
} }

View File

@ -6,9 +6,9 @@
#include "x11/x.h" #include "x11/x.h"
enum alignment { left, center, right }; enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT };
enum ellipsize { start, middle, end }; enum ellipsize { ELLIPSE_START, ELLIPSE_MIDDLE, ELLIPSE_END };
enum icon_position_t { icons_left, icons_right, icons_off }; enum icon_position { ICON_LEFT, ICON_RIGHT, ICON_OFF };
enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM }; enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM };
enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD };
enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL }; enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL };
@ -26,7 +26,7 @@ struct geometry {
}; };
typedef struct _settings { struct settings {
bool print_notifications; bool print_notifications;
bool per_monitor_dpi; bool per_monitor_dpi;
enum markup_mode markup; enum markup_mode markup;
@ -75,23 +75,23 @@ typedef struct _settings {
char *dmenu; char *dmenu;
char **dmenu_cmd; char **dmenu_cmd;
char *browser; char *browser;
enum icon_position_t icon_position; enum icon_position icon_position;
int max_icon_size; int max_icon_size;
char *icon_path; char *icon_path;
enum follow_mode f_mode; enum follow_mode f_mode;
bool always_run_script; bool always_run_script;
keyboard_shortcut close_ks; struct keyboard_shortcut close_ks;
keyboard_shortcut close_all_ks; struct keyboard_shortcut close_all_ks;
keyboard_shortcut history_ks; struct keyboard_shortcut history_ks;
keyboard_shortcut context_ks; struct keyboard_shortcut context_ks;
bool force_xinerama; bool force_xinerama;
int corner_radius; int corner_radius;
enum mouse_action mouse_left_click; enum mouse_action mouse_left_click;
enum mouse_action mouse_middle_click; enum mouse_action mouse_middle_click;
enum mouse_action mouse_right_click; enum mouse_action mouse_right_click;
} settings_t; };
extern settings_t settings; extern struct settings settings;
void load_settings(char *cmdline_config_path); void load_settings(char *cmdline_config_path);

View File

@ -19,7 +19,7 @@
#include "src/settings.h" #include "src/settings.h"
#include "x.h" #include "x.h"
screen_info *screens; struct screen_info *screens;
int screens_len; int screens_len;
bool dunst_follow_errored = false; bool dunst_follow_errored = false;
@ -80,9 +80,9 @@ void alloc_screen_ar(int n)
assert(n > 0); assert(n > 0);
if (n <= screens_len) return; if (n <= screens_len) return;
screens = g_realloc(screens, n * sizeof(screen_info)); screens = g_realloc(screens, n * sizeof(struct screen_info));
memset(screens, 0, n * sizeof(screen_info)); memset(screens, 0, n * sizeof(struct screen_info));
screens_len = n; screens_len = n;
} }
@ -137,7 +137,7 @@ void randr_update(void)
XRRFreeMonitors(m); XRRFreeMonitors(m);
} }
static int autodetect_dpi(screen_info *scr) static int autodetect_dpi(struct screen_info *scr)
{ {
return (double)scr->h * 25.4 / (double)scr->mmh; return (double)scr->h * 25.4 / (double)scr->mmh;
} }
@ -278,7 +278,7 @@ bool window_is_fullscreen(Window window)
* Select the screen on which the Window * Select the screen on which the Window
* should be displayed. * should be displayed.
*/ */
screen_info *get_active_screen(void) struct screen_info *get_active_screen(void)
{ {
int ret = 0; int ret = 0;
if (settings.monitor > 0 && settings.monitor < screens_len) { if (settings.monitor > 0 && settings.monitor < screens_len) {
@ -351,7 +351,7 @@ sc_cleanup:
return &screens[ret]; return &screens[ret];
} }
double get_dpi_for_screen(screen_info *scr) double get_dpi_for_screen(struct screen_info *scr)
{ {
double dpi = 0; double dpi = 0;
if ((!settings.force_xinerama && settings.per_monitor_dpi && if ((!settings.force_xinerama && settings.per_monitor_dpi &&

View File

@ -7,20 +7,20 @@
#define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh)) #define INRECT(x,y,rx,ry,rw,rh) ((x) >= (rx) && (x) < (rx)+(rw) && (y) >= (ry) && (y) < (ry)+(rh))
typedef struct { struct screen_info {
int id; int id;
int x; int x;
int y; int y;
unsigned int h; unsigned int h;
unsigned int mmh; unsigned int mmh;
unsigned int w; unsigned int w;
} screen_info; };
void init_screens(void); void init_screens(void);
void screen_check_event(XEvent event); void screen_check_event(XEvent event);
screen_info *get_active_screen(void); struct screen_info *get_active_screen(void);
double get_dpi_for_screen(screen_info *scr); double get_dpi_for_screen(struct screen_info *scr);
/** /**
* Find the currently focused window and check if it's in * Find the currently focused window and check if it's in

View File

@ -46,24 +46,24 @@ struct window_x11 {
struct x11_source { struct x11_source {
GSource source; GSource source;
window_x11 *win; struct window_x11 *win;
}; };
xctx_t xctx; struct x_context xctx;
bool dunst_grab_errored = false; bool dunst_grab_errored = false;
static bool fullscreen_last = false; static bool fullscreen_last = false;
static void x_shortcut_init(keyboard_shortcut *ks); static void x_shortcut_init(struct keyboard_shortcut *ks);
static int x_shortcut_grab(keyboard_shortcut *ks); static int x_shortcut_grab(struct keyboard_shortcut *ks);
static void x_shortcut_ungrab(keyboard_shortcut *ks); static void x_shortcut_ungrab(struct keyboard_shortcut *ks);
/* FIXME refactor setup teardown handlers into one setup and one teardown */ /* FIXME refactor setup teardown handlers into one setup and one teardown */
static void x_shortcut_setup_error_handler(void); static void x_shortcut_setup_error_handler(void);
static int x_shortcut_tear_down_error_handler(void); static int x_shortcut_tear_down_error_handler(void);
static void setopacity(Window win, unsigned long opacity); static void setopacity(Window win, unsigned long opacity);
static void x_handle_click(XEvent ev); static void x_handle_click(XEvent ev);
static void x_win_move(window_x11 *win, int x, int y, int width, int height) static void x_win_move(struct window_x11 *win, int x, int y, int width, int height)
{ {
/* move and resize */ /* move and resize */
if (x != win->dim.x || y != win->dim.y) { if (x != win->dim.x || y != win->dim.y) {
@ -81,7 +81,7 @@ static void x_win_move(window_x11 *win, int x, int y, int width, int height)
} }
} }
static void x_win_round_corners(window_x11 *win, const int rad) static void x_win_round_corners(struct window_x11 *win, const int rad)
{ {
const int width = win->dim.w; const int width = win->dim.w;
const int height = win->dim.h; const int height = win->dim.h;
@ -148,7 +148,7 @@ static void x_win_round_corners(window_x11 *win, const int rad)
win->xwin, ShapeNotifyMask); win->xwin, ShapeNotifyMask);
} }
void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimensions *dim) void x_display_surface(cairo_surface_t *srf, struct window_x11 *win, const struct dimensions *dim)
{ {
x_win_move(win, dim->x, dim->y, dim->w, dim->h); x_win_move(win, dim->x, dim->y, dim->w, dim->h);
cairo_xlib_surface_set_size(win->root_surface, dim->w, dim->h); cairo_xlib_surface_set_size(win->root_surface, dim->w, dim->h);
@ -164,12 +164,12 @@ void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimen
} }
bool x_win_visible(window_x11 *win) bool x_win_visible(struct window_x11 *win)
{ {
return win->visible; return win->visible;
} }
cairo_t* x_win_get_context(window_x11 *win) cairo_t* x_win_get_context(struct window_x11 *win)
{ {
return win->c_ctx; return win->c_ctx;
} }
@ -266,10 +266,10 @@ gboolean x_mainloop_fd_check(GSource *source)
*/ */
gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
{ {
window_x11 *win = ((struct x11_source*) source)->win; struct window_x11 *win = ((struct x11_source*) source)->win;
bool fullscreen_now; bool fullscreen_now;
screen_info *scr; struct screen_info *scr;
XEvent ev; XEvent ev;
unsigned int state; unsigned int state;
while (XPending(xctx.dpy) > 0) { while (XPending(xctx.dpy) > 0) {
@ -411,7 +411,7 @@ static void x_handle_click(XEvent ev)
if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT) { if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT) {
int y = settings.separator_height; int y = settings.separator_height;
notification *n = NULL; struct notification *n = NULL;
int first = true; int first = true;
for (const GList *iter = queues_get_displayed(); iter; for (const GList *iter = queues_get_displayed(); iter;
iter = iter->next) { iter = iter->next) {
@ -571,7 +571,7 @@ static void x_set_wm(Window win)
PropModeReplace, (unsigned char *) data, 1L); PropModeReplace, (unsigned char *) data, 1L);
} }
GSource* x_win_reg_source(window_x11 *win) GSource* x_win_reg_source(struct window_x11 *win)
{ {
// Static is necessary here because glib keeps the pointer and we need // Static is necessary here because glib keeps the pointer and we need
// to keep the reference alive. // to keep the reference alive.
@ -599,9 +599,9 @@ GSource* x_win_reg_source(window_x11 *win)
/* /*
* Setup the window * Setup the window
*/ */
window_x11 *x_win_create(void) struct window_x11 *x_win_create(void)
{ {
window_x11 *win = g_malloc0(sizeof(window_x11)); struct window_x11 *win = g_malloc0(sizeof(struct window_x11));
Window root; Window root;
XSetWindowAttributes wa; XSetWindowAttributes wa;
@ -614,7 +614,7 @@ window_x11 *x_win_create(void)
ExposureMask | KeyPressMask | VisibilityChangeMask | ExposureMask | KeyPressMask | VisibilityChangeMask |
ButtonReleaseMask | FocusChangeMask| StructureNotifyMask; ButtonReleaseMask | FocusChangeMask| StructureNotifyMask;
screen_info *scr = get_active_screen(); struct screen_info *scr = get_active_screen();
win->xwin = XCreateWindow(xctx.dpy, win->xwin = XCreateWindow(xctx.dpy,
root, root,
scr->x, scr->x,
@ -651,7 +651,7 @@ window_x11 *x_win_create(void)
return win; return win;
} }
void x_win_destroy(window_x11 *win) void x_win_destroy(struct window_x11 *win)
{ {
g_source_destroy(win->esrc); g_source_destroy(win->esrc);
g_source_unref(win->esrc); g_source_unref(win->esrc);
@ -666,7 +666,7 @@ void x_win_destroy(window_x11 *win)
/* /*
* Show the window and grab shortcuts. * Show the window and grab shortcuts.
*/ */
void x_win_show(window_x11 *win) void x_win_show(struct window_x11 *win)
{ {
/* window is already mapped or there's nothing to show */ /* window is already mapped or there's nothing to show */
if (win->visible || queues_length_displayed() == 0) { if (win->visible || queues_length_displayed() == 0) {
@ -699,7 +699,7 @@ void x_win_show(window_x11 *win)
/* /*
* Hide the window and ungrab unused keyboard_shortcuts * Hide the window and ungrab unused keyboard_shortcuts
*/ */
void x_win_hide(window_x11 *win) void x_win_hide(struct window_x11 *win)
{ {
x_shortcut_ungrab(&settings.close_ks); x_shortcut_ungrab(&settings.close_ks);
x_shortcut_ungrab(&settings.close_all_ks); x_shortcut_ungrab(&settings.close_all_ks);
@ -777,7 +777,7 @@ static int x_shortcut_tear_down_error_handler(void)
/* /*
* Grab the given keyboard shortcut. * Grab the given keyboard shortcut.
*/ */
static int x_shortcut_grab(keyboard_shortcut *ks) static int x_shortcut_grab(struct keyboard_shortcut *ks)
{ {
if (!ks->is_valid) if (!ks->is_valid)
return 1; return 1;
@ -814,7 +814,7 @@ static int x_shortcut_grab(keyboard_shortcut *ks)
/* /*
* Ungrab the given keyboard shortcut. * Ungrab the given keyboard shortcut.
*/ */
static void x_shortcut_ungrab(keyboard_shortcut *ks) static void x_shortcut_ungrab(struct keyboard_shortcut *ks)
{ {
Window root; Window root;
root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)); root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy));
@ -827,7 +827,7 @@ static void x_shortcut_ungrab(keyboard_shortcut *ks)
/* /*
* Initialize the keyboard shortcut. * Initialize the keyboard shortcut.
*/ */
static void x_shortcut_init(keyboard_shortcut *ks) static void x_shortcut_init(struct keyboard_shortcut *ks)
{ {
if (!ks|| !ks->str) if (!ks|| !ks->str)
return; return;

View File

@ -13,18 +13,18 @@
#include "screen.h" #include "screen.h"
typedef struct _keyboard_shortcut { struct keyboard_shortcut {
const char *str; const char *str;
KeyCode code; KeyCode code;
KeySym sym; KeySym sym;
KeySym mask; KeySym mask;
bool is_valid; bool is_valid;
} keyboard_shortcut; };
// Cyclical dependency // Cyclical dependency
#include "src/settings.h" #include "src/settings.h"
typedef struct window_x11 window_x11; struct window_x11;
struct dimensions { struct dimensions {
int x; int x;
@ -35,31 +35,31 @@ struct dimensions {
int corner_radius; int corner_radius;
}; };
typedef struct _xctx { struct x_context {
Display *dpy; Display *dpy;
const char *colors[3][3]; const char *colors[3][3];
XScreenSaverInfo *screensaver_info; XScreenSaverInfo *screensaver_info;
} xctx_t; };
typedef struct _color_t { struct color {
double r; double r;
double g; double g;
double b; double b;
} color_t; };
extern xctx_t xctx; extern struct x_context xctx;
/* window */ /* window */
window_x11 *x_win_create(void); struct window_x11 *x_win_create(void);
void x_win_destroy(window_x11 *win); void x_win_destroy(struct window_x11 *win);
void x_win_show(window_x11 *win); void x_win_show(struct window_x11 *win);
void x_win_hide(window_x11 *win); void x_win_hide(struct window_x11 *win);
void x_display_surface(cairo_surface_t *srf, window_x11 *win, const struct dimensions *dim); void x_display_surface(cairo_surface_t *srf, struct window_x11 *win, const struct dimensions *dim);
bool x_win_visible(window_x11 *win); bool x_win_visible(struct window_x11 *win);
cairo_t* x_win_get_context(window_x11 *win); cairo_t* x_win_get_context(struct window_x11 *win);
/* X misc */ /* X misc */
bool x_is_idle(void); bool x_is_idle(void);

View File

@ -5,8 +5,9 @@
#include <glib.h> #include <glib.h>
TEST test_notification_is_duplicate_field(char **field, notification *a, TEST test_notification_is_duplicate_field(char **field,
notification *b) struct notification *a,
struct notification *b)
{ {
ASSERT(notification_is_duplicate(a, b)); ASSERT(notification_is_duplicate(a, b));
char *tmp = *field; char *tmp = *field;
@ -19,9 +20,9 @@ TEST test_notification_is_duplicate_field(char **field, notification *a,
TEST test_notification_is_duplicate(void *notifications) TEST test_notification_is_duplicate(void *notifications)
{ {
notification **n = (notification**)notifications; struct notification **n = (struct notification**)notifications;
notification *a = n[0]; struct notification *a = n[0];
notification *b = n[1]; struct notification *b = n[1];
ASSERT(notification_is_duplicate(a, b)); ASSERT(notification_is_duplicate(a, b));
@ -32,26 +33,26 @@ TEST test_notification_is_duplicate(void *notifications)
ASSERT(notification_is_duplicate(a, b)); ASSERT(notification_is_duplicate(a, b));
char *tmp = b->icon; char *tmp = b->icon;
enum icon_position_t icon_setting_tmp = settings.icon_position; enum icon_position icon_setting_tmp = settings.icon_position;
b->icon = "Test1"; b->icon = "Test1";
settings.icon_position = icons_off; settings.icon_position = ICON_OFF;
ASSERT(notification_is_duplicate(a, b)); ASSERT(notification_is_duplicate(a, b));
//Setting pointer to a random value since we are checking for null //Setting pointer to a random value since we are checking for null
b->raw_icon = (RawImage*)0xff; b->raw_icon = (struct raw_image*)0xff;
ASSERT(notification_is_duplicate(a, b)); ASSERT(notification_is_duplicate(a, b));
b->raw_icon = NULL; b->raw_icon = NULL;
settings.icon_position = icons_left; settings.icon_position = ICON_LEFT;
ASSERT_FALSE(notification_is_duplicate(a, b)); ASSERT_FALSE(notification_is_duplicate(a, b));
b->raw_icon = (RawImage*)0xff; b->raw_icon = (struct raw_image*)0xff;
ASSERT_FALSE(notification_is_duplicate(a, b)); ASSERT_FALSE(notification_is_duplicate(a, b));
b->raw_icon = NULL; b->raw_icon = NULL;
settings.icon_position = icons_right; settings.icon_position = ICON_RIGHT;
ASSERT_FALSE(notification_is_duplicate(a, b)); ASSERT_FALSE(notification_is_duplicate(a, b));
b->raw_icon = (RawImage*)0xff; b->raw_icon = (struct raw_image*)0xff;
ASSERT_FALSE(notification_is_duplicate(a, b)); ASSERT_FALSE(notification_is_duplicate(a, b));
b->raw_icon = NULL; b->raw_icon = NULL;
@ -102,18 +103,18 @@ SUITE(suite_notification)
cmdline_load(0, NULL); cmdline_load(0, NULL);
load_settings("data/dunstrc.default"); load_settings("data/dunstrc.default");
notification *a = notification_create(); struct notification *a = notification_create();
a->appname = "Test"; a->appname = "Test";
a->summary = "Summary"; a->summary = "Summary";
a->body = "Body"; a->body = "Body";
a->icon = "Icon"; a->icon = "Icon";
a->urgency = URG_NORM; a->urgency = URG_NORM;
notification *b = notification_create(); struct notification *b = notification_create();
memcpy(b, a, sizeof(*b)); memcpy(b, a, sizeof(*b));
//2 equal notifications to be passed for duplicate checking, //2 equal notifications to be passed for duplicate checking,
notification *n[2] = {a, b}; struct notification *n[2] = {a, b};
RUN_TEST1(test_notification_is_duplicate, (void*) n); RUN_TEST1(test_notification_is_duplicate, (void*) n);
g_free(a); g_free(a);