summaryrefslogtreecommitdiff
path: root/src/xcb_colors.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2021-01-27 22:06:49 +0100
committerJoel Klinghed <the_jk@spawned.biz>2021-01-27 22:06:49 +0100
commit06950aab233de6a2f47293d59575bb42f6131660 (patch)
tree62f6eed4a6d35414f656d22b9ac7420849018a11 /src/xcb_colors.hh
parent1ef9c463f1efc1adfb62e42ab3dd17e8c6394373 (diff)
Complete rewrite using C++ and with shared state support
Diffstat (limited to 'src/xcb_colors.hh')
-rw-r--r--src/xcb_colors.hh57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/xcb_colors.hh b/src/xcb_colors.hh
new file mode 100644
index 0000000..4db2b93
--- /dev/null
+++ b/src/xcb_colors.hh
@@ -0,0 +1,57 @@
+#ifndef XCB_COLORS_HH
+#define XCB_COLORS_HH
+
+#include "xcb_connection.hh"
+
+#include <memory>
+
+namespace xcb {
+
+class Colors {
+protected:
+ class Storage;
+
+public:
+ virtual ~Colors() = default;
+
+ class Color {
+ public:
+ uint32_t get() {
+ return colors_->get(id_);
+ }
+
+ Color(std::shared_ptr<Storage> colors, size_t id)
+ : colors_(colors), id_(id) {}
+
+ private:
+ std::shared_ptr<Storage> colors_;
+ size_t id_;
+ };
+
+ virtual Color get_with_fallback(uint8_t r, uint8_t g, uint8_t b,
+ uint32_t fallback) = 0;
+
+ virtual bool sync() = 0;
+
+ static std::unique_ptr<Colors> create(shared_conn conn,
+ xcb_colormap_t colormap);
+
+protected:
+ Colors() = default;
+ Colors(Colors const&) = delete;
+ Colors& operator=(Colors const&) = delete;
+
+ class Storage {
+ public:
+ virtual ~Storage() = default;
+
+ virtual uint32_t get(size_t id) const = 0;
+
+ protected:
+ Storage() = default;
+ };
+};
+
+} // namespace xcb
+
+#endif // XCB_COLORS_HH