diff options
| author | nasr <nsrddyn@gmail.com> | 2026-10-09 12:37:56 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-10-09 12:37:56 +0200 |
| commit | 9a2fe3e091849518f3d2f79114ba67fa4fc63adf (patch) | |
| tree | 62678a2ff13752d8f8916aca8b6ff70d9bbd6d80 /source/base/base_platform.h | |
| parent | e467661baf3d035fb4726559abee52a0c8897ab0 (diff) | |
feature: window with sqaures etc etcmain
Diffstat (limited to 'source/base/base_platform.h')
| -rw-r--r-- | source/base/base_platform.h | 134 |
1 files changed, 74 insertions, 60 deletions
diff --git a/source/base/base_platform.h b/source/base/base_platform.h index 10f90b0..875986d 100644 --- a/source/base/base_platform.h +++ b/source/base/base_platform.h | |||
| @@ -16,14 +16,30 @@ struct Directory { | |||
| 16 | String8List *file_names; | 16 | String8List *file_names; |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | #if 0 // TODO: @WAYLAND and @X11 implementation | 19 | #if 1 // TODO: @WAYLAND and @X11 implementation |
| 20 | typedef struct LinuxWindowHandle LinuxWindowHandle; | 20 | |
| 21 | struct LinuxWindowHandle { | 21 | typedef struct Display Display; |
| 22 | struct Display | ||
| 23 | { | ||
| 24 | int width; | ||
| 25 | int height; | ||
| 26 | }; | ||
| 27 | |||
| 28 | typedef struct Window Window; | ||
| 29 | struct Window | ||
| 30 | { | ||
| 31 | int width; | ||
| 32 | int height; | ||
| 33 | }; | ||
| 34 | |||
| 35 | typedef struct LinuxWindowParams LinuxWindowParams; | ||
| 36 | struct LinuxWindowParams { | ||
| 37 | cstring name; | ||
| 22 | Display *display; | 38 | Display *display; |
| 23 | Window window; | 39 | Window window; |
| 24 | }; | 40 | }; |
| 25 | 41 | ||
| 26 | #define LinuxLoadSharedLibrary(library, name) unix_ | 42 | #define LinuxLoadSharedLibrary(arena, library) unix_load_shared_library(arena, library) |
| 27 | #endif | 43 | #endif |
| 28 | 44 | ||
| 29 | //- Shared libraries | 45 | //- Shared libraries |
| @@ -51,14 +67,16 @@ internal void unix_log_with_args(const char *format, ...); | |||
| 51 | #define FileExists(path) unix_file_exists(path) | 67 | #define FileExists(path) unix_file_exists(path) |
| 52 | #define DirLoad(arena, path) unix_open_dir(arena, path) | 68 | #define DirLoad(arena, path) unix_open_dir(arena, path) |
| 53 | 69 | ||
| 54 | #define OSExit() unix_os_exit(); | ||
| 55 | 70 | ||
| 56 | #if COMPILER_GCC || COMPILER_CLANG | 71 | #if DEBUG |
| 57 | // TODO: __VA_ARGS__ CLANG | 72 | #define OSExit(code) _exit(code) |
| 58 | #define Log(...) unix_log_with_args(__VA_ARGS__) | 73 | #define Log(...) unix_log_with_args(__VA_ARGS__) |
| 59 | #define LogStr8(message) \ | 74 | #define LogStr8(message) Log(Str8Fmt, Str8Arg(message)) |
| 60 | Log(Str8Fmt, Str8Arg(message)) // NOTE: for this to wwork we need the /analyze argument | 75 | #else |
| 61 | #endif // COMPILER_GCC || COMPILER_CLANG | 76 | #define OSExit(code) Unused(code) |
| 77 | #define Log(...) ((void)0) | ||
| 78 | #define LogStr8(message) ((void)0) | ||
| 79 | #endif // disable comments when debug mode is disabled | ||
| 62 | 80 | ||
| 63 | //- Entrypoint and platform window layer | 81 | //- Entrypoint and platform window layer |
| 64 | #define ENTRYPOINT() int main(int count, char **args) | 82 | #define ENTRYPOINT() int main(int count, char **args) |
| @@ -95,59 +113,55 @@ internal s32 x11_read_input(); | |||
| 95 | //- Wayland | 113 | //- Wayland |
| 96 | #elif WAYLAND | 114 | #elif WAYLAND |
| 97 | 115 | ||
| 98 | //- protocol values defined in the wayland library. it's a library load less i guess | 116 | typedef struct WaylandState WaylandState; |
| 99 | global_variable const u32 wayland_display_object_id = 1; | 117 | struct WaylandState { |
| 100 | global_variable const u16 wayland_wl_registry_event_global = 0; | 118 | //- connection |
| 101 | global_variable const u16 wayland_shm_pool_event_format = 0; | 119 | struct wl_display *display; |
| 102 | global_variable const u16 wayland_wl_buffer_event_release = 0; | 120 | struct wl_registry *registry; |
| 103 | global_variable const u16 wayland_xdg_wm_base_event_ping = 0; | ||
| 104 | global_variable const u16 wayland_xdg_toplevel_event_configure = 0; | ||
| 105 | global_variable const u16 wayland_xdg_toplevel_event_close = 1; | ||
| 106 | global_variable const u16 wayland_xdg_surface_event_configure = 0; | ||
| 107 | global_variable const u16 wayland_wl_display_get_registry_opcode = 1; | ||
| 108 | global_variable const u16 wayland_wl_registry_bind_opcode = 0; | ||
| 109 | global_variable const u16 wayland_wl_compositor_create_surface_opcode = 0; | ||
| 110 | global_variable const u16 wayland_xdg_wm_base_pong_opcode = 3; | ||
| 111 | global_variable const u16 wayland_xdg_surface_ack_configure_opcode = 4; | ||
| 112 | global_variable const u16 wayland_wl_shm_create_pool_opcode = 0; | ||
| 113 | global_variable const u16 wayland_xdg_wm_base_get_xdg_surface_opcode = 2; | ||
| 114 | global_variable const u16 wayland_wl_shm_pool_create_buffer_opcode = 0; | ||
| 115 | global_variable const u16 wayland_wl_surface_attach_opcode = 1; | ||
| 116 | global_variable const u16 wayland_xdg_surface_get_toplevel_opcode = 1; | ||
| 117 | global_variable const u16 wayland_wl_surface_commit_opcode = 6; | ||
| 118 | global_variable const u16 wayland_wl_display_error_event = 0; | ||
| 119 | global_variable const u32 wayland_format_xrgb8888 = 1; | ||
| 120 | global_variable const u32 wayland_header_size = 8; | ||
| 121 | global_variable const u32 color_channels = 4; | ||
| 122 | 121 | ||
| 123 | enum state_state_t: u16 { | 122 | struct wl_compositor *compositor; |
| 124 | STATE_NONE, | 123 | struct wl_shm *shm; |
| 125 | STATE_SURFACE_ACKED_CONFIGURE, | 124 | struct xdg_wm_base *xdg_wm_base; |
| 126 | STATE_SURFACE_ATTACHED, | 125 | struct wl_seat *seat; |
| 127 | }; | 126 | |
| 127 | //- window objects | ||
| 128 | 128 | ||
| 129 | typedef struct state_t state_t; | 129 | struct wl_surface *surface; |
| 130 | struct state_t { | 130 | struct xdg_surface *xdg_surface; |
| 131 | uint32_t wl_registry; | 131 | struct xdg_toplevel *xdg_toplevel; |
| 132 | uint32_t wl_shm; | 132 | |
| 133 | uint32_t wl_shm_pool; | 133 | //- keyboard input |
| 134 | uint32_t wl_buffer; | 134 | struct wl_keyboard *keyboard; |
| 135 | uint32_t xdg_wm_base; | 135 | b32 keys_down[256]; // indexed by linux scancode |
| 136 | uint32_t xdg_surface; | 136 | |
| 137 | uint32_t wl_compositor; | 137 | //- mouse (pointer) input |
| 138 | uint32_t wl_surface; | 138 | |
| 139 | uint32_t xdg_toplevel; | 139 | struct wl_pointer *pointer; // wl_pointer is a predefined <wayland-client.h> struct |
| 140 | uint32_t stride; | 140 | f32 mouse_x, mouse_y; |
| 141 | uint32_t w; | 141 | b32 mouse_buttons[3]; |
| 142 | uint32_t h; | 142 | f32 x_offset, y_offset; |
| 143 | uint32_t shm_pool_size; | 143 | b32 mouse_in_window; |
| 144 | int shm_fd; | 144 | |
| 145 | uint8_t *shm_pool_data; | 145 | |
| 146 | 146 | ||
| 147 | state_state_t state; | 147 | //- software framebuffer |
| 148 | struct wl_buffer *buffer; | ||
| 149 | u8 *pixels; | ||
| 150 | u32 width; | ||
| 151 | u32 height; | ||
| 152 | u32 stride; | ||
| 153 | u32 size; | ||
| 154 | |||
| 155 | b32 should_close; | ||
| 148 | }; | 156 | }; |
| 149 | 157 | ||
| 158 | #pragma GCC diagnostic push | ||
| 159 | #pragma GCC diagnostic ignored "-Wattributes" | ||
| 160 | #include "xdg-shell-protocol.c" | ||
| 161 | #pragma GCC diagnostic pop | ||
| 162 | |||
| 150 | 163 | ||
| 164 | #include "base_platform_linux_wayland_input.cpp" | ||
| 151 | #include "base_platform_linux_wayland.cpp" | 165 | #include "base_platform_linux_wayland.cpp" |
| 152 | 166 | ||
| 153 | #endif // X11 and Wayland -- set by build params | 167 | #endif // X11 and Wayland -- set by build params |
| @@ -190,7 +204,7 @@ internal void win32_log(String8List messages); | |||
| 190 | #define FileExists(path) win32_file_exists(path) | 204 | #define FileExists(path) win32_file_exists(path) |
| 191 | #define Win32FileExists(path) win32_file_exists(path) | 205 | #define Win32FileExists(path) win32_file_exists(path) |
| 192 | #define DirLoad(arena, path) win32_open_dir(arena, original_path); | 206 | #define DirLoad(arena, path) win32_open_dir(arena, original_path); |
| 193 | #define OSExit() win32_os_exit(); | 207 | #define OSExit(code) win32_os_exit() |
| 194 | 208 | ||
| 195 | #if COMPILER_GCC || COMPILER_CLANG | 209 | #if COMPILER_GCC || COMPILER_CLANG |
| 196 | 210 | ||
| @@ -200,7 +214,7 @@ internal void win32_logf(const char *fmt, ...) PRINTF_FORMAT; | |||
| 200 | #elif COMPILER_MSVC | 214 | #elif COMPILER_MSVC |
| 201 | internal void win32_logf(_Printf_format_string_ const char *fmt, ...); | 215 | internal void win32_logf(_Printf_format_string_ const char *fmt, ...); |
| 202 | 216 | ||
| 203 | #define Log(fmt, ...) win32_logf(fmt, __VA_ARGS__) | 217 | #define Log(fmt, ...) win32_logf(fmt, ##__VA_ARGS__) |
| 204 | 218 | ||
| 205 | #endif // COMPILER_GCC || COMPILER_CLANG | 219 | #endif // COMPILER_GCC || COMPILER_CLANG |
| 206 | 220 | ||
