glonkers/glonkers.c

77 lines
2.3 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include <stdint.h>
#include <wayland-client.h>
#include <wayland-util.h>
#include <pthread.h>
#include <sys/mman.h>
#include "renderer.h"
#include "wayland.h"
#include <string.h>
int main(int argc, char *argv[]) {
char *shader_path = NULL;
int output_type = OUTPUT_WINDOW;
bool currently_reading_output = false;
char **output_list = NULL;
int output_count = 0;
// syntax: --window for a normal window or --layer for a wallpaper
for (int i = 1; i < argc; i++) {
if (strcmp("--window", argv[i]) == 0) {
output_type = OUTPUT_WINDOW;
currently_reading_output = false;
}
else if (strcmp("--layer", argv[i]) == 0) {
output_type = OUTPUT_LAYER;
currently_reading_output = false;
}
else if (strcmp("--output", argv[i]) == 0) {
output_list = &argv[i];
currently_reading_output = true;
}
else if (strcmp("--", argv[i]) == 0) {
currently_reading_output = false;
}
else if (currently_reading_output) {
output_count++;
}
else if (!currently_reading_output) {
// 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 = wayland_init(output_type, output_list, output_count);
Renderer renderer = new_renderer();
bool running = true;
while (running) {
struct event event = wait_for_event(state);
if (event.type == EVENT_DRAW) {
int width = event.data.draw.width;
int height = event.data.draw.height;
double time = event.data.draw.time / 1000.0;
render(&renderer, width, height, time, shader_path, 0);
swap_buffers(state, event.data.draw.surface);
}
if (event.type == EVENT_NONE) {
}
if (event.type == EVENT_EXIT) {
running = false;
}
}
return 0;
}