summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-09-26 07:44:03 +0530
committersinanmohd <sinan@firemail.cc>2023-09-26 07:47:19 +0530
commit1bbbd7a29de5ad21f295bae0c8ac127fb30923bd (patch)
treeb7d93e40918d89c8b2b64cda256959e498127450
repo: init
-rw-r--r--.gitignore2
-rw-r--r--Makefile9
-rw-r--r--globals.c64
3 files changed, 75 insertions, 0 deletions
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 <stdio.h>
+#include <stdint.h>
+#include <wayland-client.h>
+
+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, &registry_listener, NULL);
+ wl_display_roundtrip(display);
+
+ wl_display_disconnect(display);
+ return 0;
+}