//////////////////////////////// //~ Win32 headers #pragma warning(push, 0) # define UNICODE # define WIN32_LEAN_AND_MEAN # include # include # include # include # include # include # include # include # include # include # include #pragma warning(pop) //////////////////////////////// //~ Window types typedef i32 P_W32_CursorFlag; enum { P_W32_CursorFlag_None = (0 << 0), P_W32_CursorFlag_Position = (1 << 0), P_W32_CursorFlag_Hide = (1 << 1), P_W32_CursorFlag_Show = (1 << 2), P_W32_CursorFlag_EnableClip = (1 << 3), P_W32_CursorFlag_DisableClip = (1 << 4) }; Struct(P_W32_Window) { u32 flags; HWND hwnd; Counter ready_fence; u16 utf16_high_surrogate_last_input; Mutex settings_mutex; P_WindowSettings settings; i32 monitor_width; i32 monitor_height; /* NOTE: width & height are unaffected by window minimization (they retain * their pre-minimized values) */ i32 x, y, width, height; /* FIXME: Use a cmd buffer for updating cursor (and maybe also settings). * Current setup means cursor_set calls can be applied out of order */ u32 cursor_set_flags; Vec2 cursor_set_position; Rect cursor_clip_bounds; Atomic32 topmost_toggles; b32 is_topmost; Mutex event_arena_swp_mutex; i32 current_event_arena_index; Arena *event_arenas[2]; W32_Thread *window_thread; Atomic32 shutdown; P_W32_Window *next_free; }; //////////////////////////////// //~ Watch types Struct(P_W32_Watch) { HANDLE dir_handle; HANDLE wake_handle; P_W32_Watch *next_free; u8 results_buff[Kibi(64)]; }; //////////////////////////////// //~ Address types Struct(P_W32_Address) { i32 size; i32 family; union { struct sockaddr_storage sas; struct sockaddr sa; struct sockaddr_in sin; struct sockaddr_in6 sin6; }; }; //////////////////////////////// //~ Sock types Struct(P_W32_Sock) { SOCKET sock; P_W32_Sock *next_free; }; //////////////////////////////// //~ Shared state #define P_W32_WindowClassName L"power_play_window_class" Struct(P_W32_SharedCtx) { //- Key lookup table P_Btn vk_btn_table[256]; //- Watches pool Mutex watches_mutex; Arena *watches_arena; P_W32_Watch *watches_first_free; //- Windows pool WNDCLASSEXW window_class; Mutex windows_mutex; Arena *windows_arena; P_W32_Window *first_free_window; //- Socket pool WSADATA wsa_data; Arena *socks_arena; Mutex socks_mutex; P_W32_Sock *first_free_sock; }; extern P_W32_SharedCtx P_W32_shared_ctx; //////////////////////////////// //~ Time operations P_DateTime P_W32_DateTimeFromWin32SystemTime(SYSTEMTIME st); //////////////////////////////// //~ File system operations String P_W32_StringFromWin32Path(Arena *arena, wchar_t *src); //////////////////////////////// //~ Window operations P_W32_Window *P_W32_AllocWindow(void); void P_W32_ReleaseWindow(P_W32_Window *window); HWND P_W32_InitWindow(P_W32_Window *window); //- Window settings void P_W32_UpdateWindowFromSystem(P_W32_Window *window); void P_W32_UpdateWindowFromSettings(P_W32_Window *window, P_WindowSettings *settings); //- Window thread W32_ThreadDef(P_W32_WindowThreadEntryFunc, arg); void P_W32_ProcessWindowEvent(P_W32_Window *window, P_WindowEvent event); void P_W32_WakeWindow(P_W32_Window *window); LRESULT CALLBACK P_W32_Win32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); //////////////////////////////// //~ Address operations P_W32_Address P_W32_Win32AddressFromPlatformAddress(P_Address addr); P_W32_Address P_W32_ConvertAnyaddrToLocalhost(P_W32_Address addr); P_Address P_W32_PlatformAddressFromWin32Address(P_W32_Address ws_addr);