#ifndef PLATFORM_H #define PLATFORM_H #include "render_surface.h" //- window typedef enum PlatformAnchor { PLATFORM_ANCHOR_TOP = 1, PLATFORM_ANCHOR_BOTTOM = 2, PLATFORM_ANCHOR_LEFT = 4, PLATFORM_ANCHOR_RIGHT = 8, } PlatformAnchor; typedef struct WindowParams WindowParams; struct WindowParams { cstring name; // app id (matches the .desktop file) and layer namespace cstring title; u32 min_width; u32 min_height; u32 width; // logical pixels u32 height; b32 layer; // wlr layer shell surface instead of an xdg toplevel u32 anchor; // PlatformAnchor flags, 0 = centered s32 margin; }; typedef struct PlatformWindow PlatformWindow; //- input // NOTE: everything is in logical pixels, the renderer multiplies by the buffer scale typedef struct PlatformButton PlatformButton; struct PlatformButton { s32 half_transition_count; b32 ended_down; }; typedef enum PlatformModifier { PLATFORM_MOD_SHIFT = 1, PLATFORM_MOD_CTRL = 2, PLATFORM_MOD_ALT = 4, } PlatformModifier; typedef struct PlatformKeyEvent PlatformKeyEvent; struct PlatformKeyEvent { u32 keysym; // xkb keysym, layout aware u32 mods; b32 repeat; }; #define PLATFORM_MAX_KEY_EVENTS 64 #define PLATFORM_MAX_DROPS 8 #define PLATFORM_DROP_PATH_SIZE 1024 typedef struct PlatformInput PlatformInput; struct PlatformInput { PlatformButton mouse[3]; // left, right, middle f32 mouse_x; f32 mouse_y; b32 mouse_in_window; f32 scroll_x; // horizontal wheel / touchpad scroll f32 scroll_y; // wheel notches this frame, positive = down PlatformKeyEvent keys[PLATFORM_MAX_KEY_EVENTS]; u32 key_count; u8 text[128]; // utf8 typed this frame u32 text_size; u32 mods; b32 focused; b32 changed; // any input or window event since the last pump, i.e. worth a redraw // NOTE: files dropped onto the window this frame (wayland: text/uri-list, win32: WM_DROPFILES), // utf-8 absolute paths. drop_x / drop_y is where they landed, logical pixels. char drop_paths[PLATFORM_MAX_DROPS][PLATFORM_DROP_PATH_SIZE]; u32 drop_count; f32 drop_x; f32 drop_y; }; typedef enum PlatformCursor { PLATFORM_CURSOR_DEFAULT, PLATFORM_CURSOR_POINTER, PLATFORM_CURSOR_GRABBING, PLATFORM_CURSOR_RESIZE_X, PLATFORM_CURSOR_RESIZE_Y, PLATFORM_CURSOR_CROSSHAIR, PLATFORM_CURSOR_MOVE, PLATFORM_CURSOR_RESIZE_NWSE, } PlatformCursor; // NOTE: live resize. win32 and cocoa run a modal loop while the user drags the window edge, our // main loop is blocked inside the pump for the whole drag. the platform calls this from inside // that loop so the app can draw a frame at the new size. NULL = no live redraw. typedef void PlatformRefreshProc(void *user); // NOTE: every backend implements these with the same names: // platform_show_error(title, message) blocking message box (stderr where there is none), // usable before a window exists // PlatformWindowSurfaceSource(window) VulkanSurfaceSource for vk_init // PlatformWindowUiScale(window) fractional part of the display scale the integer buffer // scale can't express (150% = scale 1 * 1.5 or 2 * 0.75) // PlatformWindowSetRefresh(window, proc, user) internal void platform_show_error(const char *title, const char *message); #define ButtonPressed(button) ((button).ended_down && (button).half_transition_count > 0) #define ButtonReleased(button) (!(button).ended_down && (button).half_transition_count > 0) #endif // PLATFORM_H