base
This commit is contained in:
+139
@@ -0,0 +1,139 @@
|
||||
#include <stdlib.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include <wlr/types/wlr_subcompositor.h>
|
||||
#include <wlr/types/wlr_data_device.h>
|
||||
#include <wlr/types/wlr_screencopy_v1.h>
|
||||
#include <wlr/types/wlr_xcursor_manager.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "server.h"
|
||||
#include "seat.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
wlr_log_init(WLR_DEBUG, NULL);
|
||||
|
||||
struct absinthe_server server = {0};
|
||||
|
||||
server.display = wl_display_create();
|
||||
if (!server.display) {
|
||||
wlr_log(WLR_ERROR, "Failed to create wl_display");
|
||||
return 1;
|
||||
}
|
||||
|
||||
server.backend = wlr_backend_autocreate(wl_display_get_event_loop(server.display), NULL);
|
||||
if (!server.backend) {
|
||||
wlr_log(WLR_ERROR, "Failed to create wlr_backend");
|
||||
return 1;
|
||||
}
|
||||
|
||||
server.renderer = wlr_renderer_autocreate(server.backend);
|
||||
if (!server.renderer) {
|
||||
wlr_log(WLR_ERROR, "Failed to create wlr_renderer");
|
||||
return 1;
|
||||
}
|
||||
|
||||
wlr_renderer_init_wl_display(server.renderer, server.display);
|
||||
|
||||
server.allocator = wlr_allocator_autocreate(server.backend, server.renderer);
|
||||
if (!server.allocator) {
|
||||
wlr_log(WLR_ERROR, "Failed to create wlr_allocator");
|
||||
return 1;
|
||||
}
|
||||
|
||||
wlr_compositor_create(server.display, 5, server.renderer);
|
||||
wlr_subcompositor_create(server.display);
|
||||
wlr_data_device_manager_create(server.display);
|
||||
wlr_screencopy_manager_v1_create(server.display);
|
||||
|
||||
server.output_layout = wlr_output_layout_create(server.display);
|
||||
|
||||
wl_list_init(&server.outputs);
|
||||
server.new_output.notify = server_new_output;
|
||||
wl_signal_add(&server.backend->events.new_output, &server.new_output);
|
||||
|
||||
server.scene = wlr_scene_create();
|
||||
server.scene_layout = wlr_scene_attach_output_layout(server.scene, server.output_layout);
|
||||
|
||||
wl_list_init(&server.toplevels);
|
||||
server.xdg_shell = wlr_xdg_shell_create(server.display, 3);
|
||||
server.new_xdg_toplevel.notify = server_new_xdg_toplevel;
|
||||
wl_signal_add(&server.xdg_shell->events.new_toplevel, &server.new_xdg_toplevel);
|
||||
server.new_xdg_popup.notify = server_new_xdg_popup;
|
||||
wl_signal_add(&server.xdg_shell->events.new_popup, &server.new_xdg_popup);
|
||||
|
||||
server.cursor = wlr_cursor_create();
|
||||
wlr_cursor_attach_output_layout(server.cursor, server.output_layout);
|
||||
|
||||
server.cursor_mgr = wlr_xcursor_manager_create(NULL, 24);
|
||||
|
||||
server.cursor_mode = ABSINTHE_CURSOR_PASSTHROUGH;
|
||||
server.cursor_motion.notify = server_cursor_motion;
|
||||
wl_signal_add(&server.cursor->events.motion, &server.cursor_motion);
|
||||
server.cursor_motion_absolute.notify = server_cursor_motion_absolute;
|
||||
wl_signal_add(&server.cursor->events.motion_absolute, &server.cursor_motion_absolute);
|
||||
server.cursor_button.notify = server_cursor_button;
|
||||
wl_signal_add(&server.cursor->events.button, &server.cursor_button);
|
||||
server.cursor_axis.notify = server_cursor_axis;
|
||||
wl_signal_add(&server.cursor->events.axis, &server.cursor_axis);
|
||||
server.cursor_frame.notify = server_cursor_frame;
|
||||
wl_signal_add(&server.cursor->events.frame, &server.cursor_frame);
|
||||
|
||||
wl_list_init(&server.keyboards);
|
||||
server.new_input.notify = server_new_input;
|
||||
wl_signal_add(&server.backend->events.new_input, &server.new_input);
|
||||
server.seat = wlr_seat_create(server.display, "seat0");
|
||||
server.request_cursor.notify = seat_request_cursor;
|
||||
wl_signal_add(&server.seat->events.request_set_cursor, &server.request_cursor);
|
||||
server.pointer_focus_change.notify = seat_pointer_focus_change;
|
||||
wl_signal_add(&server.seat->pointer_state.events.focus_change, &server.pointer_focus_change);
|
||||
server.request_set_selection.notify = seat_request_set_selection;
|
||||
wl_signal_add(&server.seat->events.request_set_selection, &server.request_set_selection);
|
||||
|
||||
const char *socket = wl_display_add_socket_auto(server.display);
|
||||
if (!socket) {
|
||||
wlr_log(WLR_ERROR, "Failed to add socket");
|
||||
wlr_backend_destroy(server.backend);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!wlr_backend_start(server.backend)) {
|
||||
wlr_log(WLR_ERROR, "Failed to start wlr_backend");
|
||||
wlr_backend_destroy(server.backend);
|
||||
wl_display_destroy(server.display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
setenv("WAYLAND_DISPLAY", socket, true);
|
||||
|
||||
wlr_log(WLR_INFO, "Running absinthe on WAYLAND_DISPLAY=%s", socket);
|
||||
wl_display_run(server.display);
|
||||
|
||||
wl_display_destroy_clients(server.display);
|
||||
|
||||
wl_list_remove(&server.new_xdg_toplevel.link);
|
||||
wl_list_remove(&server.new_xdg_popup.link);
|
||||
|
||||
wl_list_remove(&server.cursor_motion.link);
|
||||
wl_list_remove(&server.cursor_motion_absolute.link);
|
||||
wl_list_remove(&server.cursor_button.link);
|
||||
wl_list_remove(&server.cursor_axis.link);
|
||||
wl_list_remove(&server.cursor_frame.link);
|
||||
|
||||
wl_list_remove(&server.new_input.link);
|
||||
wl_list_remove(&server.request_cursor.link);
|
||||
wl_list_remove(&server.pointer_focus_change.link);
|
||||
wl_list_remove(&server.request_set_selection.link);
|
||||
|
||||
wl_list_remove(&server.new_output.link);
|
||||
|
||||
wlr_scene_node_destroy(&server.scene->tree.node);
|
||||
wlr_xcursor_manager_destroy(server.cursor_mgr);
|
||||
wlr_cursor_destroy(server.cursor);
|
||||
wlr_allocator_destroy(server.allocator);
|
||||
wlr_renderer_destroy(server.renderer);
|
||||
wlr_backend_destroy(server.backend);
|
||||
wl_display_destroy(server.display);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user