From f6d3090f7fa76eb8e0dbe060b8490cb49c001c39 Mon Sep 17 00:00:00 2001 From: nasr Date: Mon, 5 Oct 2026 22:02:56 +0200 Subject: init: base --- source/base/base_platform_linux_wayland.cpp | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 source/base/base_platform_linux_wayland.cpp (limited to 'source/base/base_platform_linux_wayland.cpp') diff --git a/source/base/base_platform_linux_wayland.cpp b/source/base/base_platform_linux_wayland.cpp new file mode 100644 index 0000000..cd1fde8 --- /dev/null +++ b/source/base/base_platform_linux_wayland.cpp @@ -0,0 +1,55 @@ +// TODO: replace unix_get_env with a generic macro + +//- wayland +internal void wayland_display_connect(MemArena *arena) { + + +ScratchArena env_scratch = scratch_start(arena); + + + String8 str8_xdg_runtime_dir = unix_get_env("XDG_RUNTIME_DIR"); + char *xdg_runtime_dir = null_terminate(arena, &str8_xdg_runtime_dir); + +u64 xdg_runtime_dir_len = str8_xdg_runtime_dir.size; + + sockaddr_un addr = {}; +addr.sun_family = AF_UNIX; + + Assert(xdg_runtime_dir_len <= cstring8_length((u8 *)addr.sun_path)); + +u64 socket_path_len = 0; +MemCpy(addr.sun_path, xdg_runtime_dir, str8_xdg_runtime_dir.size); +socket_path_len += xdg_runtime_dir_len; + + +addr.sun_path[socket_path_len++] = '/'; +String8 str8_wayland_display_value = unix_get_env("WAYLAND_DISPLAY"); +char *wayland_display = null_terminate(arena, &str8_wayland_display_value); +if(wayland_display == NULL) +{ +const char *wayland_display_default = "wayland-0"; +u64 wayland_display_default_len = cstring8_length((u8 *)wayland_display_default); +MemCpy(addr.sun_path + socket_path_len, wayland_display_default, wayland_display_default_len); +} +else +{ +u64 wayland_display_len = cstring8_length((u8 *)wayland_display); +MemCpy(addr.sun_path + socket_path_len, wayland_display, wayland_display_len); +socket_path_len += wayland_display_len; +} + +scratch_end(&env_scratch); + +int fd = socket(AF_UNIX, SOCK_STREAM, 0); +if(fd == -1) +{ +exit(1); +} + +if(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) +{ +exit(1); +} + + +} \ No newline at end of file -- cgit v1.3.1