forked from vvavrychuk/hello_wayland
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello_wayland.c
65 lines (52 loc) · 1.49 KB
/
hello_wayland.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
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wayland-client.h>
#include "helpers.h"
static const unsigned WIDTH = 320;
static const unsigned HEIGHT = 200;
static const unsigned CURSOR_WIDTH = 100;
static const unsigned CURSOR_HEIGHT = 59;
static const int32_t CURSOR_HOT_SPOT_X = 10;
static const int32_t CURSOR_HOT_SPOT_Y = 35;
static bool done = false;
void on_button(uint32_t button)
{
done = true;
}
int main(void)
{
struct wl_buffer *buffer;
struct wl_shm_pool *pool;
struct wl_shell_surface *surface;
int image;
hello_setup_wayland();
image = open("images.bin", O_RDWR);
if (image < 0) {
perror("Error opening surface image");
return EXIT_FAILURE;
}
pool = hello_create_memory_pool(image);
surface = hello_create_surface();
buffer = hello_create_buffer(pool, WIDTH, HEIGHT);
hello_bind_buffer(buffer, surface);
hello_set_cursor_from_pool(pool, CURSOR_WIDTH,
CURSOR_HEIGHT, CURSOR_HOT_SPOT_X, CURSOR_HOT_SPOT_Y);
hello_set_button_callback(surface, on_button);
while (!done) {
if (wl_display_dispatch(display) < 0) {
perror("Main loop error");
done = true;
}
}
fprintf(stderr, "Exiting sample wayland client...\n");
hello_free_cursor();
hello_free_buffer(buffer);
hello_free_surface(surface);
hello_free_memory_pool(pool);
close(image);
hello_cleanup_wayland();
return EXIT_SUCCESS;
}