1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#pragma once
#include <cairo/cairo-xcb.h>
#include "cairo/types.hpp"
#include "common.hpp"
#include "errors.hpp"
#include "utils/color.hpp"
#include "utils/string.hpp"
POLYBAR_NS
namespace cairo {
/**
* @brief Base surface
*/
class surface {
public:
explicit surface(cairo_surface_t* s) : m_s(s) {}
virtual ~surface() {
cairo_surface_destroy(m_s);
}
operator cairo_surface_t*() const {
return m_s;
}
void flush() {
cairo_surface_flush(m_s);
}
void show(bool clear = true) {
if (clear) {
cairo_surface_show_page(m_s);
} else {
cairo_surface_copy_page(m_s);
}
}
void dirty() {
cairo_surface_mark_dirty(m_s);
}
void dirty(const rect& r) {
cairo_surface_mark_dirty_rectangle(m_s, r.x, r.y, r.w, r.h);
}
void write_png(const string& dst) {
auto status = cairo_surface_write_to_png(m_s, dst.c_str());
if (status != CAIRO_STATUS_SUCCESS) {
throw application_error(sstream() << "cairo_surface_write_to_png(): " << cairo_status_to_string(status));
}
}
protected:
cairo_surface_t* m_s;
};
/**
* @brief Surface for xcb
*/
class xcb_surface : public surface {
public:
explicit xcb_surface(xcb_connection_t* c, xcb_pixmap_t p, xcb_visualtype_t* v, int w, int h)
: surface(cairo_xcb_surface_create(c, p, v, w, h)) {}
~xcb_surface() override {}
void set_drawable(xcb_drawable_t d, int w, int h) {
cairo_surface_flush(m_s);
cairo_xcb_surface_set_drawable(m_s, d, w, h);
}
};
}
POLYBAR_NS_END
|