Add option to align icons left or right
This commit is contained in:
		
							parent
							
								
									d9e68803dc
								
							
						
					
					
						commit
						01327a6bc4
					
				
							
								
								
									
										1
									
								
								dunst.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								dunst.h
									
									
									
									
									
								
							| @ -16,6 +16,7 @@ | |||||||
| #define ColBG 0 | #define ColBG 0 | ||||||
| 
 | 
 | ||||||
| enum alignment { left, center, right }; | enum alignment { left, center, right }; | ||||||
|  | enum icon_position_t { icons_left, icons_right, icons_off }; | ||||||
| enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM }; | enum separator_color { FOREGROUND, AUTO, FRAME, CUSTOM }; | ||||||
| enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; | enum follow_mode { FOLLOW_NONE, FOLLOW_MOUSE, FOLLOW_KEYBOARD }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								dunstrc
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								dunstrc
									
									
									
									
									
								
							| @ -138,8 +138,8 @@ | |||||||
|     # Browser for opening urls in context menu. |     # Browser for opening urls in context menu. | ||||||
|     browser = /usr/bin/firefox -new-tab |     browser = /usr/bin/firefox -new-tab | ||||||
| 
 | 
 | ||||||
|     # Show icons in notifications. |     # Align icons left/right/off | ||||||
|     show_icons = no |     icon_position = off | ||||||
| 
 | 
 | ||||||
|     # Path to default icons. |     # Path to default icons. | ||||||
|     icon_path = /usr/share/icons/gnome/32x32/status/ |     icon_path = /usr/share/icons/gnome/32x32/status/ | ||||||
|  | |||||||
							
								
								
									
										21
									
								
								settings.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								settings.c
									
									
									
									
									
								
							| @ -192,10 +192,23 @@ void load_settings(char *cmdline_config_path) | |||||||
|             option_get_string("global", "browser", "-browser", browser, |             option_get_string("global", "browser", "-browser", browser, | ||||||
|                               "path to browser"); |                               "path to browser"); | ||||||
| 
 | 
 | ||||||
|         settings.show_icons = |         { | ||||||
|             option_get_bool("global", "show_icons", |                 char *c = option_get_string("global", "icon_position", | ||||||
|                             "-show_icons", false, |                                             "-icon_position", "off", | ||||||
|                             "show icons in notifications"); |                                             "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 = |         settings.icon_path = | ||||||
|             option_get_string("global", "icon_path", "-icon_path", icon_path, |             option_get_string("global", "icon_path", "-icon_path", icon_path, | ||||||
|  | |||||||
| @ -42,7 +42,7 @@ typedef struct _settings { | |||||||
|         char *dmenu; |         char *dmenu; | ||||||
|         char **dmenu_cmd; |         char **dmenu_cmd; | ||||||
|         char *browser; |         char *browser; | ||||||
|         bool show_icons; |         enum icon_position_t icon_position; | ||||||
|         char *icon_path; |         char *icon_path; | ||||||
|         enum follow_mode f_mode; |         enum follow_mode f_mode; | ||||||
|         keyboard_shortcut close_ks; |         keyboard_shortcut close_ks; | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								x.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								x.c
									
									
									
									
									
								
							| @ -268,7 +268,7 @@ static colored_layout *r_init_shared(cairo_t *c, notification *n) | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         cl->icon = NULL; |         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->icon = cairo_image_surface_create_from_png(n->icon); | ||||||
| 
 | 
 | ||||||
|         cl->fg = x_string_to_color_t(n->color_strings[ColFG]); |         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); |         cairo_fill(c); | ||||||
| 
 | 
 | ||||||
|         dim.y += settings.padding; |         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); |         cairo_set_source_rgb(c, cl->fg.r, cl->fg.g, cl->fg.b); | ||||||
|         pango_cairo_update_layout(c, cl->l); |         pango_cairo_update_layout(c, cl->l); | ||||||
|         pango_cairo_show_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)  { |         if (cl->icon)  { | ||||||
|                 unsigned int image_width = cairo_image_surface_get_width(cl->icon), |                 unsigned int image_width = cairo_image_surface_get_width(cl->icon), | ||||||
|                              image_height = cairo_image_surface_get_height(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; |                              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_set_source_surface (c, cl->icon, image_x, image_y); | ||||||
|                 cairo_rectangle (c, image_x, image_y, image_width, image_height); |                 cairo_rectangle (c, image_x, image_y, image_width, image_height); | ||||||
|                 cairo_fill (c); |                 cairo_fill (c); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Gjum
						Gjum