aboutsummaryrefslogtreecommitdiffstats
path: root/src/wayland.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wayland.hpp')
-rw-r--r--src/wayland.hpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/wayland.hpp b/src/wayland.hpp
index 40b18b0..2321fff 100644
--- a/src/wayland.hpp
+++ b/src/wayland.hpp
@@ -6,8 +6,8 @@
#include "util.h"
#include <functional>
-#include <unordered_map>
#include <memory>
+#include <unordered_map>
#include <vector>
// _ _
@@ -18,18 +18,14 @@
// |___/ |_____|_| |___/
template <typename ProxyT>
struct wayland_proxy {
- ProxyT *proxy;
-
- wayland_proxy(void *p) : proxy(static_cast<ProxyT *>(p)) {}
-
- virtual ~wayland_proxy() {
- // If this is the nullptr, then it means it already was destroyed by a
- // custom wayland dtor
- if (this->proxy) {
- logdebug("%s %p @ %p", __func__, this, this->proxy);
- wl_proxy_destroy(reinterpret_cast<struct wl_proxy *>(this->proxy));
- }
- }
+ std::unique_ptr<ProxyT, std::function<void(ProxyT *)>> proxy;
+ wayland_proxy(void *p)
+ : wayland_proxy(p, [](ProxyT *p) {
+ wl_proxy_destroy(reinterpret_cast<struct wl_proxy *>(p));
+ }) {}
+ wayland_proxy(void *p, std::function<void(ProxyT *)> p_del)
+ : proxy(std::unique_ptr<ProxyT, std::function<void(ProxyT *)>>(
+ static_cast<ProxyT *>(p), p_del)) {}
};
// _
@@ -146,15 +142,14 @@ struct surface : public wayland_proxy<struct ivi_controller_surface>,
float opacity;
surface(uint32_t i, struct controller *c);
- ~surface() override;
// Requests
void set_visibility(uint32_t visibility);
void set_opacity(wl_fixed_t opacity);
void set_source_rectangle(int32_t x, int32_t y, int32_t width,
- int32_t height);
+ int32_t height);
void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
- int32_t height);
+ int32_t height);
void set_configuration(int32_t width, int32_t height);
void set_orientation(int32_t orientation);
void screenshot(const char *filename);
@@ -179,7 +174,6 @@ struct layer : public wayland_proxy<struct ivi_controller_layer>,
layer(uint32_t i, struct controller *c);
layer(uint32_t i, int32_t w, int32_t h, struct controller *c);
- ~layer() override;
// Requests
void set_visibility(uint32_t visibility);
@@ -239,13 +233,16 @@ struct controller : public wayland_proxy<struct ivi_controller> {
void add_proxy_to_id_mapping(struct wl_output *p, uint32_t id);
void remove_proxy_to_id_mapping(struct wl_output *p);
- void add_task(char const *name, std::function<void(struct controller *)> &&f);
+ void add_task(char const *name,
+ std::function<void(struct controller *)> &&f);
void execute_pending();
controller(struct wl_registry *r, uint32_t name, uint32_t version);
// Requests
- void commit_changes() const { ivi_controller_commit_changes(this->proxy); }
+ void commit_changes() const {
+ ivi_controller_commit_changes(this->proxy.get());
+ }
void layer_create(uint32_t id, int32_t w, int32_t h);
void surface_create(uint32_t id);