put everything in a class

This commit is contained in:
2026-07-04 00:26:59 -07:00
parent b3ef2f0046
commit 24cae3d544
3 changed files with 86 additions and 4 deletions
+4 -4
View File
@@ -12,13 +12,13 @@ LIB_OBJ := $(LIB_SRC:.c=.o)
.PHONY: all clean .PHONY: all clean
all: libwaymini.a example waymini all: libwaymini.a test waymini
libwaymini.a: $(LIB_OBJ) libwaymini.a: $(LIB_OBJ)
ar rcs $@ $^ ar rcs $@ $^
example: example.c libwaymini.a test: test.cpp libwaymini.a
$(CC) $(CFLAGS) -o $@ example.c -L. -lwaymini $(LDFLAGS) g++ $(CFLAGS) -o $@ test.cpp -L. -lwaymini $(LDFLAGS)
waymini: waymini_standalone.c waymini.c xdg-shell-client-protocol.c waymini: waymini_standalone.c waymini.c xdg-shell-client-protocol.c
$(CC) $(CFLAGS) -o $@ waymini_standalone.c waymini.c xdg-shell-client-protocol.c $(LDFLAGS) $(CC) $(CFLAGS) -o $@ waymini_standalone.c waymini.c xdg-shell-client-protocol.c $(LDFLAGS)
@@ -27,7 +27,7 @@ waymini: waymini_standalone.c waymini.c xdg-shell-client-protocol.c
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
clean: clean:
rm -f $(LIB_OBJ) libwaymini.a example waymini rm -f $(LIB_OBJ) libwaymini.a test waymini
xdg-shell-client-protocol.c xdg-shell-client-protocol.h: gen-protocols.sh xdg-shell-client-protocol.c xdg-shell-client-protocol.h: gen-protocols.sh
bash gen-protocols.sh bash gen-protocols.sh
Executable
BIN
View File
Binary file not shown.
+82
View File
@@ -0,0 +1,82 @@
/* Example program that links against the waymini library.
* No external dependencies beyond waymini itself and the C standard library.
*/
#include "waymini.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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;
}