From 9a2fe3e091849518f3d2f79114ba67fa4fc63adf Mon Sep 17 00:00:00 2001 From: nasr Date: Fri, 9 Oct 2026 12:37:56 +0200 Subject: feature: window with sqaures etc etc --- source/base/base_platform.h | 136 ++++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 61 deletions(-) (limited to 'source/base/base_platform.h') 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 { String8List *file_names; }; -#if 0 // TODO: @WAYLAND and @X11 implementation -typedef struct LinuxWindowHandle LinuxWindowHandle; -struct LinuxWindowHandle { +#if 1 // TODO: @WAYLAND and @X11 implementation + +typedef struct Display Display; +struct Display +{ + int width; + int height; +}; + +typedef struct Window Window; +struct Window +{ + int width; + int height; +}; + +typedef struct LinuxWindowParams LinuxWindowParams; +struct LinuxWindowParams { + cstring name; Display *display; Window window; }; -#define LinuxLoadSharedLibrary(library, name) unix_ +#define LinuxLoadSharedLibrary(arena, library) unix_load_shared_library(arena, library) #endif //- Shared libraries @@ -51,14 +67,16 @@ internal void unix_log_with_args(const char *format, ...); #define FileExists(path) unix_file_exists(path) #define DirLoad(arena, path) unix_open_dir(arena, path) -#define OSExit() unix_os_exit(); -#if COMPILER_GCC || COMPILER_CLANG -// TODO: __VA_ARGS__ CLANG +#if DEBUG +#define OSExit(code) _exit(code) #define Log(...) unix_log_with_args(__VA_ARGS__) -#define LogStr8(message) \ - Log(Str8Fmt, Str8Arg(message)) // NOTE: for this to wwork we need the /analyze argument -#endif // COMPILER_GCC || COMPILER_CLANG +#define LogStr8(message) Log(Str8Fmt, Str8Arg(message)) +#else +#define OSExit(code) Unused(code) +#define Log(...) ((void)0) +#define LogStr8(message) ((void)0) +#endif // disable comments when debug mode is disabled //- Entrypoint and platform window layer #define ENTRYPOINT() int main(int count, char **args) @@ -95,59 +113,55 @@ internal s32 x11_read_input(); //- Wayland #elif WAYLAND -//- protocol values defined in the wayland library. it's a library load less i guess -global_variable const u32 wayland_display_object_id = 1; -global_variable const u16 wayland_wl_registry_event_global = 0; -global_variable const u16 wayland_shm_pool_event_format = 0; -global_variable const u16 wayland_wl_buffer_event_release = 0; -global_variable const u16 wayland_xdg_wm_base_event_ping = 0; -global_variable const u16 wayland_xdg_toplevel_event_configure = 0; -global_variable const u16 wayland_xdg_toplevel_event_close = 1; -global_variable const u16 wayland_xdg_surface_event_configure = 0; -global_variable const u16 wayland_wl_display_get_registry_opcode = 1; -global_variable const u16 wayland_wl_registry_bind_opcode = 0; -global_variable const u16 wayland_wl_compositor_create_surface_opcode = 0; -global_variable const u16 wayland_xdg_wm_base_pong_opcode = 3; -global_variable const u16 wayland_xdg_surface_ack_configure_opcode = 4; -global_variable const u16 wayland_wl_shm_create_pool_opcode = 0; -global_variable const u16 wayland_xdg_wm_base_get_xdg_surface_opcode = 2; -global_variable const u16 wayland_wl_shm_pool_create_buffer_opcode = 0; -global_variable const u16 wayland_wl_surface_attach_opcode = 1; -global_variable const u16 wayland_xdg_surface_get_toplevel_opcode = 1; -global_variable const u16 wayland_wl_surface_commit_opcode = 6; -global_variable const u16 wayland_wl_display_error_event = 0; -global_variable const u32 wayland_format_xrgb8888 = 1; -global_variable const u32 wayland_header_size = 8; -global_variable const u32 color_channels = 4; - -enum state_state_t: u16 { - STATE_NONE, - STATE_SURFACE_ACKED_CONFIGURE, - STATE_SURFACE_ATTACHED, -}; +typedef struct WaylandState WaylandState; +struct WaylandState { + //- connection + struct wl_display *display; + struct wl_registry *registry; + + struct wl_compositor *compositor; + struct wl_shm *shm; + struct xdg_wm_base *xdg_wm_base; + struct wl_seat *seat; + + //- window objects -typedef struct state_t state_t; -struct state_t { - uint32_t wl_registry; - uint32_t wl_shm; - uint32_t wl_shm_pool; - uint32_t wl_buffer; - uint32_t xdg_wm_base; - uint32_t xdg_surface; - uint32_t wl_compositor; - uint32_t wl_surface; - uint32_t xdg_toplevel; - uint32_t stride; - uint32_t w; - uint32_t h; - uint32_t shm_pool_size; - int shm_fd; - uint8_t *shm_pool_data; - - state_state_t state; + struct wl_surface *surface; + struct xdg_surface *xdg_surface; + struct xdg_toplevel *xdg_toplevel; + + //- keyboard input + struct wl_keyboard *keyboard; + b32 keys_down[256]; // indexed by linux scancode + +//- mouse (pointer) input + +struct wl_pointer *pointer; // wl_pointer is a predefined struct +f32 mouse_x, mouse_y; +b32 mouse_buttons[3]; +f32 x_offset, y_offset; +b32 mouse_in_window; + + + + //- software framebuffer + struct wl_buffer *buffer; + u8 *pixels; + u32 width; + u32 height; + u32 stride; + u32 size; + + b32 should_close; }; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wattributes" +#include "xdg-shell-protocol.c" +#pragma GCC diagnostic pop + +#include "base_platform_linux_wayland_input.cpp" #include "base_platform_linux_wayland.cpp" #endif // X11 and Wayland -- set by build params @@ -190,7 +204,7 @@ internal void win32_log(String8List messages); #define FileExists(path) win32_file_exists(path) #define Win32FileExists(path) win32_file_exists(path) #define DirLoad(arena, path) win32_open_dir(arena, original_path); -#define OSExit() win32_os_exit(); +#define OSExit(code) win32_os_exit() #if COMPILER_GCC || COMPILER_CLANG @@ -200,7 +214,7 @@ internal void win32_logf(const char *fmt, ...) PRINTF_FORMAT; #elif COMPILER_MSVC internal void win32_logf(_Printf_format_string_ const char *fmt, ...); -#define Log(fmt, ...) win32_logf(fmt, __VA_ARGS__) +#define Log(fmt, ...) win32_logf(fmt, ##__VA_ARGS__) #endif // COMPILER_GCC || COMPILER_CLANG -- cgit v1.3.1