Basic C comp
This commit is contained in:
parent
84f7487c2f
commit
3e94dae39b
7 changed files with 189 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
30
include/kiwmi/server.h
Normal file
30
include/kiwmi/server.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||
*
|
||||
* 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 <wayland-server.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_data_device.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
|
||||
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 */
|
32
kiwmi/main.c
Normal file
32
kiwmi/main.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#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);
|
||||
}
|
17
kiwmi/meson.build
Normal file
17
kiwmi/meson.build
Normal file
|
@ -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,
|
||||
)
|
69
kiwmi/server.c
Normal file
69
kiwmi/server.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include "kiwmi/server.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/backend.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_data_device.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
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);
|
||||
}
|
39
meson.build
Normal file
39
meson.build
Normal file
|
@ -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')
|
1
meson_options.txt
Normal file
1
meson_options.txt
Normal file
|
@ -0,0 +1 @@
|
|||
option('kiwmi-version', type: 'string', description: 'The version string reported in `kiwmi --version`.')
|
Loading…
Reference in a new issue