forked from emersion/wleird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe-callback.c
55 lines (42 loc) · 1.35 KB
/
frame-callback.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "client.h"
static struct wleird_toplevel toplevel = {0};
static uint32_t last_time_ms = 0;
static const struct wl_callback_listener callback_listener;
static void request_frame_callback(void) {
struct wl_callback *callback = wl_surface_frame(toplevel.surface.wl_surface);
wl_callback_add_listener(callback, &callback_listener, NULL);
wl_surface_commit(toplevel.surface.wl_surface);
}
static void callback_handle_done(void *data, struct wl_callback *callback,
uint32_t time_ms) {
if (callback != NULL) {
wl_callback_destroy(callback);
}
fprintf(stderr, "received frame (time=%"PRIu32"ms, delta=%"PRIu32"ms)\n",
time_ms, time_ms - last_time_ms);
last_time_ms = time_ms;
request_frame_callback();
}
static const struct wl_callback_listener callback_listener = {
.done = callback_handle_done,
};
int main(int argc, char *argv[]) {
struct wl_display *display = wl_display_connect(NULL);
if (display == NULL) {
fprintf(stderr, "failed to create display\n");
return EXIT_FAILURE;
}
registry_init(display);
toplevel_init(&toplevel);
float color[4] = {1, 0, 0, 1};
memcpy(toplevel.surface.color, color, sizeof(float[4]));
request_frame_callback();
while (wl_display_dispatch(display) != -1) {
// This space intentionally left blank
}
return EXIT_SUCCESS;
}