This commit is contained in:
Rakarake 2025-12-27 17:42:01 +01:00
parent 1e0c44cc3d
commit 3de9bcea6b
4 changed files with 19 additions and 80 deletions

View file

@ -28,22 +28,26 @@ double time_since_start() {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char *shader_path = NULL; char *shader_path = NULL;
int output_type = OUTPUT_WINDOW; int output_type = OUTPUT_WINDOW;
if (argc >= 2) { // syntax: --window for a normal window or --layer for a wallpaper
shader_path = argv[1]; for (int i = 1; i < argc; i++) {
} else { if (strncmp("--window", argv[i], strlen("--window")) == 0) {
printf("need to supply path to shader\n");
exit(1);
}
if (argc >= 3) {
// xdg toplevel window (window) or wlr_layer_shell window (layer)
if (strcmp(argv[2], "window") == 0) {
output_type = OUTPUT_WINDOW; output_type = OUTPUT_WINDOW;
} else if (strcmp(argv[2], "layer") == 0) { }
else if (strncmp("--layer", argv[i], strlen("--layer")) == 0) {
output_type = OUTPUT_LAYER; output_type = OUTPUT_LAYER;
} else { }
printf("argument 2 is either 'window' or 'layer' 🍰\n"); else {
// path to fragment shader
if (shader_path != NULL) {
fprintf(stderr, "tried supplying '%s' as a shader file while one has already been selected\n", argv[i]);
return 1; return 1;
} }
shader_path = argv[i];
}
}
if (shader_path == NULL) {
printf("need to supply path to shader\n");
return 1;
} }
struct client_state state; struct client_state state;

View file

@ -57,7 +57,7 @@ GLuint create_shader(const char *fragment_src) {
GLuint load_shader(const char *path) { GLuint load_shader(const char *path) {
FILE *handle = fopen(path, "r"); FILE *handle = fopen(path, "r");
if (handle == NULL) { if (handle == NULL) {
printf("failed to open shader file\n"); printf("failed to open shader file: '%s'\n", path);
exit(1); exit(1);
} }
fseek(handle, 0L, SEEK_END); fseek(handle, 0L, SEEK_END);
@ -156,10 +156,6 @@ void render(Renderer *state, int w, int h, double time, char *shader_path, int r
int uniform_time = glGetUniformLocation(state->shader, "time"); int uniform_time = glGetUniformLocation(state->shader, "time");
glUniform1f(uniform_time, (float)time); glUniform1f(uniform_time, (float)time);
//glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
//glEnableVertexAttribArray(0);
//glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(state->vao); glBindVertexArray(state->vao);
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
} }

53
shm.c
View file

@ -1,53 +0,0 @@
#define _POSIX_C_SOURCE 200112L
#include <errno.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#include "shm.h"
static void
randname(char *buf)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
long r = ts.tv_nsec;
for (int i = 0; i < 6; ++i) {
buf[i] = 'A'+(r&15)+(r&16)*2;
r >>= 5;
}
}
static int
create_shm_file(void)
{
int retries = 100;
do {
char name[] = "/wl_shm-XXXXXX";
randname(name + sizeof(name) - 7);
--retries;
int fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd >= 0) {
shm_unlink(name);
return fd;
}
} while (retries > 0 && errno == EEXIST);
return -1;
}
int
allocate_shm_file(size_t size)
{
int fd = create_shm_file();
if (fd < 0)
return -1;
int ret;
do {
ret = ftruncate(fd, size);
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
close(fd);
return -1;
}
return fd;
}

8
shm.h
View file

@ -1,8 +0,0 @@
#ifndef SHM_H
#define SHM_H
#include <unistd.h>
int allocate_shm_file(size_t size);
#endif