~kennylevinsen/wayllpaper

c98f05ee4f481411a9c273164117d4feb86c195b — Kenny Levinsen 1 year, 1 month ago e93449e
Minor cleanup
3 files changed, 37 insertions(+), 59 deletions(-)

M .clang-format
M main.c
M meson.build
M .clang-format => .clang-format +1 -0
@@ 12,6 12,7 @@ AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortBlocksOnASingleLine: Empty

BreakBeforeBinaryOperators: None
BreakStringLiterals: false

M main.c => main.c +32 -49
@@ 1,5 1,3 @@
#define _DEFAULT_SOURCE
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <errno.h>
#include <fcntl.h>


@@ 59,13 57,20 @@ static void layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *su
}

static void layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
	(void)surface;
	struct output *output = data;
	zwlr_layer_surface_v1_destroy(surface);
	wp_viewport_destroy(output->wp_viewport);
	wl_surface_destroy(output->wl_surface);
	output->layer_surface = NULL;
	output->wp_viewport = NULL;
	output->wl_surface = NULL;
	if (output->layer_surface != NULL) {
		zwlr_layer_surface_v1_destroy(output->layer_surface);
		output->layer_surface = NULL;
	}
	if (output->wp_viewport != NULL) {
		wp_viewport_destroy(output->wp_viewport);
		output->wp_viewport = NULL;
	}
	if (output->wl_surface != NULL) {
		wl_surface_destroy(output->wl_surface);
		output->wl_surface = NULL;
	}
}

