cleanup
This commit is contained in:
parent
1e0c44cc3d
commit
3de9bcea6b
4 changed files with 19 additions and 80 deletions
28
glonkers.c
28
glonkers.c
|
|
@ -28,22 +28,26 @@ double time_since_start() {
|
|||
int main(int argc, char *argv[]) {
|
||||
char *shader_path = NULL;
|
||||
int output_type = OUTPUT_WINDOW;
|
||||
if (argc >= 2) {
|
||||
shader_path = argv[1];
|
||||
} else {
|
||||
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) {
|
||||
// syntax: --window for a normal window or --layer for a wallpaper
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strncmp("--window", argv[i], strlen("--window")) == 0) {
|
||||
output_type = OUTPUT_WINDOW;
|
||||
} else if (strcmp(argv[2], "layer") == 0) {
|
||||
}
|
||||
else if (strncmp("--layer", argv[i], strlen("--layer")) == 0) {
|
||||
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;
|
||||
}
|
||||
shader_path = argv[i];
|
||||
}
|
||||
}
|
||||
if (shader_path == NULL) {
|
||||
printf("need to supply path to shader\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct client_state state;
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ GLuint create_shader(const char *fragment_src) {
|
|||
GLuint load_shader(const char *path) {
|
||||
FILE *handle = fopen(path, "r");
|
||||
if (handle == NULL) {
|
||||
printf("failed to open shader file\n");
|
||||
printf("failed to open shader file: '%s'\n", path);
|
||||
exit(1);
|
||||
}
|
||||
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");
|
||||
glUniform1f(uniform_time, (float)time);
|
||||
|
||||
//glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
|
||||
//glEnableVertexAttribArray(0);
|
||||
//glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
glBindVertexArray(state->vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
|
|
|||
53
shm.c
53
shm.c
|
|
@ -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
8
shm.h
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef SHM_H
|
||||
#define SHM_H
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
int allocate_shm_file(size_t size);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue