From 01327a6bc4d9d2a99b0ce9804436ebdc4e84cf0d Mon Sep 17 00:00:00 2001 From: Gjum Date: Wed, 26 Feb 2014 22:42:05 +0100 Subject: [PATCH] Add option to align icons left or right --- dunst.h | 1 + dunstrc | 4 ++-- settings.c | 21 +++++++++++++++++---- settings.h | 2 +- x.c | 12 +++++++++--- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/dunst.h b/dunst.h index 97d67a7..ad17b19 100644 --- a/dunst.h +++ b/dunst.h @@ -16,6 +16,7 @@ #define ColBG 0 enum alignment { left, center, right }; +enum icon_position_t { icons_left, icons_right, icons_off }; enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM }; enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; diff --git a/dunstrc b/dunstrc index e9f78bf..21bf6f8 100644 --- a/dunstrc +++ b/dunstrc @@ -138,8 +138,8 @@ # Browser for opening urls in context menu. browser = /usr/bin/firefox -new-tab - # Show icons in notifications. - show_icons = no + # Align icons left/right/off + icon_position = off # Path to default icons. icon_path = /usr/share/icons/gnome/32x32/status/ diff --git a/settings.c b/settings.c index a52a948..1eaeb44 100644 --- a/settings.c +++ b/settings.c @@ -192,10 +192,23 @@ void load_settings(char *cmdline_config_path) option_get_string("global", "browser", "-browser", browser, "path to browser"); - settings.show_icons = - option_get_bool("global", "show_icons", - "-show_icons", false, - "show icons in notifications"); + { + char *c = option_get_string("global", "icon_position", + "-icon_position", "off", + "Align icons left/right/off"); + if (strlen(c) > 0) { + if (strcmp(c, "left") == 0) + settings.icon_position = icons_left; + else if (strcmp(c, "right") == 0) + settings.icon_position = icons_right; + else if (strcmp(c, "off") == 0) + settings.icon_position = icons_off; + else + fprintf(stderr, + "Warning: unknown icon position: %s\n", c); + free(c); + } + } settings.icon_path = option_get_string("global", "icon_path", "-icon_path", icon_path, diff --git a/settings.h b/settings.h index dc368a8..6f6e3c2 100644 --- a/settings.h +++ b/settings.h @@ -42,7 +42,7 @@ typedef struct _settings { char *dmenu; char **dmenu_cmd; char *browser; - bool show_icons; + enum icon_position_t icon_position; char *icon_path; enum follow_mode f_mode; keyboard_shortcut close_ks; diff --git a/x.c b/x.c index 88c2504..4b835e7 100644 --- a/x.c +++ b/x.c @@ -268,7 +268,7 @@ static colored_layout *r_init_shared(cairo_t *c, notification *n) } cl->icon = NULL; - if (strlen(n->icon) > 0 && settings.show_icons) + if (strlen(n->icon) > 0 && settings.icon_position != icons_off) cl->icon = cairo_image_surface_create_from_png(n->icon); cl->fg = x_string_to_color_t(n->color_strings[ColFG]); @@ -396,7 +396,9 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d cairo_fill(c); dim.y += settings.padding; - cairo_move_to(c, settings.h_padding, dim.y); + if (cl->icon && settings.icon_position == icons_left) + cairo_move_to(c, cairo_image_surface_get_width(cl->icon) + 2 * settings.h_padding, dim.y); + else cairo_move_to(c, settings.h_padding, dim.y); cairo_set_source_rgb(c, cl->fg.r, cl->fg.g, cl->fg.b); pango_cairo_update_layout(c, cl->l); pango_cairo_show_layout(c, cl->l); @@ -417,8 +419,12 @@ static dimension_t x_render_layout(cairo_t *c, colored_layout *cl, dimension_t d if (cl->icon) { unsigned int image_width = cairo_image_surface_get_width(cl->icon), image_height = cairo_image_surface_get_height(cl->icon), - image_x = bg_width - settings.h_padding - image_width, + image_x, image_y = bg_y + settings.padding; + + if (settings.icon_position == icons_left) image_x = settings.h_padding; + else image_x = bg_width - settings.h_padding - image_width; + cairo_set_source_surface (c, cl->icon, image_x, image_y); cairo_rectangle (c, image_x, image_y, image_width, image_height); cairo_fill (c);