#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; }