logo

inaban

Unnamed repository; edit this file 'description' to name the repository.
commit: eefa0cb094c30c0d15d0a8af05824a976549c795
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  1 Jul 2019 05:37:49 +0200

Initial Commit

Diffstat:

A.clang-format21+++++++++++++++++++++
AMakefile47+++++++++++++++++++++++++++++++++++++++++++++++
Ainaban.c92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainaban.h27+++++++++++++++++++++++++++
4 files changed, 187 insertions(+), 0 deletions(-)

diff --git a/.clang-format b/.clang-format @@ -0,0 +1,21 @@ +AlignAfterOpenBracket: true +AlignConsecutiveAssignments: true +AlignOperands: true +AlignTrailingComments: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: true +AllowShortIfStatementsOnASingleLine: true +AlwaysBreakAfterReturnType: AllDefinitions +BinPackArguments: false +BinPackParameters: false +BreakBeforeBraces: Allman +SpaceBeforeParens: Never +IncludeBlocks: Regroup +ReflowComments: false +SortIncludes: true +UseTab: ForIndentation +IndentWidth: 2 +TabWidth: 2 +ColumnLimit: 100 + +NamespaceIndentation: All diff --git a/Makefile b/Makefile @@ -0,0 +1,47 @@ +.POSIX: + +PREFIX = /usr/local +BINDIR = $(PREFIX)/bin +MANDIR = $(PREFIX)/share/man +DATADIR = $(PREFIX)/share/inaban +PACKAGE = inaban + +DEPS = pixman-1 wlroots wayland-server +OBJS = inaban +TRANS = + +CC = cc +CFLAGS = -g -Wall -Wextra -Wconversion -Wsign-conversion +CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_POSIX_C_SOURCE=200809L +LIBS = `pkg-config --libs $(DEPS)` + +all: $(OBJS) $(TRANS) + +po/messages.pot: badwolf.c + xgettext --keyword=_ --language=C -o $@ --add-comments --sort-output -j badwolf.c + +po/%.po: po/messages.pot + msgmerge --update $@ $< + +${TRANS}: po/${@:.mo=.po} + mkdir -p locale/${@:.mo=}/LC_MESSAGES + msgfmt -o locale/${@:.mo=}/LC_MESSAGES/$(PACKAGE).mo po/${@:.mo=.po} + +.c: + $(CC) -std=c11 $(CFLAGS) $(CDEPS) -o $@ $< $(LDFLAGS) $(LIBS) + +install: all + mkdir -p $(DESTDIR)$(BINDIR) + cp -p badwolf $(DESTDIR)$(BINDIR)/badwolf + mkdir -p $(DESTDIR)$(MANDIR)/man1 + cp -p badwolf.1 $(DESTDIR)$(MANDIR)/man1 + mkdir -p $(DESTDIR)$(DATADIR)/locale + cp -r locale/ $(DESTDIR)$(DATADIR) + +clean: + rm -fr locale $(OBJS) + +format: *.c *.h + clang-format -style=file -assume-filename=.clang-format -i *.c *.h + +.PHONY: clean install diff --git a/inaban.c b/inaban.c @@ -0,0 +1,92 @@ +#include "inaban.h" + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +static void +output_destroy_notify(struct wl_listener *listener, void *data) +{ + struct inaban_output *output = wl_container_of(listener, output, destroy); + + wl_list_remove(&output->link); + wl_list_remove(&output->destroy.link); + wl_list_remove(&output->frame.link); + free(output); +} + +static void +output_frame_notify(struct wl_listener *listener, void *data) +{ + struct inaban_output *output = wl_container_of(listener, output, frame); + struct wlr_output *wlr_output = data; + struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_putput->backend); + + wlr_output_make_current(wlr_output, NULL); + wlr_renderer_begin(renderer, wlr_output); + + float color[4] = {1.0, 0, 0, 1.0}; + wlr_renderer_clear(renderer, color); + + wlr_output_swap_buffers(wlr_output, NULL, NULL); + wlr_renderer_end(renderer); +} + +static void +new_output_notify(struct wl_listener *listener, void *data) +{ + struct inaban_server *server = wl_container_of(listener, server, new_output); + + struct wlr_output *wlr_output = data; + + if(!wl_list_empty(&wlr_output->modes)) + { + struct wlr_output_mode *mode = wl_container_of(wlr_output->modes.prev, mode, link); + wlr_output_set_mode(wlr_output, mode); + } + + struct inaban_output *output = calloc(1, sizeof(struct inanban_output)); + // TODO: Handle a NULL calloc + clock_gettime(CLOCK_MONOTONIC, *output->last_frame); + output->server = server.output->wlr_output = wlr_output; + wl_list_insert(&server->outputs, &output->link); + + output->destroy.notify = output_destroy_notify; + wl_signal_add(&wlr_output->events.destroy, &output.destroy); + output->frame.notify = output_frame_notify; + wl_signal_add(&wlr_output->events.frame, &output.frame); +} + +int +main(int argc, char *argv[]) +{ + (void)argc; + (void)argv; + struct inaban_server server; + + server.wl_display = wl_display_create(); + assert(server.wl_display); + server.wl_event_loop = wl_display_get_event_loop(server.wl_display); + assert(server.wl_event_loop); + + server.backend = wlr_backend_autocreate(server.wl_display); + assert(server.backend); + + wl_list_init(&server.outputs); + + server.new_output.notify = new_output_notify; + wl_signal_add(&server.backend->events.new_output, &server.new_output); + + if(!wlr_backend_start(server.backend)) + { + fprintf(stderr, "Failed to start backend\n"); + wl_display_destroy(server.wl_display); + return 1; + } + + wl_display_run(server.wl_display); + wl_display_destroy(server.wl_display); + + return 0; +} diff --git a/inaban.h b/inaban.h @@ -0,0 +1,27 @@ +#include <wayland-server.h> +#include <wlr/backend.h> +#include <wlr/render/wlr_renderer.h> + +struct inaban_server +{ + struct wl_display *wl_display; + struct wl_event_loop *wl_event_loop; + + struct wlr_backend *backend; + + struct wl_listener new_output; + + struct wl_list outputs; // inaban_output::link +}; + +struct inaban_output +{ + struct wlr_output *wlr_output; + struct inaban_server *server; + struct timespec last_frame; + + struct wl_listener destroy; + struct wl_listener frame; + + struct wl_list link; +};