summaryrefslogtreecommitdiff
path: root/source/base/base_platform_linux_wayland.cpp
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-10-05 22:02:56 +0200
committernasr <nsrddyn@gmail.com>2026-10-05 22:02:56 +0200
commitf6d3090f7fa76eb8e0dbe060b8490cb49c001c39 (patch)
tree433c773997e51f22738acb8b04c4fd2fc6b1bdc9 /source/base/base_platform_linux_wayland.cpp
init: base
Diffstat (limited to 'source/base/base_platform_linux_wayland.cpp')
-rw-r--r--source/base/base_platform_linux_wayland.cpp55
1 files changed, 55 insertions, 0 deletions
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 @@
1// TODO: replace unix_get_env with a generic macro
2
3//- wayland
4internal void wayland_display_connect(MemArena *arena) {
5
6
7ScratchArena env_scratch = scratch_start(arena);
8
9
10 String8 str8_xdg_runtime_dir = unix_get_env("XDG_RUNTIME_DIR");
11 char *xdg_runtime_dir = null_terminate(arena, &str8_xdg_runtime_dir);
12
13u64 xdg_runtime_dir_len = str8_xdg_runtime_dir.size;
14
15 sockaddr_un addr = {};
16addr.sun_family = AF_UNIX;
17
18 Assert(xdg_runtime_dir_len <= cstring8_length((u8 *)addr.sun_path));
19
20u64 socket_path_len = 0;
21MemCpy(addr.sun_path, xdg_runtime_dir, str8_xdg_runtime_dir.size);
22socket_path_len += xdg_runtime_dir_len;
23
24
25addr.sun_path[socket_path_len++] = '/';
26String8 str8_wayland_display_value = unix_get_env("WAYLAND_DISPLAY");
27char *wayland_display = null_terminate(arena, &str8_wayland_display_value);
28if(wayland_display == NULL)
29{
30const char *wayland_display_default = "wayland-0";
31u64 wayland_display_default_len = cstring8_length((u8 *)wayland_display_default);
32MemCpy(addr.sun_path + socket_path_len, wayland_display_default, wayland_display_default_len);
33}
34else
35{
36u64 wayland_display_len = cstring8_length((u8 *)wayland_display);
37MemCpy(addr.sun_path + socket_path_len, wayland_display, wayland_display_len);
38socket_path_len += wayland_display_len;
39}
40
41scratch_end(&env_scratch);
42
43int fd = socket(AF_UNIX, SOCK_STREAM, 0);
44if(fd == -1)
45{
46exit(1);
47}
48
49if(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
50{
51exit(1);
52}
53
54
55} \ No newline at end of file