diff options
| author | nasr <nsrddyn@gmail.com> | 2026-10-05 22:02:56 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-10-05 22:02:56 +0200 |
| commit | f6d3090f7fa76eb8e0dbe060b8490cb49c001c39 (patch) | |
| tree | 433c773997e51f22738acb8b04c4fd2fc6b1bdc9 /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.cpp | 55 |
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 | ||
| 4 | internal void wayland_display_connect(MemArena *arena) { | ||
| 5 | |||
| 6 | |||
| 7 | ScratchArena 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 | |||
| 13 | u64 xdg_runtime_dir_len = str8_xdg_runtime_dir.size; | ||
| 14 | |||
| 15 | sockaddr_un addr = {}; | ||
| 16 | addr.sun_family = AF_UNIX; | ||
| 17 | |||
| 18 | Assert(xdg_runtime_dir_len <= cstring8_length((u8 *)addr.sun_path)); | ||
| 19 | |||
| 20 | u64 socket_path_len = 0; | ||
| 21 | MemCpy(addr.sun_path, xdg_runtime_dir, str8_xdg_runtime_dir.size); | ||
| 22 | socket_path_len += xdg_runtime_dir_len; | ||
| 23 | |||
| 24 | |||
| 25 | addr.sun_path[socket_path_len++] = '/'; | ||
| 26 | String8 str8_wayland_display_value = unix_get_env("WAYLAND_DISPLAY"); | ||
| 27 | char *wayland_display = null_terminate(arena, &str8_wayland_display_value); | ||
| 28 | if(wayland_display == NULL) | ||
| 29 | { | ||
| 30 | const char *wayland_display_default = "wayland-0"; | ||
| 31 | u64 wayland_display_default_len = cstring8_length((u8 *)wayland_display_default); | ||
| 32 | MemCpy(addr.sun_path + socket_path_len, wayland_display_default, wayland_display_default_len); | ||
| 33 | } | ||
| 34 | else | ||
| 35 | { | ||
| 36 | u64 wayland_display_len = cstring8_length((u8 *)wayland_display); | ||
| 37 | MemCpy(addr.sun_path + socket_path_len, wayland_display, wayland_display_len); | ||
| 38 | socket_path_len += wayland_display_len; | ||
| 39 | } | ||
| 40 | |||
| 41 | scratch_end(&env_scratch); | ||
| 42 | |||
| 43 | int fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
| 44 | if(fd == -1) | ||
| 45 | { | ||
| 46 | exit(1); | ||
| 47 | } | ||
| 48 | |||
| 49 | if(connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) | ||
| 50 | { | ||
| 51 | exit(1); | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | } \ No newline at end of file | ||
