2017-01-18 23:38:42 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cairo/cairo-xcb.h>
|
|
|
|
|
|
|
|
#include "cairo/types.hpp"
|
|
|
|
#include "common.hpp"
|
2017-01-24 00:59:58 -05:00
|
|
|
#include "errors.hpp"
|
2017-01-18 23:38:42 -05:00
|
|
|
#include "utils/color.hpp"
|
2017-01-24 00:59:58 -05:00
|
|
|
#include "utils/string.hpp"
|
2017-01-18 23:38:42 -05:00
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
namespace cairo {
|
2017-01-24 00:59:58 -05:00
|
|
|
/**
|
2018-11-04 10:08:54 -05:00
|
|
|
* \brief Base surface
|
2017-01-24 00:59:58 -05:00
|
|
|
*/
|
2017-01-18 23:38:42 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:59:58 -05:00
|
|
|
void flush() {
|
2017-01-18 23:38:42 -05:00
|
|
|
cairo_surface_flush(m_s);
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:59:58 -05:00
|
|
|
void show(bool clear = true) {
|
|
|
|
if (clear) {
|
|
|
|
cairo_surface_show_page(m_s);
|
|
|
|
} else {
|
|
|
|
cairo_surface_copy_page(m_s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dirty() {
|
2017-01-18 23:38:42 -05:00
|
|
|
cairo_surface_mark_dirty(m_s);
|
|
|
|
}
|
|
|
|
|
2017-01-24 00:59:58 -05:00
|
|
|
void dirty(const rect& r) {
|
2017-01-18 23:38:42 -05:00
|
|
|
cairo_surface_mark_dirty_rectangle(m_s, r.x, r.y, r.w, r.h);
|
2017-01-24 00:59:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2017-01-18 23:38:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
cairo_surface_t* m_s;
|
|
|
|
};
|
|
|
|
|
2017-01-24 00:59:58 -05:00
|
|
|
/**
|
2018-11-04 10:08:54 -05:00
|
|
|
* \brief Surface for xcb
|
2017-01-24 00:59:58 -05:00
|
|
|
*/
|
2017-01-18 23:38:42 -05:00
|
|
|
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)) {}
|
2017-01-24 00:59:58 -05:00
|
|
|
|
2017-01-18 23:38:42 -05:00
|
|
|
~xcb_surface() override {}
|
2017-01-24 00:59:58 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2017-01-18 23:38:42 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|