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
|
#include <wayland-server.h>
#include <stdio.h>
#include <stdlib.h>
static void die(char const* s)
{
perror(s);
exit(EXIT_FAILURE);
}
static void on_release_shm(struct wl_client* client, struct wl_resource* resource)
{
fprintf(stderr, "Releasing shm %p\n", (void*)resource);
wl_resource_destroy(resource);
}
static const struct wl_shm_interface shm_impl = {
.release = on_release_shm,
};
static void on_destroy_shm(struct wl_resource* resource)
{
fprintf(stderr, "Destroyed shm %p\n", (void*)resource);
}
static void on_bind_shm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
struct wl_resource* resource = wl_resource_create(client, &wl_shm_interface, wl_shm_interface.version, id);
fprintf(stderr, "Bound shm %p\n", (void*)resource);
wl_resource_set_implementation(resource, &shm_impl, NULL, on_destroy_shm);
}
int main(int argc, char** argv)
{
struct wl_display* disp = wl_display_create();
if (!disp) { die("wl_display_create"); }
char const* sock = wl_display_add_socket_auto(disp);
if (!sock) { die("wl_display_add_socket_auto"); }
printf("Compositor running on %s\n", sock);
wl_global_create(disp, &wl_shm_interface, wl_shm_interface.version, NULL, on_bind_shm);
wl_display_run(disp);
wl_display_destroy(disp);
return EXIT_SUCCESS;
}
|