struct zwlr_layer_surface_v1_listener layer_surface_listener = {


@@ 101,15 106,6 @@ static void prepare_output(struct output *output) {
	wl_surface_commit(output->wl_surface);
}

static void finish_output(struct output *output) {
	zwlr_layer_surface_v1_destroy(output->layer_surface);
	wp_viewport_destroy(output->wp_viewport);
	wl_surface_destroy(output->wl_surface);
	output->layer_surface = NULL;
	output->wp_viewport = NULL;
	output->wl_surface = NULL;
}

static void registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
				   const char *interface, uint32_t version) {
	struct context *ctx = (struct context *)data;


@@ 117,8 113,8 @@ static void registry_handle_global(void *data, struct wl_registry *registry, uin
		fprintf(stderr, "registry: adding output %d\n", name);
		struct output *output = calloc(1, sizeof(struct output));
		output->id = name;
		output->wl_output = wl_registry_bind(registry, name, &wl_output_interface, 1);
		output->context = ctx;
		output->wl_output = wl_registry_bind(registry, name, &wl_output_interface, 1);
		wl_list_insert(&ctx->outputs, &output->link);
	} else if (strcmp(interface, wl_compositor_interface.name) == 0) {
		ctx->wl_compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);


@@ 131,9 127,7 @@ static void registry_handle_global(void *data, struct wl_registry *registry, uin
		ctx->buffer = wl_shm_pool_create_buffer(pool, 0, ctx->width, ctx->height,
							ctx->width * 4, WL_SHM_FORMAT_ARGB8888);
		wl_shm_pool_destroy(pool);

		close(ctx->fd);
		ctx->fd = -1;
		wl_shm_destroy(shm);
	} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
		assert(version >= 3);
		ctx->layer_shell =


@@ 155,7 149,10 @@ static void registry_handle_global_remove(void *data, struct wl_registry *regist
	wl_list_for_each_safe(output, tmp, &ctx->outputs, link) {
		if (output->id == name) {
			fprintf(stderr, "registry: removing output %d\n", name);
			finish_output(output);
			layer_surface_closed(output, output->layer_surface);
			wl_output_destroy(output->wl_output);
			output->wl_output = NULL;
			output->context = NULL;
			wl_list_remove(&output->link);
			free(output);
			break;


@@ 175,41 172,27 @@ int main(int argc, char *argv[]) {
		fprintf(stderr, usage);
		return argc == 1 ? EXIT_SUCCESS : EXIT_FAILURE;
	}
	char *filename = argv[1];
	int width = atoi(argv[2]);
	int height = atoi(argv[3]);

	if (filename == NULL) {
		fprintf(stderr, "no file selected\n");
		return EXIT_FAILURE;
	}

	int fd = open(filename, O_RDWR | O_EXCL);
	if (fd == -1) {
	struct context ctx = {
		.fd = open(argv[1], O_RDWR | O_EXCL),
		.width = atoi(argv[2]),
		.height = atoi(argv[3]),
	};
	wl_list_init(&ctx.outputs);
	if (ctx.fd == -1) {
		fprintf(stderr, "could not open file: %d\n", errno);
		return EXIT_FAILURE;
	}

	struct stat st;
	if (fstat(fd, &st) == -1) {
	if (fstat(ctx.fd, &st) == -1) {
		fprintf(stderr, "could not stat file: %d\n", errno);
		return EXIT_FAILURE;
	}

	if (st.st_size != width * height * 4) {
	} else if (st.st_size != ctx.width * ctx.height * 4) {
		fprintf(stderr, "dimensions do not match file size: %ld != %d\n", st.st_size,
			width * height * 4);
			ctx.width * ctx.height * 4);
		return EXIT_FAILURE;
	}

	// Initialize defaults
	struct context ctx = {
		.fd = fd,
		.width = width,
		.height = height,
	};
	wl_list_init(&ctx.outputs);

	struct wl_display *display = wl_display_connect(NULL);
	if (display == NULL) {
		fprintf(stderr, "could not create display\n");


@@ 228,10 211,10 @@ int main(int argc, char *argv[]) {
			return EXIT_FAILURE;
		}
	}
	close(ctx.fd);
	ctx.fd = -1;

	while (wl_display_dispatch(display) != -1) {
		// pass
	}
	while (wl_display_dispatch(display) != -1) {}

	return EXIT_SUCCESS;
}

M meson.build => meson.build +4 -10
@@ 11,23 11,18 @@ project(
	],
)

add_project_arguments(
cc = meson.get_compiler('c')
add_project_arguments(cc.get_supported_arguments(
	[
		'-Wundef',
		'-Wunused',
		'-Wlogical-op',
		'-Wmissing-include-dirs',
		'-Wold-style-definition', # nop
		'-Wpointer-arith',
		'-Wstrict-prototypes',
		'-Wmissing-prototypes',
		'-Wno-implicit-fallthrough',
		'-Wno-unknown-warning-option',
		'-Wno-unused-command-line-argument',
		'-Wvla',
		'-Wl,--exclude-libs=ALL',
		'-DWAYLL_VERSION="@0@"'.format(meson.project_version()),
	],
	]),
	language: 'c',
)



@@ 37,13 32,12 @@ wl_protocols_dir = wl_protocols.get_variable('pkgdatadir')

scanner = find_program('wayland-scanner')
scanner_private_code = generator(scanner, output: '@BASENAME@-protocol.c', arguments: ['private-code', '@INPUT@', '@OUTPUT@'])
scanner_client_header = generator(scanner, output: '@BASENAME@-client-protocol.h', arguments: ['client-header', '@INPUT@', '@OUTPUT@'])

protocols_src = [
	scanner_private_code.process(wl_protocols_dir / 'stable/xdg-shell/xdg-shell.xml'),
	scanner_private_code.process(wl_protocols_dir / 'stable/viewporter/viewporter.xml'),
	scanner_private_code.process('wlr-layer-shell-unstable-v1.xml'),
]
scanner_client_header = generator(scanner, output: '@BASENAME@-client-protocol.h', arguments: ['client-header', '@INPUT@', '@OUTPUT@'])
protocols_headers = [
	scanner_client_header.process(wl_protocols_dir / 'stable/xdg-shell/xdg-shell.xml'),
	scanner_client_header.process(wl_protocols_dir / 'stable/viewporter/viewporter.xml'),