2026-07-07 03:25:10 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-07-07 08:09:54 -07:00
|
|
|
#include "waymini/waymini.h"
|
2026-07-07 03:25:10 -07:00
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "datatypes.cpp"
|
|
|
|
|
#include "buffer.cpp"
|
|
|
|
|
|
|
|
|
|
namespace UwU {
|
|
|
|
|
class Surface {
|
2026-07-07 07:46:27 -07:00
|
|
|
// should probably be a child of buffer
|
2026-07-07 03:25:10 -07:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|