]> git.sur5r.net Git - i3/i3/blob - i3bar/include/cairo_util.h
Use 32-bit visuals for i3bar when possible and allow RGBA colors.
[i3/i3] / i3bar / include / cairo_util.h
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * © 2015 Ingo Bürk and contributors (see also: LICENSE)
5  *
6  * cairo_util.h: Utility for operations using cairo.
7  *
8  */
9 #pragma once
10
11 #include <cairo/cairo-xcb.h>
12
13 /* Represents a color split by color channel. */
14 typedef struct color_t {
15     double red;
16     double green;
17     double blue;
18     double alpha;
19
20     /* For compatibility, we also store the colorpixel for now. */
21     uint32_t colorpixel;
22 } color_t;
23
24 /* A wrapper grouping an XCB drawable and both a graphics context
25  * and the corresponding cairo objects representing it. */
26 typedef struct surface_t {
27     /* The drawable which is being represented. */
28     xcb_drawable_t id;
29
30     // TODO remove this once i3 uses solely cairo for drawing operations
31     /* A classic XCB graphics context. This should not be used for
32      * drawing operations. */
33     xcb_gcontext_t gc;
34
35     /* A cairo surface representing the drawable. */
36     cairo_surface_t *surface;
37
38     /* The cairo object representing the drawale. In general,
39      * this is what one should use for any drawing operation. */
40     cairo_t *cr;
41 } surface_t;
42
43 /**
44  * Initialize the cairo surface to represent the given drawable.
45  *
46  */
47 void cairo_surface_init(surface_t *surface, xcb_drawable_t drawable, int width, int height);
48
49 /**
50  * Destroys the surface.
51  *
52  */
53 void cairo_surface_free(surface_t *surface);
54
55 /**
56  * Parses the given color in hex format to an internal color representation.
57  * Note that the input must begin with a hash sign, e.g., "#3fbc59".
58  *
59  */
60 color_t cairo_hex_to_color(const char *color);
61
62 /**
63  * Set the given color as the source color on the surface.
64  *
65  */
66 void cairo_set_source_color(surface_t *surface, color_t color);