]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/include/cairo_util.h
Introduce a macro to flush a cairo surface twice.
[i3/i3] / i3bar / include / cairo_util.h
index 749beec8b60e1fd1a718d57facbcce94182bfb59..3e4ebec4f143dec0dbf1a278e0f06c9a6c448a89 100644 (file)
 
 #include <cairo/cairo-xcb.h>
 
+/* We need to flush cairo surfaces twice to avoid an assertion bug. See #1989
+ * and https://bugs.freedesktop.org/show_bug.cgi?id=92455. */
+#define CAIRO_SURFACE_FLUSH(surface)  \
+    do {                              \
+        cairo_surface_flush(surface); \
+        cairo_surface_flush(surface); \
+    } while (0)
+
 /* Represents a color split by color channel. */
 typedef struct color_t {
     double red;
@@ -63,3 +71,28 @@ color_t cairo_hex_to_color(const char *color);
  *
  */
 void cairo_set_source_color(surface_t *surface, color_t color);
+
+/**
+ * Draw the given text using libi3.
+ * This function also marks the surface dirty which is needed if other means of
+ * drawing are used. This will be the case when using XCB to draw text.
+ *
+ */
+void cairo_draw_text(i3String *text, surface_t *surface, color_t fg_color, color_t bg_color, int x, int y, int max_width);
+
+/**
+ * Draws a filled rectangle.
+ * This function is a convenience wrapper and takes care of flushing the
+ * surface as well as restoring the cairo state.
+ * Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
+ *
+ */
+void cairo_draw_rectangle(surface_t *surface, color_t color, double x, double y, double w, double h);
+
+/**
+ * Copies a surface onto another surface.
+ * Note that the drawing is done using CAIRO_OPERATOR_SOURCE.
+ *
+ */
+void cairo_copy_surface(surface_t *src, surface_t *dest, double src_x, double src_y,
+                        double dest_x, double dest_y, double dest_w, double dest_h);