#ifndef PLATFORM_H #define PLATFORM_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 typedef struct PlatformInput PlatformInput; struct PlatformInput { PlatformButton mouse[3]; // left, right, middle f32 mouse_x; f32 mouse_y; b32 mouse_in_window; 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 }; typedef enum PlatformCursor { PLATFORM_CURSOR_DEFAULT, PLATFORM_CURSOR_POINTER, PLATFORM_CURSOR_GRABBING, PLATFORM_CURSOR_RESIZE_X, PLATFORM_CURSOR_RESIZE_Y, } PlatformCursor; #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