Dunst
Lightweight notification daemon
Loading...
Searching...
No Matches
draw.c File Reference
#include <assert.h>
#include <math.h>
#include <pango/pango-attributes.h>
#include <pango/pangocairo.h>
#include <pango/pango-font.h>
#include <pango/pango-layout.h>
#include <pango/pango-types.h>
#include <stdlib.h>
#include <inttypes.h>
#include <glib.h>
#include "draw.h"
#include "dunst.h"
#include "icon.h"
#include "log.h"
#include "markup.h"
#include "notification.h"
#include "queues.h"
#include "output.h"
#include "settings.h"
#include "utils.h"
#include "icon-lookup.h"
+ Include dependency graph for draw.c:

Go to the source code of this file.

Data Structures

struct  colored_layout
 

Macros

#define COLOR(cl, field)
 

Functions

void load_icon_themes (void)
 
char * color_to_string (struct color c, char buf[10])
 Stringify a color struct to a RRGGBBAA string.
 
struct gradientgradient_alloc (size_t length)
 
struct gradientgradient_acquire (struct gradient *grad)
 
static void gradient_free (struct gradient *grad)
 
void gradient_release (struct gradient *grad)
 
void gradient_pattern (struct gradient *grad)
 
char * gradient_to_string (const struct gradient *grad)
 
void draw_setup (void)
 
static double color_apply_delta (double base, double delta)
 
static struct color calculate_foreground_color (struct color bg)
 
static struct color layout_get_sepcolor (struct colored_layout *cl, struct colored_layout *cl_next)
 
static int get_horizontal_text_icon_padding (struct notification *n)
 
static int get_vertical_text_icon_padding (struct notification *n)
 
static bool have_progress_bar (const struct colored_layout *cl)
 
static void get_text_size (PangoLayout *l, int *w, int *h, double scale)
 
static void layout_setup_pango (PangoLayout *layout, int width, int height, bool word_wrap, PangoEllipsizeMode ellipsize_mode, PangoAlignment alignment)
 
static void layout_setup (struct colored_layout *cl, int width, int height, double scale)
 
static void free_colored_layout (void *data)
 
static struct dimensions calculate_notification_dimensions (struct colored_layout *cl, double scale)
 
static struct dimensions calculate_dimensions (GSList *layouts)
 
static PangoLayout * layout_create (cairo_t *c)
 
static struct colored_layoutlayout_init_shared (cairo_t *c, struct notification *n)
 
static struct colored_layoutlayout_derive_xmore (cairo_t *c, struct notification *n, int qlen)
 
static struct colored_layoutlayout_from_notification (cairo_t *c, struct notification *n)
 
static GSList * create_layouts (cairo_t *c)
 
static int layout_get_height (struct colored_layout *cl, double scale)
 
static int frame_internal_radius (int r, int w, int h)
 
static void draw_rect (cairo_t *c, double x, double y, double width, double height, double scale)
 A small wrapper around cairo_rectange for drawing a scaled rectangle.
 
void draw_rounded_rect (cairo_t *c, float x, float y, int width, int height, int corner_radius, double scale, enum corner_pos corners)
 Create a path on the given cairo context to draw the background of a notification.
 
static cairo_surface_t * render_background (cairo_surface_t *srf, struct colored_layout *cl, struct colored_layout *cl_next, int y, int width, int height, int corner_radius, enum corner_pos corners, int *ret_width, double scale)
 
static void render_content (cairo_t *c, struct colored_layout *cl, int width, int height, double scale)
 
static struct dimensions layout_render (cairo_surface_t *srf, struct colored_layout *cl, struct colored_layout *cl_next, struct dimensions dim, enum corner_pos corners)
 
void calc_window_pos (const struct screen_info *scr, int width, int height, int *ret_x, int *ret_y)
 Calculates the position the window should be placed at given its width and height and stores them in ret_x and ret_y.
 
void draw (void)
 
void draw_deinit (void)
 
double draw_get_scale (void)
 

Variables

const struct output * output
 
window win
 
PangoFontDescription * pango_fdesc
 

Detailed Description

License
BSD-3-Clause

Definition in file draw.c.

Macro Definition Documentation

◆ COLOR

#define COLOR ( cl,
field )
Value:
(cl)->n->colors.field

Definition at line 46 of file draw.c.

Function Documentation

◆ calc_window_pos()

void calc_window_pos ( const struct screen_info * scr,
int width,
int height,
int * ret_x,
int * ret_y )

Calculates the position the window should be placed at given its width and height and stores them in ret_x and ret_y.

Definition at line 975 of file draw.c.

◆ calculate_dimensions()

static struct dimensions calculate_dimensions ( GSList * layouts)
static

Definition at line 340 of file draw.c.

◆ calculate_foreground_color()

static struct color calculate_foreground_color ( struct color bg)
static

Definition at line 179 of file draw.c.

◆ calculate_notification_dimensions()

static struct dimensions calculate_notification_dimensions ( struct colored_layout * cl,
double scale )
static

Definition at line 298 of file draw.c.

◆ color_apply_delta()

static double color_apply_delta ( double base,
double delta )
inlinestatic

Definition at line 168 of file draw.c.

◆ color_to_string()

char * color_to_string ( struct color c,
char buf[10] )

Stringify a color struct to a RRGGBBAA string.

Returns the buffer on success and NULL if the struct is invalid.

