forked from emersion/wleird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sigbus.c
69 lines (54 loc) · 1.76 KB
/
sigbus.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#define _POSIX_C_SOURCE 200112L
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "client.h"
#include "pool-buffer.h"
static void xdg_surface_handle_configure(void *data,
struct xdg_surface *xdg_surface, uint32_t serial) {
xdg_surface_ack_configure(xdg_surface, serial);
}
static const struct xdg_surface_listener sigbus_xdg_surface_listener = {
.configure = xdg_surface_handle_configure,
};
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);
int width = 512, height = 512, stride = width * 4;
size_t size = stride * height;
int fd = create_pool_file(size);
if (fd < 0) {
fprintf(stderr, "failed to create shm file\n");
return EXIT_FAILURE;
}
struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);
struct wl_buffer *buffer = wl_shm_pool_create_buffer(pool, 0,
width, height, stride, WL_SHM_FORMAT_ARGB8888);
wl_display_roundtrip(display);
// Shrink the file
size = 42;
if (ftruncate(fd, size) < 0) {
perror("ftruncate failed");
return EXIT_FAILURE;
}
struct wl_surface *surface = wl_compositor_create_surface(compositor);
struct xdg_surface *xdg_surface =
xdg_wm_base_get_xdg_surface(wm_base, surface);
xdg_surface_add_listener(xdg_surface, &sigbus_xdg_surface_listener, NULL);
xdg_surface_get_toplevel(xdg_surface);
wl_surface_commit(surface);
// Wait for the xdg_surface.configure event
wl_display_roundtrip(display);
wl_surface_attach(surface, buffer, 0, 0);
wl_surface_damage_buffer(surface, 0, 0, width, height);
wl_surface_commit(surface);
while (wl_display_dispatch(display) != -1) {
// This space intentionally left blank
}
close(fd);
return 0;
}