logo

bytemedia

Home to byte-level sounds, images, videos, … git clone https://hacktivis.me/git/bytemedia.git
commit: 100970ba9410a0571c15a0261e9b3d1a93210440
parent 01765eace2b83bc543e23044352c92db39680f5a
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 22 Jun 2021 16:12:36 +0200

C/wayland: Add fatal errors

Diffstat:

MC/wayland.c19+++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/C/wayland.c b/C/wayland.c @@ -5,6 +5,8 @@ #include <fcntl.h> #include <limits.h> #include <stdbool.h> +#include <stdlib.h> /* exit(), EXIT_FAILURE */ +#include <stdio.h> /* fputs(), stderr */ #include <string.h> #include <sys/mman.h> #include <time.h> @@ -260,19 +262,32 @@ static const struct wl_registry_listener wl_registry_listener = { .global_remove = registry_global_remove, }; +static void +fatal(const char *message) { + fputs(message, stderr); + exit(EXIT_FAILURE); +} + int main(int argc, char *argv[]) { struct client_state state = {0}; - state.wl_display = wl_display_connect(NULL); - state.wl_registry = wl_display_get_registry(state.wl_display); state.width = 800; state.height = 600; state.closed = false; + state.wl_display = wl_display_connect(NULL); + if(!state.wl_display) fatal("Failed to connect to wayland display, exiting...\n"); + + state.wl_registry = wl_display_get_registry(state.wl_display); wl_registry_add_listener(state.wl_registry, &wl_registry_listener, &state); + wl_display_roundtrip(state.wl_display); + if(!state.wl_shm) fatal("wl_shm protocol not found, exiting...\n"); + if(!state.wl_compositor) fatal("wl_compositor protocol not found, exiting...\n"); + if(!state.xdg_wm_base) fatal("xdg_wm_base protocol not found, exiting...\n"); + state.wl_surface = wl_compositor_create_surface(state.wl_compositor); state.xdg_surface = xdg_wm_base_get_xdg_surface(state.xdg_wm_base, state.wl_surface); xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state);