Dunst
Lightweight notification daemon
Loading...
Searching...
No Matches
icon.c File Reference
#include <assert.h>
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include "log.h"
#include "icon.h"
#include "settings.h"
#include "utils.h"
#include "icon-lookup.h"
+ Include dependency graph for icon.c:

Go to the source code of this file.

Functions

static void pixbuf_data_to_cairo_data (const unsigned char *pixels_p, unsigned char *pixels_c, size_t rowstride_p, size_t rowstride_c, int width, int height, int n_channels)
 Reassemble the data parts of a GdkPixbuf into a cairo_surface_t's data field.
 
int get_icon_width (cairo_surface_t *icon, double scale)
 Get the unscaled icon width.
 
int get_icon_height (cairo_surface_t *icon, double scale)
 Get the unscaled icon height, see get_icon_width.
 
cairo_surface_t * gdk_pixbuf_to_cairo_surface (GdkPixbuf *pixbuf)
 
static bool icon_size_clamp (int *w, int *h, int min_size, int max_size)
 Scales the given image dimensions if necessary according to the settings.
 
static GdkPixbuf * icon_pixbuf_scale_to_size (GdkPixbuf *pixbuf, double dpi_scale, int min_size, int max_size)
 Scales the given GdkPixbuf to a given size.
 
static char * get_id_from_data (const uint8_t *data_pb, size_t width, size_t height, size_t pixelstride, size_t rowstride)
 
GdkPixbuf * get_pixbuf_from_file (const char *filename, char **id, int min_size, int max_size, double scale)
 Retrieve an icon by its full filepath, scaled according to settings.
 
char * get_path_from_icon_name (const char *iconname, int size)
 Retrieve a path from an icon name.
 
static void icon_destroy (guchar *pixels, gpointer data)
 
GdkPixbuf * icon_get_for_data (GVariant *data, char **id, double dpi_scale, int min_size, int max_size)
 Convert a GVariant like described in GdkPixbuf, scaled according to settings.
 

Detailed Description

License
BSD-3-Clause

Definition in file icon.c.

Function Documentation

◆ gdk_pixbuf_to_cairo_surface()

cairo_surface_t * gdk_pixbuf_to_cairo_surface ( GdkPixbuf * pixbuf)

Definition at line 99 of file icon.c.

◆ get_icon_height()

int get_icon_height ( cairo_surface_t * icon,
double scale )

Get the unscaled icon height, see get_icon_width.

Definition at line 95 of file icon.c.

◆ get_icon_width()

int get_icon_width ( cairo_surface_t * icon,
double scale )

Get the unscaled icon width.

If scale is 2 for example, the icon will render in twice the size, but get_icon_width still returns the same size as when scale is 1.

Definition at line 91 of file icon.c.

◆ get_id_from_data()

static char * get_id_from_data ( const uint8_t * data_pb,
size_t width,
size_t height,
size_t pixelstride,
size_t rowstride )
static

Definition at line 191 of file icon.c.

◆ get_path_from_icon_name()

char * get_path_from_icon_name ( const char * iconname,
int size )

Retrieve a path from an icon name.

Parameters
iconnameA string describing a file:// URL, an arbitary filename or an icon name, which then gets searched for in the settings.icon_path
sizeSize of the icon to look for. This is only used when recursive icon lookup is enabled.
Returns
a newly allocated string with the icon path
Return values
NULLfile does not exist, not readable, etc..

Definition at line 249 of file icon.c.

◆ get_pixbuf_from_file()

GdkPixbuf * get_pixbuf_from_file ( const char * filename,
char ** id,
int min_size,
int max_size,
double scale )

Retrieve an icon by its full filepath, scaled according to settings.

Parameters
filenameA string representing a readable file path
id(necessary) A unique identifier of the returned pixbuf. Only filled, if the return value is non-NULL.
min_sizeAn iteger representing the desired minimum unscaled icon size.
max_sizeAn iteger representing the desired maximum unscaled icon size.
scaleAn integer representing the output dpi scaling.
Returns
an instance of GdkPixbuf
Return values
NULLfile does not exist, not readable, etc..

Definition at line 213 of file icon.c.

◆ icon_destroy()

static void icon_destroy ( guchar * pixels,
gpointer data )
static

Definition at line 307 of file icon.c.

◆ icon_get_for_data()

GdkPixbuf * icon_get_for_data ( GVariant * data,
char ** id,
double dpi_scale,
int min_size,
int max_size )

Convert a GVariant like described in GdkPixbuf, scaled according to settings.

The returned id will be a unique identifier. To check if two given GdkPixbufs are equal, it's sufficient to just compare the id strings.

Parameters
dataA GVariant in the format "(iiibii@ay)" filled with values like described in the notification spec.
id(necessary) A unique identifier of the returned pixbuf. Only filled, if the return value is non-NULL.
dpi_scaleAn integer representing the output dpi scaling.
min_sizeAn integer representing the desired minimum unscaled icon size.
max_sizeAn integer representing the desired maximum unscaled icon size.
Returns
an instance of GdkPixbuf derived from the GVariant
Return values
NULLGVariant parameter nulled, invalid or in wrong format

Definition at line 313 of file icon.c.

◆ icon_pixbuf_scale_to_size()

static GdkPixbuf * icon_pixbuf_scale_to_size ( GdkPixbuf * pixbuf,
double dpi_scale,
int min_size,
int max_size )
static

Scales the given GdkPixbuf to a given size.

. If the image is not square, the largest size will be scaled up to the given size.

Parameters
pixbuf(nullable) The pixbuf, which may be too big. Takes ownership of the reference.
dpi_scaleA double for the dpi scaling.
min_sizeThe minimum allowed icon size.
max_sizeThe maximum allowed icon size.
Returns
the scaled version of the pixbuf. If scaling wasn't necessary, it returns the same pixbuf. Transfers full ownership of the reference.

Definition at line 169 of file icon.c.

◆ icon_size_clamp()

static bool icon_size_clamp ( int * w,
int * h,
int min_size,
int max_size )
static

Scales the given image dimensions if necessary according to the settings.

Parameters
wa pointer to the image width, to be modified in-place
ha pointer to the image height, to be modified in-place
min_sizethe minimum icon size setting for this notification
max_sizethe maximum icon size setting for this notification
Returns
TRUE if the dimensions were updated, FALSE if they were left unchanged

Definition at line 134 of file icon.c.

◆ pixbuf_data_to_cairo_data()

static void pixbuf_data_to_cairo_data ( const unsigned char * pixels_p,
unsigned char * pixels_c,
size_t rowstride_p,
size_t rowstride_c,
int width,
int height,
int n_channels )
static

Reassemble the data parts of a GdkPixbuf into a cairo_surface_t's data field.

Requires to call on the surface flush before and mark_dirty after the execution.

Definition at line 26 of file icon.c.