/* Example program that links against the waymini library. * No external dependencies beyond waymini itself and the C standard library. */ #include "waymini.h" #include #include #include #include static void on_key(void *user, uint32_t keycode, uint32_t state) { (void)user; const char *label = state ? "down" : "up "; printf("key %s: %u\n", label, keycode); fflush(stdout); } namespace UwU { class Draw { public: struct waymini* wm; uint32_t width; uint32_t height; uint32_t stride; uint8_t *pixels; Draw(uint32_t width, uint32_t height, waymini_key_cb on_key) { this->wm = waymini_create(width, height, on_key, NULL); if (!this->wm) exit(1); this->width = waymini_get_width(this->wm); this->height = waymini_get_height(this->wm); this->stride = waymini_get_stride(this->wm); printf("surface: %ux%u stride=%u\n", this->width, this->height, this->stride); this->pixels = (uint8_t *)waymini_get_pixels(this->wm); if (!this->pixels) { waymini_destroy(this->wm); exit(1); } } // Draw a rectangle (duh) void rectangle(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1, uint8_t r, uint8_t g, uint8_t b) { return; } // Fill a simple gradient. Each row is stride bytes. void rainbow() { for (uint32_t y = 0; y < this->height; y++) { for (uint32_t x = 0; x < this->width; x++) { size_t i = (size_t)y * waymini_get_stride(this->wm) + (size_t)x * 4; this->pixels[i + 0] = (uint8_t)(y * 255 / this->height); /* B */ this->pixels[i + 1] = 0x00; /* G */ this->pixels[i + 2] = (uint8_t)(x * 255 / this->width); /* R */ this->pixels[i + 3] = 0xFF; /* A (ignored for XRGB) */ } } } }; } int main(void) { uint32_t w = 800, h = 480; // struct waymini *wm = waymini_create(w, h, on_key, NULL); UwU::Draw draw = UwU::Draw(w, h, on_key); draw.rainbow(); waymini_present(draw.wm); draw.pixels[200001] = 255; while (!waymini_should_close(draw.wm)) { if (waymini_dispatch(draw.wm) < 0) break; } waymini_destroy(draw.wm); return 0; }