#pragma once #include "waymini.h" #include #include #include #include #include "datatypes.cpp" #include "buffer.cpp" namespace UwU { class Surface { public: Surface(uint16_t width, uint16_t height, waymini_key_cb onKey) { this->wm = waymini_create((uint32_t)width, (uint32_t)height, onKey, NULL); if (!this->wm) exit(1); // this->buffer = Buffer( // (uint8_t*)waymini_get_pixels(this->wm), // waymini_get_width(this->wm), // waymini_get_height(this->wm), // waymini_get_stride(this->wm)); this->buffer.pixels = (uint8_t*)waymini_get_pixels(this->wm); this->buffer.width = waymini_get_width(this->wm); this->buffer.height = waymini_get_height(this->wm); this->buffer.stride = waymini_get_stride(this->wm); printf("surface: %ux%u stride=%u\n", waymini_get_width(this->wm), waymini_get_height(this->wm), waymini_get_stride(this->wm)); if (!this->buffer.pixels) { waymini_destroy(this->wm); exit(1); } } class Buffer buffer; struct waymini* wm; // get current size of wayland surface and update buffer void updateSize() { buffer.width = waymini_get_width(wm); buffer.height = waymini_get_height(wm); buffer.stride = waymini_get_stride(wm); return; } uint32_t getWidth() { updateSize(); return buffer.width; } uint32_t getHeight() { updateSize(); return buffer.height; } uint32_t getStride() { updateSize(); return buffer.stride; } void present() { waymini_present(wm); return; } void destroy() { waymini_destroy(wm); return; } bool shouldClose() { if (waymini_should_close(wm) || waymini_dispatch(wm) < 0) { return true; } else { return false; } } }; }