diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build diff --git a/include/kiwmi/server.h b/include/kiwmi/server.h new file mode 100644 index 0000000..5ce3677 --- /dev/null +++ b/include/kiwmi/server.h @@ -0,0 +1,30 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#ifndef KIWMI_SERVER_H +#define KIWMI_SERVER_H + +#include +#include +#include +#include +#include + +struct kiwmi_server { + struct wl_display *wl_display; + struct wlr_backend *backend; + struct wlr_compositor *compositor; + struct wlr_data_device_manager *data_device_manager; + struct wlr_output_layout *output_layout; + const char *socket; +}; + +bool server_init(struct kiwmi_server *server); +void server_run(struct kiwmi_server *server); +void server_fini(struct kiwmi_server *server); + +#endif /* KIWMI_SERVER_H */ diff --git a/kiwmi/main.c b/kiwmi/main.c new file mode 100644 index 0000000..c3226fd --- /dev/null +++ b/kiwmi/main.c @@ -0,0 +1,32 @@ +/* Copyright (c), Charlotte Meyer + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include + +#include "kiwmi/server.h" + +int +main(void) +{ + wlr_log_init(WLR_DEBUG, NULL); + + struct kiwmi_server server; + + if (!server_init(&server)) { + wlr_log(WLR_ERROR, "Failed to initialize server"); + exit(EXIT_FAILURE); + } + + wlr_log(WLR_INFO, "Starting kiwmi v" KIWMI_VERSION); + + server_run(&server); + + server_fini(&server); +} diff --git a/kiwmi/meson.build b/kiwmi/meson.build new file mode 100644 index 0000000..150c379 --- /dev/null +++ b/kiwmi/meson.build @@ -0,0 +1,17 @@ +kiwmi_sources = files( + 'main.c', + 'server.c', +) + +kiwmi_deps = [ + wayland_server, + wlroots, +] + +executable( + 'kiwmi', + kiwmi_sources, + include_directories: [include], + dependencies: kiwmi_deps, + install: true, +) diff --git a/kiwmi/server.c b/kiwmi/server.c new file mode 100644 index 0000000..708ce34 --- /dev/null +++ b/kiwmi/server.c @@ -0,0 +1,69 @@ +#include "kiwmi/server.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +bool +server_init(struct kiwmi_server *server) +{ + wlr_log(WLR_DEBUG, "Initializing Wayland server"); + + server->wl_display = wl_display_create(); + server->backend = wlr_backend_autocreate(server->wl_display, NULL); + if (!server->backend) { + wlr_log(WLR_ERROR, "Failed to create backend"); + return false; + } + + struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); + wlr_renderer_init_wl_display(renderer, server->wl_display); + + server->compositor = wlr_compositor_create(server->wl_display, renderer); + server->data_device_manager = wlr_data_device_manager_create(server->wl_display); + + server->output_layout = wlr_output_layout_create(); + + server->socket = wl_display_add_socket_auto(server->wl_display); + if (!server->socket) { + wlr_log(WLR_ERROR, "Failed to open Wayland socket"); + wlr_backend_destroy(server->backend); + wl_display_destroy(server->wl_display); + return false; + } + + if (!wlr_backend_start(server->backend)) { + wlr_log(WLR_ERROR, "Failed to start backend"); + wlr_backend_destroy(server->backend); + wl_display_destroy(server->wl_display); + return false; + } + + setenv("WAYLAND_DISPLAY", server->socket, true); + + return true; +} + +void +server_run(struct kiwmi_server *server) +{ + wlr_log(WLR_DEBUG, "Running Wayland server on display '%s'", server->socket); + + wl_display_run(server->wl_display); +} + +void +server_fini(struct kiwmi_server *server) +{ + wlr_log(WLR_DEBUG, "Shutting down Wayland server"); + + wlr_backend_destroy(server->backend); + wl_display_destroy_clients(server->wl_display); + wl_display_destroy(server->wl_display); +} diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..9d2f6ad --- /dev/null +++ b/meson.build @@ -0,0 +1,39 @@ +project( + 'kiwmi', + 'c', + license: 'MPL-2.0', + default_options: [ + 'c_std=c11', + 'warning_level=2', + ], +) + +add_project_arguments( + [ + '-DWLR_USE_UNSTABLE', + '-D_POSIX_C_SOURCE=200112L' + ], + language: 'c', +) + +git = find_program('git', required: false) +wayland_server = dependency('wayland-server') +wlroots = dependency('wlroots') + +include = include_directories('include') + +version = get_option('kiwmi-version') +if version != '' + version = '"@0@"'.format(version) +else + if not git.found() + error('git is required to make the version string') + endif + + git_commit_hash = run_command([git.path(), 'describe', '--always', '--tags']).stdout().strip() + git_branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip() + version = '"@0@ (" __DATE__ ", branch \'@1@\')"'.format(git_commit_hash, git_branch) +endif +add_project_arguments('-DKIWMI_VERSION=@0@'.format(version), language: 'c') + +subdir('kiwmi') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..d3ccf91 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('kiwmi-version', type: 'string', description: 'The version string reported in `kiwmi --version`.')