79 lines
2.1 KiB
C
79 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <signal.h>
|
|
#include <time.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>
|
|
|
|
struct timespec program_start;
|
|
|
|
void init_timer() {
|
|
clock_gettime(CLOCK_MONOTONIC, &program_start);
|
|
}
|
|
|
|
double time_since_start() {
|
|
struct timespec now;
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
return (now.tv_sec - program_start.tv_sec) +
|
|
(now.tv_nsec - program_start.tv_nsec) / 1e9;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
char *shader_path = NULL;
|
|
int output_type = OUTPUT_WINDOW;
|
|
// 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;
|
|
}
|
|
else if (strcmp("--layer", argv[i]) == 0) {
|
|
output_type = OUTPUT_LAYER;
|
|
}
|
|
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;
|
|
wayland_init(&state, output_type);
|
|
|
|
Renderer renderer = new_renderer();
|
|
|
|
bool running = true;
|
|
while (running) {
|
|
double time = time_since_start();
|
|
|
|
struct event event;
|
|
wait_for_event(&state, &event);
|
|
if (event.type == EVENT_DRAW) {
|
|
int width = event.data.draw.width;
|
|
int height = event.data.draw.height;
|
|
render(&renderer, width, height, time, shader_path, 0);
|
|
}
|
|
}
|
|
//while (state.running) {
|
|
// double time = time_since_start();
|
|
// render(&renderer, state.width, state.height, time, shader_path, 0);
|
|
// commit(&state);
|
|
//}
|
|
|
|
return 0;
|
|
}
|
|
|