2017-05-07 18:26:48 +02:00
|
|
|
#define _POSIX_C_SOURCE 199309L
|
2017-06-13 03:53:41 +02:00
|
|
|
#include <string.h>
|
2017-05-07 18:26:48 +02:00
|
|
|
#include <stdio.h>
|
2017-04-25 21:06:58 +02:00
|
|
|
#include <stdlib.h>
|
2017-05-07 18:26:48 +02:00
|
|
|
#include <time.h>
|
2017-06-07 14:39:40 +02:00
|
|
|
#include <inttypes.h>
|
2017-04-25 21:06:58 +02:00
|
|
|
#include <wayland-server.h>
|
2017-05-07 18:26:48 +02:00
|
|
|
#include <GLES3/gl3.h>
|
2017-05-31 21:38:26 +02:00
|
|
|
#include <wlr/backend.h>
|
2017-05-07 18:26:48 +02:00
|
|
|
#include <wlr/session.h>
|
2017-05-31 22:24:32 +02:00
|
|
|
#include <wlr/types.h>
|
2017-06-13 03:53:41 +02:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2017-06-13 16:13:11 +02:00
|
|
|
#include "shared.h"
|
2017-04-25 21:06:58 +02:00
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
struct sample_state {
|
2017-05-07 18:26:48 +02:00
|
|
|
float color[3];
|
|
|
|
int dec;
|
|
|
|
};
|
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
void handle_output_frame(struct output_state *output, struct timespec *ts) {
|
|
|
|
struct compositor_state *state = output->compositor;
|
|
|
|
struct sample_state *sample = state->data;
|
2017-05-07 18:26:48 +02:00
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
long ms = (ts->tv_sec - state->last_frame.tv_sec) * 1000 +
|
|
|
|
(ts->tv_nsec - state->last_frame.tv_nsec) / 1000000;
|
|
|
|
int inc = (sample->dec + 1) % 3;
|
2017-05-07 18:26:48 +02:00
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
sample->color[inc] += ms / 2000.0f;
|
|
|
|
sample->color[sample->dec] -= ms / 2000.0f;
|
2017-05-07 18:26:48 +02:00
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
if (sample->color[sample->dec] < 0.0f) {
|
|
|
|
sample->color[inc] = 1.0f;
|
|
|
|
sample->color[sample->dec] = 0.0f;
|
|
|
|
sample->dec = inc;
|
2017-05-07 18:26:48 +02:00
|
|
|
}
|
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
glClearColor(sample->color[0], sample->color[1], sample->color[2], 1.0);
|
2017-05-07 18:26:48 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
static void handle_keyboard_key(struct keyboard_state *kbstate,
|
|
|
|
xkb_keysym_t sym, enum wlr_key_state key_state) {
|
2017-06-13 03:53:41 +02:00
|
|
|
if (sym == XKB_KEY_Escape) {
|
2017-06-13 16:13:11 +02:00
|
|
|
kbstate->compositor->exit = true;
|
2017-05-31 21:38:26 +02:00
|
|
|
}
|
2017-06-13 03:53:41 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 18:26:48 +02:00
|
|
|
int main() {
|
2017-06-13 16:13:11 +02:00
|
|
|
struct sample_state state = {
|
2017-05-07 18:26:48 +02:00
|
|
|
.color = { 1.0, 0.0, 0.0 },
|
|
|
|
.dec = 0,
|
|
|
|
};
|
2017-06-13 16:13:11 +02:00
|
|
|
struct compositor_state compositor;
|
2017-05-07 18:26:48 +02:00
|
|
|
|
2017-06-13 16:13:11 +02:00
|
|
|
compositor_init(&compositor);
|
|
|
|
compositor.output_frame_cb = handle_output_frame;
|
|
|
|
compositor.keyboard_key_cb = handle_keyboard_key;
|
|
|
|
compositor.data = &state;
|
|
|
|
compositor_run(&compositor);
|
2017-04-25 21:06:58 +02:00
|
|
|
}
|