Isolate GdkPixbuf usage to icon.c
Cleans up the clutter in draw and since only a single icon function is called externally from icon.c it'll make things easier if we ever decide to switch icon libraries.
This commit is contained in:
		
							parent
							
								
									a2863d5312
								
							
						
					
					
						commit
						4faa9cbaaa
					
				
							
								
								
									
										32
									
								
								src/draw.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								src/draw.c
									
									
									
									
									
								
							| @ -267,38 +267,8 @@ static colored_layout *layout_init_shared(cairo_t *c, notification *n) | |||||||
|                 pango_layout_set_ellipsize(cl->l, ellipsize); |                 pango_layout_set_ellipsize(cl->l, ellipsize); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         GdkPixbuf *pixbuf = NULL; |  | ||||||
| 
 |  | ||||||
|         if (settings.icon_position != icons_off) { |         if (settings.icon_position != icons_off) { | ||||||
|                 if (n->raw_icon) |                 cl->icon = icon_get_for_notification(n); | ||||||
|                         pixbuf = get_pixbuf_from_raw_image(n->raw_icon); |  | ||||||
|                 else if (n->icon) |  | ||||||
|                         pixbuf = get_pixbuf_from_icon(n->icon); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (pixbuf != NULL) { |  | ||||||
|                 int w = gdk_pixbuf_get_width(pixbuf); |  | ||||||
|                 int h = gdk_pixbuf_get_height(pixbuf); |  | ||||||
|                 int larger = w > h ? w : h; |  | ||||||
|                 if (settings.max_icon_size && larger > settings.max_icon_size) { |  | ||||||
|                         GdkPixbuf *scaled; |  | ||||||
|                         if (w >= h) { |  | ||||||
|                                 scaled = gdk_pixbuf_scale_simple(pixbuf, |  | ||||||
|                                                 settings.max_icon_size, |  | ||||||
|                                                 (int) ((double) settings.max_icon_size / w * h), |  | ||||||
|                                                 GDK_INTERP_BILINEAR); |  | ||||||
|                         } else { |  | ||||||
|                                 scaled = gdk_pixbuf_scale_simple(pixbuf, |  | ||||||
|                                                 (int) ((double) settings.max_icon_size / h * w), |  | ||||||
|                                                 settings.max_icon_size, |  | ||||||
|                                                 GDK_INTERP_BILINEAR); |  | ||||||
|                         } |  | ||||||
|                         g_object_unref(pixbuf); |  | ||||||
|                         pixbuf = scaled; |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 cl->icon = gdk_pixbuf_to_cairo_surface(pixbuf); |  | ||||||
|                 g_object_unref(pixbuf); |  | ||||||
|         } else { |         } else { | ||||||
|                 cl->icon = NULL; |                 cl->icon = NULL; | ||||||
|         } |         } | ||||||
|  | |||||||
							
								
								
									
										40
									
								
								src/icon.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/icon.c
									
									
									
									
									
								
							| @ -138,4 +138,44 @@ GdkPixbuf *get_pixbuf_from_raw_image(const RawImage *raw_image) | |||||||
| 
 | 
 | ||||||
|         return pixbuf; |         return pixbuf; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | cairo_surface_t *icon_get_for_notification(const notification *n) | ||||||
|  | { | ||||||
|  |         GdkPixbuf *pixbuf; | ||||||
|  | 
 | ||||||
|  |         if (n->raw_icon) | ||||||
|  |                 pixbuf = get_pixbuf_from_raw_image(n->raw_icon); | ||||||
|  |         else if (n->icon) | ||||||
|  |                 pixbuf = get_pixbuf_from_icon(n->icon); | ||||||
|  |         else | ||||||
|  |                 return NULL; | ||||||
|  | 
 | ||||||
|  |         if (!pixbuf) | ||||||
|  |                 return NULL; | ||||||
|  | 
 | ||||||
|  |         int w = gdk_pixbuf_get_width(pixbuf); | ||||||
|  |         int h = gdk_pixbuf_get_height(pixbuf); | ||||||
|  |         int larger = w > h ? w : h; | ||||||
|  |         if (settings.max_icon_size && larger > settings.max_icon_size) { | ||||||
|  |                 GdkPixbuf *scaled; | ||||||
|  |                 if (w >= h) { | ||||||
|  |                         scaled = gdk_pixbuf_scale_simple(pixbuf, | ||||||
|  |                                         settings.max_icon_size, | ||||||
|  |                                         (int) ((double) settings.max_icon_size / w * h), | ||||||
|  |                                         GDK_INTERP_BILINEAR); | ||||||
|  |                 } else { | ||||||
|  |                         scaled = gdk_pixbuf_scale_simple(pixbuf, | ||||||
|  |                                         (int) ((double) settings.max_icon_size / h * w), | ||||||
|  |                                         settings.max_icon_size, | ||||||
|  |                                         GDK_INTERP_BILINEAR); | ||||||
|  |                 } | ||||||
|  |                 g_object_unref(pixbuf); | ||||||
|  |                 pixbuf = scaled; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         cairo_surface_t *ret = gdk_pixbuf_to_cairo_surface(pixbuf); | ||||||
|  |         g_object_unref(pixbuf); | ||||||
|  |         return ret; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ | /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ | ||||||
|  | |||||||
| @ -22,5 +22,13 @@ GdkPixbuf *get_pixbuf_from_icon(const char *iconname); | |||||||
|  */ |  */ | ||||||
| GdkPixbuf *get_pixbuf_from_raw_image(const RawImage *raw_image); | GdkPixbuf *get_pixbuf_from_raw_image(const RawImage *raw_image); | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * Get a cairo surface with the appropriate icon for the notification, scaled | ||||||
|  |  * according to the current settings | ||||||
|  |  * | ||||||
|  |  * @return a cairo_surface_t pointer or NULL if no icon could be retrieved. | ||||||
|  |  */ | ||||||
|  | cairo_surface_t *icon_get_for_notification(const notification *n); | ||||||
|  | 
 | ||||||
| #endif | #endif | ||||||
| /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ | /* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nikos Tsipinakis
						Nikos Tsipinakis