From 1bbbd7a29de5ad21f295bae0c8ac127fb30923bd Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Tue, 26 Sep 2023 07:44:03 +0530 Subject: repo: init --- .gitignore | 2 ++ Makefile | 9 +++++++++ globals.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 globals.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1366983 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +globals +*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9748866 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +OBJECTS = globals.o +CC = gcc + +globals: $(OBJECTS) + $(CC) -o globals $(OBJECTS) -lwayland-client + +.PHONY: clean +clean: + rm -rf globals *.o diff --git a/globals.c b/globals.c new file mode 100644 index 0000000..66c5bfb --- /dev/null +++ b/globals.c @@ -0,0 +1,64 @@ +#include +#include +#include + +void plog(char *type, char *fmt, ...); +static void +registry_handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version); +static void +registry_handle_global_remove(void *data, struct wl_registry *registry, + uint32_t name); + +static const struct wl_registry_listener +registry_listener = { + .global = registry_handle_global, + .global_remove = registry_handle_global_remove, +}; + +static void +registry_handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + plog("info", "interface: %s, version: %d, name: %d", interface, + version, name); +} + +static void +registry_handle_global_remove(void *data, struct wl_registry *registry, + uint32_t name) +{ + plog("info", "interface with name %d removed", name); +} + +void plog(char *type, char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + fprintf(stderr, "%s",type); + fprintf(stderr, ": "); + vfprintf(stderr, fmt, args); + putc('\n', stderr); + va_end(args); +} + +int main(void) +{ + struct wl_display *display; + struct wl_registry *registry; + + display = wl_display_connect(NULL); + if (!display) { + plog("eror", "Unable to connect to wayland display"); + return 1; + } + plog("info", "Running wayland display"); + + registry = wl_display_get_registry(display); + wl_registry_add_listener(registry, ®istry_listener, NULL); + wl_display_roundtrip(display); + + wl_display_disconnect(display); + return 0; +} -- cgit v1.2.3