diff --git a/engine/platform/dos/vid_dos.c b/engine/platform/dos/vid_dos.c index 08bf206a..ae5129c2 100644 --- a/engine/platform/dos/vid_dos.c +++ b/engine/platform/dos/vid_dos.c @@ -543,9 +543,9 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint * return true; } -qboolean R_GetWindowHandle( void **handle, int type ) +ref_window_type_t R_GetWindowHandle( void **handle, ref_window_type_t type ) { - return FALSE; + return REF_WINDOW_TYPE_NULL; } #endif diff --git a/engine/platform/linux/vid_fbdev.c b/engine/platform/linux/vid_fbdev.c index e9a788d5..24c2be7e 100644 --- a/engine/platform/linux/vid_fbdev.c +++ b/engine/platform/linux/vid_fbdev.c @@ -246,9 +246,9 @@ qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint * return true; } -qboolean R_GetWindowHandle( void **handle, int type ) +ref_window_type_t R_GetWindowHandle( void **handle, ref_window_type_t type ) { - return FALSE; + return REF_WINDOW_TYPE_NULL; } #endif diff --git a/engine/platform/platform.h b/engine/platform/platform.h index 3d58f414..51fea09c 100644 --- a/engine/platform/platform.h +++ b/engine/platform/platform.h @@ -314,6 +314,8 @@ typedef enum struct vidmode_s; typedef enum window_mode_e window_mode_t; +typedef enum ref_window_type_e ref_window_type_t; + // Window qboolean R_Init_Video( const int type ); void R_Free_Video( void ); @@ -330,7 +332,7 @@ void *SW_LockBuffer( void ); void SW_UnlockBuffer( void ); qboolean SW_CreateBuffer( int width, int height, uint *stride, uint *bpp, uint *r, uint *g, uint *b ); void Platform_Minimize_f( void ); -qboolean R_GetWindowHandle( void **handle, int type ); +ref_window_type_t R_GetWindowHandle( void **handle, ref_window_type_t type ); // // in_evdev.c diff --git a/engine/platform/sdl1/vid_sdl1.c b/engine/platform/sdl1/vid_sdl1.c index 682efa7f..88fc8c00 100644 --- a/engine/platform/sdl1/vid_sdl1.c +++ b/engine/platform/sdl1/vid_sdl1.c @@ -513,9 +513,9 @@ qboolean VID_SetMode( void ) return true; } -qboolean R_GetWindowHandle( void **handle, int type ) +ref_window_type_t R_GetWindowHandle( void **handle, ref_window_type_t type ) { - return FALSE; + return REF_WINDOW_TYPE_NULL; } /* diff --git a/engine/platform/sdl2/vid_sdl2.c b/engine/platform/sdl2/vid_sdl2.c index b786d912..ef0b074c 100644 --- a/engine/platform/sdl2/vid_sdl2.c +++ b/engine/platform/sdl2/vid_sdl2.c @@ -19,6 +19,9 @@ GNU General Public License for more details. #include "vid_common.h" #include "platform_sdl2.h" +// include it after because it breaks definitions in net_api.h wtf +#include + static vidmode_t *vidmodes = NULL; static int num_vidmodes = 0; static void GL_SetupAttributes( void ); @@ -367,14 +370,13 @@ static void WIN_SetDPIAwareness( void ) } } -#include static qboolean WIN_SetWindowIcon( HICON ico ) { SDL_SysWMinfo wminfo; SDL_VERSION( &wminfo.version ); - if( SDL_GetWindowWMInfo( host.hWnd, &wminfo ) == SDL_TRUE ) + if( SDL_GetWindowWMInfo( host.hWnd, &wminfo ) == SDL_TRUE && wminfo.subsystem == SDL_SYSWM_WINDOWS ) { SendMessage( wminfo.info.win.window, WM_SETICON, ICON_SMALL, (LONG_PTR)ico ); SendMessage( wminfo.info.win.window, WM_SETICON, ICON_BIG, (LONG_PTR)ico ); @@ -1165,52 +1167,67 @@ qboolean VID_SetMode( void ) return true; } -qboolean R_GetWindowHandle( void **handle, int type ) +ref_window_type_t R_GetWindowHandle( void **handle, ref_window_type_t type ) { SDL_SysWMinfo wmInfo; + + if( type == REF_WINDOW_TYPE_SDL ) + { + if( handle ) + *handle = (void *)host.hWnd; + return REF_WINDOW_TYPE_SDL; + } + SDL_VERSION( &wmInfo.version ); - if ( SDL_GetWindowWMInfo( host.hWnd, &wmInfo ) != SDL_TRUE ) - { - return FALSE; - } + if( SDL_GetWindowWMInfo( host.hWnd, &wmInfo )) + return REF_WINDOW_TYPE_NULL; - switch( type ) + switch( wmInfo.subsystem ) { - case REF_WINDOW_TYPE_WIN32: + case SDL_SYSWM_WINDOWS: + if( !type || type == REF_WINDOW_TYPE_WIN32 ) + { #ifdef SDL_VIDEO_DRIVER_WINDOWS - *handle = (void*)wmInfo.info.win.window; // HWND - return TRUE; -#else - return FALSE; -#endif - case REF_WINDOW_TYPE_MACOS: -#ifdef SDL_VIDEO_DRIVER_COCOA - *handle = (void*)wmInfo.info.cocoa.window; // NSWindow* - return TRUE; -#else - return FALSE; -#endif - case REF_WINDOW_TYPE_X11: + if( handle ) + *handle = (void *)wmInfo.info.win.window; + return REF_WINDOW_TYPE_WIN32; +#endif // SDL_VIDEO_DRIVER_WINDOWS + } + break; + case SDL_SYSWM_X11: + if( !type || type == REF_WINDOW_TYPE_X11 ) + { #ifdef SDL_VIDEO_DRIVER_X11 - *handle = (void*)(uintptr_t)wmInfo.info.x11.window; // X11 Window - return TRUE; -#else - return FALSE; -#endif - case REF_WINDOW_TYPE_WAYLAND: + if( handle ) + *handle = (void *)(uintptr_t)wmInfo.info.x11.window; + return REF_WINDOW_TYPE_X11; +#endif // SDL_VIDEO_DRIVER_X11 + } + break; + case SDL_SYSWM_COCOA: + if( !type || type == REF_WINDOW_TYPE_MACOS ) + { +#ifdef SDL_VIDEO_DRIVER_COCOA + if( handle ) + *handle = (void *)wmInfo.info.cocoa.window; + return REF_WINDOW_TYPE_MACOS; +#endif // SDL_VIDEO_DRIVER_COCOA + } + break; + case SDL_SYSWM_WAYLAND: + if( !type || type == REF_WINDOW_TYPE_WAYLAND ) + { #ifdef SDL_VIDEO_DRIVER_WAYLAND - *handle = (void*)wmInfo.info.wl.surface; // wl_surface* - return TRUE; -#else - return FALSE; -#endif - case REF_WINDOW_TYPE_SDL: - *handle = (void*)host.hWnd; // SDL_Window* - return TRUE; + if( handle ) + *handle = (void *)wmInfo.info.wl.surface; + return REF_WINDOW_TYPE_WAYLAND; +#endif // SDL_VIDEO_DRIVER_WAYLAND + } + break; } - return FALSE; + return REF_WINDOW_TYPE_NULL; } /* diff --git a/engine/ref_api.h b/engine/ref_api.h index dc9ad5fb..4c6610d2 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -57,8 +57,8 @@ GNU General Public License for more details. // CL_RunLightStyles now accepts lightstyles array. // Removed R_DrawTileClear and Mod_LoadMapSprite, as they're implemented on engine side // Removed FillRGBABlend. Now FillRGBA accepts rendermode parameter. -// 10. Added R_GetWindowHandle. -#define REF_API_VERSION 9 +// 10. Added R_GetWindowHandle to retrieve platform-specific window object. +#define REF_API_VERSION 10 #define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP|TF_ALLOW_NEAREST) #define TF_FONT (TF_NOMIPMAP|TF_CLAMP|TF_ALLOW_NEAREST) @@ -104,14 +104,15 @@ typedef enum DEMO_QUAKE1 } demo_mode; -enum +typedef enum ref_window_type_e { - REF_WINDOW_TYPE_WIN32 = 1, // HWND - REF_WINDOW_TYPE_X11 = 2, // Display* - REF_WINDOW_TYPE_WAYLAND = 3, // wl_display* - REF_WINDOW_TYPE_MACOS = 4, // NSWindow* - REF_WINDOW_TYPE_SDL = 5, // SDL_Window* -}; + REF_WINDOW_TYPE_NULL = 0, + REF_WINDOW_TYPE_WIN32, // HWND + REF_WINDOW_TYPE_X11, // Display* + REF_WINDOW_TYPE_WAYLAND, // wl_display* + REF_WINDOW_TYPE_MACOS, // NSWindow* + REF_WINDOW_TYPE_SDL, // SDL_Window* +} ref_window_type_t; typedef struct { @@ -479,7 +480,7 @@ typedef struct ref_api_s fs_api_t *fsapi; // for abstracting the engine's rendering - qboolean (*R_GetWindowHandle)( void **handle, int type ); + ref_window_type_t (*R_GetWindowHandle)( void **handle, ref_window_type_t type ); } ref_api_t; struct mip_s;