Definition at line 68 of file draw.c.

◆ create_layouts()

static GSList * create_layouts ( cairo_t * c)
static

Definition at line 455 of file draw.c.

◆ draw()

void draw ( void )

Definition at line 1021 of file draw.c.

◆ draw_deinit()

void draw_deinit ( void )

Definition at line 1062 of file draw.c.

◆ draw_get_scale()

double draw_get_scale ( void )

Definition at line 1071 of file draw.c.

◆ draw_rect()

static void draw_rect ( cairo_t * c,
double x,
double y,
double width,
double height,
double scale )
inlinestatic

A small wrapper around cairo_rectange for drawing a scaled rectangle.

Definition at line 543 of file draw.c.

◆ draw_rounded_rect()

void draw_rounded_rect ( cairo_t * c,
float x,
float y,
int width,
int height,
int corner_radius,
double scale,
enum corner_pos corners )

Create a path on the given cairo context to draw the background of a notification.

The top corners will get rounded by corner_radius, if first is set. Respectably the same for last with the bottom corners.

TODO: Pass additional frame width information to fix blurry lines due to fractional scaling X and Y can then be calculated as: x = round(x*scale) + half_frame_width

Definition at line 556 of file draw.c.

◆ draw_setup()

void draw_setup ( void )

Definition at line 153 of file draw.c.

◆ frame_internal_radius()

static int frame_internal_radius ( int r,
int w,
int h )
static

Definition at line 520 of file draw.c.

◆ free_colored_layout()

static void free_colored_layout ( void * data)
static

Definition at line 288 of file draw.c.

◆ get_horizontal_text_icon_padding()

static int get_horizontal_text_icon_padding ( struct notification * n)
static

Definition at line 214 of file draw.c.

◆ get_text_size()

static void get_text_size ( PangoLayout * l,
int * w,
int * h,
double scale )
static

Definition at line 242 of file draw.c.

◆ get_vertical_text_icon_padding()

static int get_vertical_text_icon_padding ( struct notification * n)
static

Definition at line 226 of file draw.c.

◆ gradient_acquire()

struct gradient * gradient_acquire ( struct gradient * grad)

Definition at line 93 of file draw.c.

◆ gradient_alloc()

struct gradient * gradient_alloc ( size_t length)

Definition at line 80 of file draw.c.

◆ gradient_free()

static void gradient_free ( struct gradient * grad)
static

Definition at line 98 of file draw.c.

◆ gradient_pattern()

void gradient_pattern ( struct gradient * grad)

Definition at line 110 of file draw.c.

◆ gradient_release()

void gradient_release ( struct gradient * grad)

Definition at line 104 of file draw.c.

◆ gradient_to_string()

char * gradient_to_string ( const struct gradient * grad)

Definition at line 131 of file draw.c.

◆ have_progress_bar()

static bool have_progress_bar ( const struct colored_layout * cl)
static

Definition at line 236 of file draw.c.

◆ layout_create()

static PangoLayout * layout_create ( cairo_t * c)
static

Definition at line 379 of file draw.c.

◆ layout_derive_xmore()

static struct colored_layout * layout_derive_xmore ( cairo_t * c,
struct notification * n,
int qlen )
static

Definition at line 408 of file draw.c.

◆ layout_from_notification()

static struct colored_layout * layout_from_notification ( cairo_t * c,
struct notification * n )
static

Definition at line 419 of file draw.c.

◆ layout_get_height()

static int layout_get_height ( struct colored_layout * cl,
double scale )
static

Definition at line 488 of file draw.c.

◆ layout_get_sepcolor()

static struct color layout_get_sepcolor ( struct colored_layout * cl,
struct colored_layout * cl_next )
static

Definition at line 196 of file draw.c.

◆ layout_init_shared()

static struct colored_layout * layout_init_shared ( cairo_t * c,
struct notification * n )
static

Definition at line 393 of file draw.c.

◆ layout_render()

static struct dimensions layout_render ( cairo_surface_t * srf,
struct colored_layout * cl,
struct colored_layout * cl_next,
struct dimensions dim,
enum corner_pos corners )
static

Definition at line 934 of file draw.c.

◆ layout_setup()

static void layout_setup ( struct colored_layout * cl,
int width,
int height,
double scale )
static

Definition at line 278 of file draw.c.

◆ layout_setup_pango()

static void layout_setup_pango ( PangoLayout * layout,
int width,
int height,
bool word_wrap,
PangoEllipsizeMode ellipsize_mode,
PangoAlignment alignment )
static

Definition at line 255 of file draw.c.

◆ load_icon_themes()

void load_icon_themes ( void )

Definition at line 48 of file draw.c.

◆ render_background()

static cairo_surface_t * render_background ( cairo_surface_t * srf,
struct colored_layout * cl,
struct colored_layout * cl_next,
int y,
int width,
int height,
int corner_radius,
enum corner_pos corners,
int * ret_width,
double scale )
static

Definition at line 708 of file draw.c.

◆ render_content()

static void render_content ( cairo_t * c,
struct colored_layout * cl,
int width,
int height,
double scale )
static

Definition at line 786 of file draw.c.

Variable Documentation

◆ output

const struct output* output

Definition at line 40 of file draw.c.

◆ pango_fdesc

PangoFontDescription* pango_fdesc

Definition at line 43 of file draw.c.

◆ win

window win

Definition at line 41 of file draw.c.