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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#include "wm.h"
Server server = {
.event = {
.make_input = { .notify = make_input },
.make_output = { .notify = make_output },
.make_xdg_surface = { .notify = make_xdg_surface },
.cursor_move = { .notify = cursor_move },
.cursor_move_abs = { .notify = cursor_move_abs },
.cursor_button = { .notify = cursor_button },
.cursor_axis = { .notify = cursor_axis },
.cursor_frame = { .notify = cursor_frame },
.request_cursor = { .notify = request_cursor },
.request_set_selection = { .notify = request_set_selection },
},
};
// -----------------------------------------------------------------------
// helper functions
static inline
void
init_compositor(void)
{
server.display = wl_display_create();
server.backend = wlr_backend_autocreate(server.display);
server.renderer = wlr_backend_get_renderer(server.backend);
wlr_renderer_init_wl_display(server.renderer, server.display);
wlr_compositor_create(server.display, server.renderer);
wlr_data_device_manager_create(server.display);
server.output.layout = wlr_output_layout_create();
wl_list_init(&server.output.list);
wl_signal_add(&server.backend->events.new_output, &server.event.make_output);
}
static inline
void
init_desktop(void)
{
wl_list_init(&server.clients);
server.shell.xdg = wlr_xdg_shell_create(server.display);
wl_signal_add(&server.shell.xdg->events.new_surface, &server.event.make_xdg_surface);
}
static inline
void
init_inputs(void)
{
server.cursor.dot = wlr_cursor_create();
wlr_cursor_attach_output_layout(server.cursor.dot, server.output.layout);
server.cursor.manager = wlr_xcursor_manager_create(nil, 24);
wlr_xcursor_manager_load(server.cursor.manager, 1);
wl_signal_add(&server.cursor.dot->events.motion, &server.event.cursor_move);
wl_signal_add(&server.cursor.dot->events.motion_absolute, &server.event.cursor_move_abs);
wl_signal_add(&server.cursor.dot->events.button, &server.event.cursor_button);
wl_signal_add(&server.cursor.dot->events.axis, &server.event.cursor_axis);
wl_signal_add(&server.cursor.dot->events.frame, &server.event.cursor_frame);
wl_list_init(&server.input.keyboards);
wl_signal_add(&server.backend->events.new_input, &server.event.make_input);
server.input.seat = wlr_seat_create(server.display, "seat0");
wl_signal_add(&server.input.seat->events.request_set_cursor, &server.event.request_cursor);
wl_signal_add(&server.input.seat->events.request_set_selection, &server.event.request_set_selection);
}
static inline
void
cleanup(void)
{
wl_display_destroy_clients(server.display);
wl_display_destroy(server.display);
}
// -----------------------------------------------------------------------
// main point of entry
int
main(int argc, char *argv[])
{
char *socket;
wlr_log_init(WLR_DEBUG, nil);
init_compositor();
init_desktop();
init_inputs();
if(!(socket=(char*)wl_display_add_socket_auto(server.display))) {
wlr_backend_destroy(server.backend);
return 1;
}
if(!(wlr_backend_start(server.backend))) {
wlr_backend_destroy(server.backend);
wl_display_destroy(server.display);
return 1;
}
setenv("WAYLAND_DISPLAY", socket, true);
wlr_log(WLR_INFO, "Running Wayland compositor on WAYLAND_DISPLAY=%s", socket);
wl_display_run(server.display); /* event loop */
cleanup();
return 0;
}
|