From c944949e362f63dc9710a5171305f68c2061c7e7 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:13 +0200 Subject: [PATCH 01/12] Pack types from x.c into structs --- src/draw.c | 65 ++++++++++++++++++++++++------------------------ src/draw.h | 2 +- src/settings.h | 8 +++--- src/x11/screen.c | 12 ++++----- src/x11/screen.h | 8 +++--- src/x11/x.c | 44 ++++++++++++++++---------------- src/x11/x.h | 30 +++++++++++----------- 7 files changed, 85 insertions(+), 84 deletions(-) diff --git a/src/draw.c b/src/draw.c index 6d40a02..6b1971a 100644 --- a/src/draw.c +++ b/src/draw.c @@ -18,18 +18,18 @@ #include "queues.h" #include "x11/x.h" -typedef struct { +struct colored_layout { PangoLayout *l; - color_t fg; - color_t bg; - color_t frame; + struct color fg; + struct color bg; + struct color frame; char *text; PangoAttrList *attr; cairo_surface_t *icon; const notification *n; -} colored_layout; +}; -window_x11 *win; +struct window_x11 *win; PangoFontDescription *pango_fdesc; @@ -41,9 +41,9 @@ void draw_setup(void) pango_fdesc = pango_font_description_from_string(settings.font); } -static color_t color_hex_to_double(int hexValue) +static struct color color_hex_to_double(int hexValue) { - color_t color; + struct color color; color.r = ((hexValue >> 16) & 0xFF) / 255.0; color.g = ((hexValue >> 8) & 0xFF) / 255.0; color.b = ((hexValue) & 0xFF) / 255.0; @@ -51,7 +51,7 @@ static color_t color_hex_to_double(int hexValue) return color; } -static color_t string_to_color(const char *str) +static struct color string_to_color(const char *str) { char *end; long int val = strtol(str+1, &end, 16); @@ -73,10 +73,10 @@ static double color_apply_delta(double base, double delta) 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; - color_t color = bg; + struct color color = bg; /* do we need to darken or brighten the colors? */ bool darken = (bg.r + bg.g + bg.b) / 3 > 0.5; @@ -90,7 +90,8 @@ static color_t calculate_foreground_color(color_t bg) return color; } -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) { case SEP_FRAME: @@ -136,7 +137,7 @@ static void layout_setup_pango(PangoLayout *layout, int width) static void free_colored_layout(void *data) { - colored_layout *cl = data; + struct colored_layout *cl = data; g_object_unref(cl->l); pango_attr_list_unref(cl->attr); g_free(cl->text); @@ -153,7 +154,7 @@ static struct dimensions calculate_dimensions(GSList *layouts) { struct dimensions dim = { 0 }; - screen_info *scr = get_active_screen(); + struct screen_info *scr = get_active_screen(); if (have_dynamic_width()) { /* dynamic width */ dim.w = 0; @@ -176,7 +177,7 @@ static struct dimensions calculate_dimensions(GSList *layouts) int text_width = 0, total_width = 0; for (GSList *iter = layouts; iter; iter = iter->next) { - colored_layout *cl = iter->data; + struct colored_layout *cl = iter->data; int w=0,h=0; pango_layout_get_pixel_size(cl->l, &w, &h); if (cl->icon) { @@ -233,7 +234,7 @@ static struct dimensions calculate_dimensions(GSList *layouts) 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); pango_cairo_context_set_resolution(context, get_dpi_for_screen(screen)); @@ -245,9 +246,9 @@ static PangoLayout *layout_create(cairo_t *c) 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 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); if (!settings.word_wrap) { @@ -301,19 +302,19 @@ static colored_layout *layout_init_shared(cairo_t *c, const notification *n) 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 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->attr = NULL; pango_layout_set_text(cl->l, cl->text, -1); return cl; } -static colored_layout *layout_from_notification(cairo_t *c, notification *n) +static struct colored_layout *layout_from_notification(cairo_t *c, notification *n) { - colored_layout *cl = layout_init_shared(c, n); + struct colored_layout *cl = layout_init_shared(c, n); /* markup */ GError *err = NULL; @@ -380,7 +381,7 @@ static void free_layouts(GSList *layouts) 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_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, - colored_layout *cl, - colored_layout *cl_next, + struct colored_layout *cl, + struct colored_layout *cl_next, int y, int width, int height, @@ -492,7 +493,7 @@ static cairo_surface_t *render_background(cairo_surface_t *srf, if ( settings.sep_color != SEP_FRAME && settings.separator_height > 0 && !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_rectangle(c, settings.frame_width, y + height, width, settings.separator_height); @@ -508,7 +509,7 @@ static cairo_surface_t *render_background(cairo_surface_t *srf, 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); int h_text; @@ -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, - colored_layout *cl, - colored_layout *cl_next, + struct colored_layout *cl, + struct colored_layout *cl_next, struct dimensions dim, bool first, 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) { - screen_info *scr = get_active_screen(); + struct screen_info *scr = get_active_screen(); if (ret_x) { if (settings.geometry.negative_x) { @@ -624,8 +625,8 @@ void draw(void) bool first = true; for (GSList *iter = layouts; iter; iter = iter->next) { - colored_layout *cl_this = iter->data; - colored_layout *cl_next = iter->next ? iter->next->data : NULL; + struct colored_layout *cl_this = iter->data; + struct colored_layout *cl_next = iter->next ? iter->next->data : NULL; dim = layout_render(image_surface, cl_this, cl_next, dim, first, !cl_next); diff --git a/src/draw.h b/src/draw.h index 3a3ea88..581d0ca 100644 --- a/src/draw.h +++ b/src/draw.h @@ -2,7 +2,7 @@ #define DUNST_DRAW_H #include "src/x11/x.h" -extern window_x11 *win; // Temporary +extern struct window_x11 *win; // Temporary void draw_setup(void); diff --git a/src/settings.h b/src/settings.h index 272e079..f35a11c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -80,10 +80,10 @@ typedef struct _settings { char *icon_path; enum follow_mode f_mode; bool always_run_script; - keyboard_shortcut close_ks; - keyboard_shortcut close_all_ks; - keyboard_shortcut history_ks; - keyboard_shortcut context_ks; + struct keyboard_shortcut close_ks; + struct keyboard_shortcut close_all_ks; + struct keyboard_shortcut history_ks; + struct keyboard_shortcut context_ks; bool force_xinerama; int corner_radius; enum mouse_action mouse_left_click; diff --git a/src/x11/screen.c b/src/x11/screen.c index 185a607..edf9838 100644 --- a/src/x11/screen.c +++ b/src/x11/screen.c @@ -19,7 +19,7 @@ #include "src/settings.h" #include "x.h" -screen_info *screens; +struct screen_info *screens; int screens_len; bool dunst_follow_errored = false; @@ -80,9 +80,9 @@ void alloc_screen_ar(int n) assert(n > 0); 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; } @@ -137,7 +137,7 @@ void randr_update(void) 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; } @@ -278,7 +278,7 @@ bool window_is_fullscreen(Window window) * Select the screen on which the Window * should be displayed. */ -screen_info *get_active_screen(void) +struct screen_info *get_active_screen(void) { int ret = 0; if (settings.monitor > 0 && settings.monitor < screens_len) { @@ -351,7 +351,7 @@ sc_cleanup: return &screens[ret]; } -double get_dpi_for_screen(screen_info *scr) +double get_dpi_for_screen(struct screen_info *scr) { double dpi = 0; if ((!settings.force_xinerama && settings.per_monitor_dpi && diff --git a/src/x11/screen.h b/src/x11/screen.h index 1188299..5ff2e69 100644 --- a/src/x11/screen.h +++ b/src/x11/screen.h @@ -7,20 +7,20 @@ #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 x; int y; unsigned int h; unsigned int mmh; unsigned int w; -} screen_info; +}; void init_screens(void); void screen_check_event(XEvent event); -screen_info *get_active_screen(void); -double get_dpi_for_screen(screen_info *scr); +struct screen_info *get_active_screen(void); +double get_dpi_for_screen(struct screen_info *scr); /** * Find the currently focused window and check if it's in diff --git a/src/x11/x.c b/src/x11/x.c index bf50a73..52430f8 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -46,24 +46,24 @@ struct window_x11 { struct x11_source { GSource source; - window_x11 *win; + struct window_x11 *win; }; -xctx_t xctx; +struct x_context xctx; bool dunst_grab_errored = false; static bool fullscreen_last = false; -static void x_shortcut_init(keyboard_shortcut *ks); -static int x_shortcut_grab(keyboard_shortcut *ks); -static void x_shortcut_ungrab(keyboard_shortcut *ks); +static void x_shortcut_init(struct keyboard_shortcut *ks); +static int x_shortcut_grab(struct keyboard_shortcut *ks); +static void x_shortcut_ungrab(struct keyboard_shortcut *ks); /* FIXME refactor setup teardown handlers into one setup and one teardown */ static void x_shortcut_setup_error_handler(void); static int x_shortcut_tear_down_error_handler(void); static void setopacity(Window win, unsigned long opacity); 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 */ 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 height = win->dim.h; @@ -148,7 +148,7 @@ static void x_win_round_corners(window_x11 *win, const int rad) 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); 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; } -cairo_t* x_win_get_context(window_x11 *win) +cairo_t* x_win_get_context(struct window_x11 *win) { 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) { - window_x11 *win = ((struct x11_source*) source)->win; + struct window_x11 *win = ((struct x11_source*) source)->win; bool fullscreen_now; - screen_info *scr; + struct screen_info *scr; XEvent ev; unsigned int state; while (XPending(xctx.dpy) > 0) { @@ -571,7 +571,7 @@ static void x_set_wm(Window win) 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 // to keep the reference alive. @@ -599,9 +599,9 @@ GSource* x_win_reg_source(window_x11 *win) /* * 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; XSetWindowAttributes wa; @@ -614,7 +614,7 @@ window_x11 *x_win_create(void) ExposureMask | KeyPressMask | VisibilityChangeMask | ButtonReleaseMask | FocusChangeMask| StructureNotifyMask; - screen_info *scr = get_active_screen(); + struct screen_info *scr = get_active_screen(); win->xwin = XCreateWindow(xctx.dpy, root, scr->x, @@ -651,7 +651,7 @@ window_x11 *x_win_create(void) return win; } -void x_win_destroy(window_x11 *win) +void x_win_destroy(struct window_x11 *win) { g_source_destroy(win->esrc); g_source_unref(win->esrc); @@ -666,7 +666,7 @@ void x_win_destroy(window_x11 *win) /* * 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 */ 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 */ -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_all_ks); @@ -777,7 +777,7 @@ static int x_shortcut_tear_down_error_handler(void) /* * 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) return 1; @@ -814,7 +814,7 @@ static int x_shortcut_grab(keyboard_shortcut *ks) /* * Ungrab the given keyboard shortcut. */ -static void x_shortcut_ungrab(keyboard_shortcut *ks) +static void x_shortcut_ungrab(struct keyboard_shortcut *ks) { Window root; root = RootWindow(xctx.dpy, DefaultScreen(xctx.dpy)); @@ -827,7 +827,7 @@ static void x_shortcut_ungrab(keyboard_shortcut *ks) /* * 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) return; diff --git a/src/x11/x.h b/src/x11/x.h index 6974ca1..3a644cf 100644 --- a/src/x11/x.h +++ b/src/x11/x.h @@ -13,18 +13,18 @@ #include "screen.h" -typedef struct _keyboard_shortcut { +struct keyboard_shortcut { const char *str; KeyCode code; KeySym sym; KeySym mask; bool is_valid; -} keyboard_shortcut; +}; // Cyclical dependency #include "src/settings.h" -typedef struct window_x11 window_x11; +struct window_x11; struct dimensions { int x; @@ -35,31 +35,31 @@ struct dimensions { int corner_radius; }; -typedef struct _xctx { +struct x_context { Display *dpy; const char *colors[3][3]; XScreenSaverInfo *screensaver_info; -} xctx_t; +}; -typedef struct _color_t { +struct color { double r; double g; double b; -} color_t; +}; -extern xctx_t xctx; +extern struct x_context xctx; /* window */ -window_x11 *x_win_create(void); -void x_win_destroy(window_x11 *win); +struct window_x11 *x_win_create(void); +void x_win_destroy(struct window_x11 *win); -void x_win_show(window_x11 *win); -void x_win_hide(window_x11 *win); +void x_win_show(struct 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); -cairo_t* x_win_get_context(window_x11 *win); +bool x_win_visible(struct window_x11 *win); +cairo_t* x_win_get_context(struct window_x11 *win); /* X misc */ bool x_is_idle(void); From a661b2bb85b28febbcdcc029b8c4d3d937e64b34 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:19 +0200 Subject: [PATCH 02/12] Pack settings related types into structs --- config.h | 2 +- src/settings.c | 2 +- src/settings.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index f0432f6..15c0c53 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,6 @@ /* see example dunstrc for additional explanations about these options */ -settings_t defaults = { +struct settings defaults = { .font = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*", .markup = MARKUP_NO, diff --git a/src/settings.c b/src/settings.c index 5d3fbff..d6e5834 100644 --- a/src/settings.c +++ b/src/settings.c @@ -19,7 +19,7 @@ #include "utils.h" #include "x11/x.h" -settings_t settings; +struct settings settings; static void parse_follow_mode(const char *mode) { diff --git a/src/settings.h b/src/settings.h index f35a11c..3c50490 100644 --- a/src/settings.h +++ b/src/settings.h @@ -26,7 +26,7 @@ struct geometry { }; -typedef struct _settings { +struct settings { bool print_notifications; bool per_monitor_dpi; enum markup_mode markup; @@ -89,9 +89,9 @@ typedef struct _settings { enum mouse_action mouse_left_click; enum mouse_action mouse_middle_click; enum mouse_action mouse_right_click; -} settings_t; +}; -extern settings_t settings; +extern struct settings settings; void load_settings(char *cmdline_config_path); From a4ebf4f4e65b3572eb341dd80ea44e4effa03b22 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:21 +0200 Subject: [PATCH 03/12] Pack option_parser.c types into structs --- src/option_parser.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/option_parser.c b/src/option_parser.c index df59030..0cb8354 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -12,22 +12,22 @@ #include "log.h" #include "utils.h" -typedef struct _entry_t { +struct entry { char *key; char *value; -} entry_t; +}; -typedef struct _section_t { +struct section { char *name; int entry_count; - entry_t *entries; -} section_t; + struct entry *entries; +}; static int section_count = 0; -static section_t *sections; +static struct section *sections; -static section_t *new_section(const char *name); -static section_t *get_section(const char *name); +static struct section *new_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 const char *get_value(const char *section, const char *key); 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); -section_t *new_section(const char *name) +struct section *new_section(const char *name) { for (int i = 0; i < section_count; i++) { if (!strcmp(name, sections[i].name)) { @@ -49,7 +49,7 @@ section_t *new_section(const char *name) } 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].entries = NULL; sections[section_count - 1].entry_count = 0; @@ -70,7 +70,7 @@ void free_ini(void) 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++) { 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) { - section_t *s = get_section(section_name); + struct section *s = get_section(section_name); if (!s) s = new_section(section_name); 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].value = clean_value(value); } const char *get_value(const char *section, const char *key) { - section_t *s = get_section(section); + struct section *s = get_section(section); if (!s) { return NULL; } From 8010f83286e5079d538c3fdbfa9887e7b41e7175 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:23 +0200 Subject: [PATCH 04/12] Pack Actions type into struct actions --- src/dbus.c | 2 +- src/notification.c | 2 +- src/notification.h | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 35fcc00..6196a1e 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -135,7 +135,7 @@ static notification *dbus_message_to_notification(const gchar *sender, GVariant notification *n = notification_create(); - n->actions = g_malloc0(sizeof(Actions)); + n->actions = g_malloc0(sizeof(struct actions)); n->dbus_client = g_strdup(sender); { diff --git a/src/notification.c b/src/notification.c index badd82b..cc7511d 100644 --- a/src/notification.c +++ b/src/notification.c @@ -186,7 +186,7 @@ int notification_is_duplicate(const notification *a, const notification *b) } /* see notification.h */ -void actions_free(Actions *a) +void actions_free(struct actions *a) { if (!a) return; diff --git a/src/notification.h b/src/notification.h index 74ddcb6..e6ef0ae 100644 --- a/src/notification.h +++ b/src/notification.h @@ -36,11 +36,11 @@ typedef struct _raw_image { unsigned char *data; } RawImage; -typedef struct _actions { +struct actions { char **actions; char *dmenu_str; gsize count; -} Actions; +}; typedef struct _notification { int id; @@ -59,7 +59,7 @@ typedef struct _notification { gint64 timestamp; /**< arrival time */ gint64 timeout; /**< time to display */ - Actions *actions; + struct actions *actions; enum markup_mode markup; const char *format; @@ -106,9 +106,9 @@ void notification_init(notification *n); /** * 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 From de0f0bf3d9dbb9f92c89fcd6dbfca03f5faae725 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:26 +0200 Subject: [PATCH 05/12] Pack type RawImage into raw_image struct --- src/dbus.c | 6 +++--- src/icon.c | 2 +- src/icon.h | 4 ++-- src/notification.c | 2 +- src/notification.h | 12 ++++++------ test/notification.c | 6 +++--- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 6196a1e..1a5379d 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -81,7 +81,7 @@ static void on_get_server_information(GDBusConnection *connection, const gchar *sender, const GVariant *parameters, 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, const gchar *sender, @@ -520,9 +520,9 @@ static void on_name_lost(GDBusConnection *connection, 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; gsize expected_len; diff --git a/src/icon.c b/src/icon.c index 9721961..4356a2b 100644 --- a/src/icon.c +++ b/src/icon.c @@ -126,7 +126,7 @@ GdkPixbuf *get_pixbuf_from_icon(const char *iconname) 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; diff --git a/src/icon.h b/src/icon.h index 2b3d92a..54aa3e4 100644 --- a/src/icon.h +++ b/src/icon.h @@ -26,9 +26,9 @@ GdkPixbuf *get_pixbuf_from_file(const char *filename); */ 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 diff --git a/src/notification.c b/src/notification.c index cc7511d..dbb1b10 100644 --- a/src/notification.c +++ b/src/notification.c @@ -197,7 +197,7 @@ void actions_free(struct actions *a) } /* see notification.h */ -void rawimage_free(RawImage *i) +void rawimage_free(struct raw_image *i) { if (!i) return; diff --git a/src/notification.h b/src/notification.h index e6ef0ae..55ed0d0 100644 --- a/src/notification.h +++ b/src/notification.h @@ -26,7 +26,7 @@ enum urgency { URG_MAX = 2, /**< Maximum value, useful for boundary checking */ }; -typedef struct _raw_image { +struct raw_image { int width; int height; int rowstride; @@ -34,7 +34,7 @@ typedef struct _raw_image { int bits_per_sample; int n_channels; unsigned char *data; -} RawImage; +}; struct actions { char **actions; @@ -53,7 +53,7 @@ typedef struct _notification { enum urgency urgency; 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 timestamp; /**< arrival time */ @@ -111,11 +111,11 @@ void notification_init(notification *n); 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. diff --git a/test/notification.c b/test/notification.c index a9c02d6..ba74fb8 100644 --- a/test/notification.c +++ b/test/notification.c @@ -39,19 +39,19 @@ TEST test_notification_is_duplicate(void *notifications) settings.icon_position = icons_off; ASSERT(notification_is_duplicate(a, b)); //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)); b->raw_icon = NULL; settings.icon_position = icons_left; 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)); b->raw_icon = NULL; settings.icon_position = icons_right; 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)); b->raw_icon = NULL; From 1fa1532d7f922b7f8457457309ce4b2b4e31f91d Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:28 +0200 Subject: [PATCH 06/12] Pack type rule_t into struct rule --- config.h | 2 +- src/rules.c | 8 ++++---- src/rules.h | 10 +++++----- src/settings.c | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/config.h b/config.h index 15c0c53..d2cf382 100644 --- a/config.h +++ b/config.h @@ -110,7 +110,7 @@ struct settings defaults = { }; -rule_t default_rules[] = { +struct rule default_rules[] = { /* name can be any unique string. It is used to identify * the rule in dunstrc to override it there */ diff --git a/src/rules.c b/src/rules.c index 47f452e..a97b03f 100644 --- a/src/rules.c +++ b/src/rules.c @@ -10,7 +10,7 @@ /* * Apply rule to notification. */ -void rule_apply(rule_t *r, notification *n) +void rule_apply(struct rule *r, notification *n) { if (r->timeout != -1) n->timeout = r->timeout; @@ -53,7 +53,7 @@ void rule_apply(rule_t *r, notification *n) void rule_apply_all(notification *n) { for (GSList *iter = rules; iter; iter = iter->next) { - rule_t *r = iter->data; + struct rule *r = iter->data; if (rule_matches_notification(r, n)) { rule_apply(r, n); } @@ -63,7 +63,7 @@ void rule_apply_all(notification *n) /* * Initialize rule with default values. */ -void rule_init(rule_t *r) +void rule_init(struct rule *r) { r->name = NULL; r->appname = NULL; @@ -89,7 +89,7 @@ void rule_init(rule_t *r) /* * Check whether rule should be applied to n. */ -bool rule_matches_notification(rule_t *r, notification *n) +bool rule_matches_notification(struct rule *r, notification *n) { return ( (!r->appname || (n->appname && !fnmatch(r->appname, n->appname, 0))) && (!r->summary || (n->summary && !fnmatch(r->summary, n->summary, 0))) diff --git a/src/rules.h b/src/rules.h index 0e22eb8..e2a26a6 100644 --- a/src/rules.h +++ b/src/rules.h @@ -8,7 +8,7 @@ #include "notification.h" #include "settings.h" -typedef struct _rule_t { +struct rule { char *name; /* filters */ char *appname; @@ -32,14 +32,14 @@ typedef struct _rule_t { const char *format; const char *script; enum behavior_fullscreen fullscreen; -} rule_t; +}; extern GSList *rules; -void rule_init(rule_t *r); -void rule_apply(rule_t *r, notification *n); +void rule_init(struct rule *r); +void rule_apply(struct rule *r, notification *n); void rule_apply_all(notification *n); -bool rule_matches_notification(rule_t *r, notification *n); +bool rule_matches_notification(struct rule *r, notification *n); #endif /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/settings.c b/src/settings.c index d6e5834..a2c38f4 100644 --- a/src/settings.c +++ b/src/settings.c @@ -727,16 +727,16 @@ void load_settings(char *cmdline_config_path) continue; /* check for existing rule with same name */ - rule_t *r = NULL; + struct rule *r = NULL; for (GSList *iter = rules; iter; iter = iter->next) { - rule_t *match = iter->data; + struct rule *match = iter->data; if (match->name && strcmp(match->name, cur_section) == 0) r = match; } if (!r) { - r = g_malloc(sizeof(rule_t)); + r = g_malloc(sizeof(struct rule)); rule_init(r); rules = g_slist_insert(rules, r, -1); } From bbbddad3a751d2da6848ac4ceb33db0acc5f5617 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:31 +0200 Subject: [PATCH 07/12] Use structs for notifications --- src/dbus.c | 10 +++++----- src/dbus.h | 4 ++-- src/draw.c | 10 +++++----- src/dunst.c | 2 +- src/icon.c | 2 +- src/icon.h | 2 +- src/menu.c | 6 +++--- src/notification.c | 36 +++++++++++++++++----------------- src/notification.h | 23 +++++++++++----------- src/queues.c | 47 ++++++++++++++++++++++----------------------- src/queues.h | 10 +++++----- src/rules.c | 6 +++--- src/rules.h | 6 +++--- src/x11/x.c | 2 +- test/notification.c | 17 ++++++++-------- 15 files changed, 92 insertions(+), 91 deletions(-) diff --git a/src/dbus.c b/src/dbus.c index 1a5379d..fb75b75 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -130,10 +130,10 @@ static void on_get_capabilities(GDBusConnection *connection, 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(struct actions)); n->dbus_client = g_strdup(sender); @@ -272,7 +272,7 @@ static void on_notify(GDBusConnection *connection, GVariant *parameters, 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); 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); } -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) { 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); GError *err = NULL; diff --git a/src/dbus.h b/src/dbus.h index bd5901f..217c74c 100644 --- a/src/dbus.h +++ b/src/dbus.h @@ -17,8 +17,8 @@ enum reason { int initdbus(void); void dbus_tear_down(int id); -void signal_notification_closed(notification *n, enum reason reason); -void signal_action_invoked(notification *n, const char *identifier); +void signal_notification_closed(struct notification *n, enum reason reason); +void signal_action_invoked(const struct notification *n, const char *identifier); #endif /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/draw.c b/src/draw.c index 6b1971a..cc64653 100644 --- a/src/draw.c +++ b/src/draw.c @@ -26,7 +26,7 @@ struct colored_layout { char *text; PangoAttrList *attr; cairo_surface_t *icon; - const notification *n; + const struct notification *n; }; struct window_x11 *win; @@ -246,7 +246,7 @@ static PangoLayout *layout_create(cairo_t *c) return layout; } -static struct 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) { struct colored_layout *cl = g_malloc(sizeof(struct colored_layout)); cl->l = layout_create(c); @@ -302,7 +302,7 @@ static struct colored_layout *layout_init_shared(cairo_t *c, const notification return cl; } -static struct 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) { struct colored_layout *cl = layout_init_shared(c, n); cl->text = g_strdup_printf("(%d more)", qlen); @@ -311,7 +311,7 @@ static struct colored_layout *layout_derive_xmore(cairo_t *c, const notification return cl; } -static struct colored_layout *layout_from_notification(cairo_t *c, notification *n) +static struct colored_layout *layout_from_notification(cairo_t *c, struct notification *n) { struct colored_layout *cl = layout_init_shared(c, n); @@ -354,7 +354,7 @@ static GSList *create_layouts(cairo_t *c) for (const GList *iter = queues_get_displayed(); iter; iter = iter->next) { - notification *n = iter->data; + struct notification *n = iter->data; notification_update_text_to_render(n); diff --git a/src/dunst.c b/src/dunst.c index 5abd86e..19032f4 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -161,7 +161,7 @@ int dunst_main(int argc, char *argv[]) guint int_src = g_unix_signal_add(SIGINT, quit_signal, NULL); if (settings.startup_notification) { - notification *n = notification_create(); + struct notification *n = notification_create(); n->id = 0; n->appname = g_strdup("dunst"); n->summary = g_strdup("startup"); diff --git a/src/icon.c b/src/icon.c index 4356a2b..8755585 100644 --- a/src/icon.c +++ b/src/icon.c @@ -143,7 +143,7 @@ GdkPixbuf *get_pixbuf_from_raw_image(const struct raw_image *raw_image) 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; diff --git a/src/icon.h b/src/icon.h index 54aa3e4..a93b8ae 100644 --- a/src/icon.h +++ b/src/icon.h @@ -36,7 +36,7 @@ GdkPixbuf *get_pixbuf_from_raw_image(const struct raw_image *raw_image); * * @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 /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/menu.c b/src/menu.c index a32d55c..d724cdd 100644 --- a/src/menu.c +++ b/src/menu.c @@ -135,7 +135,7 @@ void open_browser(const char *in) */ void invoke_action(const char *action) { - notification *invoked = NULL; + struct notification *invoked = NULL; char *action_identifier = NULL; char *appname_begin = strchr(action, '['); @@ -149,7 +149,7 @@ void invoke_action(const char *action) for (const GList *iter = queues_get_displayed(); iter; 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 (!n->actions) continue; @@ -201,7 +201,7 @@ void context_menu(void) for (const GList *iter = queues_get_displayed(); iter; iter = iter->next) { - notification *n = iter->data; + struct notification *n = iter->data; if (n->urls) dmenu_input = string_append(dmenu_input, n->urls, "\n"); diff --git a/src/notification.c b/src/notification.c index dbb1b10..6ea99a6 100644 --- a/src/notification.c +++ b/src/notification.c @@ -24,9 +24,9 @@ #include "utils.h" #include "x11/x.h" -static void notification_extract_urls(notification *n); -static void notification_format_message(notification *n); -static void notification_dmenu_string(notification *n); +static void notification_extract_urls(struct notification *n); +static void notification_format_message(struct notification *n); +static void notification_dmenu_string(struct notification *n); /* see notification.h */ 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 */ -void notification_print(notification *n) +void notification_print(const struct notification *n) { //TODO: use logging info for this printf("{\n"); @@ -87,7 +87,7 @@ void notification_print(notification *n) } /* see notification.h */ -void notification_run_script(notification *n) +void notification_run_script(struct notification *n) { if (!n->script || strlen(n->script) < 1) return; @@ -150,7 +150,7 @@ const char *notification_urgency_to_string(const enum urgency urgency) } /* 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) { return b->urgency - a->urgency; @@ -162,8 +162,8 @@ int notification_cmp(const notification *a, const notification *b) /* see notification.h */ int notification_cmp_data(const void *va, const void *vb, void *data) { - notification *a = (notification *) va; - notification *b = (notification *) vb; + struct notification *a = (struct notification *) va; + struct notification *b = (struct notification *) vb; if (!settings.sort) return 1; @@ -171,7 +171,7 @@ int notification_cmp_data(const void *va, const void *vb, void *data) 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 if (settings.icon_position != icons_off @@ -207,7 +207,7 @@ void rawimage_free(struct raw_image *i) } /* see notification.h */ -void notification_free(notification *n) +void notification_free(struct notification *n) { if (!n) return; @@ -256,9 +256,9 @@ void notification_replace_single_field(char **haystack, } /* 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 */ n->first_render = true; @@ -281,7 +281,7 @@ notification *notification_create(void) } /* see notification.h */ -void notification_init(notification *n) +void notification_init(struct notification *n) { /* default to empty string to avoid further NULL faults */ n->appname = n->appname ? n->appname : g_strdup("unknown"); @@ -326,7 +326,7 @@ void notification_init(notification *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); @@ -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); @@ -455,7 +455,7 @@ static void notification_extract_urls(notification *n) g_free(urls_text); } -static void notification_dmenu_string(notification *n) +static void notification_dmenu_string(struct notification *n) { if (n->actions) { 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); @@ -529,7 +529,7 @@ void notification_update_text_to_render(notification *n) } /* see notification.h */ -void notification_do_action(notification *n) +void notification_do_action(const struct notification *n) { if (n->actions) { if (n->actions->count == 2) { diff --git a/src/notification.h b/src/notification.h index 55ed0d0..80d64ab 100644 --- a/src/notification.h +++ b/src/notification.h @@ -42,7 +42,7 @@ struct actions { gsize count; }; -typedef struct _notification { +struct notification { int id; char *dbus_client; @@ -83,7 +83,7 @@ typedef struct _notification { char *msg; /**< formatted message */ char *text_to_render; /**< formatted message (with age and action indicators) */ char *urls; /**< urllist delimited by '\\n' */ -} notification; +}; /** * 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. * @returns The generated notification */ -notification *notification_create(void); +struct notification *notification_create(void); /** * Sanitize values of notification, apply all matching rules @@ -101,7 +101,7 @@ notification *notification_create(void); * * @param n: the notification to sanitize */ -void notification_init(notification *n); +void notification_init(struct notification *n); /** * Free the actions structure @@ -122,12 +122,12 @@ void rawimage_free(struct raw_image *i); * * @param n (nullable): pointer to #notification */ -void notification_free(notification *n); +void notification_free(struct notification *n); /** * 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 @@ -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_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 @@ -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 * 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 * 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 @@ -162,14 +162,15 @@ void notification_replace_single_field(char **haystack, char **needle, const char *replacement, 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, * invoke it. If there are multiple and no default, open the context menu. If * 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); diff --git a/src/queues.c b/src/queues.c index 2850fa4..f5d2077 100644 --- a/src/queues.c +++ b/src/queues.c @@ -33,7 +33,7 @@ static GQueue *history = NULL; /**< history of displayed notifications */ int next_notification_id = 1; bool pause_displayed = false; -static bool queues_stack_duplicate(notification *n); +static bool queues_stack_duplicate(struct notification *n); /* see queues.h */ void queues_init(void) @@ -50,7 +50,7 @@ const GList *queues_get_displayed(void) } /* see queues.h */ -const notification *queues_get_head_waiting(void) +const struct notification *queues_get_head_waiting(void) { if (waiting->length == 0) return NULL; @@ -91,8 +91,8 @@ static void queues_swap_notifications(GQueue *queueA, GQueue *queueB, GList *elemB) { - notification *toB = elemA->data; - notification *toA = elemB->data; + struct notification *toB = elemA->data; + struct notification *toA = elemB->data; g_queue_delete_link(queueA, elemA); 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 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) return n && n->fullscreen != FS_PUSHBACK; @@ -121,7 +121,7 @@ static bool queues_notification_is_ready(const notification *n, bool fullscreen, } /* 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 */ @@ -167,13 +167,13 @@ int queues_notification_insert(notification *n) * @return true, if notification got 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 }; for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) { for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter; iter = iter->next) { - notification *orig = iter->data; + struct notification *orig = iter->data; if (notification_is_duplicate(orig, n)) { /* 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. @@ -201,14 +201,14 @@ static bool queues_stack_duplicate(notification *n) } /* see queues.h */ -bool queues_notification_replace_id(notification *new) +bool queues_notification_replace_id(struct notification *new) { GQueue *allqueues[] = { displayed, waiting }; for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) { for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter; iter = iter->next) { - notification *old = iter->data; + struct notification *old = iter->data; if (old->id == new->id) { iter->data = new; new->dup_count = old->dup_count; @@ -222,7 +222,6 @@ bool queues_notification_replace_id(notification *new) return true; } } - } return false; } @@ -230,13 +229,13 @@ bool queues_notification_replace_id(notification *new) /* see queues.h */ void queues_notification_close_id(int id, enum reason reason) { - notification *target = NULL; + struct notification *target = NULL; GQueue *allqueues[] = { displayed, waiting }; for (int i = 0; i < sizeof(allqueues)/sizeof(GList*); i++) { for (GList *iter = g_queue_peek_head_link(allqueues[i]); iter; iter = iter->next) { - notification *n = iter->data; + struct notification *n = iter->data; if (n->id == id) { g_queue_remove(allqueues[i], n); target = n; @@ -254,7 +253,7 @@ void queues_notification_close_id(int id, enum reason reason) } /* 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); queues_notification_close_id(n->id, reason); @@ -266,7 +265,7 @@ void queues_history_pop(void) if (g_queue_is_empty(history)) return; - notification *n = g_queue_pop_tail(history); + struct notification *n = g_queue_pop_tail(history); n->redisplayed = true; n->start = 0; n->timeout = settings.sticky_history ? 0 : n->timeout; @@ -274,11 +273,11 @@ void queues_history_pop(void) } /* see queues.h */ -void queues_history_push(notification *n) +void queues_history_push(struct notification *n) { if (!n->history_ignore) { 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); } @@ -311,7 +310,7 @@ void queues_check_timeouts(bool idle, bool fullscreen) GList *iter = g_queue_peek_head_link(displayed); while (iter) { - notification *n = iter->data; + struct notification *n = iter->data; /* * Update iter to the next item before we either exit the @@ -353,7 +352,7 @@ void queues_update(bool fullscreen) if (fullscreen) { GList *iter = g_queue_peek_head_link(displayed); while (iter) { - notification *n = iter->data; + struct notification *n = iter->data; GList *nextiter = iter->next; if (n->fullscreen == FS_PUSHBACK){ @@ -378,7 +377,7 @@ void queues_update(bool fullscreen) /* move notifications from queue to displayed */ GList *iter = g_queue_peek_head_link(waiting); while (displayed->length < cur_displayed_limit && iter) { - notification *n = iter->data; + struct notification *n = iter->data; GList *nextiter = iter->next; if (!n) @@ -400,7 +399,7 @@ void queues_update(bool fullscreen) /* if necessary, push the overhanging notifications from displayed to waiting again */ 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 } @@ -418,7 +417,7 @@ void queues_update(bool fullscreen) } 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(); 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; iter = iter->next) { - notification *n = iter->data; + struct notification *n = iter->data; gint64 ttl = n->timeout - (time - n->start); if (n->timeout > 0) { @@ -488,7 +487,7 @@ bool queues_pause_status(void) */ static void teardown_notification(gpointer data) { - notification *n = data; + struct notification *n = data; notification_free(n); } diff --git a/src/queues.h b/src/queues.h index 1e185d7..d093582 100644 --- a/src/queues.h +++ b/src/queues.h @@ -30,7 +30,7 @@ const GList *queues_get_displayed(void); * * @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, @@ -63,7 +63,7 @@ unsigned int queues_length_history(void); * @return `0`, the notification was dismissed and freed * @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 @@ -75,7 +75,7 @@ int queues_notification_insert(notification *n); * @return true, if a matching notification has been found and is replaced * @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 @@ -96,7 +96,7 @@ void queues_notification_close_id(int id, enum reason reason); * @param n (transfer full) The notification 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 @@ -110,7 +110,7 @@ void queues_history_pop(void); * * @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 diff --git a/src/rules.c b/src/rules.c index a97b03f..a6d373c 100644 --- a/src/rules.c +++ b/src/rules.c @@ -10,7 +10,7 @@ /* * Apply rule to notification. */ -void rule_apply(struct rule *r, notification *n) +void rule_apply(struct rule *r, struct notification *n) { if (r->timeout != -1) n->timeout = r->timeout; @@ -50,7 +50,7 @@ void rule_apply(struct rule *r, notification *n) /* * 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) { struct rule *r = iter->data; @@ -89,7 +89,7 @@ void rule_init(struct rule *r) /* * Check whether rule should be applied to n. */ -bool rule_matches_notification(struct rule *r, notification *n) +bool rule_matches_notification(struct rule *r, struct notification *n) { return ( (!r->appname || (n->appname && !fnmatch(r->appname, n->appname, 0))) && (!r->summary || (n->summary && !fnmatch(r->summary, n->summary, 0))) diff --git a/src/rules.h b/src/rules.h index e2a26a6..3ab82be 100644 --- a/src/rules.h +++ b/src/rules.h @@ -37,9 +37,9 @@ struct rule { extern GSList *rules; void rule_init(struct rule *r); -void rule_apply(struct rule *r, notification *n); -void rule_apply_all(notification *n); -bool rule_matches_notification(struct rule *r, notification *n); +void rule_apply(struct rule *r, struct notification *n); +void rule_apply_all(struct notification *n); +bool rule_matches_notification(struct rule *r, struct notification *n); #endif /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/x11/x.c b/src/x11/x.c index 52430f8..87ec127 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -411,7 +411,7 @@ static void x_handle_click(XEvent ev) if (act == MOUSE_DO_ACTION || act == MOUSE_CLOSE_CURRENT) { int y = settings.separator_height; - notification *n = NULL; + struct notification *n = NULL; int first = true; for (const GList *iter = queues_get_displayed(); iter; iter = iter->next) { diff --git a/test/notification.c b/test/notification.c index ba74fb8..26ba2e9 100644 --- a/test/notification.c +++ b/test/notification.c @@ -5,8 +5,9 @@ #include -TEST test_notification_is_duplicate_field(char **field, notification *a, - notification *b) +TEST test_notification_is_duplicate_field(char **field, + struct notification *a, + struct notification *b) { ASSERT(notification_is_duplicate(a, b)); char *tmp = *field; @@ -19,9 +20,9 @@ TEST test_notification_is_duplicate_field(char **field, notification *a, TEST test_notification_is_duplicate(void *notifications) { - notification **n = (notification**)notifications; - notification *a = n[0]; - notification *b = n[1]; + struct notification **n = (struct notification**)notifications; + struct notification *a = n[0]; + struct notification *b = n[1]; ASSERT(notification_is_duplicate(a, b)); @@ -102,18 +103,18 @@ SUITE(suite_notification) cmdline_load(0, NULL); load_settings("data/dunstrc.default"); - notification *a = notification_create(); + struct notification *a = notification_create(); a->appname = "Test"; a->summary = "Summary"; a->body = "Body"; a->icon = "Icon"; a->urgency = URG_NORM; - notification *b = notification_create(); + struct notification *b = notification_create(); memcpy(b, a, sizeof(*b)); //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); g_free(a); From 2a5fe938f6203a46890beac5f44ca902ff10ae12 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:33 +0200 Subject: [PATCH 08/12] Reformat alignment enum --- config.h | 2 +- src/draw.c | 6 +++--- src/settings.c | 6 +++--- src/settings.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config.h b/config.h index d2cf382..1aaa546 100644 --- a/config.h +++ b/config.h @@ -32,7 +32,7 @@ struct settings defaults = { .indicate_hidden = true, /* show count of hidden messages */ .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 */ -.align = left, /* text alignment [left/center/right] */ +.align = ALIGN_LEFT, /* text alignment ALIGN_[LEFT|CENTER|RIGHT] */ .sticky_history = true, .history_length = 20, /* max amount of notifications kept in history */ .show_indicators = true, diff --git a/src/draw.c b/src/draw.c index cc64653..c08a4e4 100644 --- a/src/draw.c +++ b/src/draw.c @@ -120,14 +120,14 @@ static void layout_setup_pango(PangoLayout *layout, int width) PangoAlignment align; switch (settings.align) { - case left: + case ALIGN_LEFT: default: align = PANGO_ALIGN_LEFT; break; - case center: + case ALIGN_CENTER: align = PANGO_ALIGN_CENTER; break; - case right: + case ALIGN_RIGHT: align = PANGO_ALIGN_RIGHT; break; } diff --git a/src/settings.c b/src/settings.c index a2c38f4..bd8c7bd 100644 --- a/src/settings.c +++ b/src/settings.c @@ -320,11 +320,11 @@ void load_settings(char *cmdline_config_path) if (strlen(c) > 0) { if (strcmp(c, "left") == 0) - settings.align = left; + settings.align = ALIGN_LEFT; else if (strcmp(c, "center") == 0) - settings.align = center; + settings.align = ALIGN_CENTER; else if (strcmp(c, "right") == 0) - settings.align = right; + settings.align = ALIGN_RIGHT; else LOG_W("Unknown alignment value: '%s'", c); g_free(c); diff --git a/src/settings.h b/src/settings.h index 3c50490..249156a 100644 --- a/src/settings.h +++ b/src/settings.h @@ -6,7 +6,7 @@ #include "x11/x.h" -enum alignment { left, center, right }; +enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }; enum ellipsize { start, middle, end }; enum icon_position_t { icons_left, icons_right, icons_off }; enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM }; From c5d552856f32daeb53abc2183f287f120adb61e3 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:35 +0200 Subject: [PATCH 09/12] Reformat icon_position enum --- src/draw.c | 10 +++++----- src/notification.c | 4 ++-- src/settings.c | 6 +++--- src/settings.h | 4 ++-- test/notification.c | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/draw.c b/src/draw.c index c08a4e4..d6830a3 100644 --- a/src/draw.c +++ b/src/draw.c @@ -270,7 +270,7 @@ static struct colored_layout *layout_init_shared(cairo_t *c, const struct notifi 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); } else { cl->icon = NULL; @@ -515,10 +515,10 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width) int 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, 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); } else { cairo_move_to(c, settings.h_padding, settings.padding); @@ -535,9 +535,9 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width) image_x, 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; - } else if (settings.icon_position == icons_right){ + } else if (settings.icon_position == ICON_RIGHT){ image_x = width - settings.h_padding - image_width; } else { LOG_E("Tried to draw icon but icon position is not valid. %s:%d", __FILE__, __LINE__); diff --git a/src/notification.c b/src/notification.c index 6ea99a6..b36a817 100644 --- a/src/notification.c +++ b/src/notification.c @@ -174,14 +174,14 @@ int notification_cmp_data(const void *va, const void *vb, void *data) int notification_is_duplicate(const struct notification *a, const struct notification *b) { //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)) return false; return strcmp(a->appname, b->appname) == 0 && strcmp(a->summary, b->summary) == 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; } diff --git a/src/settings.c b/src/settings.c index bd8c7bd..c05d4d5 100644 --- a/src/settings.c +++ b/src/settings.c @@ -457,11 +457,11 @@ void load_settings(char *cmdline_config_path) if (strlen(c) > 0) { if (strcmp(c, "left") == 0) - settings.icon_position = icons_left; + settings.icon_position = ICON_LEFT; else if (strcmp(c, "right") == 0) - settings.icon_position = icons_right; + settings.icon_position = ICON_RIGHT; else if (strcmp(c, "off") == 0) - settings.icon_position = icons_off; + settings.icon_position = ICON_OFF; else LOG_W("Unknown icon position: '%s'", c); g_free(c); diff --git a/src/settings.h b/src/settings.h index 249156a..0a19f73 100644 --- a/src/settings.h +++ b/src/settings.h @@ -8,7 +8,7 @@ enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }; enum ellipsize { start, middle, 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 follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; enum markup_mode { MARKUP_NULL, MARKUP_NO, MARKUP_STRIP, MARKUP_FULL }; @@ -75,7 +75,7 @@ struct settings { char *dmenu; char **dmenu_cmd; char *browser; - enum icon_position_t icon_position; + enum icon_position icon_position; int max_icon_size; char *icon_path; enum follow_mode f_mode; diff --git a/test/notification.c b/test/notification.c index 26ba2e9..de189ad 100644 --- a/test/notification.c +++ b/test/notification.c @@ -33,24 +33,24 @@ TEST test_notification_is_duplicate(void *notifications) ASSERT(notification_is_duplicate(a, b)); 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"; - settings.icon_position = icons_off; + settings.icon_position = ICON_OFF; ASSERT(notification_is_duplicate(a, b)); //Setting pointer to a random value since we are checking for null b->raw_icon = (struct raw_image*)0xff; ASSERT(notification_is_duplicate(a, b)); b->raw_icon = NULL; - settings.icon_position = icons_left; + settings.icon_position = ICON_LEFT; ASSERT_FALSE(notification_is_duplicate(a, b)); b->raw_icon = (struct raw_image*)0xff; ASSERT_FALSE(notification_is_duplicate(a, b)); b->raw_icon = NULL; - settings.icon_position = icons_right; + settings.icon_position = ICON_RIGHT; ASSERT_FALSE(notification_is_duplicate(a, b)); b->raw_icon = (struct raw_image*)0xff; ASSERT_FALSE(notification_is_duplicate(a, b)); From c712f57ace5be164369507eb7c29b4dc455fdbe8 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:37 +0200 Subject: [PATCH 10/12] Reformat ellipsize enum --- config.h | 2 +- src/draw.c | 6 +++--- src/settings.c | 6 +++--- src/settings.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config.h b/config.h index 1aaa546..40207a3 100644 --- a/config.h +++ b/config.h @@ -37,7 +37,7 @@ struct settings defaults = { .history_length = 20, /* max amount of notifications kept in history */ .show_indicators = true, .word_wrap = false, -.ellipsize = middle, +.ellipsize = ELLIPSE_MIDDLE, .ignore_newline = false, .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 */ diff --git a/src/draw.c b/src/draw.c index d6830a3..e1f15c8 100644 --- a/src/draw.c +++ b/src/draw.c @@ -254,13 +254,13 @@ static struct colored_layout *layout_init_shared(cairo_t *c, const struct notifi if (!settings.word_wrap) { PangoEllipsizeMode ellipsize; switch (settings.ellipsize) { - case start: + case ELLIPSE_START: ellipsize = PANGO_ELLIPSIZE_START; break; - case middle: + case ELLIPSE_MIDDLE: ellipsize = PANGO_ELLIPSIZE_MIDDLE; break; - case end: + case ELLIPSE_END: ellipsize = PANGO_ELLIPSIZE_END; break; default: diff --git a/src/settings.c b/src/settings.c index c05d4d5..110b98b 100644 --- a/src/settings.c +++ b/src/settings.c @@ -219,11 +219,11 @@ void load_settings(char *cmdline_config_path) if (strlen(c) == 0) { settings.ellipsize = defaults.ellipsize; } else if (strcmp(c, "start") == 0) { - settings.ellipsize = start; + settings.ellipsize = ELLIPSE_START; } else if (strcmp(c, "middle") == 0) { - settings.ellipsize = middle; + settings.ellipsize = ELLIPSE_MIDDLE; } else if (strcmp(c, "end") == 0) { - settings.ellipsize = end; + settings.ellipsize = ELLIPSE_END; } else { LOG_W("Unknown ellipsize value: '%s'", c); settings.ellipsize = defaults.ellipsize; diff --git a/src/settings.h b/src/settings.h index 0a19f73..afa39c1 100644 --- a/src/settings.h +++ b/src/settings.h @@ -7,7 +7,7 @@ #include "x11/x.h" enum alignment { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }; -enum ellipsize { start, middle, end }; +enum ellipsize { ELLIPSE_START, ELLIPSE_MIDDLE, ELLIPSE_END }; enum icon_position { ICON_LEFT, ICON_RIGHT, ICON_OFF }; enum separator_color { SEP_FOREGROUND, SEP_AUTO, SEP_FRAME, SEP_CUSTOM }; enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; From 41af2e0a0e151a1c6adea92858f44656efa6be23 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:38 +0200 Subject: [PATCH 11/12] Rename variable name color to actual foreground --- src/draw.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/draw.c b/src/draw.c index e1f15c8..1405374 100644 --- a/src/draw.c +++ b/src/draw.c @@ -76,18 +76,18 @@ static double color_apply_delta(double base, double delta) static struct color calculate_foreground_color(struct color bg) { double c_delta = 0.1; - struct color color = bg; + struct color fg = bg; /* do we need to darken or brighten the colors? */ bool darken = (bg.r + bg.g + bg.b) / 3 > 0.5; int signedness = darken ? -1 : 1; - color.r = color_apply_delta(color.r, c_delta * signedness); - color.g = color_apply_delta(color.g, c_delta * signedness); - color.b = color_apply_delta(color.b, c_delta * signedness); + fg.r = color_apply_delta(fg.r, c_delta * signedness); + fg.g = color_apply_delta(fg.g, c_delta * signedness); + fg.b = color_apply_delta(fg.b, c_delta * signedness); - return color; + return fg; } static struct color layout_get_sepcolor(struct colored_layout *cl, From 476ddc81ff694078ed6b602fb6e3450aba926112 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Sun, 16 Sep 2018 02:58:40 +0200 Subject: [PATCH 12/12] Remove last "color color" --- src/draw.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/draw.c b/src/draw.c index 1405374..96c4a94 100644 --- a/src/draw.c +++ b/src/draw.c @@ -41,14 +41,14 @@ void draw_setup(void) pango_fdesc = pango_font_description_from_string(settings.font); } -static struct color color_hex_to_double(int hexValue) +static struct color hex_to_color(int hexValue) { - struct color color; - color.r = ((hexValue >> 16) & 0xFF) / 255.0; - color.g = ((hexValue >> 8) & 0xFF) / 255.0; - color.b = ((hexValue) & 0xFF) / 255.0; + struct color ret; + ret.r = ((hexValue >> 16) & 0xFF) / 255.0; + ret.g = ((hexValue >> 8) & 0xFF) / 255.0; + ret.b = ((hexValue) & 0xFF) / 255.0; - return color; + return ret; } static struct color string_to_color(const char *str) @@ -59,7 +59,7 @@ static struct color string_to_color(const char *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)