From 22c69bccdf18d6c5c0990de9bc89e5e76d3a7c50 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 29 Jan 2023 13:30:55 -0800 Subject: [PATCH] Displays are now referenced by instance ID instead of index --- build-scripts/SDL_migration.cocci | 9 +- docs/README-migration.md | 32 +- docs/README-winrt.md | 2 +- include/SDL3/SDL_events.h | 2 +- include/SDL3/SDL_oldnames.h | 10 +- include/SDL3/SDL_system.h | 22 +- include/SDL3/SDL_video.h | 139 +++--- src/core/android/SDL_android.c | 8 +- src/core/windows/SDL_windows.c | 9 +- src/core/winrt/SDL_winrtapp_direct3d.cpp | 4 +- src/dynapi/SDL_dynapi.sym | 9 +- src/dynapi/SDL_dynapi_overrides.h | 9 +- src/dynapi/SDL_dynapi_procs.h | 33 +- src/events/SDL_displayevents.c | 2 +- src/events/SDL_events.c | 2 +- src/events/SDL_windowevents.c | 4 +- src/render/SDL_render.c | 8 +- src/render/direct3d/SDL_render_d3d.c | 6 +- src/test/SDL_test_common.c | 125 +++-- src/video/SDL_egl_c.h | 19 +- src/video/SDL_shape.c | 30 +- src/video/SDL_sysvideo.h | 61 ++- src/video/SDL_video.c | 450 ++++++++++-------- src/video/android/SDL_androidevents.c | 8 +- src/video/android/SDL_androidgl.c | 6 +- src/video/android/SDL_androidkeyboard.c | 4 +- src/video/android/SDL_androidvideo.c | 12 +- src/video/android/SDL_androidvideo.h | 4 +- src/video/android/SDL_androidvulkan.c | 2 +- src/video/android/SDL_androidwindow.c | 6 +- src/video/android/SDL_androidwindow.h | 4 +- src/video/cocoa/SDL_cocoaclipboard.m | 2 +- src/video/cocoa/SDL_cocoaevents.m | 6 +- src/video/cocoa/SDL_cocoakeyboard.m | 12 +- src/video/cocoa/SDL_cocoamessagebox.m | 2 +- src/video/cocoa/SDL_cocoametalview.m | 2 +- src/video/cocoa/SDL_cocoamodes.h | 8 +- src/video/cocoa/SDL_cocoamodes.m | 10 +- src/video/cocoa/SDL_cocoamouse.m | 8 +- src/video/cocoa/SDL_cocoaopengl.m | 10 +- src/video/cocoa/SDL_cocoaopengles.m | 10 +- src/video/cocoa/SDL_cocoashape.m | 4 +- src/video/cocoa/SDL_cocoavideo.m | 10 +- src/video/cocoa/SDL_cocoavulkan.m | 2 +- src/video/cocoa/SDL_cocoawindow.h | 2 +- src/video/cocoa/SDL_cocoawindow.m | 91 ++-- src/video/emscripten/SDL_emscriptenevents.c | 2 +- src/video/emscripten/SDL_emscriptenevents.h | 11 +- .../emscripten/SDL_emscriptenframebuffer.c | 6 +- src/video/emscripten/SDL_emscriptenmouse.c | 2 +- src/video/emscripten/SDL_emscriptenopengles.c | 8 +- src/video/emscripten/SDL_emscriptenvideo.c | 8 +- src/video/emscripten/SDL_emscriptenvideo.h | 4 +- src/video/haiku/SDL_bvideo.cc | 5 +- src/video/kmsdrm/SDL_kmsdrmmouse.c | 45 +- src/video/kmsdrm/SDL_kmsdrmopengles.c | 8 +- src/video/kmsdrm/SDL_kmsdrmvideo.c | 98 ++-- src/video/kmsdrm/SDL_kmsdrmvideo.h | 16 +- src/video/kmsdrm/SDL_kmsdrmvulkan.c | 2 +- src/video/n3ds/SDL_n3dsframebuffer.c | 2 +- src/video/n3ds/SDL_n3dsvideo.c | 12 +- src/video/n3ds/SDL_n3dsvideo.h | 5 +- src/video/ngage/SDL_ngageevents.cpp | 4 +- src/video/ngage/SDL_ngageframebuffer.cpp | 10 +- src/video/ngage/SDL_ngagevideo.cpp | 2 +- src/video/ngage/SDL_ngagevideo.h | 4 +- src/video/ngage/SDL_ngagewindow.cpp | 4 +- src/video/offscreen/SDL_offscreenopengles.c | 6 +- src/video/offscreen/SDL_offscreenwindow.c | 4 +- src/video/offscreen/SDL_offscreenwindow.h | 9 +- src/video/psp/SDL_pspgl.c | 4 +- src/video/psp/SDL_pspvideo.c | 7 +- src/video/psp/SDL_pspvideo.h | 13 +- src/video/raspberry/SDL_rpimouse.c | 8 +- src/video/raspberry/SDL_rpiopengles.c | 2 +- src/video/raspberry/SDL_rpivideo.c | 11 +- src/video/raspberry/SDL_rpivideo.h | 13 +- src/video/riscos/SDL_riscosevents.c | 8 +- src/video/riscos/SDL_riscosframebuffer.c | 8 +- src/video/riscos/SDL_riscosvideo.h | 4 +- src/video/riscos/SDL_riscoswindow.c | 2 +- src/video/riscos/SDL_riscoswindow.h | 4 +- src/video/uikit/SDL_uikitappdelegate.m | 2 +- src/video/uikit/SDL_uikitclipboard.m | 4 +- src/video/uikit/SDL_uikitmessagebox.m | 2 +- src/video/uikit/SDL_uikitmetalview.m | 2 +- src/video/uikit/SDL_uikitmodes.m | 38 +- src/video/uikit/SDL_uikitopengles.m | 2 +- src/video/uikit/SDL_uikitvideo.m | 8 +- src/video/uikit/SDL_uikitview.m | 4 +- src/video/uikit/SDL_uikitviewcontroller.m | 4 +- src/video/uikit/SDL_uikitwindow.m | 39 +- src/video/vita/SDL_vitaframebuffer.c | 4 +- src/video/vita/SDL_vitagl_pvr.c | 2 +- src/video/vita/SDL_vitagles.c | 4 +- src/video/vita/SDL_vitagles_pvr.c | 12 +- src/video/vita/SDL_vitavideo.c | 14 +- src/video/vita/SDL_vitavideo.h | 13 +- src/video/vivante/SDL_vivanteopengles.c | 4 +- src/video/vivante/SDL_vivantevideo.c | 16 +- src/video/vivante/SDL_vivantevideo.h | 12 +- src/video/wayland/SDL_waylandmouse.c | 6 +- src/video/wayland/SDL_waylandopengles.c | 20 +- src/video/wayland/SDL_waylandtouch.c | 2 +- src/video/wayland/SDL_waylandvideo.c | 126 +++-- src/video/wayland/SDL_waylandvideo.h | 14 +- src/video/wayland/SDL_waylandvulkan.c | 2 +- src/video/wayland/SDL_waylandwindow.c | 125 ++--- src/video/wayland/SDL_waylandwindow.h | 6 +- src/video/windows/SDL_windowsclipboard.c | 4 +- src/video/windows/SDL_windowsevents.c | 14 +- src/video/windows/SDL_windowsframebuffer.c | 6 +- src/video/windows/SDL_windowskeyboard.c | 18 +- src/video/windows/SDL_windowsmessagebox.c | 4 +- src/video/windows/SDL_windowsmodes.c | 68 +-- src/video/windows/SDL_windowsmodes.h | 8 +- src/video/windows/SDL_windowsmouse.c | 6 +- src/video/windows/SDL_windowsopengl.c | 12 +- src/video/windows/SDL_windowsopengles.c | 6 +- src/video/windows/SDL_windowsshape.c | 2 +- src/video/windows/SDL_windowsvideo.c | 29 +- src/video/windows/SDL_windowsvideo.h | 4 +- src/video/windows/SDL_windowsvulkan.c | 2 +- src/video/windows/SDL_windowswindow.c | 69 ++- src/video/windows/SDL_windowswindow.h | 4 +- src/video/winrt/SDL_winrtgamebar.cpp | 4 +- src/video/winrt/SDL_winrtopengles.cpp | 4 +- src/video/winrt/SDL_winrtpointerinput.cpp | 2 +- src/video/winrt/SDL_winrtvideo.cpp | 22 +- src/video/winrt/SDL_winrtvideo_cpp.h | 4 +- src/video/x11/SDL_x11clipboard.c | 10 +- src/video/x11/SDL_x11events.c | 28 +- src/video/x11/SDL_x11framebuffer.c | 6 +- src/video/x11/SDL_x11keyboard.c | 18 +- src/video/x11/SDL_x11messagebox.c | 7 +- src/video/x11/SDL_x11modes.c | 46 +- src/video/x11/SDL_x11modes.h | 8 +- src/video/x11/SDL_x11mouse.c | 68 +-- src/video/x11/SDL_x11opengl.c | 29 +- src/video/x11/SDL_x11opengles.c | 6 +- src/video/x11/SDL_x11shape.c | 2 +- src/video/x11/SDL_x11video.c | 8 +- src/video/x11/SDL_x11video.h | 4 +- src/video/x11/SDL_x11vulkan.c | 10 +- src/video/x11/SDL_x11window.c | 105 ++-- src/video/x11/SDL_x11window.h | 4 +- src/video/x11/SDL_x11xfixes.c | 14 +- src/video/x11/SDL_x11xinput2.c | 12 +- test/testautomation_video.c | 407 ++++++++-------- test/testbounds.c | 24 +- test/testdisplayinfo.c | 11 +- test/testgl.c | 2 +- test/testgles.c | 2 +- test/testgles2.c | 2 +- test/testgles2_sdf.c | 2 +- test/testvulkan.c | 2 +- test/testwm.c | 12 +- 157 files changed, 1620 insertions(+), 1589 deletions(-) diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci index 9d22580de..feaf0c9b0 100644 --- a/build-scripts/SDL_migration.cocci +++ b/build-scripts/SDL_migration.cocci @@ -1993,12 +1993,12 @@ typedef SDL_GameControllerButtonBind, SDL_GamepadBinding; @@ @@ - SDL_GetPointDisplayIndex -+ SDL_GetDisplayIndexForPoint ++ SDL_GetDisplayForPoint (...) @@ @@ - SDL_GetRectDisplayIndex -+ SDL_GetDisplayIndexForRect ++ SDL_GetDisplayForRect (...) @ depends on rule_init_noparachute @ expression e; @@ -2354,3 +2354,8 @@ SDL_DisplayMode e; - e.h + e.screen_h ) +@@ +@@ +- SDL_GetWindowDisplayIndex ++ SDL_GetDisplayForWindow + (...) diff --git a/docs/README-migration.md b/docs/README-migration.md index 4b0ee7e2f..66bf8e513 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -444,7 +444,7 @@ The following functions have been removed: * SDL_JoystickGetDeviceVendor() - replaced with SDL_GetJoystickInstanceVendor() * SDL_JoystickNameForIndex() - replaced with SDL_GetJoystickInstanceName() * SDL_JoystickPathForIndex() - replaced with SDL_GetJoystickInstancePath() -* SDL_NumJoysticks - replaced with SDL_GetJoysticks() +* SDL_NumJoysticks() - replaced with SDL_GetJoysticks() ## SDL_keyboard.h @@ -958,6 +958,28 @@ SDL_GetRevisionNumber() has been removed from the API, it always returned 0 in S SDL_VideoInit() and SDL_VideoQuit() have been removed. Instead you can call SDL_InitSubSytem() and SDL_QuitSubSytem() with SDL_INIT_VIDEO, which will properly refcount the subsystems. You can choose a specific audio driver using SDL_VIDEO_DRIVER hint. +Rather than iterating over displays using display index, there is a new function SDL_GetDisplays() to get the current list of displays, and functions which used to take a display index now take SDL_DisplayID, with an invalid ID being 0. +```c +{ + if (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) { + int i, num_displays; + SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); + if (displays) { + for (i = 0; i < num_displays; ++i) { + SDL_DisplayID instance_id = displays[i]; + const char *name = SDL_GetDisplayName(instance_id); + + SDL_Log("Display %" SDL_PRIu32 ": %s\n", instance_id, name ? name : "Unknown"); + } + SDL_free(displays); + } + SDL_QuitSubSystem(SDL_INIT_VIDEO); + } +} +``` + +The SDL_WINDOWPOS_UNDEFINED_DISPLAY() and SDL_WINDOWPOS_CENTERED_DISPLAY() macros take a display ID instead of display index. The display ID 0 has a special meaning in this case, and is used to indicate the primary display. + The SDL_WINDOW_SHOWN flag has been removed. Windows are shown by default and can be created hidden by using the SDL_WINDOW_HIDDEN flag. The SDL_WINDOW_ALLOW_HIGHDPI flag has been removed. Windows are automatically high DPI aware and their coordinates are in screen space, which may differ from physical pixels on displays using display scaling. @@ -982,8 +1004,12 @@ SDL_GL_GetDrawableSize() has been removed. SDL_GetWindowSizeInPixels() can be us The following functions have been renamed: * SDL_GetDisplayDPI() => SDL_GetDisplayPhysicalDPI() -* SDL_GetPointDisplayIndex() => SDL_GetDisplayIndexForPoint() -* SDL_GetRectDisplayIndex() => SDL_GetDisplayIndexForRect() +* SDL_GetPointDisplayIndex() => SDL_GetDisplayForPoint() +* SDL_GetRectDisplayIndex() => SDL_GetDisplayForRect() +* SDL_GetWindowDisplayIndex() => SDL_GetDisplayForWindow() + +The following functions have been removed: +* SDL_GetNumVideoDisplays() - replaced with SDL_GetDisplays() SDL_Window id type is named SDL_WindowID diff --git a/docs/README-winrt.md b/docs/README-winrt.md index 8f7bbbe3f..7d26fbf5d 100644 --- a/docs/README-winrt.md +++ b/docs/README-winrt.md @@ -341,7 +341,7 @@ int main(int argc, char **argv) if (SDL_Init(SDL_INIT_VIDEO) != 0) { return 1; - } else if (SDL_GetCurrentDisplayMode(0, &mode) != 0) { + } else if (SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode) != 0) { return 1; } else if (SDL_CreateWindowAndRenderer(mode.w, mode.h, SDL_WINDOW_FULLSCREEN_EXCLUSIVE, &window, &renderer) != 0) { return 1; diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h index 89bfaceda..e5b0ceaeb 100644 --- a/include/SDL3/SDL_events.h +++ b/include/SDL3/SDL_events.h @@ -215,7 +215,7 @@ typedef struct SDL_DisplayEvent { Uint32 type; /**< ::SDL_DISPLAYEVENT_* */ Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */ - Uint32 display; /**< The associated display index */ + SDL_DisplayID displayID;/**< The associated display */ Sint32 data1; /**< event dependent data */ } SDL_DisplayEvent; diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h index 23fb15632..f84b8e0df 100644 --- a/include/SDL3/SDL_oldnames.h +++ b/include/SDL3/SDL_oldnames.h @@ -413,8 +413,9 @@ /* ##SDL_video.h */ #define SDL_GetDisplayDPI SDL_GetDisplayPhysicalDPI -#define SDL_GetPointDisplayIndex SDL_GetDisplayIndexForPoint -#define SDL_GetRectDisplayIndex SDL_GetDisplayIndexForRect +#define SDL_GetPointDisplayIndex SDL_GetDisplayForPoint +#define SDL_GetRectDisplayIndex SDL_GetDisplayForRect +#define SDL_GetWindowDisplayIndex SDL_GetDisplayForWindow #define SDL_WINDOW_FULLSCREEN SDL_WINDOW_FULLSCREEN_EXCLUSIVE #define SDL_WINDOW_INPUT_GRABBED SDL_WINDOW_MOUSE_GRABBED @@ -795,8 +796,9 @@ /* ##SDL_video.h */ #define SDL_GetDisplayDPI SDL_GetDisplayDPI_renamed_SDL_GetDisplayPhysicalDPI -#define SDL_GetPointDisplayIndex SDL_GetPointDisplayIndex_renamed_SDL_GetDisplayIndexForPoint -#define SDL_GetRectDisplayIndex SDL_GetRectDisplayIndex_renamed_SDL_GetDisplayIndexForRect +#define SDL_GetPointDisplayIndex SDL_GetPointDisplayIndex_renamed_SDL_GetDisplayForPoint +#define SDL_GetRectDisplayIndex SDL_GetRectDisplayIndex_renamed_SDL_GetDisplayForRect +#define SDL_GetWindowDisplayIndex SDL_GetWindowDisplayIndex_renamed_SDL_GetDisplayForWindow #define SDL_WINDOW_FULLSCREEN SDL_WINDOW_FULLSCREEN_renamed_SDL_WINDOW_FULLSCREEN_EXCLUSIVE #define SDL_WINDOW_INPUT_GRABBED SDL_WINDOW_INPUT_GRABBED_renamed_SDL_WINDOW_MOUSE_GRABBED diff --git a/include/SDL3/SDL_system.h b/include/SDL3/SDL_system.h index ab482396f..7c13f5af8 100644 --- a/include/SDL3/SDL_system.h +++ b/include/SDL3/SDL_system.h @@ -42,7 +42,7 @@ extern "C" { /* Platform specific functions for Windows */ #if defined(__WIN32__) || defined(__GDK__) - + typedef void (SDLCALL * SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam); /** @@ -60,19 +60,18 @@ extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook ca #if defined(__WIN32__) || defined(__WINGDK__) /** - * Get the D3D9 adapter index that matches the specified display index. + * Get the D3D9 adapter index that matches the specified display. * * The returned adapter index can be passed to `IDirect3D9::CreateDevice` and * controls on which monitor a full screen application will appear. * - * \param displayIndex the display index for which to get the D3D9 adapter - * index + * \param displayID the instance of the display to query * \returns the D3D9 adapter index on success or a negative error code on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex ); +extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex(SDL_DisplayID displayID); typedef struct IDirect3DDevice9 IDirect3DDevice9; @@ -131,16 +130,13 @@ extern DECLSPEC ID3D12Device* SDLCALL SDL_RenderGetD3D12Device(SDL_Renderer* ren #if defined(__WIN32__) || defined(__WINGDK__) /** - * Get the DXGI Adapter and Output indices for the specified display index. + * Get the DXGI Adapter and Output indices for the specified display. * * The DXGI Adapter and Output indices can be passed to `EnumAdapters` and * `EnumOutputs` respectively to get the objects required to create a DX10 or * DX11 device and swap chain. * - * Before SDL 2.0.4 this function did not return a value. Since SDL 2.0.4 it - * returns an SDL_bool. - * - * \param displayIndex the display index for which to get both indices + * \param displayID the instance of the display to query * \param adapterIndex a pointer to be filled in with the adapter index * \param outputIndex a pointer to be filled in with the output index * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() @@ -148,7 +144,7 @@ extern DECLSPEC ID3D12Device* SDLCALL SDL_RenderGetD3D12Device(SDL_Renderer* ren * * \since This function is available since SDL 3.0.0. */ -extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex ); +extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex); #endif /* defined(__WIN32__) || defined(__WINGDK__) */ @@ -182,9 +178,9 @@ extern DECLSPEC int SDLCALL SDL_LinuxSetThreadPriority(Sint64 threadID, int prio * \since This function is available since SDL 3.0.0. */ extern DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy); - + #endif /* __LINUX__ */ - + /* Platform specific functions for iOS */ #ifdef __IOS__ diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h index 1d8255abb..f33c89f15 100644 --- a/include/SDL3/SDL_video.h +++ b/include/SDL3/SDL_video.h @@ -40,6 +40,7 @@ extern "C" { #endif +typedef Uint32 SDL_DisplayID; typedef Uint32 SDL_WindowID; /** @@ -300,53 +301,61 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void); /** - * Get the number of available video displays. + * Get a list of currently connected displays. * - * \returns a number >= 1 or a negative error code on failure; call - * SDL_GetError() for more information. + * \param count a pointer filled in with the number of displays returned + * \returns a 0 terminated array of display instance IDs which should be + * freed with SDL_free(), or NULL on error; call SDL_GetError() for + * more details. + * + * \since This function is available since SDL 3.0.0. + */ +extern DECLSPEC SDL_DisplayID *SDLCALL SDL_GetDisplays(int *count); + +/** + * Return the primary display. + * + * \returns the instance ID of the primary display on success or 0 on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * - * \sa SDL_GetDisplayBounds + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void); +extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetPrimaryDisplay(void); /** * Get the name of a display in UTF-8 encoding. * - * \param displayIndex the index of display from which the name should be - * queried - * \returns the name of a display or NULL for an invalid display index or - * failure; call SDL_GetError() for more information. + * \param displayID the instance ID of the display to query + * \returns the name of a display or NULL on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC const char *SDLCALL SDL_GetDisplayName(int displayIndex); +extern DECLSPEC const char *SDLCALL SDL_GetDisplayName(SDL_DisplayID displayID); /** * Get the desktop area represented by a display, in screen coordinates. * - * The primary display (`displayIndex` zero) is always located at 0,0. + * The primary display is always located at (0,0). * - * \param displayIndex the index of the display to query + * \param displayID the instance ID of the display to query * \param rect the SDL_Rect structure filled in with the display bounds * \returns 0 on success or a negative error code on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplayUsableBounds + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect *rect); +extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect); /** * Get the usable desktop area represented by a display, in screen * coordinates. * - * The primary display (`displayIndex` zero) is always located at 0,0. - * * This is the same area as SDL_GetDisplayBounds() reports, but with portions * reserved by the system removed. For example, on Apple's macOS, this * subtracts the area occupied by the menu bar and dock. @@ -355,13 +364,7 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect *rec * so these are good guidelines for the maximum space available to a * non-fullscreen window. * - * The parameter `rect` is ignored if it is NULL. - * - * This function also returns -1 if the parameter `displayIndex` is out of - * range. - * - * \param displayIndex the index of the display to query the usable bounds - * from + * \param displayID the instance ID of the display to query * \param rect the SDL_Rect structure filled in with the display bounds * \returns 0 on success or a negative error code on failure; call * SDL_GetError() for more information. @@ -369,9 +372,9 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect *rec * \since This function is available since SDL 3.0.0. * * \sa SDL_GetDisplayBounds - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect *rect); +extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect); /** * Get the dots/pixels-per-inch for a display. @@ -379,9 +382,6 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rec * Diagonal, horizontal and vertical DPI can all be optionally returned if the * appropriate parameter is non-NULL. * - * A failure of this function usually means that either no DPI information is - * available or the `displayIndex` is out of range. - * * **WARNING**: This reports the DPI that the hardware reports, and it is not * always reliable! It is almost always better to use SDL_GetWindowSize() to * find the window size, which might be in logical points instead of pixels, @@ -390,8 +390,7 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rec * will be rethinking how high-dpi details should be managed in SDL3 to make * things more consistent, reliable, and clear. * - * \param displayIndex the index of the display from which DPI information - * should be queried + * \param displayID the instance ID of the display to query * \param ddpi a pointer filled in with the diagonal DPI of the display; may * be NULL * \param hdpi a pointer filled in with the horizontal DPI of the display; may @@ -403,53 +402,51 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rec * * \since This function is available since SDL 3.0.0. * - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetDisplayPhysicalDPI(int displayIndex, float *ddpi, float *hdpi, float *vdpi); +extern DECLSPEC int SDLCALL SDL_GetDisplayPhysicalDPI(SDL_DisplayID displayID, float *ddpi, float *hdpi, float *vdpi); /** * Get the orientation of a display. * - * \param displayIndex the index of the display to query + * \param displayID the instance ID of the display to query * \returns The SDL_DisplayOrientation enum value of the display, or * `SDL_ORIENTATION_UNKNOWN` if it isn't available. * * \since This function is available since SDL 3.0.0. * - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC SDL_DisplayOrientation SDLCALL SDL_GetDisplayOrientation(int displayIndex); +extern DECLSPEC SDL_DisplayOrientation SDLCALL SDL_GetDisplayOrientation(SDL_DisplayID displayID); /** * Get the number of available display modes. * - * The `displayIndex` needs to be in the range from 0 to - * SDL_GetNumVideoDisplays() - 1. - * - * \param displayIndex the index of the display to query + * \param displayID the instance ID of the display to query * \returns a number >= 1 on success or a negative error code on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetDisplayMode - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex); +extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(SDL_DisplayID displayID); /** * Get information about a specific display mode. * * The display modes are sorted in this priority: * - * - width -> largest to smallest - * - height -> largest to smallest - * - display_scale -> smallest to largest + * - screen_w -> largest to smallest + * - screen_h -> largest to smallest + * - pixel_w -> largest to smallest + * - pixel_h -> largest to smallest * - bits per pixel -> more colors to fewer colors * - packed pixel layout -> largest to smallest * - refresh rate -> highest to lowest * - * \param displayIndex the index of the display to query + * \param displayID the instance ID of the display to query * \param modeIndex the index of the display mode to query * \param mode an SDL_DisplayMode structure filled in with the mode at * `modeIndex` @@ -460,7 +457,7 @@ extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex); * * \sa SDL_GetNumDisplayModes */ -extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex, SDL_DisplayMode *mode); +extern DECLSPEC int SDLCALL SDL_GetDisplayMode(SDL_DisplayID displayID, int modeIndex, SDL_DisplayMode *mode); /** * Get information about the desktop's display mode. @@ -470,7 +467,7 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex, * function will return the previous native display mode, and not the current * display mode. * - * \param displayIndex the index of the display to query + * \param displayID the instance ID of the display to query * \param mode an SDL_DisplayMode structure filled in with the current display * mode * \returns 0 on success or a negative error code on failure; call @@ -482,7 +479,7 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex, * \sa SDL_GetDisplayMode * \sa SDL_SetWindowDisplayMode */ -extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode); +extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayID displayID, SDL_DisplayMode *mode); /** * Get information about the current display mode. @@ -492,7 +489,7 @@ extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_Disp * function will return the current display mode, and not the previous native * display mode. * - * \param displayIndex the index of the display to query + * \param displayID the instance ID of the display to query * \param mode an SDL_DisplayMode structure filled in with the current display * mode * \returns 0 on success or a negative error code on failure; call @@ -502,11 +499,10 @@ extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(int displayIndex, SDL_Disp * * \sa SDL_GetDesktopDisplayMode * \sa SDL_GetDisplayMode - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays * \sa SDL_SetWindowDisplayMode */ -extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode *mode); - +extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayID displayID, SDL_DisplayMode *mode); /** * Get the closest match to the requested display mode. @@ -518,9 +514,9 @@ extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_Disp * and finally checking the refresh rate. If all the available modes are too * small, then NULL is returned. * - * \param displayIndex the index of the display to query + * \param displayID the instance ID of the display to query * \param mode an SDL_DisplayMode structure containing the desired display - * mode + * mode, should be zero initialized * \param closest an SDL_DisplayMode structure filled in with the closest * match of the available display modes * \returns the passed in value `closest` or NULL if no matching video mode @@ -531,51 +527,48 @@ extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(int displayIndex, SDL_Disp * \sa SDL_GetDisplayMode * \sa SDL_GetNumDisplayModes */ -extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode *mode, SDL_DisplayMode *closest); +extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(SDL_DisplayID displayID, const SDL_DisplayMode *mode, SDL_DisplayMode *closest); /** - * Get the index of the display containing a point + * Get the display containing a point * * \param point the point to query - * \returns the index of the display containing the point or a negative error - * code on failure; call SDL_GetError() for more information. + * \returns the instance ID of the display containing the point or 0 on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetDisplayBounds - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetDisplayIndexForPoint(const SDL_Point *point); +extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetDisplayForPoint(const SDL_Point *point); /** - * Get the index of the display primarily containing a rect + * Get the display primarily containing a rect * * \param rect the rect to query - * \returns the index of the display entirely containing the rect or closest - * to the center of the rect on success or a negative error code on - * failure; call SDL_GetError() for more information. + * \returns the instance ID of the display entirely containing the rect or closest + * to the center of the rect on success or 0 on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetDisplayBounds - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetDisplayIndexForRect(const SDL_Rect *rect); +extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetDisplayForRect(const SDL_Rect *rect); /** - * Get the index of the display associated with a window. + * Get the display associated with a window. * * \param window the window to query - * \returns the index of the display containing the center of the window on - * success or a negative error code on failure; call SDL_GetError() - * for more information. + * \returns the instance ID of the display containing the center of the window on + * success or 0 on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetDisplayBounds - * \sa SDL_GetNumVideoDisplays + * \sa SDL_GetDisplays */ -extern DECLSPEC int SDLCALL SDL_GetWindowDisplayIndex(SDL_Window *window); +extern DECLSPEC SDL_DisplayID SDLCALL SDL_GetDisplayForWindow(SDL_Window *window); /** * Set the display mode to use when a window is visible at fullscreen. diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index ba45fbc1f..f6f8ae596 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -901,7 +901,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeOrientationChanged)( displayOrientation = (SDL_DisplayOrientation)orientation; if (Android_Window) { - SDL_VideoDisplay *display = SDL_GetDisplay(0); + SDL_VideoDisplay *display = SDL_GetVideoDisplay(SDL_GetPrimaryDisplay()); SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_ORIENTATION, orientation); } @@ -1034,7 +1034,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceCreated)(JNIEnv *env, j SDL_LockMutex(Android_ActivityMutex); if (Android_Window) { - SDL_WindowData *data = (SDL_WindowData *)Android_Window->driverdata; + SDL_WindowData *data = Android_Window->driverdata; data->native_window = Android_JNI_GetNativeWindow(); if (data->native_window == NULL) { @@ -1053,7 +1053,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeSurfaceChanged)(JNIEnv *env, j #if SDL_VIDEO_OPENGL_EGL if (Android_Window) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - SDL_WindowData *data = (SDL_WindowData *)Android_Window->driverdata; + SDL_WindowData *data = Android_Window->driverdata; /* If the surface has been previously destroyed by onNativeSurfaceDestroyed, recreate it here */ if (data->egl_surface == EGL_NO_SURFACE) { @@ -1078,7 +1078,7 @@ retry: if (Android_Window) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); - SDL_WindowData *data = (SDL_WindowData *)Android_Window->driverdata; + SDL_WindowData *data = Android_Window->driverdata; /* Wait for Main thread being paused and context un-activated to release 'egl_surface' */ if (!data->backup_done) { diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index 83fb4b28d..3945a9e24 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -432,16 +432,15 @@ void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata) #endif /* __WIN32__ || __GDK__ */ #if defined(__WIN32__) || defined(__WINGDK__) -int SDL_Direct3D9GetAdapterIndex(int displayIndex) +int SDL_Direct3D9GetAdapterIndex(SDL_DisplayID displayID) { - (void)displayIndex; + (void)displayID; return 0; /* D3DADAPTER_DEFAULT */ } -SDL_bool -SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex) +SDL_bool SDL_DXGIGetOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex) { - (void)displayIndex; + (void)displayID; if (adapterIndex) { *adapterIndex = -1; } diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp index 9c450d345..1a20b3136 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp @@ -114,7 +114,7 @@ static void WINRT_ProcessWindowSizeChange() // TODO: Pass an SDL_Window-identify if (coreWindow) { if (WINRT_GlobalSDLWindow) { SDL_Window *window = WINRT_GlobalSDLWindow; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; int x = (int)SDL_lroundf(data->coreWindow->Bounds.Left); int y = (int)SDL_lroundf(data->coreWindow->Bounds.Top); @@ -234,7 +234,7 @@ void SDL_WinRTApp::OnOrientationChanged(Object ^ sender) // TODO, WinRT: do more extensive research into why orientation changes on Win 8.x don't need D3D changes, or if they might, in some cases SDL_Window *window = WINRT_GlobalSDLWindow; if (window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; int w = (int)SDL_floorf(data->coreWindow->Bounds.Width); int h = (int)SDL_floorf(data->coreWindow->Bounds.Height); SDL_SendWindowEvent(WINRT_GlobalSDLWindow, SDL_EVENT_WINDOW_RESIZED, w, h); diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym index 11f0f2477..22bbb4027 100644 --- a/src/dynapi/SDL_dynapi.sym +++ b/src/dynapi/SDL_dynapi.sym @@ -164,8 +164,8 @@ SDL3_0.0.0 { SDL_GetDesktopDisplayMode; SDL_GetDisplayBounds; SDL_GetDisplayPhysicalDPI; - SDL_GetDisplayIndexForPoint; - SDL_GetDisplayIndexForRect; + SDL_GetDisplayForPoint; + SDL_GetDisplayForRect; SDL_GetDisplayMode; SDL_GetDisplayName; SDL_GetDisplayOrientation; @@ -268,7 +268,6 @@ SDL3_0.0.0 { SDL_GetNumRenderDrivers; SDL_GetNumTouchDevices; SDL_GetNumTouchFingers; - SDL_GetNumVideoDisplays; SDL_GetNumVideoDrivers; SDL_GetOriginalMemoryFunctions; SDL_GetPerformanceCounter; @@ -348,7 +347,7 @@ SDL3_0.0.0 { SDL_GetVideoDriver; SDL_GetWindowBordersSize; SDL_GetWindowData; - SDL_GetWindowDisplayIndex; + SDL_GetDisplayForWindow; SDL_GetWindowDisplayMode; SDL_GetWindowFlags; SDL_GetWindowFromID; @@ -839,6 +838,8 @@ SDL3_0.0.0 { SDL_aligned_alloc; SDL_aligned_free; SDL_ConvertAudioSamples; + SDL_GetDisplays; + SDL_GetPrimaryDisplay; # extra symbols go here (don't modify this line) local: *; }; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index 831d5c486..2f2c0c466 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -189,8 +189,8 @@ #define SDL_GetDesktopDisplayMode SDL_GetDesktopDisplayMode_REAL #define SDL_GetDisplayBounds SDL_GetDisplayBounds_REAL #define SDL_GetDisplayPhysicalDPI SDL_GetDisplayPhysicalDPI_REAL -#define SDL_GetDisplayIndexForPoint SDL_GetDisplayIndexForPoint_REAL -#define SDL_GetDisplayIndexForRect SDL_GetDisplayIndexForRect_REAL +#define SDL_GetDisplayForPoint SDL_GetDisplayForPoint_REAL +#define SDL_GetDisplayForRect SDL_GetDisplayForRect_REAL #define SDL_GetDisplayMode SDL_GetDisplayMode_REAL #define SDL_GetDisplayName SDL_GetDisplayName_REAL #define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_REAL @@ -293,7 +293,6 @@ #define SDL_GetNumRenderDrivers SDL_GetNumRenderDrivers_REAL #define SDL_GetNumTouchDevices SDL_GetNumTouchDevices_REAL #define SDL_GetNumTouchFingers SDL_GetNumTouchFingers_REAL -#define SDL_GetNumVideoDisplays SDL_GetNumVideoDisplays_REAL #define SDL_GetNumVideoDrivers SDL_GetNumVideoDrivers_REAL #define SDL_GetOriginalMemoryFunctions SDL_GetOriginalMemoryFunctions_REAL #define SDL_GetPerformanceCounter SDL_GetPerformanceCounter_REAL @@ -373,7 +372,7 @@ #define SDL_GetVideoDriver SDL_GetVideoDriver_REAL #define SDL_GetWindowBordersSize SDL_GetWindowBordersSize_REAL #define SDL_GetWindowData SDL_GetWindowData_REAL -#define SDL_GetWindowDisplayIndex SDL_GetWindowDisplayIndex_REAL +#define SDL_GetDisplayForWindow SDL_GetDisplayForWindow_REAL #define SDL_GetWindowDisplayMode SDL_GetWindowDisplayMode_REAL #define SDL_GetWindowFlags SDL_GetWindowFlags_REAL #define SDL_GetWindowFromID SDL_GetWindowFromID_REAL @@ -866,3 +865,5 @@ #define SDL_aligned_alloc SDL_aligned_alloc_REAL #define SDL_aligned_free SDL_aligned_free_REAL #define SDL_ConvertAudioSamples SDL_ConvertAudioSamples_REAL +#define SDL_GetDisplays SDL_GetDisplays_REAL +#define SDL_GetPrimaryDisplay SDL_GetPrimaryDisplay_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 2f8b17810..74214a85b 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -72,8 +72,8 @@ SDL_DYNAPI_PROC(void,SDL_UnregisterApp,(void),(),) #endif #if defined(__WIN32__) || defined(__WINGDK__) -SDL_DYNAPI_PROC(SDL_bool,SDL_DXGIGetOutputInfo,(int a, int *b, int *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_Direct3D9GetAdapterIndex,(int a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_DXGIGetOutputInfo,(SDL_DisplayID a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_Direct3D9GetAdapterIndex,(SDL_DisplayID a),(a),return) SDL_DYNAPI_PROC(ID3D11Device*,SDL_GetRenderD3D11Device,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(IDirect3DDevice9*,SDL_GetRenderD3D9Device,(SDL_Renderer *a),(a),return) #endif @@ -252,23 +252,23 @@ SDL_DYNAPI_PROC(char*,SDL_GetBasePath,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetCPUCacheLineSize,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetCPUCount,(void),(),return) SDL_DYNAPI_PROC(char*,SDL_GetClipboardText,(void),(),return) -SDL_DYNAPI_PROC(SDL_DisplayMode*,SDL_GetClosestDisplayMode,(int a, const SDL_DisplayMode *b, SDL_DisplayMode *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_DisplayMode*,SDL_GetClosestDisplayMode,(SDL_DisplayID a, const SDL_DisplayMode *b, SDL_DisplayMode *c),(a,b,c),return) SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_GetCurrentDisplayMode,(int a, SDL_DisplayMode *b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_GetCurrentDisplayMode,(SDL_DisplayID a, SDL_DisplayMode *b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetCurrentVideoDriver,(void),(),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetCursor,(void),(),return) SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetDefaultAssertionHandler,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetDefaultAudioInfo,(char **a, SDL_AudioSpec *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetDefaultCursor,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_GetDesktopDisplayMode,(int a, SDL_DisplayMode *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayBounds,(int a, SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayPhysicalDPI,(int a, float *b, float *c, float *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayIndexForPoint,(const SDL_Point *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayIndexForRect,(const SDL_Rect *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayMode,(int a, int b, SDL_DisplayMode *c),(a,b,c),return) -SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(int a),(a),return) -SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(int a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(int a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_GetDesktopDisplayMode,(SDL_DisplayID a, SDL_DisplayMode *b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_GetDisplayBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_GetDisplayPhysicalDPI,(SDL_DisplayID a, float *b, float *c, float *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForPoint,(const SDL_Point *a),(a),return) +SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForRect,(const SDL_Rect *a),(a),return) +SDL_DYNAPI_PROC(int,SDL_GetDisplayMode,(SDL_DisplayID a, int b, SDL_DisplayMode *c),(a,b,c),return) +SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(SDL_DisplayID a),(a),return) +SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetDisplayOrientation,(SDL_DisplayID a),(a),return) +SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetError,(void),(),return) SDL_DYNAPI_PROC(char*,SDL_GetErrorMsg,(char *a, int b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),return) @@ -359,7 +359,7 @@ SDL_DYNAPI_PROC(Uint32,SDL_GetMouseState,(float *a, float *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_GetNumAllocations,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetNumAudioDevices,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetNumAudioDrivers,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_GetNumDisplayModes,(int a),(a),return) +SDL_DYNAPI_PROC(int,SDL_GetNumDisplayModes,(SDL_DisplayID a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetNumGamepadMappings,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetNumJoystickAxes,(SDL_Joystick *a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetNumJoystickButtons,(SDL_Joystick *a),(a),return) @@ -367,7 +367,6 @@ SDL_DYNAPI_PROC(int,SDL_GetNumJoystickHats,(SDL_Joystick *a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetNumRenderDrivers,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetNumTouchDevices,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetNumTouchFingers,(SDL_TouchID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetNumVideoDisplays,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetNumVideoDrivers,(void),(),return) SDL_DYNAPI_PROC(void,SDL_GetOriginalMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),) SDL_DYNAPI_PROC(Uint64,SDL_GetPerformanceCounter,(void),(),return) @@ -445,7 +444,7 @@ SDL_DYNAPI_PROC(void,SDL_GetVersion,(SDL_version *a),(a),) SDL_DYNAPI_PROC(const char*,SDL_GetVideoDriver,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(void*,SDL_GetWindowData,(SDL_Window *a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowDisplayIndex,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForWindow,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetWindowDisplayMode,(SDL_Window *a, SDL_DisplayMode *b),(a,b),return) SDL_DYNAPI_PROC(Uint32,SDL_GetWindowFlags,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowFromID,(Uint32 a),(a),return) @@ -911,3 +910,5 @@ SDL_DYNAPI_PROC(void,SDL_PlayAudioDevice,(SDL_AudioDeviceID a),(a),) SDL_DYNAPI_PROC(void*,SDL_aligned_alloc,(size_t a, size_t b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_aligned_free,(void *a),(a),) SDL_DYNAPI_PROC(int,SDL_ConvertAudioSamples,(SDL_AudioFormat a, Uint8 b, int c, int d, Uint8 *e, SDL_AudioFormat f, Uint8 g, int h, int *i, Uint8 **j),(a,b,c,d,e,f,g,h,i,j),return) +SDL_DYNAPI_PROC(SDL_DisplayID*,SDL_GetDisplays,(int *a),(a),return) +SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return) diff --git a/src/events/SDL_displayevents.c b/src/events/SDL_displayevents.c index 39497a420..10d7bdcce 100644 --- a/src/events/SDL_displayevents.c +++ b/src/events/SDL_displayevents.c @@ -48,7 +48,7 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, SDL_Event event; event.type = displayevent; event.common.timestamp = 0; - event.display.display = SDL_GetIndexOfDisplay(display); + event.display.displayID = display->id; event.display.data1 = data1; posted = (SDL_PushEvent(&event) > 0); } diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index d863ee5c2..10c65c907 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -217,7 +217,7 @@ static void SDL_LogEvent(const SDL_Event *event) case x: \ SDL_strlcpy(name, #x, sizeof(name)); \ (void)SDL_snprintf(details, sizeof(details), " (timestamp=%u display=%u event=%s data1=%d)", \ - (uint)event->display.timestamp, (uint)event->display.display, name, (int)event->display.data1); \ + (uint)event->display.timestamp, (uint)event->display.displayID, name, (int)event->display.data1); \ break SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_ORIENTATION); SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CONNECTED); diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index 1939bbfc6..dd5695575 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -141,10 +141,10 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, window->flags &= ~SDL_WINDOW_INPUT_FOCUS; break; case SDL_EVENT_WINDOW_DISPLAY_CHANGED: - if (data1 < 0 || data1 == window->display_index) { + if (data1 == 0 || (SDL_DisplayID)data1 == window->displayID) { return 0; } - window->display_index = data1; + window->displayID = (SDL_DisplayID)data1; break; default: break; diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index a6a8de093..f72fa492e 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -915,15 +915,15 @@ static SDL_RenderLineMethod SDL_GetRenderLineMethod() static void SDL_CalculateSimulatedVSyncInterval(SDL_Renderer *renderer, SDL_Window *window) { - int display_index = SDL_GetWindowDisplayIndex(window); + SDL_DisplayID displayID = SDL_GetDisplayForWindow(window); SDL_DisplayMode mode; float refresh_rate; int num, den; - if (display_index < 0) { - display_index = 0; + if (displayID == 0) { + displayID = SDL_GetPrimaryDisplay(); } - if (SDL_GetDesktopDisplayMode(display_index, &mode) == 0 && mode.refresh_rate > 0.0f) { + if (SDL_GetDesktopDisplayMode(displayID, &mode) == 0 && mode.refresh_rate > 0.0f) { refresh_rate = mode.refresh_rate; } else { /* Pick a good default refresh rate */ diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index d5f7a71ff..3ae071b50 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -1557,7 +1557,7 @@ D3D_CreateRenderer(SDL_Window *window, Uint32 flags) Uint32 window_flags; int w, h; SDL_DisplayMode fullscreen_mode; - int displayIndex; + SDL_DisplayID displayID; if (SDL_GetWindowWMInfo(window, &windowinfo, SDL_SYSWM_CURRENT_VERSION) < 0 || windowinfo.subsystem != SDL_SYSWM_WINDOWS) { @@ -1639,8 +1639,8 @@ D3D_CreateRenderer(SDL_Window *window, Uint32 flags) } /* Get the adapter for the display that the window is on */ - displayIndex = SDL_GetWindowDisplayIndex(window); - data->adapter = SDL_Direct3D9GetAdapterIndex(displayIndex); + displayID = SDL_GetDisplayForWindow(window); + data->adapter = SDL_Direct3D9GetAdapterIndex(displayID); IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index 9163f6141..92435fd36 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1099,6 +1099,7 @@ SDLTest_CommonInit(SDLTest_CommonState *state) } if (state->verbose & VERBOSE_MODES) { + SDL_DisplayID *displays; SDL_Rect bounds, usablebounds; float hdpi = 0; float vdpi = 0; @@ -1109,24 +1110,25 @@ SDLTest_CommonInit(SDLTest_CommonState *state) int adapterIndex = 0; int outputIndex = 0; #endif - n = SDL_GetNumVideoDisplays(); + displays = SDL_GetDisplays(&n); SDL_Log("Number of displays: %d\n", n); for (i = 0; i < n; ++i) { - SDL_Log("Display %d: %s\n", i, SDL_GetDisplayName(i)); + SDL_DisplayID displayID = displays[i]; + SDL_Log("Display %" SDL_PRIu32 ": %s\n", displayID, SDL_GetDisplayName(displayID)); SDL_zero(bounds); - SDL_GetDisplayBounds(i, &bounds); + SDL_GetDisplayBounds(displayID, &bounds); SDL_zero(usablebounds); - SDL_GetDisplayUsableBounds(i, &usablebounds); + SDL_GetDisplayUsableBounds(displayID, &usablebounds); - SDL_GetDisplayPhysicalDPI(i, NULL, &hdpi, &vdpi); + SDL_GetDisplayPhysicalDPI(displayID, NULL, &hdpi, &vdpi); SDL_Log("Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y); SDL_Log("Usable bounds: %dx%d at %d,%d\n", usablebounds.w, usablebounds.h, usablebounds.x, usablebounds.y); SDL_Log("DPI: %gx%g\n", hdpi, vdpi); - SDL_GetDesktopDisplayMode(i, &mode); + SDL_GetDesktopDisplayMode(displayID, &mode); SDL_GetMasksForPixelFormatEnum(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); SDL_Log(" Current mode: %dx%d@%gHz, %d%% scale, %d bits-per-pixel (%s)\n", @@ -1142,13 +1144,13 @@ SDLTest_CommonInit(SDLTest_CommonState *state) } /* Print available fullscreen video modes */ - m = SDL_GetNumDisplayModes(i); + m = SDL_GetNumDisplayModes(displayID); if (m == 0) { SDL_Log("No available fullscreen video modes\n"); } else { SDL_Log(" Fullscreen video modes:\n"); for (j = 0; j < m; ++j) { - SDL_GetDisplayMode(i, j, &mode); + SDL_GetDisplayMode(displayID, j, &mode); SDL_GetMasksForPixelFormatEnum(mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); SDL_Log(" Mode %d: %dx%d@%gHz, %d%% scale, %d bits-per-pixel (%s)\n", @@ -1170,14 +1172,15 @@ SDLTest_CommonInit(SDLTest_CommonState *state) #if SDL_VIDEO_DRIVER_WINDOWS && !defined(__XBOXONE__) && !defined(__XBOXSERIES__) /* Print the D3D9 adapter index */ - adapterIndex = SDL_Direct3D9GetAdapterIndex(i); + adapterIndex = SDL_Direct3D9GetAdapterIndex(displayID); SDL_Log("D3D9 Adapter Index: %d", adapterIndex); /* Print the DXGI adapter and output indices */ - SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex); + SDL_DXGIGetOutputInfo(displayID, &adapterIndex, &outputIndex); SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex); #endif } + SDL_free(displays); } if (state->verbose & VERBOSE_RENDER) { @@ -1236,7 +1239,14 @@ SDLTest_CommonInit(SDLTest_CommonState *state) /* !!! FIXME: hack to make --usable-bounds work for now. */ if ((r.x == -1) && (r.y == -1) && (r.w == -1) && (r.h == -1)) { - SDL_GetDisplayUsableBounds(state->display, &r); + int num_displays; + SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); + if (displays && state->display < num_displays) { + SDL_GetDisplayUsableBounds(displays[state->display], &r); + } else { + SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &r); + } + SDL_free(displays); } if (state->num_windows > 1) { @@ -1421,19 +1431,19 @@ static void SDLTest_PrintEvent(SDL_Event *event) switch (event->type) { case SDL_EVENT_DISPLAY_CONNECTED: SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " connected", - event->display.display); + event->display.displayID); break; case SDL_EVENT_DISPLAY_MOVED: SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " changed position", - event->display.display); + event->display.displayID); break; case SDL_EVENT_DISPLAY_ORIENTATION: SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " changed orientation to %s", - event->display.display, DisplayOrientationName(event->display.data1)); + event->display.displayID, DisplayOrientationName(event->display.data1)); break; case SDL_EVENT_DISPLAY_DISCONNECTED: SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " disconnected", - event->display.display); + event->display.displayID); break; case SDL_EVENT_WINDOW_SHOWN: SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " shown", event->window.windowID); @@ -1720,23 +1730,29 @@ static void SDLTest_ScreenShot(SDL_Renderer *renderer) static void FullscreenTo(int index, int windowId) { + int num_displays; + SDL_DisplayID *displays; + SDL_Window *window; Uint32 flags; struct SDL_Rect rect = { 0, 0, 0, 0 }; - SDL_Window *window = SDL_GetWindowFromID(windowId); - if (window == NULL) { - return; + + displays = SDL_GetDisplays(&num_displays); + if (displays && index < num_displays) { + window = SDL_GetWindowFromID(windowId); + if (window) { + SDL_GetDisplayBounds(displays[index], &rect); + + flags = SDL_GetWindowFlags(window); + if ((flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) { + SDL_SetWindowFullscreen(window, 0); + SDL_Delay(15); + } + + SDL_SetWindowPosition(window, rect.x, rect.y); + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_EXCLUSIVE); + } } - - SDL_GetDisplayBounds(index, &rect); - - flags = SDL_GetWindowFlags(window); - if ((flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) { - SDL_SetWindowFullscreen(window, 0); - SDL_Delay(15); - } - - SDL_SetWindowPosition(window, rect.x, rect.y); - SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_EXCLUSIVE); + SDL_free(displays); } void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done) @@ -1831,20 +1847,31 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done /* Alt-Up/Down/Left/Right switches between displays */ SDL_Window *window = SDL_GetWindowFromID(event->key.windowID); if (window) { - int currentIndex = SDL_GetWindowDisplayIndex(window); - int numDisplays = SDL_GetNumVideoDisplays(); + int num_displays; + SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); + if (displays) { + SDL_DisplayID displayID = SDL_GetDisplayForWindow(window); + int current_index = -1; - if (currentIndex >= 0 && numDisplays >= 1) { - int dest; - if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) { - dest = (currentIndex + numDisplays - 1) % numDisplays; - } else { - dest = (currentIndex + numDisplays + 1) % numDisplays; + for (i = 0; i < num_displays; ++i) { + if (displayID == displays[i]) { + current_index = i; + break; + } } - SDL_Log("Centering on display %d\n", dest); - SDL_SetWindowPosition(window, - SDL_WINDOWPOS_CENTERED_DISPLAY(dest), - SDL_WINDOWPOS_CENTERED_DISPLAY(dest)); + if (current_index >= 0) { + SDL_DisplayID dest; + if (event->key.keysym.sym == SDLK_UP || event->key.keysym.sym == SDLK_LEFT) { + dest = displays[(current_index + num_displays - 1) % num_displays]; + } else { + dest = displays[(current_index + num_displays + 1) % num_displays]; + } + SDL_Log("Centering on display (%" SDL_PRIu32 ")\n", dest); + SDL_SetWindowPosition(window, + SDL_WINDOWPOS_CENTERED_DISPLAY(dest), + SDL_WINDOWPOS_CENTERED_DISPLAY(dest)); + } + SDL_free(displays); } } } @@ -2169,7 +2196,7 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl float ddpi, hdpi, vdpi; float scaleX, scaleY; Uint32 flags; - const int windowDisplayIndex = SDL_GetWindowDisplayIndex(window); + SDL_DisplayID windowDisplayID = SDL_GetDisplayForWindow(window); SDL_RendererInfo info; /* Video */ @@ -2259,36 +2286,36 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255); - (void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex); + (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayForWindow: %" SDL_PRIu32 "", windowDisplayID); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; - (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex)); + (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayID)); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; - if (0 == SDL_GetDisplayBounds(windowDisplayIndex, &rect)) { + if (0 == SDL_GetDisplayBounds(windowDisplayID, &rect)) { (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayBounds: %d,%d, %dx%d", rect.x, rect.y, rect.w, rect.h); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; } - if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) { + if (0 == SDL_GetCurrentDisplayMode(windowDisplayID, &mode)) { (void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentDisplayMode: %dx%d@%gHz %d%% scale, (%s)", mode.pixel_w, mode.pixel_h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format)); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; } - if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) { + if (0 == SDL_GetDesktopDisplayMode(windowDisplayID, &mode)) { (void)SDL_snprintf(text, sizeof text, "SDL_GetDesktopDisplayMode: %dx%d@%gHz %d%% scale, (%s)", mode.pixel_w, mode.pixel_h, mode.refresh_rate, (int)(mode.display_scale * 100.0f), SDL_GetPixelFormatName(mode.format)); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; } - if (0 == SDL_GetDisplayPhysicalDPI(windowDisplayIndex, &ddpi, &hdpi, &vdpi)) { + if (0 == SDL_GetDisplayPhysicalDPI(windowDisplayID, &ddpi, &hdpi, &vdpi)) { (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayPhysicalDPI: ddpi: %g, hdpi: %g, vdpi: %g", ddpi, hdpi, vdpi); SDLTest_DrawString(renderer, 0.0f, textY, text); @@ -2296,7 +2323,7 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl } (void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayOrientation: "); - SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayIndex)); + SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayID)); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; diff --git a/src/video/SDL_egl_c.h b/src/video/SDL_egl_c.h index cd4b02c2a..ab299b1b6 100644 --- a/src/video/SDL_egl_c.h +++ b/src/video/SDL_egl_c.h @@ -148,24 +148,21 @@ extern int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, /* A few of useful macros */ #define SDL_EGL_SwapWindow_impl(BACKEND) \ - int \ - BACKEND##_GLES_SwapWindow(_THIS, SDL_Window *window) \ + int BACKEND##_GLES_SwapWindow(_THIS, SDL_Window *window) \ { \ - return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); \ + return SDL_EGL_SwapBuffers(_this, window->driverdata->egl_surface); \ } #define SDL_EGL_MakeCurrent_impl(BACKEND) \ - int \ - BACKEND##_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) \ + int BACKEND##_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) \ { \ - return SDL_EGL_MakeCurrent(_this, window ? ((SDL_WindowData *)window->driverdata)->egl_surface : EGL_NO_SURFACE, context); \ + return SDL_EGL_MakeCurrent(_this, window ? window->driverdata->egl_surface : EGL_NO_SURFACE, context); \ } -#define SDL_EGL_CreateContext_impl(BACKEND) \ - SDL_GLContext \ - BACKEND##_GLES_CreateContext(_THIS, SDL_Window *window) \ - { \ - return SDL_EGL_CreateContext(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); \ +#define SDL_EGL_CreateContext_impl(BACKEND) \ + SDL_GLContext BACKEND##_GLES_CreateContext(_THIS, SDL_Window *window) \ + { \ + return SDL_EGL_CreateContext(_this, window->driverdata->egl_surface); \ } #endif /* SDL_VIDEO_OPENGL_EGL */ diff --git a/src/video/SDL_shape.c b/src/video/SDL_shape.c index 1ecb08ae0..c59e4411f 100644 --- a/src/video/SDL_shape.c +++ b/src/video/SDL_shape.c @@ -273,32 +273,24 @@ int SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape, SDL_WindowShapeMo result = _this->shape_driver.SetWindowShape(window->shaper, shape, shape_mode); window->shaper->hasshape = SDL_TRUE; if (window->shaper->userx != 0 && window->shaper->usery != 0) { + SDL_DisplayID displayID = 0; int x = window->shaper->userx; int y = window->shaper->usery; - if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) || - SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) { - int displayIndex; + if (!displayID) { + displayID = SDL_GetDisplayForWindowCoordinate(x); + } + if (!displayID) { + displayID = SDL_GetDisplayForWindowCoordinate(y); + } + if (displayID) { SDL_Rect bounds; - + SDL_GetDisplayBounds(displayID, &bounds); if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) { - displayIndex = (x & 0xFFFF); - if (displayIndex >= _this->num_displays) { - displayIndex = 0; - } - } else { - displayIndex = (y & 0xFFFF); - if (displayIndex >= _this->num_displays) { - displayIndex = 0; - } - } - - SDL_GetDisplayBounds(displayIndex, &bounds); - if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) { - window->x = bounds.x + (bounds.w - window->w) / 2; + x = bounds.x + (bounds.w - window->w) / 2; } if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) { - window->y = bounds.y + (bounds.h - window->h) / 2; + y = bounds.y + (bounds.h - window->h) / 2; } } SDL_SetWindowPosition(window, x, y); diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 4caef3ff1..bc21ff689 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -31,6 +31,34 @@ typedef struct SDL_WindowShaper SDL_WindowShaper; typedef struct SDL_ShapeDriver SDL_ShapeDriver; typedef struct SDL_VideoDisplay SDL_VideoDisplay; typedef struct SDL_VideoDevice SDL_VideoDevice; +#if defined(SDL_VIDEO_DRIVER_COCOA) +#ifdef __OBJC__ +@class SDL_VideoData; +@class SDL_WindowData; +#else +typedef struct _SDL_VideoData SDL_VideoData; +typedef struct _SDL_WindowData SDL_WindowData; +#endif +typedef struct SDL_DisplayData SDL_DisplayData; +typedef struct SDL_DisplayModeData SDL_DisplayModeData; +#elif defined(SDL_VIDEO_DRIVER_UIKIT) +#ifdef __OBJC__ +@class SDL_VideoData; +@class SDL_WindowData; +@class SDL_DisplayData; +@class SDL_DisplayModeData; +#else +typedef struct _SDL_VideoData SDL_VideoData; +typedef struct _SDL_WindowData SDL_WindowData; +typedef struct _SDL_DisplayData SDL_DisplayData; +typedef struct _SDL_DisplayModeData SDL_DisplayModeData; +#endif +#else +typedef struct SDL_VideoData SDL_VideoData; +typedef struct SDL_DisplayData SDL_DisplayData; +typedef struct SDL_DisplayModeData SDL_DisplayModeData; +typedef struct SDL_WindowData SDL_WindowData; +#endif /* SDL_VIDEO_DRIVER_COCOA || SDL_VIDEO_DRIVER_UIKIT */ /* Define the SDL window-shaper structure */ struct SDL_WindowShaper @@ -79,7 +107,7 @@ struct SDL_Window int last_pixel_w, last_pixel_h; Uint32 flags; Uint32 last_fullscreen_flags; - Uint32 display_index; + SDL_DisplayID displayID; /* Stored position and size for windowed mode */ SDL_Rect windowed; @@ -104,7 +132,7 @@ struct SDL_Window SDL_WindowUserData *data; - void *driverdata; + SDL_WindowData *driverdata; SDL_Window *prev; SDL_Window *next; @@ -120,6 +148,7 @@ struct SDL_Window */ struct SDL_VideoDisplay { + SDL_DisplayID id; char *name; int max_display_modes; int num_display_modes; @@ -132,7 +161,7 @@ struct SDL_VideoDisplay SDL_VideoDevice *device; - void *driverdata; + SDL_DisplayData *driverdata; }; /* Forward declaration */ @@ -240,7 +269,7 @@ struct SDL_VideoDevice void (*SetWindowAlwaysOnTop)(_THIS, SDL_Window *window, SDL_bool on_top); void (*SetWindowFullscreen)(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen); void *(*GetWindowICCProfile)(_THIS, SDL_Window *window, size_t *size); - int (*GetWindowDisplayIndex)(_THIS, SDL_Window *window); + SDL_DisplayID (*GetDisplayForWindow)(_THIS, SDL_Window *window); void (*SetWindowMouseRect)(_THIS, SDL_Window *window); void (*SetWindowMouseGrab)(_THIS, SDL_Window *window, SDL_bool grabbed); void (*SetWindowKeyboardGrab)(_THIS, SDL_Window *window, SDL_bool grabbed); @@ -422,7 +451,7 @@ struct SDL_VideoDevice /* * * */ /* Data private to this driver */ - void *driverdata; + SDL_VideoData *driverdata; struct SDL_GLDriverData *gl_data; #if SDL_VIDEO_OPENGL_EGL @@ -473,18 +502,20 @@ extern VideoBootStrap NGAGE_bootstrap; /* Use SDL_OnVideoThread() sparingly, to avoid regressions in use cases that currently happen to work */ extern SDL_bool SDL_OnVideoThread(void); extern SDL_VideoDevice *SDL_GetVideoDevice(void); -extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode); -extern int SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event); -extern void SDL_DelVideoDisplay(int index); +extern SDL_bool SDL_IsVideoContextExternal(void); +extern SDL_DisplayID SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode); +extern SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event); +extern void SDL_DelVideoDisplay(SDL_DisplayID display); extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode); extern void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode); extern void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode); -extern void SDL_ResetDisplayModes(int displayIndex); -extern int SDL_GetIndexOfDisplay(SDL_VideoDisplay *display); -extern SDL_VideoDisplay *SDL_GetDisplay(int displayIndex); -extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window); -extern void *SDL_GetDisplayDriverData(int displayIndex); -extern SDL_bool SDL_IsVideoContextExternal(void); +extern void SDL_ResetDisplayModes(SDL_VideoDisplay *display); +extern SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID display); +extern SDL_VideoDisplay *SDL_GetVideoDisplayForWindow(SDL_Window *window); +extern int SDL_GetDisplayIndex(SDL_DisplayID displayID); +extern SDL_DisplayData *SDL_GetDisplayDriverData(SDL_DisplayID display); +extern SDL_DisplayData *SDL_GetDisplayDriverDataForWindow(SDL_Window *window); +extern SDL_DisplayID SDL_GetDisplayForWindowCoordinate(int coordinate); extern int SDL_GetMessageBoxCount(void); extern void SDL_GL_DeduceMaxSupportedESProfile(int *major, int *minor); @@ -515,8 +546,6 @@ extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vin extern void SDL_ToggleDragAndDropSupport(void); -extern int SDL_GetDisplayIndexForPoint(const SDL_Point *point); - /* This has been moved out of the public API, but is still available for now */ #define SDL_WINDOW_ALLOW_HIGHDPI 0x00002000 diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 8918428c9..96cc25d1b 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -140,16 +140,10 @@ static VideoBootStrap *bootstrap[] = { return retval; \ } -#define CHECK_DISPLAY_INDEX(displayIndex, retval) \ - if (!_this) { \ - SDL_UninitializedVideo(); \ +#define CHECK_DISPLAY_MAGIC(display, retval) \ + if (!display) { \ return retval; \ } \ - if ((displayIndex) < 0 || (displayIndex) >= _this->num_displays) { \ - SDL_SetError("displayIndex must be in the range 0 - %d", \ - _this->num_displays - 1); \ - return retval; \ - } #if defined(__MACOS__) && defined(SDL_VIDEO_DRIVER_COCOA) /* Support for macOS fullscreen spaces */ @@ -578,6 +572,11 @@ SDL_VideoDevice *SDL_GetVideoDevice(void) return _this; } +SDL_bool SDL_IsVideoContextExternal(void) +{ + return SDL_GetHintBoolean(SDL_HINT_VIDEO_EXTERNAL_CONTEXT, SDL_FALSE); +} + SDL_bool SDL_OnVideoThread() { return (_this && SDL_ThreadID() == _this->thread) ? SDL_TRUE : SDL_FALSE; @@ -617,7 +616,7 @@ static void SDL_FinalizeDisplayMode(SDL_DisplayMode *mode) } } -int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode) +SDL_DisplayID SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode) { SDL_VideoDisplay display; @@ -631,17 +630,18 @@ int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode) return SDL_AddVideoDisplay(&display, SDL_FALSE); } -int SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event) +SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event) { SDL_VideoDisplay *displays; - int index = -1; + SDL_DisplayID id = 0; + int index; - displays = - SDL_realloc(_this->displays, - (_this->num_displays + 1) * sizeof(*displays)); + displays = (SDL_VideoDisplay *)SDL_realloc(_this->displays, (_this->num_displays + 1) * sizeof(*displays)); if (displays) { + id = _this->next_object_id++; index = _this->num_displays++; displays[index] = *display; + displays[index].id = id; displays[index].device = _this; _this->displays = displays; @@ -663,78 +663,131 @@ int SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event) } else { SDL_OutOfMemory(); } - return index; + return id; } -void SDL_DelVideoDisplay(int index) +void SDL_DelVideoDisplay(SDL_DisplayID displayID) { - if (index < 0 || index >= _this->num_displays) { + SDL_VideoDisplay *display; + int display_index = SDL_GetDisplayIndex(displayID); + if (display_index < 0) { return; } - SDL_SendDisplayEvent(&_this->displays[index], SDL_EVENT_DISPLAY_DISCONNECTED, 0); + display = &_this->displays[display_index]; - if (index < (_this->num_displays - 1)) { - SDL_free(_this->displays[index].driverdata); - SDL_memmove(&_this->displays[index], &_this->displays[index + 1], (_this->num_displays - index - 1) * sizeof(_this->displays[index])); + SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_DISCONNECTED, 0); + + if (display->driverdata) { + SDL_free(display->driverdata); + } + if (display_index < (_this->num_displays - 1)) { + SDL_memmove(&_this->displays[display_index], &_this->displays[display_index + 1], (_this->num_displays - display_index - 1) * sizeof(_this->displays[display_index])); } --_this->num_displays; } -int SDL_GetNumVideoDisplays(void) +SDL_DisplayID *SDL_GetDisplays(int *count) { - if (_this == NULL) { + int i; + SDL_DisplayID *displays; + + displays = (SDL_DisplayID *)SDL_malloc((_this->num_displays + 1) * sizeof(*displays)); + if (displays) { + if (count) { + *count = _this->num_displays; + } + + for (i = 0; i < _this->num_displays; ++i) { + displays[i] = _this->displays[i].id; + } + displays[i] = 0; + } else { + if (count) { + *count = 0; + } + + SDL_OutOfMemory(); + } + return displays; +} + +SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID displayID) +{ + int display_index; + + display_index = SDL_GetDisplayIndex(displayID); + if (display_index < 0) { + return NULL; + } + return &_this->displays[display_index]; +} + +SDL_VideoDisplay *SDL_GetVideoDisplayForWindow(SDL_Window *window) +{ + return SDL_GetVideoDisplay(SDL_GetDisplayForWindow(window)); +} + +SDL_DisplayID SDL_GetPrimaryDisplay(void) +{ + if (!_this || _this->num_displays == 0) { SDL_UninitializedVideo(); return 0; } - return _this->num_displays; + return _this->displays[0].id; } -int SDL_GetIndexOfDisplay(SDL_VideoDisplay *display) +int SDL_GetDisplayIndex(SDL_DisplayID displayID) { - int displayIndex; + int display_index; - for (displayIndex = 0; displayIndex < _this->num_displays; ++displayIndex) { - if (display == &_this->displays[displayIndex]) { - return displayIndex; - } + if (!_this) { + SDL_UninitializedVideo(); + return -1; } - /* Couldn't find the display, just use index 0 */ - return 0; + for (display_index = 0; display_index < _this->num_displays; ++display_index) { + if (displayID == _this->displays[display_index].id) { + return display_index; + } + } + SDL_SetError("Invalid display"); + return -1; } -void *SDL_GetDisplayDriverData(int displayIndex) +SDL_DisplayData *SDL_GetDisplayDriverData(SDL_DisplayID displayID) { - CHECK_DISPLAY_INDEX(displayIndex, NULL); + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - return _this->displays[displayIndex].driverdata; + CHECK_DISPLAY_MAGIC(display, NULL); + + return display->driverdata; } -SDL_bool SDL_IsVideoContextExternal(void) +SDL_DisplayData *SDL_GetDisplayDriverDataForWindow(SDL_Window *window) { - return SDL_GetHintBoolean(SDL_HINT_VIDEO_EXTERNAL_CONTEXT, SDL_FALSE); + return SDL_GetDisplayDriverData(SDL_GetDisplayForWindow(window)); } -const char *SDL_GetDisplayName(int displayIndex) +const char *SDL_GetDisplayName(SDL_DisplayID displayID) { - CHECK_DISPLAY_INDEX(displayIndex, NULL); + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - return _this->displays[displayIndex].name; + CHECK_DISPLAY_MAGIC(display, NULL); + + return display->name; } -int SDL_GetDisplayBounds(int displayIndex, SDL_Rect *rect) +int SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect) { - SDL_VideoDisplay *display; + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_INDEX(displayIndex, -1); + CHECK_DISPLAY_MAGIC(display, -1); if (rect == NULL) { return SDL_InvalidParamError("rect"); } - display = &_this->displays[displayIndex]; - if (_this->GetDisplayBounds) { if (_this->GetDisplayBounds(_this, display, rect) == 0) { return 0; @@ -742,11 +795,11 @@ int SDL_GetDisplayBounds(int displayIndex, SDL_Rect *rect) } /* Assume that the displays are left to right */ - if (displayIndex == 0) { + if (displayID == SDL_GetPrimaryDisplay()) { rect->x = 0; rect->y = 0; } else { - SDL_GetDisplayBounds(displayIndex - 1, rect); + SDL_GetDisplayBounds(_this->displays[SDL_GetDisplayIndex(displayID) - 1].id, rect); rect->x += rect->w; } rect->w = display->current_mode.screen_w; @@ -760,19 +813,17 @@ static int ParseDisplayUsableBoundsHint(SDL_Rect *rect) return hint && (SDL_sscanf(hint, "%d,%d,%d,%d", &rect->x, &rect->y, &rect->w, &rect->h) == 4); } -int SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect *rect) +int SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect) { - SDL_VideoDisplay *display; + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_INDEX(displayIndex, -1); + CHECK_DISPLAY_MAGIC(display, -1); if (rect == NULL) { return SDL_InvalidParamError("rect"); } - display = &_this->displays[displayIndex]; - - if ((displayIndex == 0) && ParseDisplayUsableBoundsHint(rect)) { + if (displayID == SDL_GetPrimaryDisplay() && ParseDisplayUsableBoundsHint(rect)) { return 0; } @@ -783,35 +834,32 @@ int SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect *rect) } /* Oh well, just give the entire display bounds. */ - return SDL_GetDisplayBounds(displayIndex, rect); + return SDL_GetDisplayBounds(displayID, rect); } -int SDL_GetDisplayPhysicalDPI(int displayIndex, float *ddpi, float *hdpi, float *vdpi) +int SDL_GetDisplayPhysicalDPI(SDL_DisplayID displayID, float *ddpi, float *hdpi, float *vdpi) { - SDL_VideoDisplay *display; + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_INDEX(displayIndex, -1); - - display = &_this->displays[displayIndex]; + CHECK_DISPLAY_MAGIC(display, -1); if (_this->GetDisplayPhysicalDPI) { - if (_this->GetDisplayPhysicalDPI(_this, display, ddpi, hdpi, vdpi) == 0) { + if (_this->GetDisplayPhysicalDPI(_this, display, ddpi, hdpi, vdpi) < 0) { + return -1; + } else { return 0; } } else { return SDL_Unsupported(); } - - return -1; } -SDL_DisplayOrientation SDL_GetDisplayOrientation(int displayIndex) +SDL_DisplayOrientation SDL_GetDisplayOrientation(SDL_DisplayID displayID) { - SDL_VideoDisplay *display; + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_INDEX(displayIndex, SDL_ORIENTATION_UNKNOWN); + CHECK_DISPLAY_MAGIC(display, SDL_ORIENTATION_UNKNOWN); - display = &_this->displays[displayIndex]; return display->orientation; } @@ -861,31 +909,10 @@ void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode SDL_FinalizeDisplayMode(&display->desktop_mode); } -static int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay *display) +void SDL_ResetDisplayModes(SDL_VideoDisplay *display) { - if (!display->num_display_modes && _this->GetDisplayModes) { - _this->GetDisplayModes(_this, display); - SDL_qsort(display->display_modes, display->num_display_modes, - sizeof(SDL_DisplayMode), cmpmodes); - } - return display->num_display_modes; -} - -int SDL_GetNumDisplayModes(int displayIndex) -{ - CHECK_DISPLAY_INDEX(displayIndex, -1); - - return SDL_GetNumDisplayModesForDisplay(&_this->displays[displayIndex]); -} - -void SDL_ResetDisplayModes(int displayIndex) -{ - SDL_VideoDisplay *display; int i; - CHECK_DISPLAY_INDEX(displayIndex, ); - - display = &_this->displays[displayIndex]; for (i = display->num_display_modes; i--;) { SDL_free(display->display_modes[i].driverdata); display->display_modes[i].driverdata = NULL; @@ -896,13 +923,31 @@ void SDL_ResetDisplayModes(int displayIndex) display->max_display_modes = 0; } -int SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode *mode) +static int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay *display) { - SDL_VideoDisplay *display; + if (!display->num_display_modes && _this->GetDisplayModes) { + _this->GetDisplayModes(_this, display); + SDL_qsort(display->display_modes, display->num_display_modes, + sizeof(SDL_DisplayMode), cmpmodes); + } + return display->num_display_modes; +} - CHECK_DISPLAY_INDEX(displayIndex, -1); +int SDL_GetNumDisplayModes(SDL_DisplayID displayID) +{ + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); + + CHECK_DISPLAY_MAGIC(display, -1); + + return SDL_GetNumDisplayModesForDisplay(display); +} + +int SDL_GetDisplayMode(SDL_DisplayID displayID, int index, SDL_DisplayMode *mode) +{ + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); + + CHECK_DISPLAY_MAGIC(display, -1); - display = &_this->displays[displayIndex]; if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) { return SDL_SetError("index must be in the range of 0 - %d", SDL_GetNumDisplayModesForDisplay(display) - 1); } @@ -912,26 +957,24 @@ int SDL_GetDisplayMode(int displayIndex, int index, SDL_DisplayMode *mode) return 0; } -int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode) +int SDL_GetDesktopDisplayMode(SDL_DisplayID displayID, SDL_DisplayMode *mode) { - SDL_VideoDisplay *display; + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_INDEX(displayIndex, -1); + CHECK_DISPLAY_MAGIC(display, -1); - display = &_this->displays[displayIndex]; if (mode) { *mode = display->desktop_mode; } return 0; } -int SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode *mode) +int SDL_GetCurrentDisplayMode(SDL_DisplayID displayID, SDL_DisplayMode *mode) { - SDL_VideoDisplay *display; + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_INDEX(displayIndex, -1); + CHECK_DISPLAY_MAGIC(display, -1); - display = &_this->displays[displayIndex]; if (mode) { *mode = display->current_mode; } @@ -1058,13 +1101,12 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay *di return NULL; } -SDL_DisplayMode *SDL_GetClosestDisplayMode(int displayIndex, const SDL_DisplayMode *mode, SDL_DisplayMode *closest) +SDL_DisplayMode *SDL_GetClosestDisplayMode(SDL_DisplayID displayID, const SDL_DisplayMode *mode, SDL_DisplayMode *closest) { - SDL_VideoDisplay *display; + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_INDEX(displayIndex, NULL); + CHECK_DISPLAY_MAGIC(display, NULL); - display = &_this->displays[displayIndex]; return SDL_GetClosestDisplayModeForDisplay(display, mode, closest); } @@ -1132,13 +1174,6 @@ static int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, const SDL_Dis return 0; } -SDL_VideoDisplay *SDL_GetDisplay(int displayIndex) -{ - CHECK_DISPLAY_INDEX(displayIndex, NULL); - - return &_this->displays[displayIndex]; -} - /** * If x, y are outside of rect, snaps them to the closest point inside rect * (between rect->x, rect->y, inclusive, and rect->x + w, rect->y + h, exclusive) @@ -1161,10 +1196,10 @@ static void SDL_GetClosestPointOnRect(const SDL_Rect *rect, SDL_Point *point) } } -static int GetDisplayIndexForRect(int x, int y, int w, int h) +static SDL_DisplayID GetDisplayForRect(int x, int y, int w, int h) { int i, dist; - int closest = -1; + SDL_DisplayID closest = 0; int closest_dist = 0x7FFFFFFF; SDL_Point closest_point_on_display; SDL_Point delta; @@ -1174,8 +1209,9 @@ static int GetDisplayIndexForRect(int x, int y, int w, int h) if (_this) { for (i = 0; i < _this->num_displays; ++i) { + SDL_VideoDisplay *display = &_this->displays[i]; SDL_Rect display_rect; - SDL_GetDisplayBounds(i, &display_rect); + SDL_GetDisplayBounds(display->id, &display_rect); /* Check if the window is fully enclosed */ if (SDL_GetRectEnclosingPoints(¢er, 1, &display_rect, NULL)) { @@ -1190,75 +1226,82 @@ static int GetDisplayIndexForRect(int x, int y, int w, int h) delta.y = center.y - closest_point_on_display.y; dist = (delta.x * delta.x + delta.y * delta.y); if (dist < closest_dist) { - closest = i; + closest = display->id; closest_dist = dist; } } } - if (closest < 0) { + if (closest == 0) { SDL_SetError("Couldn't find any displays"); } return closest; } -int SDL_GetDisplayIndexForPoint(const SDL_Point *point) +SDL_DisplayID SDL_GetDisplayForPoint(const SDL_Point *point) { - return GetDisplayIndexForRect(point->x, point->y, 1, 1); + return GetDisplayForRect(point->x, point->y, 1, 1); } -int SDL_GetDisplayIndexForRect(const SDL_Rect *rect) +SDL_DisplayID SDL_GetDisplayForRect(const SDL_Rect *rect) { - return GetDisplayIndexForRect(rect->x, rect->y, rect->w, rect->h); + return GetDisplayForRect(rect->x, rect->y, rect->w, rect->h); } -int SDL_GetWindowDisplayIndex(SDL_Window *window) +SDL_DisplayID SDL_GetDisplayForWindowCoordinate(int coordinate) { - int displayIndex = -1; + SDL_DisplayID displayID = 0; - CHECK_WINDOW_MAGIC(window, -1); - if (_this->GetWindowDisplayIndex) { - displayIndex = _this->GetWindowDisplayIndex(_this, window); + if (SDL_WINDOWPOS_ISUNDEFINED(coordinate) || + SDL_WINDOWPOS_ISCENTERED(coordinate)) { + displayID = (coordinate & 0xFFFF); + if (SDL_GetDisplayIndex(displayID) < 0) { + displayID = SDL_GetPrimaryDisplay(); + } + } + return displayID; +} + +SDL_DisplayID SDL_GetDisplayForWindow(SDL_Window *window) +{ + SDL_DisplayID displayID = 0; + + CHECK_WINDOW_MAGIC(window, 0); + if (_this->GetDisplayForWindow) { + displayID = _this->GetDisplayForWindow(_this, window); } /* A backend implementation may fail to get a display index for the window * (for example if the window is off-screen), but other code may expect it * to succeed in that situation, so we fall back to a generic position- * based implementation in that case. */ - if (displayIndex >= 0) { - return displayIndex; - } else { - int i; - if (SDL_WINDOWPOS_ISUNDEFINED(window->x) || - SDL_WINDOWPOS_ISCENTERED(window->x)) { - displayIndex = (window->x & 0xFFFF); - if (displayIndex >= _this->num_displays) { - displayIndex = 0; - } - return displayIndex; - } - if (SDL_WINDOWPOS_ISUNDEFINED(window->y) || - SDL_WINDOWPOS_ISCENTERED(window->y)) { - displayIndex = (window->y & 0xFFFF); - if (displayIndex >= _this->num_displays) { - displayIndex = 0; - } - return displayIndex; - } + if (!displayID) { + displayID = SDL_GetDisplayForWindowCoordinate(window->x); + } + if (!displayID) { + displayID = SDL_GetDisplayForWindowCoordinate(window->y); + } + if (!displayID) { + int i, display_index; - displayIndex = GetDisplayIndexForRect(window->x, window->y, window->w, window->h); + displayID = GetDisplayForRect(window->x, window->y, window->w, window->h); + if (!displayID) { + /* Use the primary display for a window if we can't find it anywhere else */ + displayID = SDL_GetPrimaryDisplay(); + } + display_index = SDL_GetDisplayIndex(displayID); /* Find the display containing the window if fullscreen */ for (i = 0; i < _this->num_displays; ++i) { SDL_VideoDisplay *display = &_this->displays[i]; if (display->fullscreen_window == window) { - if (displayIndex != i) { - if (displayIndex < 0) { - displayIndex = i; + if (display_index != i) { + if (display_index < 0) { + display_index = i; } else { - SDL_VideoDisplay *new_display = &_this->displays[displayIndex]; + SDL_VideoDisplay *new_display = &_this->displays[display_index]; /* The window was moved to a different display */ if (new_display->fullscreen_window != NULL) { @@ -1272,18 +1315,9 @@ int SDL_GetWindowDisplayIndex(SDL_Window *window) break; } } - return displayIndex; } -} -SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window) -{ - int displayIndex = SDL_GetWindowDisplayIndex(window); - if (displayIndex >= 0) { - return &_this->displays[displayIndex]; - } else { - return NULL; - } + return displayID; } int SDL_SetWindowDisplayMode(SDL_Window *window, const SDL_DisplayMode *mode) @@ -1299,7 +1333,7 @@ int SDL_SetWindowDisplayMode(SDL_Window *window, const SDL_DisplayMode *mode) if (SDL_WINDOW_FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) { SDL_DisplayMode fullscreen_mode; if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { - if (SDL_SetDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode) == 0) { + if (SDL_SetDisplayModeForDisplay(SDL_GetVideoDisplayForWindow(window), &fullscreen_mode) == 0) { #ifndef __ANDROID__ /* Android may not resize the window to exactly what our fullscreen mode is, especially on * windowed Android environments like the Chromebook or Samsung DeX. Given this, we shouldn't @@ -1316,7 +1350,6 @@ int SDL_SetWindowDisplayMode(SDL_Window *window, const SDL_DisplayMode *mode) int SDL_GetWindowDisplayMode(SDL_Window *window, SDL_DisplayMode *mode) { - SDL_DisplayMode fullscreen_mode; SDL_VideoDisplay *display; CHECK_WINDOW_MAGIC(window, -1); @@ -1325,28 +1358,26 @@ int SDL_GetWindowDisplayMode(SDL_Window *window, SDL_DisplayMode *mode) return SDL_InvalidParamError("mode"); } - fullscreen_mode = window->fullscreen_mode; - if (!fullscreen_mode.screen_w) { - fullscreen_mode.screen_w = window->windowed.w; - } - if (!fullscreen_mode.screen_h) { - fullscreen_mode.screen_h = window->windowed.h; - } - - display = SDL_GetDisplayForWindow(window); + display = SDL_GetVideoDisplayForWindow(window); /* if in desktop size mode, just return the size of the desktop */ if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) { - fullscreen_mode = display->desktop_mode; - } else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window), - &fullscreen_mode, - &fullscreen_mode)) { - SDL_zerop(mode); - return SDL_SetError("Couldn't find display mode match"); + *mode = display->desktop_mode; + } else { + SDL_DisplayMode fullscreen_mode; + + fullscreen_mode = window->fullscreen_mode; + if (!fullscreen_mode.screen_w) { + fullscreen_mode.screen_w = window->windowed.w; + } + if (!fullscreen_mode.screen_h) { + fullscreen_mode.screen_h = window->windowed.h; + } + if (SDL_GetClosestDisplayModeForDisplay(display, &fullscreen_mode, mode) == NULL) { + SDL_zerop(mode); + return SDL_SetError("Couldn't find display mode match"); + } } - - *mode = fullscreen_mode; - return 0; } @@ -1365,7 +1396,7 @@ Uint32 SDL_GetWindowPixelFormat(SDL_Window *window) CHECK_WINDOW_MAGIC(window, SDL_PIXELFORMAT_UNKNOWN); - display = SDL_GetDisplayForWindow(window); + display = SDL_GetVideoDisplayForWindow(window); return display->current_mode.format; } @@ -1415,7 +1446,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen) } else if (fullscreen && (window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0 && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0) { - display = SDL_GetDisplayForWindow(window); + display = SDL_GetVideoDisplayForWindow(window); SDL_SetDisplayModeForDisplay(display, NULL); if (_this->SetWindowFullscreen) { _this->SetWindowFullscreen(_this, window, display, SDL_FALSE); @@ -1456,7 +1487,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen) } #endif - display = SDL_GetDisplayForWindow(window); + display = SDL_GetVideoDisplayForWindow(window); if (fullscreen) { /* Hide any other fullscreen windows */ @@ -1480,7 +1511,7 @@ static int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_bool fullscreen) if (other == window) { setDisplayMode = fullscreen; } else if (SDL_WINDOW_FULLSCREEN_VISIBLE(other) && - SDL_GetDisplayForWindow(other) == display) { + SDL_GetVideoDisplayForWindow(other) == display) { setDisplayMode = SDL_TRUE; } @@ -1733,12 +1764,10 @@ SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint window->h = h; if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - int displayIndex; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_Rect bounds; - displayIndex = SDL_GetIndexOfDisplay(display); - SDL_GetDisplayBounds(displayIndex, &bounds); + SDL_GetDisplayBounds(display->id, &bounds); if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) { window->x = bounds.x + (bounds.w - w) / 2; } @@ -1752,12 +1781,10 @@ SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint window->windowed.h = window->h; if (flags & SDL_WINDOW_FULLSCREEN_MASK) { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - int displayIndex; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_Rect bounds; - displayIndex = SDL_GetIndexOfDisplay(display); - SDL_GetDisplayBounds(displayIndex, &bounds); + SDL_GetDisplayBounds(display->id, &bounds); /* for real fullscreen we might switch the resolution, so get width and height * from closest supported mode and use that instead of current resolution @@ -1785,7 +1812,7 @@ SDL_Window *SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint window->opacity = 1.0f; window->next = _this->windows; window->is_destroying = SDL_FALSE; - window->display_index = SDL_GetWindowDisplayIndex(window); + window->displayID = SDL_GetDisplayForWindow(window); if (_this->windows) { _this->windows->prev = window; @@ -1891,7 +1918,7 @@ SDL_Window *SDL_CreateWindowFrom(const void *data) return NULL; } - window->display_index = SDL_GetWindowDisplayIndex(window); + window->displayID = SDL_GetDisplayForWindow(window); PrepareDragAndDropSupport(window); return window; @@ -2186,15 +2213,18 @@ void SDL_SetWindowPosition(SDL_Window *window, int x, int y) CHECK_WINDOW_MAGIC(window, ); if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) { - int displayIndex = (x & 0xFFFF); + SDL_DisplayID displayID = 0; SDL_Rect bounds; - if (displayIndex >= _this->num_displays) { - displayIndex = 0; + + if (!displayID) { + displayID = SDL_GetDisplayForWindowCoordinate(x); + } + if (!displayID) { + displayID = SDL_GetDisplayForWindowCoordinate(y); } SDL_zero(bounds); - - SDL_GetDisplayBounds(displayIndex, &bounds); + SDL_GetDisplayBounds(displayID, &bounds); if (SDL_WINDOWPOS_ISCENTERED(x)) { x = bounds.x + (bounds.w - window->windowed.w) / 2; } @@ -2230,7 +2260,7 @@ void SDL_GetWindowPosition(SDL_Window *window, int *x, int *y) /* Fullscreen windows are always at their display's origin */ if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) != 0) { - int displayIndex; + SDL_DisplayID displayID; if (x) { *x = 0; @@ -2241,13 +2271,13 @@ void SDL_GetWindowPosition(SDL_Window *window, int *x, int *y) /* Find the window's monitor and update to the monitor offset. */ - displayIndex = SDL_GetWindowDisplayIndex(window); - if (displayIndex >= 0) { + displayID = SDL_GetDisplayForWindow(window); + if (displayID != 0) { SDL_Rect bounds; SDL_zero(bounds); - SDL_GetDisplayBounds(displayIndex, &bounds); + SDL_GetDisplayBounds(displayID, &bounds); if (x) { *x = bounds.x; } @@ -2415,7 +2445,7 @@ void SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h) if (_this->GetWindowSizeInPixels) { _this->GetWindowSizeInPixels(_this, window, w, h); } else { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_GetWindowSize(window, w, h); @@ -2999,10 +3029,10 @@ void SDL_OnWindowHidden(SDL_Window *window) void SDL_CheckWindowDisplayChanged(SDL_Window *window) { - int display_index; + SDL_DisplayID displayID; - display_index = SDL_GetWindowDisplayIndex(window); - SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_DISPLAY_CHANGED, display_index, 0); + displayID = SDL_GetDisplayForWindow(window); + SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_DISPLAY_CHANGED, (int)displayID, 0); } void SDL_OnWindowDisplayChanged(SDL_Window *window) @@ -3026,7 +3056,7 @@ void SDL_OnWindowDisplayChanged(SDL_Window *window) * emulated mode dimensions since the window is just being scaled. */ if (!ModeSwitchingEmulated(_this) && - SDL_GetDisplayBounds(window->display_index, &rect) == 0) { + SDL_GetDisplayBounds(window->displayID, &rect) == 0) { int old_w = window->w; int old_h = window->h; window->x = rect.x; @@ -3238,7 +3268,7 @@ void SDL_DestroyWindow(SDL_Window *window) _this->DestroyWindow(_this, window); } - display = SDL_GetDisplayForWindow(window); + display = SDL_GetVideoDisplayForWindow(window); if (display->fullscreen_window == window) { display->fullscreen_window = NULL; } @@ -3330,7 +3360,7 @@ void SDL_VideoQuit(void) for (i = 0; i < _this->num_displays; ++i) { SDL_VideoDisplay *display = &_this->displays[i]; - SDL_ResetDisplayModes(i); + SDL_ResetDisplayModes(display); SDL_free(display->desktop_mode.driverdata); display->desktop_mode.driverdata = NULL; SDL_free(display->driverdata); diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c index 5279a72bf..18a5b20e2 100644 --- a/src/video/android/SDL_androidevents.c +++ b/src/video/android/SDL_androidevents.c @@ -72,7 +72,7 @@ static void android_egl_context_restore(SDL_Window *window) { if (window) { SDL_Event event; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context) < 0) { /* The context is no longer valid, create a new one */ data->egl_context = (EGLContext)SDL_GL_CreateContext(window); @@ -89,7 +89,7 @@ static void android_egl_context_backup(SDL_Window *window) { if (window) { /* Keep a copy of the EGL Context so we can try to restore it when we resume */ - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; data->egl_context = SDL_GL_GetCurrentContext(); /* We need to do this so the EGLSurface can be freed */ SDL_GL_MakeCurrent(window, NULL); @@ -107,7 +107,7 @@ static void android_egl_context_backup(SDL_Window *window) void Android_PumpEvents_Blocking(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; if (videodata->isPaused) { SDL_bool isContextExternal = SDL_IsVideoContextExternal(); @@ -182,7 +182,7 @@ void Android_PumpEvents_Blocking(_THIS) void Android_PumpEvents_NonBlocking(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; static int backup_context = 0; if (videodata->isPaused) { diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c index 58fa3e5e7..11d63c4da 100644 --- a/src/video/android/SDL_androidgl.c +++ b/src/video/android/SDL_androidgl.c @@ -38,7 +38,7 @@ int Android_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) { if (window && context) { - return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *)window->driverdata)->egl_surface, context); + return SDL_EGL_MakeCurrent(_this, window->driverdata->egl_surface, context); } else { return SDL_EGL_MakeCurrent(_this, NULL, NULL); } @@ -51,7 +51,7 @@ Android_GLES_CreateContext(_THIS, SDL_Window *window) Android_ActivityMutex_Lock_Running(); - ret = SDL_EGL_CreateContext(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); + ret = SDL_EGL_CreateContext(_this, window->driverdata->egl_surface); SDL_UnlockMutex(Android_ActivityMutex); @@ -71,7 +71,7 @@ int Android_GLES_SwapWindow(_THIS, SDL_Window *window) /*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE); _this->egl_data->eglWaitGL();*/ - retval = SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); + retval = SDL_EGL_SwapBuffers(_this, window->driverdata->egl_surface); SDL_UnlockMutex(Android_ActivityMutex); diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c index 7c17233f1..0c44cb532 100644 --- a/src/video/android/SDL_androidkeyboard.c +++ b/src/video/android/SDL_androidkeyboard.c @@ -350,7 +350,7 @@ Android_IsScreenKeyboardShown(_THIS, SDL_Window *window) void Android_StartTextInput(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Android_JNI_ShowTextInput(&videodata->textRect); } @@ -361,7 +361,7 @@ void Android_StopTextInput(_THIS) void Android_SetTextInputRect(_THIS, const SDL_Rect *rect) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; if (rect == NULL) { SDL_InvalidParamError("rect"); diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 562df5ed9..8eee45297 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -169,8 +169,8 @@ VideoBootStrap Android_bootstrap = { int Android_VideoInit(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; - int display_index; + SDL_VideoData *videodata = _this->driverdata; + SDL_DisplayID displayID; SDL_VideoDisplay *display; SDL_DisplayMode mode; @@ -186,11 +186,11 @@ int Android_VideoInit(_THIS) mode.refresh_rate = Android_ScreenRate; mode.driverdata = NULL; - display_index = SDL_AddBasicVideoDisplay(&mode); - if (display_index < 0) { + displayID = SDL_AddBasicVideoDisplay(&mode); + if (displayID == 0) { return -1; } - display = SDL_GetDisplay(display_index); + display = SDL_GetVideoDisplay(displayID); display->orientation = Android_JNI_GetDisplayOrientation(); SDL_AddDisplayMode(&_this->displays[0], &mode); @@ -291,7 +291,7 @@ void Android_SendResize(SDL_Window *window) /* Force the current mode to match the resize otherwise the SDL_EVENT_WINDOW_RESTORED event * will fall back to the old mode */ int w, h; - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_DisplayMode current_mode; current_mode.format = Android_ScreenFormat; diff --git a/src/video/android/SDL_androidvideo.h b/src/video/android/SDL_androidvideo.h index 74aba209b..ae24b1f74 100644 --- a/src/video/android/SDL_androidvideo.h +++ b/src/video/android/SDL_androidvideo.h @@ -32,13 +32,13 @@ extern void Android_SendResize(SDL_Window *window); /* Private display data */ -typedef struct SDL_VideoData +struct SDL_VideoData { SDL_Rect textRect; int isPaused; int isPausing; int pauseAudio; -} SDL_VideoData; +}; extern int Android_SurfaceWidth; extern int Android_SurfaceHeight; diff --git a/src/video/android/SDL_androidvulkan.c b/src/video/android/SDL_androidvulkan.c index 37ba6a41f..1e16ceb34 100644 --- a/src/video/android/SDL_androidvulkan.c +++ b/src/video/android/SDL_androidvulkan.c @@ -130,7 +130,7 @@ SDL_bool Android_Vulkan_CreateSurface(_THIS, VkInstance instance, VkSurfaceKHR *surface) { - SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windowData = window->driverdata; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr; PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR = diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index 68bbd25c9..838d9d541 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -128,7 +128,7 @@ void Android_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *di goto endfunction; } - data = (SDL_WindowData *)window->driverdata; + data = window->driverdata; if (data == NULL || !data->native_window) { if (data && !data->native_window) { SDL_SetError("Missing native window"); @@ -175,7 +175,7 @@ void Android_DestroyWindow(_THIS, SDL_Window *window) Android_Window = NULL; if (window->driverdata) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; #if SDL_VIDEO_OPENGL_EGL if (data->egl_surface != EGL_NO_SURFACE) { @@ -196,7 +196,7 @@ void Android_DestroyWindow(_THIS, SDL_Window *window) int Android_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; info->subsystem = SDL_SYSWM_ANDROID; info->info.android.window = data->native_window; diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h index d22c67841..3c5260202 100644 --- a/src/video/android/SDL_androidwindow.h +++ b/src/video/android/SDL_androidwindow.h @@ -36,7 +36,7 @@ extern void Android_DestroyWindow(_THIS, SDL_Window *window); extern int Android_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info); extern SDL_Window *Android_Window; -typedef struct +struct SDL_WindowData { #if SDL_VIDEO_OPENGL_EGL EGLSurface egl_surface; @@ -45,6 +45,6 @@ typedef struct SDL_bool backup_done; ANativeWindow *native_window; -} SDL_WindowData; +}; #endif /* SDL_androidwindow_h_ */ diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m index cf6c12c31..765022750 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.m +++ b/src/video/cocoa/SDL_cocoaclipboard.m @@ -28,7 +28,7 @@ int Cocoa_SetClipboardText(_THIS, const char *text) { @autoreleasepool { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; NSPasteboard *pasteboard; NSString *format = NSPasteboardTypeString; NSString *nsstr = [NSString stringWithUTF8String:text]; diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 7657dab4d..1edac9eac 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -35,7 +35,7 @@ static SDL_Window *FindSDLWindowForNSWindow(NSWindow *win) SDL_VideoDevice *device = SDL_GetVideoDevice(); if (device && device->windows) { for (sdlwindow = device->windows; sdlwindow; sdlwindow = sdlwindow->next) { - NSWindow *nswindow = ((__bridge SDL_WindowData *)sdlwindow->driverdata).nswindow; + NSWindow *nswindow = sdlwindow->driverdata.nswindow; if (win == nswindow) { return sdlwindow; } @@ -557,7 +557,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window) location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0 - windowNumber:((__bridge SDL_WindowData *)window->driverdata).window_number + windowNumber:window->driverdata.window_number context:nil subtype:0 data1:0 @@ -570,7 +570,7 @@ void Cocoa_SendWakeupEvent(_THIS, SDL_Window *window) void Cocoa_SuspendScreenSaver(_THIS) { @autoreleasepool { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data.screensaver_assertion) { IOPMAssertionRelease(data.screensaver_assertion); diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index 9a4db21dc..ab8fde76d 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -294,7 +294,7 @@ cleanup: void Cocoa_InitKeyboard(_THIS) { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; UpdateKeymap(data, SDL_FALSE); @@ -314,11 +314,11 @@ void Cocoa_StartTextInput(_THIS) { @autoreleasepool { NSView *parentView; - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; SDL_Window *window = SDL_GetKeyboardFocus(); NSWindow *nswindow = nil; if (window) { - nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow; + nswindow = window->driverdata.nswindow; } parentView = [nswindow contentView]; @@ -345,7 +345,7 @@ void Cocoa_StartTextInput(_THIS) void Cocoa_StopTextInput(_THIS) { @autoreleasepool { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data && data.fieldEdit) { [data.fieldEdit removeFromSuperview]; @@ -356,7 +356,7 @@ void Cocoa_StopTextInput(_THIS) void Cocoa_SetTextInputRect(_THIS, const SDL_Rect *rect) { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (!rect) { SDL_InvalidParamError("rect"); @@ -370,7 +370,7 @@ void Cocoa_HandleKeyEvent(_THIS, NSEvent *event) { unsigned short scancode; SDL_Scancode code; - SDL_VideoData *data = _this ? ((__bridge SDL_VideoData *)_this->driverdata) : nil; + SDL_VideoData *data = _this ? _this->driverdata : nil; if (!data) { return; /* can happen when returning from fullscreen Space on shutdown */ } diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m index 926375797..9c4eb8c95 100644 --- a/src/video/cocoa/SDL_cocoamessagebox.m +++ b/src/video/cocoa/SDL_cocoamessagebox.m @@ -42,7 +42,7 @@ /* Retain the NSWindow because we'll show the alert later on the main thread */ if (window) { - nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow; + nswindow = window->driverdata.nswindow; } else { nswindow = nil; } diff --git a/src/video/cocoa/SDL_cocoametalview.m b/src/video/cocoa/SDL_cocoametalview.m index a6f187b9d..7fecc3880 100644 --- a/src/video/cocoa/SDL_cocoametalview.m +++ b/src/video/cocoa/SDL_cocoametalview.m @@ -133,7 +133,7 @@ SDL_MetalView Cocoa_Metal_CreateView(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; NSView *view = data.nswindow.contentView; BOOL highDPI = (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) != 0; Uint32 windowID = SDL_GetWindowID(window); diff --git a/src/video/cocoa/SDL_cocoamodes.h b/src/video/cocoa/SDL_cocoamodes.h index ea65fdb07..f076edccf 100644 --- a/src/video/cocoa/SDL_cocoamodes.h +++ b/src/video/cocoa/SDL_cocoamodes.h @@ -23,15 +23,15 @@ #ifndef SDL_cocoamodes_h_ #define SDL_cocoamodes_h_ -typedef struct +struct SDL_DisplayData { CGDirectDisplayID display; -} SDL_DisplayData; +}; -typedef struct +struct SDL_DisplayModeData { CFMutableArrayRef modes; -} SDL_DisplayModeData; +}; extern void Cocoa_InitModes(_THIS); extern int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect); diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index 956da1fb9..27cd9dc3c 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -364,7 +364,7 @@ void Cocoa_InitModes(_THIS) int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { - SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *displaydata = display->driverdata; CGRect cgrect; cgrect = CGDisplayBounds(displaydata->display); @@ -377,7 +377,7 @@ int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int Cocoa_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { - SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *displaydata = display->driverdata; const CGDirectDisplayID cgdisplay = displaydata->display; NSArray *screens = [NSScreen screens]; NSScreen *screen = nil; @@ -412,7 +412,7 @@ int Cocoa_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, f @autoreleasepool { const float MM_IN_INCH = 25.4f; - SDL_DisplayData *data = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *data = display->driverdata; /* we need the backingScaleFactor for Retina displays, which is only exposed through NSScreen, not CGDisplay, afaik, so find our screen... */ NSArray *screens = [NSScreen screens]; @@ -476,7 +476,7 @@ int Cocoa_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, f void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { - SDL_DisplayData *data = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *data = display->driverdata; CVDisplayLinkRef link = NULL; CGDisplayModeRef desktopmoderef; SDL_DisplayMode desktopmode; @@ -571,7 +571,7 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { - SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *displaydata = display->driverdata; SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata; CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken; CGError result; diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index db0b9b19d..9fae96684 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -219,7 +219,7 @@ static int Cocoa_ShowCursor(SDL_Cursor *cursor) SDL_VideoDevice *device = SDL_GetVideoDevice(); SDL_Window *window = (device ? device->windows : NULL); for (; window != NULL; window = window->next) { - SDL_WindowData *driverdata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *driverdata = window->driverdata; if (driverdata) { [driverdata.nswindow performSelectorOnMainThread:@selector(invalidateCursorRectsForView:) withObject:[driverdata.nswindow contentView] @@ -249,7 +249,7 @@ static int Cocoa_WarpMouseGlobal(float x, float y) CGPoint point; SDL_Mouse *mouse = SDL_GetMouse(); if (mouse->focus) { - SDL_WindowData *data = (__bridge SDL_WindowData *)mouse->focus->driverdata; + SDL_WindowData *data = mouse->focus->driverdata; if ([data.listener isMovingOrFocusClickPending]) { DLog("Postponing warp, window being moved or focused."); [data.listener setPendingMoveX:x Y:y]; @@ -317,7 +317,7 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled) /* We will re-apply the non-relative mode when the window finishes being moved, * if it is being moved right now. */ - data = (__bridge SDL_WindowData *)window->driverdata; + data = window->driverdata; if ([data.listener isMovingOrFocusClickPending]) { return 0; } @@ -398,7 +398,7 @@ static void Cocoa_HandleTitleButtonEvent(_THIS, NSEvent *event) } for (window = _this->windows; window; window = window->next) { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data && data.nswindow == nswindow) { switch ([event type]) { case NSEventTypeLeftMouseDown: diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 2c5c3a4e1..ce5eabfaa 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -138,7 +138,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt - (void)setWindow:(SDL_Window *)newWindow { if (self->window) { - SDL_WindowData *oldwindowdata = (__bridge SDL_WindowData *)self->window->driverdata; + SDL_WindowData *oldwindowdata = self->window->driverdata; /* Make sure to remove us from the old window's context list, or we'll get scheduled updates from it too. */ NSMutableArray *contexts = oldwindowdata.nscontexts; @@ -150,7 +150,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt self->window = newWindow; if (newWindow) { - SDL_WindowData *windowdata = (__bridge SDL_WindowData *)newWindow->driverdata; + SDL_WindowData *windowdata = newWindow->driverdata; NSView *contentview = windowdata.sdlContentView; /* Now sign up for scheduled updates for the new window. */ @@ -253,8 +253,8 @@ void Cocoa_GL_UnloadLibrary(_THIS) SDL_GLContext Cocoa_GL_CreateContext(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); + SDL_DisplayData *displaydata = display->driverdata; NSOpenGLPixelFormatAttribute attr[32]; NSOpenGLPixelFormat *fmt; SDLOpenGLContext *context; @@ -482,7 +482,7 @@ int Cocoa_GL_SwapWindow(_THIS, SDL_Window *window) { @autoreleasepool { SDLOpenGLContext *nscontext = (__bridge SDLOpenGLContext *)SDL_GL_GetCurrentContext(); - SDL_VideoData *videodata = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; const int setting = SDL_AtomicGet(&nscontext->swapIntervalSetting); if (setting == 0) { diff --git a/src/video/cocoa/SDL_cocoaopengles.m b/src/video/cocoa/SDL_cocoaopengles.m index 2fce94106..0e1d40804 100644 --- a/src/video/cocoa/SDL_cocoaopengles.m +++ b/src/video/cocoa/SDL_cocoaopengles.m @@ -62,7 +62,7 @@ Cocoa_GLES_CreateContext(_THIS, SDL_Window *window) { @autoreleasepool { SDL_GLContext context; - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; #if SDL_VIDEO_OPENGL_CGL if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { @@ -103,14 +103,14 @@ void Cocoa_GLES_DeleteContext(_THIS, SDL_GLContext context) int Cocoa_GLES_SwapWindow(_THIS, SDL_Window *window) { @autoreleasepool { - return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_WindowData *)window->driverdata).egl_surface); + return SDL_EGL_SwapBuffers(_this, window->driverdata.egl_surface); } } int Cocoa_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) { @autoreleasepool { - return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_WindowData *)window->driverdata).egl_surface : EGL_NO_SURFACE, context); + return SDL_EGL_MakeCurrent(_this, window ? window->driverdata.egl_surface : EGL_NO_SURFACE, context); } } @@ -119,7 +119,7 @@ int Cocoa_GLES_SetupWindow(_THIS, SDL_Window *window) @autoreleasepool { NSView *v; /* The current context is lost in here; save it and reset it. */ - SDL_WindowData *windowdata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windowdata = window->driverdata; SDL_Window *current_win = SDL_GL_GetCurrentWindow(); SDL_GLContext current_ctx = SDL_GL_GetCurrentContext(); @@ -151,7 +151,7 @@ SDL_EGLSurface Cocoa_GLES_GetEGLSurface(_THIS, SDL_Window *window) { @autoreleasepool { - return ((__bridge SDL_WindowData *)window->driverdata).egl_surface; + return window->driverdata.egl_surface; } } diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index c80e10d25..0bba18783 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -45,7 +45,7 @@ Cocoa_CreateShaper(SDL_Window *window) SDL_WindowShaper *result; SDL_ShapeData *data; int resized_properly; - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper)); if (!result) { @@ -90,7 +90,7 @@ int Cocoa_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo { @autoreleasepool { SDL_ShapeData *data = (__bridge SDL_ShapeData *)shaper->driverdata; - SDL_WindowData *windata = (__bridge SDL_WindowData *)shaper->window->driverdata; + SDL_WindowData *windata = shaper->window->driverdata; SDL_CocoaClosure *closure; if (data.saved == SDL_TRUE) { [data.context restoreGraphicsState]; diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 5bc47b44f..fac10acf0 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -48,7 +48,7 @@ static void Cocoa_DeleteDevice(SDL_VideoDevice *device) if (device->wakeup_lock) { SDL_DestroyMutex(device->wakeup_lock); } - CFBridgingRelease(device->driverdata); + device->driverdata = nil; SDL_free(device); } } @@ -73,7 +73,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void) SDL_free(device); return NULL; } - device->driverdata = (void *)CFBridgingRetain(data); + device->driverdata = data; device->wakeup_lock = SDL_CreateMutex(); /* Set the function pointers */ @@ -110,7 +110,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void) device->SetWindowAlwaysOnTop = Cocoa_SetWindowAlwaysOnTop; device->SetWindowFullscreen = Cocoa_SetWindowFullscreen; device->GetWindowICCProfile = Cocoa_GetWindowICCProfile; - device->GetWindowDisplayIndex = Cocoa_GetWindowDisplayIndex; + device->GetDisplayForWindow = Cocoa_GetDisplayForWindow; device->SetWindowMouseRect = Cocoa_SetWindowMouseRect; device->SetWindowMouseGrab = Cocoa_SetWindowMouseGrab; device->SetWindowKeyboardGrab = Cocoa_SetWindowKeyboardGrab; @@ -190,7 +190,7 @@ VideoBootStrap COCOA_bootstrap = { int Cocoa_VideoInit(_THIS) { @autoreleasepool { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Cocoa_InitModes(_this); Cocoa_InitKeyboard(_this); @@ -213,7 +213,7 @@ int Cocoa_VideoInit(_THIS) void Cocoa_VideoQuit(_THIS) { @autoreleasepool { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Cocoa_QuitModes(_this); Cocoa_QuitKeyboard(_this); Cocoa_QuitMouse(_this); diff --git a/src/video/cocoa/SDL_cocoavulkan.m b/src/video/cocoa/SDL_cocoavulkan.m index a28e12845..019d5bbce 100644 --- a/src/video/cocoa/SDL_cocoavulkan.m +++ b/src/video/cocoa/SDL_cocoavulkan.m @@ -262,7 +262,7 @@ SDL_bool Cocoa_Vulkan_CreateSurface(_THIS, if (window->flags & SDL_WINDOW_FOREIGN) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (![data.sdlContentView.layer isKindOfClass:[CAMetalLayer class]]) { [data.sdlContentView setLayer:[CAMetalLayer layer]]; } diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h index d3b108deb..009229b2f 100644 --- a/src/video/cocoa/SDL_cocoawindow.h +++ b/src/video/cocoa/SDL_cocoawindow.h @@ -160,7 +160,7 @@ extern void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizab extern void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top); extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen); extern void *Cocoa_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size); -extern int Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window *window); +extern SDL_DisplayID Cocoa_GetDisplayForWindow(_THIS, SDL_Window *window); extern void Cocoa_SetWindowMouseRect(_THIS, SDL_Window *window); extern void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed); extern void Cocoa_DestroyWindow(_THIS, SDL_Window *window); diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index ea904b580..bb53f245b 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -239,7 +239,7 @@ /* !!! FIXME: is there a better way to do this? */ if (_this) { for (sdlwindow = _this->windows; sdlwindow; sdlwindow = sdlwindow->next) { - NSWindow *nswindow = ((__bridge SDL_WindowData *)sdlwindow->driverdata).nswindow; + NSWindow *nswindow = sdlwindow->driverdata.nswindow; if (nswindow == self) { break; } @@ -333,7 +333,7 @@ static NSUInteger GetWindowStyle(SDL_Window *window) static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style) { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; NSWindow *nswindow = data.nswindow; /* The view responder chain gets messed with during setStyleMask */ @@ -353,7 +353,7 @@ static SDL_bool SetWindowStyle(SDL_Window *window, NSUInteger style) static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window *window) { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (!data || [data.listener isMovingOrFocusClickPending]) { return SDL_FALSE; @@ -410,7 +410,7 @@ static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, float x, float y, C static void Cocoa_UpdateClipCursor(SDL_Window *window) { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_13_2) { NSWindow *nswindow = data.nswindow; @@ -564,7 +564,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window) { SDL_Window *window = _data.window; NSWindow *nswindow = _data.nswindow; - SDL_VideoData *videodata = ((__bridge SDL_WindowData *)window->driverdata).videodata; + SDL_VideoData *videodata = window->driverdata.videodata; if (!videodata.allow_spaces) { return NO; /* Spaces are forcibly disabled. */ @@ -1198,7 +1198,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ // the position in the currently-focused window. We don't (currently) send a mousemove // event for the background window, this just makes sure the button is reported at the // correct position in its own event. - if (focus && ([theEvent window] == ((__bridge SDL_WindowData *)focus->driverdata).nswindow)) { + if (focus && ([theEvent window] == focus->driverdata.nswindow)) { rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks); } else { const int orig_x = mouse->x; @@ -1384,7 +1384,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ - (BOOL)isTouchFromTrackpad:(NSEvent *)theEvent { SDL_Window *window = _data.window; - SDL_VideoData *videodata = ((__bridge SDL_WindowData *)window->driverdata).videodata; + SDL_VideoData *videodata = window->driverdata.videodata; /* if this a MacBook trackpad, we'll make input look like a synthesized event. This is backwards from reality, but better matches user @@ -1573,7 +1573,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ white until the app is ready to draw. In practice on modern macOS, this only gets called for window creation and other extraordinary events. */ self.layer.backgroundColor = CGColorGetConstantColor(kCGColorBlack); - ScheduleContextUpdates((__bridge SDL_WindowData *)_sdlWindow->driverdata); + ScheduleContextUpdates(_sdlWindow->driverdata); SDL_SendWindowEvent(_sdlWindow, SDL_EVENT_WINDOW_EXPOSED, 0, 0); } @@ -1618,7 +1618,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView *nsview, SDL_bool created) { @autoreleasepool { - SDL_VideoData *videodata = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_WindowData *data; /* Allocate the window data */ @@ -1705,7 +1705,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView [nswindow setOneShot:NO]; /* All done! */ - window->driverdata = (void *)CFBridgingRetain(data); + window->driverdata = data; return 0; } } @@ -1713,9 +1713,9 @@ static int SetupWindowData(_THIS, SDL_Window *window, NSWindow *nswindow, NSView int Cocoa_CreateWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_VideoData *videodata = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; NSWindow *nswindow; - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); NSRect rect; BOOL fullscreen; SDL_Rect bounds; @@ -1882,7 +1882,7 @@ void Cocoa_SetWindowTitle(_THIS, SDL_Window *window) { @autoreleasepool { const char *title = window->title ? window->title : ""; - NSWindow *nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow; + NSWindow *nswindow = window->driverdata.nswindow; NSString *string = [[NSString alloc] initWithUTF8String:title]; [nswindow setTitle:string]; } @@ -1902,7 +1902,7 @@ void Cocoa_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon) void Cocoa_SetWindowPosition(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; NSWindow *nswindow = windata.nswindow; NSRect rect; BOOL fullscreen; @@ -1927,7 +1927,7 @@ void Cocoa_SetWindowPosition(_THIS, SDL_Window *window) void Cocoa_SetWindowSize(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; NSWindow *nswindow = windata.nswindow; NSRect rect; BOOL fullscreen; @@ -1956,7 +1956,7 @@ void Cocoa_SetWindowSize(_THIS, SDL_Window *window) void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; NSSize minSize; minSize.width = window->min_w; @@ -1969,7 +1969,7 @@ void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window *window) void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; NSSize maxSize; maxSize.width = window->max_w; @@ -1982,7 +1982,7 @@ void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window *window) void Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) { @autoreleasepool { - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; NSView *contentView = windata.sdlContentView; NSRect viewport = [contentView bounds]; @@ -1999,7 +1999,7 @@ void Cocoa_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) void Cocoa_ShowWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *windowData = ((__bridge SDL_WindowData *)window->driverdata); + SDL_WindowData *windowData = window->driverdata; NSWindow *nswindow = windowData.nswindow; if (![nswindow isMiniaturized]) { @@ -2013,7 +2013,7 @@ void Cocoa_ShowWindow(_THIS, SDL_Window *window) void Cocoa_HideWindow(_THIS, SDL_Window *window) { @autoreleasepool { - NSWindow *nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow; + NSWindow *nswindow = window->driverdata.nswindow; [nswindow orderOut:nil]; } @@ -2022,7 +2022,7 @@ void Cocoa_HideWindow(_THIS, SDL_Window *window) void Cocoa_RaiseWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *windowData = ((__bridge SDL_WindowData *)window->driverdata); + SDL_WindowData *windowData = window->driverdata; NSWindow *nswindow = windowData.nswindow; /* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing @@ -2040,7 +2040,7 @@ void Cocoa_RaiseWindow(_THIS, SDL_Window *window) void Cocoa_MaximizeWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; NSWindow *nswindow = windata.nswindow; [nswindow zoom:nil]; @@ -2052,7 +2052,7 @@ void Cocoa_MaximizeWindow(_THIS, SDL_Window *window) void Cocoa_MinimizeWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; NSWindow *nswindow = data.nswindow; if ([data.listener isInFullscreenSpaceTransition]) { [data.listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE]; @@ -2065,7 +2065,7 @@ void Cocoa_MinimizeWindow(_THIS, SDL_Window *window) void Cocoa_RestoreWindow(_THIS, SDL_Window *window) { @autoreleasepool { - NSWindow *nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow; + NSWindow *nswindow = window->driverdata.nswindow; if ([nswindow isMiniaturized]) { [nswindow deminiaturize:nil]; @@ -2093,7 +2093,7 @@ void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) * The window will get permanently stuck if resizable is false. * -flibit */ - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Cocoa_WindowListener *listener = data.listener; NSWindow *nswindow = data.nswindow; SDL_VideoData *videodata = data.videodata; @@ -2114,7 +2114,7 @@ void Cocoa_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) { @autoreleasepool { - NSWindow *nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow; + NSWindow *nswindow = window->driverdata.nswindow; if (on_top) { [nswindow setLevel:NSFloatingWindowLevel]; } else { @@ -2126,7 +2126,7 @@ void Cocoa_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) void Cocoa_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; NSWindow *nswindow = data.nswindow; NSRect rect; @@ -2216,7 +2216,7 @@ void * Cocoa_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; NSWindow *nswindow = data.nswindow; NSScreen *screen = [nswindow screen]; NSData *iccProfileData = nil; @@ -2250,17 +2250,17 @@ Cocoa_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size) } } -int Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window *window) +SDL_DisplayID Cocoa_GetDisplayForWindow(_THIS, SDL_Window *window) { @autoreleasepool { NSScreen *screen; - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; /* Not recognized via CHECK_WINDOW_MAGIC */ if (data == nil) { /* Don't set the error here, it hides other errors and is ignored anyway */ /*return SDL_SetError("Window data not set");*/ - return -1; + return 0; } /* NSWindow.screen may be nil when the window is off-screen. */ @@ -2274,18 +2274,15 @@ int Cocoa_GetWindowDisplayIndex(_THIS, SDL_Window *window) displayid = [[screen.deviceDescription objectForKey:@"NSScreenNumber"] unsignedIntValue]; for (i = 0; i < _this->num_displays; i++) { - SDL_DisplayData *displaydata = (SDL_DisplayData *)_this->displays[i].driverdata; + SDL_DisplayData *displaydata = _this->displays[i].driverdata; if (displaydata != NULL && displaydata->display == displayid) { - return i; + return _this->displays[i].id; } } } - /* Other code may expect SDL_GetWindowDisplayIndex to always return a valid - * index for a window. The higher level GetWindowDisplayIndex code will fall - * back to a generic position-based query if the backend implementation - * fails. */ - return SDL_SetError("Couldn't find the display where the window is located."); + /* The higher level code will use other logic to find the display */ + return 0; } } @@ -2297,7 +2294,7 @@ void Cocoa_SetWindowMouseRect(_THIS, SDL_Window *window) void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Cocoa_UpdateClipCursor(window); @@ -2318,7 +2315,7 @@ void Cocoa_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void Cocoa_DestroyWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (SDL_WindowData *)CFBridgingRelease(window->driverdata); + SDL_WindowData *data = window->driverdata; if (data) { #if SDL_VIDEO_OPENGL @@ -2354,14 +2351,14 @@ void Cocoa_DestroyWindow(_THIS, SDL_Window *window) window->shaper = NULL; } } - window->driverdata = NULL; + window->driverdata = nil; } } int Cocoa_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) { @autoreleasepool { - NSWindow *nswindow = ((__bridge SDL_WindowData *)window->driverdata).nswindow; + NSWindow *nswindow = window->driverdata.nswindow; info->subsystem = SDL_SYSWM_COCOA; info->info.cocoa.window = nswindow; @@ -2373,7 +2370,7 @@ SDL_bool Cocoa_IsWindowInFullscreenSpace(SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if ([data.listener isInFullscreenSpace]) { return SDL_TRUE; @@ -2388,7 +2385,7 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window *window, SDL_bool state) { @autoreleasepool { SDL_bool succeeded = SDL_FALSE; - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data.inWindowFullscreenTransition) { return SDL_FALSE; @@ -2437,7 +2434,7 @@ int Cocoa_SetWindowHitTest(SDL_Window *window, SDL_bool enabled) void Cocoa_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (accept) { [data.nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]]; } else { @@ -2450,7 +2447,7 @@ int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation) { @autoreleasepool { /* Note that this is app-wide and not window-specific! */ - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data.flash_request) { [NSApp cancelUserAttentionRequest:data.flash_request]; @@ -2477,7 +2474,7 @@ int Cocoa_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation) int Cocoa_SetWindowOpacity(_THIS, SDL_Window *window, float opacity) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; [data.nswindow setAlphaValue:opacity]; return 0; } diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 5db97b7ff..baab9c6b7 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -843,7 +843,7 @@ static EM_BOOL Emscripten_HandleFullscreenChange(int eventType, const Emscripten window_data->window->flags &= ~SDL_WINDOW_FULLSCREEN_MASK; /* reset fullscreen window if the browser left fullscreen */ - display = SDL_GetDisplayForWindow(window_data->window); + display = SDL_GetVideoDisplayForWindow(window_data->window); if (display->fullscreen_window == window_data->window) { display->fullscreen_window = NULL; diff --git a/src/video/emscripten/SDL_emscriptenevents.h b/src/video/emscripten/SDL_emscriptenevents.h index 0599329af..230b17220 100644 --- a/src/video/emscripten/SDL_emscriptenevents.h +++ b/src/video/emscripten/SDL_emscriptenevents.h @@ -24,13 +24,8 @@ #include "SDL_emscriptenvideo.h" -extern void -Emscripten_RegisterEventHandlers(SDL_WindowData *data); - -extern void -Emscripten_UnregisterEventHandlers(SDL_WindowData *data); - -extern EM_BOOL -Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData); +extern void Emscripten_RegisterEventHandlers(SDL_WindowData *data); +extern void Emscripten_UnregisterEventHandlers(SDL_WindowData *data); +extern EM_BOOL Emscripten_HandleCanvasResize(int eventType, const void *reserved, void *userData); #endif /* SDL_emscriptenevents_h_ */ diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c index 5c0f663f7..c9c539d4f 100644 --- a/src/video/emscripten/SDL_emscriptenframebuffer.c +++ b/src/video/emscripten/SDL_emscriptenframebuffer.c @@ -34,7 +34,7 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format int w, h; /* Free the old framebuffer surface */ - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; surface = data->surface; SDL_DestroySurface(surface); @@ -58,7 +58,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect { SDL_Surface *surface; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; surface = data->surface; if (surface == NULL) { return SDL_SetError("Couldn't find framebuffer surface for window"); @@ -152,7 +152,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SDL_DestroySurface(data->surface); data->surface = NULL; diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c index c2fb500b9..872c51c38 100644 --- a/src/video/emscripten/SDL_emscriptenmouse.c +++ b/src/video/emscripten/SDL_emscriptenmouse.c @@ -216,7 +216,7 @@ static int Emscripten_SetRelativeMouseMode(SDL_bool enabled) return -1; } - window_data = (SDL_WindowData *)window->driverdata; + window_data = window->driverdata; if (emscripten_request_pointerlock(window_data->canvas_id, 1) >= EMSCRIPTEN_RESULT_SUCCESS) { return 0; diff --git a/src/video/emscripten/SDL_emscriptenopengles.c b/src/video/emscripten/SDL_emscriptenopengles.c index c89c2cee5..d961cc30e 100644 --- a/src/video/emscripten/SDL_emscriptenopengles.c +++ b/src/video/emscripten/SDL_emscriptenopengles.c @@ -88,7 +88,7 @@ SDL_GLContext Emscripten_GLES_CreateContext(_THIS, SDL_Window *window) if (_this->gl_config.major_version == 3) attribs.majorVersion = 2; /* WebGL 2.0 ~= GLES 3.0 */ - window_data = (SDL_WindowData *)window->driverdata; + window_data = window->driverdata; if (window_data->gl_context) { SDL_SetError("Cannot create multiple webgl contexts per window"); @@ -118,8 +118,7 @@ void Emscripten_GLES_DeleteContext(_THIS, SDL_GLContext context) /* remove the context from its window */ for (window = _this->windows; window != NULL; window = window->next) { - SDL_WindowData *window_data; - window_data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *window_data = window->driverdata; if (window_data->gl_context == context) { window_data->gl_context = NULL; @@ -142,8 +141,7 @@ int Emscripten_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context { /* it isn't possible to reuse contexts across canvases */ if (window && context) { - SDL_WindowData *window_data; - window_data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *window_data = window->driverdata; if (context != window_data->gl_context) { return SDL_SetError("Cannot make context current to another window"); diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index ccd09fac5..f61c42254 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -267,7 +267,7 @@ static void Emscripten_SetWindowSize(_THIS, SDL_Window *window) SDL_WindowData *data; if (window->driverdata) { - data = (SDL_WindowData *)window->driverdata; + data = window->driverdata; /* update pixel ratio */ if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { data->pixel_ratio = emscripten_get_device_pixel_ratio(); @@ -285,7 +285,7 @@ static void Emscripten_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, { SDL_WindowData *data; if (window->driverdata) { - data = (SDL_WindowData *)window->driverdata; + data = window->driverdata; *w = window->w * data->pixel_ratio; *h = window->h * data->pixel_ratio; } @@ -296,7 +296,7 @@ static void Emscripten_DestroyWindow(_THIS, SDL_Window *window) SDL_WindowData *data; if (window->driverdata) { - data = (SDL_WindowData *)window->driverdata; + data = window->driverdata; Emscripten_UnregisterEventHandlers(data); @@ -313,7 +313,7 @@ static void Emscripten_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoD { SDL_WindowData *data; if (window->driverdata) { - data = (SDL_WindowData *)window->driverdata; + data = window->driverdata; if (fullscreen) { EmscriptenFullscreenStrategy strategy; diff --git a/src/video/emscripten/SDL_emscriptenvideo.h b/src/video/emscripten/SDL_emscriptenvideo.h index 5789afad8..e5e08e148 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.h +++ b/src/video/emscripten/SDL_emscriptenvideo.h @@ -28,7 +28,7 @@ #include #include -typedef struct SDL_WindowData +struct SDL_WindowData { SDL_Window *window; SDL_Surface *surface; @@ -45,6 +45,6 @@ typedef struct SDL_WindowData SDL_bool fullscreen_resize; SDL_bool has_pointer_lock; -} SDL_WindowData; +}; #endif /* SDL_emscriptenvideo_h_ */ diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index bfeb7b447..d12fe2cc0 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -57,7 +57,6 @@ static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { static SDL_VideoDevice * HAIKU_CreateDevice(void) { SDL_VideoDevice *device; - /*SDL_VideoData *data;*/ /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice)); @@ -97,7 +96,7 @@ static SDL_VideoDevice * HAIKU_CreateDevice(void) device->CreateWindowFramebuffer = HAIKU_CreateWindowFramebuffer; device->UpdateWindowFramebuffer = HAIKU_UpdateWindowFramebuffer; device->DestroyWindowFramebuffer = HAIKU_DestroyWindowFramebuffer; - + device->shape_driver.CreateShaper = NULL; device->shape_driver.SetWindowShape = NULL; device->shape_driver.ResizeWindowShape = NULL; @@ -270,7 +269,7 @@ int HAIKU_VideoInit(_THIS) if (SDL_InitBeApp() < 0) { return -1; } - + /* Initialize video modes */ HAIKU_InitModes(_this); diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c index 79a387ed9..addd257aa 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.c +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c @@ -63,7 +63,7 @@ static SDL_Cursor *KMSDRM_CreateDefaultCursor(void) destroy the driverdata for the window's display. */ void KMSDRM_DestroyCursorBO(_THIS, SDL_VideoDisplay *display) { - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *dispdata = display->driverdata; /* Destroy the curso GBM BO. */ if (dispdata->cursor_bo) { @@ -80,8 +80,8 @@ void KMSDRM_CreateCursorBO(SDL_VideoDisplay *display) { SDL_VideoDevice *dev = SDL_GetVideoDevice(); - SDL_VideoData *viddata = ((SDL_VideoData *)dev->driverdata); - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_VideoData *viddata = dev->driverdata; + SDL_DisplayData *dispdata = display->driverdata; if (!KMSDRM_gbm_device_is_format_supported(viddata->gbm_dev, GBM_FORMAT_ARGB8888, @@ -119,9 +119,9 @@ void KMSDRM_CreateCursorBO(SDL_VideoDisplay *display) static int KMSDRM_RemoveCursorFromBO(SDL_VideoDisplay *display) { int ret = 0; - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *dispdata = display->driverdata; SDL_VideoDevice *video_device = SDL_GetVideoDevice(); - SDL_VideoData *viddata = ((SDL_VideoData *)video_device->driverdata); + SDL_VideoData *viddata = video_device->driverdata; ret = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id, 0, 0, 0); @@ -136,10 +136,10 @@ static int KMSDRM_RemoveCursorFromBO(SDL_VideoDisplay *display) /* Dump a cursor buffer to a display's DRM cursor BO. */ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) { - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *dispdata = display->driverdata; KMSDRM_CursorData *curdata = (KMSDRM_CursorData *)cursor->driverdata; SDL_VideoDevice *video_device = SDL_GetVideoDevice(); - SDL_VideoData *viddata = ((SDL_VideoData *)video_device->driverdata); + SDL_VideoData *viddata = video_device->driverdata; uint32_t bo_handle; size_t bo_stride; @@ -302,7 +302,7 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor) SDL_Window *window; SDL_Mouse *mouse; - int num_displays, i; + int i; int ret = 0; /* Get the mouse focused window, if any. */ @@ -315,33 +315,28 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor) window = mouse->focus; if (window == NULL || cursor == NULL) { - /* If no window is focused by mouse or cursor is NULL, since we have no window (no mouse->focus) and hence we have no display, we simply hide mouse on all displays. This happens on video quit, where we get here after the mouse focus has been unset, yet SDL wants to restore the system default cursor (makes no sense here). */ - - num_displays = SDL_GetNumVideoDisplays(); - - /* Iterate on the displays hidding the cursor. */ - for (i = 0; i < num_displays; i++) { - display = SDL_GetDisplay(i); - ret = KMSDRM_RemoveCursorFromBO(display); + SDL_DisplayID *displays = SDL_GetDisplays(NULL); + if (displays) { + /* Iterate on the displays, hiding the cursor. */ + for (i = 0; i < displays[i]; i++) { + display = SDL_GetVideoDisplay(displays[i]); + ret = KMSDRM_RemoveCursorFromBO(display); + } + SDL_free(displays); } - } else { - - display = SDL_GetDisplayForWindow(window); - + display = SDL_GetVideoDisplayForWindow(window); if (display) { - if (cursor) { /* Dump the cursor to the display DRM cursor BO so it becomes visible on that display. */ ret = KMSDRM_DumpCursorToBO(display, cursor); - } else { /* Hide the cursor on that display. */ ret = KMSDRM_RemoveCursorFromBO(display); @@ -359,7 +354,7 @@ static int KMSDRM_WarpMouseGlobal(float x, float y) if (mouse && mouse->cur_cursor && mouse->focus) { SDL_Window *window = mouse->focus; - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); /* Update internal mouse position. */ SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y); @@ -394,7 +389,7 @@ static void KMSDRM_WarpMouse(SDL_Window *window, float x, float y) void KMSDRM_InitMouse(_THIS, SDL_VideoDisplay *display) { SDL_Mouse *mouse = SDL_GetMouse(); - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *dispdata = display->driverdata; mouse->CreateCursor = KMSDRM_CreateCursor; mouse->ShowCursor = KMSDRM_ShowCursor; @@ -427,7 +422,7 @@ static void KMSDRM_MoveCursor(SDL_Cursor *cursor) if (mouse && mouse->cur_cursor && mouse->focus) { SDL_Window *window = mouse->focus; - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); if (!dispdata->cursor_bo) { SDL_SetError("Cursor not initialized properly."); diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c index 6ad01be9d..1d0614c70 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c @@ -54,7 +54,7 @@ int KMSDRM_GLES_LoadLibrary(_THIS, const char *path) so gbm dev isn't yet created when this is called, AND we can't alter the call order in SDL_CreateWindow(). */ #if 0 - NativeDisplayType display = (NativeDisplayType)((SDL_VideoData *)_this->driverdata)->gbm_dev; + NativeDisplayType display = (NativeDisplayType)_this->driverdata->gbm_dev; return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_MESA); #endif return 0; @@ -86,9 +86,9 @@ SDL_EGL_CreateContext_impl(KMSDRM) int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window *window) { - SDL_WindowData *windata = ((SDL_WindowData *)window->driverdata); - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_WindowData *windata = window->driverdata; + SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); + SDL_VideoData *viddata = _this->driverdata; KMSDRM_FBInfo *fb_info; int ret = 0; diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index a528a8d15..ae085f74d 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -353,7 +353,7 @@ static void KMSDRM_FBDestroyCallback(struct gbm_bo *bo, void *data) KMSDRM_FBInfo * KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; unsigned w, h; int ret; Uint32 stride, handle; @@ -406,7 +406,7 @@ SDL_bool KMSDRM_WaitPageflip(_THIS, SDL_WindowData *windata) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; drmEventContext ev = { 0 }; struct pollfd pfd = { 0 }; int ret; @@ -494,7 +494,7 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display, uint32_t width, uint32_t height, uint32_t refresh_rate) { - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *dispdata = display->driverdata; drmModeConnector *connector = dispdata->connector; SDL_DisplayMode target, closest; @@ -522,29 +522,31 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display, /* Deinitializes the driverdata of the SDL Displays in the SDL display list. */ static void KMSDRM_DeinitDisplays(_THIS) { - + SDL_DisplayID *displays; SDL_DisplayData *dispdata; - int num_displays, i; + int i; - num_displays = SDL_GetNumVideoDisplays(); + displays = SDL_GetDisplays(NULL); + if (displays) { + /* Iterate on the SDL Display list. */ + for (i = 0; displays[i]; ++i) { - /* Iterate on the SDL Display list. */ - for (i = 0; i < num_displays; i++) { + /* Get the driverdata for this display */ + dispdata = SDL_GetDisplayDriverData(displays[i]); - /* Get the driverdata for this display */ - dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(i); + /* Free connector */ + if (dispdata && dispdata->connector) { + KMSDRM_drmModeFreeConnector(dispdata->connector); + dispdata->connector = NULL; + } - /* Free connector */ - if (dispdata && dispdata->connector) { - KMSDRM_drmModeFreeConnector(dispdata->connector); - dispdata->connector = NULL; - } - - /* Free CRTC */ - if (dispdata && dispdata->crtc) { - KMSDRM_drmModeFreeCrtc(dispdata->crtc); - dispdata->crtc = NULL; + /* Free CRTC */ + if (dispdata && dispdata->crtc) { + KMSDRM_drmModeFreeCrtc(dispdata->crtc); + dispdata->crtc = NULL; + } } + SDL_free(displays); } } @@ -686,7 +688,7 @@ static SDL_bool KMSDRM_CrtcGetVrr(uint32_t drm_fd, uint32_t crtc_id) list of SDL Displays in _this->displays[] */ static void KMSDRM_AddDisplay(_THIS, drmModeConnector *connector, drmModeRes *resources) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; SDL_DisplayData *dispdata = NULL; SDL_VideoDisplay display = { 0 }; SDL_DisplayModeData *modedata = NULL; @@ -908,7 +910,7 @@ cleanup: static int KMSDRM_InitDisplays(_THIS) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; drmModeRes *resources = NULL; uint64_t async_pageflip = 0; @@ -959,7 +961,7 @@ static int KMSDRM_InitDisplays(_THIS) } /* Have we added any SDL displays? */ - if (!SDL_GetNumVideoDisplays()) { + if (SDL_GetPrimaryDisplay() == 0) { ret = SDL_SetError("No connected displays found."); goto cleanup; } @@ -1003,7 +1005,7 @@ cleanup: */ static int KMSDRM_GBMInit(_THIS, SDL_DisplayData *dispdata) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; int ret = 0; /* Reopen the FD! */ @@ -1026,7 +1028,7 @@ static int KMSDRM_GBMInit(_THIS, SDL_DisplayData *dispdata) /* Deinit the Vulkan-incompatible KMSDRM stuff. */ static void KMSDRM_GBMDeinit(_THIS, SDL_DisplayData *dispdata) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; /* Destroy GBM device. GBM surface is destroyed by DestroySurfaces(), already called when we get here. */ @@ -1046,9 +1048,9 @@ static void KMSDRM_GBMDeinit(_THIS, SDL_DisplayData *dispdata) static void KMSDRM_DestroySurfaces(_THIS, SDL_Window *window) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_VideoData *viddata = _this->driverdata; + SDL_WindowData *windata = window->driverdata; + SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); int ret; /**********************************************/ @@ -1113,8 +1115,8 @@ static void KMSDRM_DestroySurfaces(_THIS, SDL_Window *window) static void KMSDRM_GetModeToSet(SDL_Window *window, drmModeModeInfo *out_mode) { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); + SDL_DisplayData *dispdata = display->driverdata; if ((window->flags & SDL_WINDOW_FULLSCREEN_EXCLUSIVE) != 0) { *out_mode = dispdata->fullscreen_mode; @@ -1134,7 +1136,7 @@ static void KMSDRM_GetModeToSet(SDL_Window *window, drmModeModeInfo *out_mode) static void KMSDRM_DirtySurfaces(SDL_Window *window) { - SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; drmModeModeInfo mode; /* Can't recreate EGL surfaces right now, need to wait until SwapWindow @@ -1152,10 +1154,10 @@ static void KMSDRM_DirtySurfaces(SDL_Window *window) that we create here. */ int KMSDRM_CreateSurfaces(_THIS, SDL_Window *window) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); - SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_VideoData *viddata = _this->driverdata; + SDL_WindowData *windata = window->driverdata; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); + SDL_DisplayData *dispdata = display->driverdata; SDL_DisplayMode current_mode; uint32_t surface_fmt = GBM_FORMAT_ARGB8888; @@ -1234,7 +1236,7 @@ int KMSDRM_VideoInit(_THIS) { int ret = 0; - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()"); viddata->video_init = SDL_FALSE; @@ -1263,7 +1265,7 @@ int KMSDRM_VideoInit(_THIS) are freed by SDL internals, so not our job. */ void KMSDRM_VideoQuit(_THIS) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; KMSDRM_DeinitDisplays(_this); @@ -1314,8 +1316,8 @@ int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mod /* Set the dispdata->mode to the new mode and leave actual modesetting pending to be done on SwapWindow() via drmModeSetCrtc() */ - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *)display->driverdata; + SDL_VideoData *viddata = _this->driverdata; + SDL_DisplayData *dispdata = display->driverdata; SDL_DisplayModeData *modedata = (SDL_DisplayModeData *)mode->driverdata; drmModeConnector *conn = dispdata->connector; int i; @@ -1342,8 +1344,8 @@ int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mod void KMSDRM_DestroyWindow(_THIS, SDL_Window *window) { - SDL_WindowData *windata = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *windata = window->driverdata; + SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); SDL_VideoData *viddata; SDL_bool is_vulkan = window->flags & SDL_WINDOW_VULKAN; /* Is this a VK window? */ unsigned int i, j; @@ -1360,7 +1362,7 @@ void KMSDRM_DestroyWindow(_THIS, SDL_Window *window) if (!is_vulkan && viddata->gbm_init) { /* Destroy cursor GBM BO of the display of this window. */ - KMSDRM_DestroyCursorBO(_this, SDL_GetDisplayForWindow(window)); + KMSDRM_DestroyCursorBO(_this, SDL_GetVideoDisplayForWindow(window)); /* Destroy GBM surface and buffers. */ KMSDRM_DestroySurfaces(_this, window); @@ -1421,8 +1423,8 @@ void KMSDRM_DestroyWindow(_THIS, SDL_Window *window) int KMSDRM_CreateWindow(_THIS, SDL_Window *window) { SDL_WindowData *windata = NULL; - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); + SDL_VideoData *viddata = _this->driverdata; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_DisplayData *dispdata = display->driverdata; SDL_bool is_vulkan = window->flags & SDL_WINDOW_VULKAN; /* Is this a VK window? */ SDL_bool vulkan_mode = viddata->vulkan_mode; /* Do we have any Vulkan windows? */ @@ -1476,7 +1478,7 @@ int KMSDRM_CreateWindow(_THIS, SDL_Window *window) If we let SDL_CreateWindow() load the lib, it would be loaded before we call KMSDRM_GBMInit(), causing all GLES programs to fail. */ if (!_this->egl_data) { - egl_display = (NativeDisplayType)((SDL_VideoData *)_this->driverdata)->gbm_dev; + egl_display = (NativeDisplayType)_this->driverdata->gbm_dev; if (SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA) < 0) { /* Try again with OpenGL ES 2.0 */ _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES; @@ -1569,7 +1571,7 @@ void KMSDRM_SetWindowPosition(_THIS, SDL_Window *window) } void KMSDRM_SetWindowSize(_THIS, SDL_Window *window) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; if (!viddata->vulkan_mode) { KMSDRM_DirtySurfaces(window); } @@ -1577,7 +1579,7 @@ void KMSDRM_SetWindowSize(_THIS, SDL_Window *window) void KMSDRM_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; if (!viddata->vulkan_mode) { KMSDRM_DirtySurfaces(window); } @@ -1606,7 +1608,7 @@ void KMSDRM_RestoreWindow(_THIS, SDL_Window *window) /*****************************************************************************/ int KMSDRM_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info) { - SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); + SDL_VideoData *viddata = _this->driverdata; info->subsystem = SDL_SYSWM_KMSDRM; info->info.kmsdrm.dev_index = viddata->devindex; diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h index b9044cecd..082379c00 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.h +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h @@ -33,7 +33,7 @@ #include #include -typedef struct SDL_VideoData +struct SDL_VideoData { int devindex; /* device index that was passed on creation */ int drm_fd; /* DRM file desc */ @@ -53,14 +53,14 @@ typedef struct SDL_VideoData open 1 FD and create 1 gbm device. */ SDL_bool gbm_init; -} SDL_VideoData; +}; -typedef struct SDL_DisplayModeData +struct SDL_DisplayModeData { int mode_index; -} SDL_DisplayModeData; +}; -typedef struct SDL_DisplayData +struct SDL_DisplayData { drmModeConnector *connector; drmModeCrtc *crtc; @@ -80,9 +80,9 @@ typedef struct SDL_DisplayData uint64_t cursor_w, cursor_h; SDL_bool default_cursor_init; -} SDL_DisplayData; +}; -typedef struct SDL_WindowData +struct SDL_WindowData { SDL_VideoData *viddata; /* SDL internals expect EGL surface to be here, and in KMSDRM the GBM surface is @@ -98,7 +98,7 @@ typedef struct SDL_WindowData EGLSurface egl_surface; SDL_bool egl_surface_dirty; -} SDL_WindowData; +}; typedef struct KMSDRM_FBInfo { diff --git a/src/video/kmsdrm/SDL_kmsdrmvulkan.c b/src/video/kmsdrm/SDL_kmsdrmvulkan.c index 74d013e56..60920cf15 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvulkan.c +++ b/src/video/kmsdrm/SDL_kmsdrmvulkan.c @@ -201,7 +201,7 @@ SDL_bool KMSDRM_Vulkan_CreateSurface(_THIS, SDL_bool plane_supports_display = SDL_FALSE; /* Get the display index from the display being used by the window. */ - int display_index = SDL_atoi(SDL_GetDisplayForWindow(window)->name); + int display_index = SDL_GetDisplayIndex(SDL_GetDisplayForWindow(window)); int i, j; /* Get the function pointers for the functions we will use. */ diff --git a/src/video/n3ds/SDL_n3dsframebuffer.c b/src/video/n3ds/SDL_n3dsframebuffer.c index 2bdad7077..6b281c707 100644 --- a/src/video/n3ds/SDL_n3dsframebuffer.c +++ b/src/video/n3ds/SDL_n3dsframebuffer.c @@ -75,7 +75,7 @@ CreateNewWindowFramebuffer(SDL_Window *window) int SDL_N3DS_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects) { - SDL_WindowData *drv_data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *drv_data = window->driverdata; SDL_Surface *surface; u16 width, height; u32 *framebuffer; diff --git a/src/video/n3ds/SDL_n3dsvideo.c b/src/video/n3ds/SDL_n3dsvideo.c index 1faa9f853..77b1b690f 100644 --- a/src/video/n3ds/SDL_n3dsvideo.c +++ b/src/video/n3ds/SDL_n3dsvideo.c @@ -40,10 +40,10 @@ static int N3DS_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec static int N3DS_CreateWindow(_THIS, SDL_Window *window); static void N3DS_DestroyWindow(_THIS, SDL_Window *window); -typedef struct +struct SDL_DisplayData { gfxScreen_t screen; -} DisplayDriverData; +}; /* N3DS driver bootstrap functions */ @@ -107,7 +107,7 @@ AddN3DSDisplay(gfxScreen_t screen) { SDL_DisplayMode mode; SDL_VideoDisplay display; - DisplayDriverData *display_driver_data = SDL_calloc(1, sizeof(DisplayDriverData)); + SDL_DisplayData *display_driver_data = SDL_calloc(1, sizeof(SDL_DisplayData)); if (display_driver_data == NULL) { SDL_OutOfMemory(); return; @@ -148,7 +148,7 @@ static void N3DS_GetDisplayModes(_THIS, SDL_VideoDisplay *display) static int N3DS_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { - DisplayDriverData *driver_data = (DisplayDriverData *)display->driverdata; + SDL_DisplayData *driver_data = display->driverdata; if (driver_data == NULL) { return -1; } @@ -162,12 +162,12 @@ static int N3DS_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rec static int N3DS_CreateWindow(_THIS, SDL_Window *window) { - DisplayDriverData *display_data; + SDL_DisplayData *display_data; SDL_WindowData *window_data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (window_data == NULL) { return SDL_OutOfMemory(); } - display_data = (DisplayDriverData *)SDL_GetDisplayDriverData(window->display_index); + display_data = SDL_GetDisplayDriverDataForWindow(window); window_data->screen = display_data->screen; window->driverdata = window_data; SDL_SetKeyboardFocus(window); diff --git a/src/video/n3ds/SDL_n3dsvideo.h b/src/video/n3ds/SDL_n3dsvideo.h index f85cd3466..fab0f7c89 100644 --- a/src/video/n3ds/SDL_n3dsvideo.h +++ b/src/video/n3ds/SDL_n3dsvideo.h @@ -26,10 +26,11 @@ #include <3ds.h> #include "../SDL_sysvideo.h" -typedef struct SDL_WindowData + +struct SDL_WindowData { gfxScreen_t screen; /**< Keeps track of which N3DS screen is targetted */ -} SDL_WindowData; +}; #define FRAMEBUFFER_FORMAT SDL_PIXELFORMAT_RGBA8888 diff --git a/src/video/ngage/SDL_ngageevents.cpp b/src/video/ngage/SDL_ngageevents.cpp index d3184b9fb..6e06840d0 100644 --- a/src/video/ngage/SDL_ngageevents.cpp +++ b/src/video/ngage/SDL_ngageevents.cpp @@ -44,7 +44,7 @@ int HandleWsEvent(_THIS, const TWsEvent &aWsEvent); void NGAGE_PumpEvents(_THIS) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; while (phdata->NGAGE_WsEventStatus != KRequestPending) { phdata->NGAGE_WsSession.GetEvent(phdata->NGAGE_WsEvent); @@ -149,7 +149,7 @@ static SDL_Scancode ConvertScancode(_THIS, int key) int HandleWsEvent(_THIS, const TWsEvent &aWsEvent) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; int posted = 0; switch (aWsEvent.Type()) { diff --git a/src/video/ngage/SDL_ngageframebuffer.cpp b/src/video/ngage/SDL_ngageframebuffer.cpp index 0d98ea82e..918afeeef 100644 --- a/src/video/ngage/SDL_ngageframebuffer.cpp +++ b/src/video/ngage/SDL_ngageframebuffer.cpp @@ -46,7 +46,7 @@ void RedrawWindowL(_THIS); int SDL_NGAGE_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; SDL_Surface *surface; const Uint32 surface_format = SDL_PIXELFORMAT_RGB444; int w, h; @@ -199,7 +199,7 @@ int GetBpp(TDisplayMode displaymode) void DrawBackground(_THIS) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; /* Draw background */ TUint16 *screenBuffer = (TUint16 *)phdata->NGAGE_FrameBuffer; /* Draw black background */ @@ -208,7 +208,7 @@ void DrawBackground(_THIS) void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16 *screenBuffer) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; SDL_Surface *screen = (SDL_Surface *)SDL_GetWindowData(_this->windows, NGAGE_SURFACE); TInt i; @@ -333,7 +333,7 @@ void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16 *screenBuffer) void DirectUpdate(_THIS, int numrects, SDL_Rect *rects) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; if (!phdata->NGAGE_IsWindowFocused) { SDL_PauseAudio(1); @@ -368,7 +368,7 @@ void DirectUpdate(_THIS, int numrects, SDL_Rect *rects) void RedrawWindowL(_THIS) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; SDL_Surface *screen = (SDL_Surface *)SDL_GetWindowData(_this->windows, NGAGE_SURFACE); int w = screen->w; diff --git a/src/video/ngage/SDL_ngagevideo.cpp b/src/video/ngage/SDL_ngagevideo.cpp index 1e37e6d6c..a3c116488 100644 --- a/src/video/ngage/SDL_ngagevideo.cpp +++ b/src/video/ngage/SDL_ngagevideo.cpp @@ -55,7 +55,7 @@ static void NGAGE_VideoQuit(_THIS); static void NGAGE_DeleteDevice(SDL_VideoDevice *device) { - SDL_VideoData *phdata = (SDL_VideoData *)device->driverdata; + SDL_VideoData *phdata = device->driverdata; if (phdata) { /* Free Epoc resources */ diff --git a/src/video/ngage/SDL_ngagevideo.h b/src/video/ngage/SDL_ngagevideo.h index 5a0e4ae63..c1a966143 100644 --- a/src/video/ngage/SDL_ngagevideo.h +++ b/src/video/ngage/SDL_ngagevideo.h @@ -34,7 +34,7 @@ #define _THIS SDL_VideoDevice *_this -typedef struct SDL_VideoData +struct SDL_VideoData { /* Epoc window server info */ RWsSession NGAGE_WsSession; @@ -61,6 +61,6 @@ typedef struct SDL_VideoData CFbsBitGc::TGraphicsOrientation NGAGE_ScreenOrientation; -} SDL_VideoData; +}; #endif /* SDL_ngagevideo_h */ diff --git a/src/video/ngage/SDL_ngagewindow.cpp b/src/video/ngage/SDL_ngagewindow.cpp index 4f334b5b9..20fa4e602 100644 --- a/src/video/ngage/SDL_ngagewindow.cpp +++ b/src/video/ngage/SDL_ngagewindow.cpp @@ -74,7 +74,7 @@ void NGAGE_DestroyWindow(_THIS, SDL_Window *window) void DisableKeyBlocking(_THIS) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; TRawEvent event; event.Set((TRawEvent::TType) /*EDisableKeyBlock*/ 51); @@ -83,7 +83,7 @@ void DisableKeyBlocking(_THIS) void ConstructWindowL(_THIS) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; TInt error; error = phdata->NGAGE_WsSession.Connect(); diff --git a/src/video/offscreen/SDL_offscreenopengles.c b/src/video/offscreen/SDL_offscreenopengles.c index 8f0d8f22e..638ea442e 100644 --- a/src/video/offscreen/SDL_offscreenopengles.c +++ b/src/video/offscreen/SDL_offscreenopengles.c @@ -57,7 +57,7 @@ int OFFSCREEN_GLES_LoadLibrary(_THIS, const char *path) SDL_GLContext OFFSCREEN_GLES_CreateContext(_THIS, SDL_Window *window) { - OFFSCREEN_Window *offscreen_window = window->driverdata; + SDL_WindowData *offscreen_window = window->driverdata; SDL_GLContext context; context = SDL_EGL_CreateContext(_this, offscreen_window->egl_surface); @@ -68,7 +68,7 @@ OFFSCREEN_GLES_CreateContext(_THIS, SDL_Window *window) int OFFSCREEN_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) { if (window) { - EGLSurface egl_surface = ((OFFSCREEN_Window *)window->driverdata)->egl_surface; + EGLSurface egl_surface = window->driverdata->egl_surface; return SDL_EGL_MakeCurrent(_this, egl_surface, context); } else { return SDL_EGL_MakeCurrent(_this, NULL, NULL); @@ -77,7 +77,7 @@ int OFFSCREEN_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) int OFFSCREEN_GLES_SwapWindow(_THIS, SDL_Window *window) { - OFFSCREEN_Window *offscreen_wind = window->driverdata; + SDL_WindowData *offscreen_wind = window->driverdata; return SDL_EGL_SwapBuffers(_this, offscreen_wind->egl_surface); } diff --git a/src/video/offscreen/SDL_offscreenwindow.c b/src/video/offscreen/SDL_offscreenwindow.c index 5f4db19e0..cfdef88fe 100644 --- a/src/video/offscreen/SDL_offscreenwindow.c +++ b/src/video/offscreen/SDL_offscreenwindow.c @@ -29,7 +29,7 @@ int OFFSCREEN_CreateWindow(_THIS, SDL_Window *window) { - OFFSCREEN_Window *offscreen_window = SDL_calloc(1, sizeof(OFFSCREEN_Window)); + SDL_WindowData *offscreen_window = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (offscreen_window == NULL) { return SDL_OutOfMemory(); @@ -70,7 +70,7 @@ int OFFSCREEN_CreateWindow(_THIS, SDL_Window *window) void OFFSCREEN_DestroyWindow(_THIS, SDL_Window *window) { - OFFSCREEN_Window *offscreen_window = window->driverdata; + SDL_WindowData *offscreen_window = window->driverdata; if (offscreen_window) { #if SDL_VIDEO_OPENGL_EGL diff --git a/src/video/offscreen/SDL_offscreenwindow.h b/src/video/offscreen/SDL_offscreenwindow.h index 6bc32bb03..067ae65a2 100644 --- a/src/video/offscreen/SDL_offscreenwindow.h +++ b/src/video/offscreen/SDL_offscreenwindow.h @@ -25,14 +25,17 @@ #include "SDL_offscreenvideo.h" -typedef struct +#if defined(SDL_VIDEO_DRIVER_COCOA) || defined(SDL_VIDEO_DRIVER_UIKIT) +struct _SDL_WindowData +#else +struct SDL_WindowData +#endif { SDL_Window *sdl_window; #if SDL_VIDEO_OPENGL_EGL EGLSurface egl_surface; #endif - -} OFFSCREEN_Window; +}; extern int OFFSCREEN_CreateWindow(_THIS, SDL_Window *window); extern void OFFSCREEN_DestroyWindow(_THIS, SDL_Window *window); diff --git a/src/video/psp/SDL_pspgl.c b/src/video/psp/SDL_pspgl.c index 2365078f0..b786d0d94 100644 --- a/src/video/psp/SDL_pspgl.c +++ b/src/video/psp/SDL_pspgl.c @@ -70,7 +70,7 @@ static EGLint height = 272; SDL_GLContext PSP_GL_CreateContext(_THIS, SDL_Window *window) { - SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *wdata = window->driverdata; EGLint attribs[32]; EGLDisplay display; @@ -167,7 +167,7 @@ int PSP_GL_SwapWindow(_THIS, SDL_Window *window) void PSP_GL_DeleteContext(_THIS, SDL_GLContext context) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; EGLBoolean status; if (phdata->egl_initialized != SDL_TRUE) { diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c index 6d55744d1..109fda456 100644 --- a/src/video/psp/SDL_pspvideo.c +++ b/src/video/psp/SDL_pspvideo.c @@ -41,11 +41,8 @@ static SDL_bool PSP_initialized = SDL_FALSE; static void PSP_Destroy(SDL_VideoDevice *device) { - /* SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; */ - - if (device->driverdata != NULL) { - device->driverdata = NULL; - } + SDL_free(device->driverdata); + SDL_free(device); } static SDL_VideoDevice *PSP_Create() diff --git a/src/video/psp/SDL_pspvideo.h b/src/video/psp/SDL_pspvideo.h index 036e7224d..a2d697f9e 100644 --- a/src/video/psp/SDL_pspvideo.h +++ b/src/video/psp/SDL_pspvideo.h @@ -27,23 +27,18 @@ #include "SDL_internal.h" #include "../SDL_sysvideo.h" -typedef struct SDL_VideoData +struct SDL_VideoData { SDL_bool egl_initialized; /* OpenGL ES device initialization status */ uint32_t egl_refcount; /* OpenGL ES reference count */ -} SDL_VideoData; +}; -typedef struct SDL_DisplayData -{ - -} SDL_DisplayData; - -typedef struct SDL_WindowData +struct SDL_WindowData { SDL_bool uses_gles; /* if true window must support OpenGL ES */ -} SDL_WindowData; +}; /****************************************************************************/ /* SDL_VideoDevice functions declaration */ diff --git a/src/video/raspberry/SDL_rpimouse.c b/src/video/raspberry/SDL_rpimouse.c index 205beb216..9c9f76fa2 100644 --- a/src/video/raspberry/SDL_rpimouse.c +++ b/src/video/raspberry/SDL_rpimouse.c @@ -107,7 +107,6 @@ static int RPI_ShowCursor(SDL_Cursor *cursor) RPI_CursorData *curdata; VC_RECT_T src_rect, dst_rect; SDL_Mouse *mouse; - SDL_VideoDisplay *display; SDL_DisplayData *data; VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE /* flags */, 255 /*opacity 0->255*/, 0 /* mask */ }; uint32_t layer = SDL_RPI_MOUSELAYER; @@ -147,12 +146,7 @@ static int RPI_ShowCursor(SDL_Cursor *cursor) return -1; } - display = SDL_GetDisplayForWindow(mouse->focus); - if (display == NULL) { - return -1; - } - - data = (SDL_DisplayData *)display->driverdata; + data = SDL_GetDisplayDriverDataForWindow(mouse->focus); if (data == NULL) { return -1; } diff --git a/src/video/raspberry/SDL_rpiopengles.c b/src/video/raspberry/SDL_rpiopengles.c index f59a45717..18446ecef 100644 --- a/src/video/raspberry/SDL_rpiopengles.c +++ b/src/video/raspberry/SDL_rpiopengles.c @@ -41,7 +41,7 @@ int RPI_GLES_LoadLibrary(_THIS, const char *path) int RPI_GLES_SwapWindow(_THIS, SDL_Window *window) { - SDL_WindowData *wdata = ((SDL_WindowData *)window->driverdata); + SDL_WindowData *wdata = window->driverdata; if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed."); diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index 4859d141a..c5bd997a4 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -227,7 +227,7 @@ int RPI_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) static void RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data) { - SDL_WindowData *wdata = ((SDL_WindowData *)data); + SDL_WindowData *wdata = (SDL_WindowData *)data; SDL_LockMutex(wdata->vsync_cond_mutex); SDL_CondSignal(wdata->vsync_cond); @@ -256,8 +256,8 @@ int RPI_CreateWindow(_THIS, SDL_Window *window) if (wdata == NULL) { return SDL_OutOfMemory(); } - display = SDL_GetDisplayForWindow(window); - displaydata = (SDL_DisplayData *)display->driverdata; + display = SDL_GetVideoDisplayForWindow(window); + displaydata = display->driverdata; /* Windows have one size for now */ window->w = display->desktop_mode.w; @@ -330,9 +330,8 @@ int RPI_CreateWindow(_THIS, SDL_Window *window) void RPI_DestroyWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); if (data) { if (data->double_buffer) { diff --git a/src/video/raspberry/SDL_rpivideo.h b/src/video/raspberry/SDL_rpivideo.h index 6fff482ea..be2598e29 100644 --- a/src/video/raspberry/SDL_rpivideo.h +++ b/src/video/raspberry/SDL_rpivideo.h @@ -28,17 +28,17 @@ #include #include -typedef struct SDL_VideoData +struct SDL_VideoData { uint32_t egl_refcount; /* OpenGL ES reference count */ -} SDL_VideoData; +}; -typedef struct SDL_DisplayData +struct SDL_DisplayData { DISPMANX_DISPLAY_HANDLE_T dispman_display; -} SDL_DisplayData; +}; -typedef struct SDL_WindowData +struct SDL_WindowData { EGL_DISPMANX_WINDOW_T dispman_window; #if SDL_VIDEO_OPENGL_EGL @@ -49,8 +49,7 @@ typedef struct SDL_WindowData SDL_cond *vsync_cond; SDL_mutex *vsync_cond_mutex; SDL_bool double_buffer; - -} SDL_WindowData; +}; #define SDL_RPI_VIDEOLAYER 10000 /* High enough so to occlude everything */ #define SDL_RPI_MOUSELAYER SDL_RPI_VIDEOLAYER + 1 diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c index 5f3faa5f3..c134c3ca4 100644 --- a/src/video/riscos/SDL_riscosevents.c +++ b/src/video/riscos/SDL_riscosevents.c @@ -50,7 +50,7 @@ static SDL_Scancode SDL_RISCOS_translate_keycode(int keycode) void RISCOS_PollKeyboard(_THIS) { - SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *driverdata = _this->driverdata; Uint8 key = 2; int i; @@ -110,13 +110,13 @@ static const Uint8 mouse_button_map[] = { void RISCOS_PollMouse(_THIS) { - SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *driverdata = _this->driverdata; SDL_Mouse *mouse = SDL_GetMouse(); SDL_Rect rect; _kernel_swi_regs regs; int i, x, y, buttons; - if (SDL_GetDisplayBounds(0, &rect) < 0) { + if (SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &rect) < 0) { return; } @@ -139,7 +139,7 @@ void RISCOS_PollMouse(_THIS) int RISCOS_InitEvents(_THIS) { - SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *driverdata = _this->driverdata; _kernel_swi_regs regs; int i, status; diff --git a/src/video/riscos/SDL_riscosframebuffer.c b/src/video/riscos/SDL_riscosframebuffer.c index 1620f4dbb..46b2b0e01 100644 --- a/src/video/riscos/SDL_riscosframebuffer.c +++ b/src/video/riscos/SDL_riscosframebuffer.c @@ -32,7 +32,7 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch) { - SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *driverdata = window->driverdata; const char *sprite_name = "display"; unsigned int sprite_mode; _kernel_oserror *error; @@ -47,7 +47,7 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, vo RISCOS_DestroyWindowFramebuffer(_this, window); /* Create a new one */ - SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(window), &mode); + SDL_GetCurrentDisplayMode(SDL_GetDisplayForWindow(window), &mode); if ((SDL_ISPIXELFORMAT_PACKED(mode.format) || SDL_ISPIXELFORMAT_ARRAY(mode.format))) { *format = mode.format; sprite_mode = (unsigned int)mode.driverdata; @@ -93,7 +93,7 @@ int RISCOS_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, vo int RISCOS_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects) { - SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *driverdata = window->driverdata; _kernel_swi_regs regs; _kernel_oserror *error; @@ -115,7 +115,7 @@ int RISCOS_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *re void RISCOS_DestroyWindowFramebuffer(_THIS, SDL_Window *window) { - SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *driverdata = window->driverdata; if (driverdata->fb_area) { SDL_free(driverdata->fb_area); diff --git a/src/video/riscos/SDL_riscosvideo.h b/src/video/riscos/SDL_riscosvideo.h index 4ae49888d..190afa97f 100644 --- a/src/video/riscos/SDL_riscosvideo.h +++ b/src/video/riscos/SDL_riscosvideo.h @@ -27,10 +27,10 @@ #define RISCOS_MAX_KEYS_PRESSED 6 -typedef struct SDL_VideoData +struct SDL_VideoData { int last_mouse_buttons; Uint8 key_pressed[RISCOS_MAX_KEYS_PRESSED]; -} SDL_VideoData; +}; #endif /* SDL_riscosvideo_h_ */ diff --git a/src/video/riscos/SDL_riscoswindow.c b/src/video/riscos/SDL_riscoswindow.c index 09b1a1d1b..99d3c79db 100644 --- a/src/video/riscos/SDL_riscoswindow.c +++ b/src/video/riscos/SDL_riscoswindow.c @@ -51,7 +51,7 @@ int RISCOS_CreateWindow(_THIS, SDL_Window *window) void RISCOS_DestroyWindow(_THIS, SDL_Window *window) { - SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *driverdata = window->driverdata; if (driverdata == NULL) { return; diff --git a/src/video/riscos/SDL_riscoswindow.h b/src/video/riscos/SDL_riscoswindow.h index 309a8e697..039ac2833 100644 --- a/src/video/riscos/SDL_riscoswindow.h +++ b/src/video/riscos/SDL_riscoswindow.h @@ -25,12 +25,12 @@ #include "SDL_riscosdefs.h" -typedef struct +struct SDL_WindowData { SDL_Window *window; sprite_area *fb_area; sprite_header *fb_sprite; -} SDL_WindowData; +}; extern int RISCOS_CreateWindow(_THIS, SDL_Window *window); extern void RISCOS_DestroyWindow(_THIS, SDL_Window *window); diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m index 88aba92ae..dca986371 100644 --- a/src/video/uikit/SDL_uikitappdelegate.m +++ b/src/video/uikit/SDL_uikitappdelegate.m @@ -468,7 +468,7 @@ static UIImage *SDL_LoadLaunchImageNamed(NSString *name, int screenh) if (_this) { SDL_Window *window = NULL; for (window = _this->windows; window != NULL; window = window->next) { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data != nil) { return data.uiwindow; } diff --git a/src/video/uikit/SDL_uikitclipboard.m b/src/video/uikit/SDL_uikitclipboard.m index a3e1bd757..54aff7f1f 100644 --- a/src/video/uikit/SDL_uikitclipboard.m +++ b/src/video/uikit/SDL_uikitclipboard.m @@ -75,7 +75,7 @@ void UIKit_InitClipboard(_THIS) { #if !TARGET_OS_TV @autoreleasepool { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; id observer = [center addObserverForName:UIPasteboardChangedNotification @@ -93,7 +93,7 @@ void UIKit_InitClipboard(_THIS) void UIKit_QuitClipboard(_THIS) { @autoreleasepool { - SDL_VideoData *data = (__bridge SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data.pasteboardObserver != nil) { [[NSNotificationCenter defaultCenter] removeObserver:data.pasteboardObserver]; diff --git a/src/video/uikit/SDL_uikitmessagebox.m b/src/video/uikit/SDL_uikitmessagebox.m index e528c40ea..83c7b46ed 100644 --- a/src/video/uikit/SDL_uikitmessagebox.m +++ b/src/video/uikit/SDL_uikitmessagebox.m @@ -94,7 +94,7 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag } if (messageboxdata->window) { - SDL_WindowData *data = (__bridge SDL_WindowData *)messageboxdata->window->driverdata; + SDL_WindowData *data = messageboxdata->window->driverdata; window = data.uiwindow; } diff --git a/src/video/uikit/SDL_uikitmetalview.m b/src/video/uikit/SDL_uikitmetalview.m index c7628b857..7befdf051 100644 --- a/src/video/uikit/SDL_uikitmetalview.m +++ b/src/video/uikit/SDL_uikitmetalview.m @@ -78,7 +78,7 @@ SDL_MetalView UIKit_Metal_CreateView(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; CGFloat scale = 1.0; SDL_uikitmetalview *metalview; diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index f4af6f063..a9761b24b 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -358,7 +358,7 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event) return SDL_OutOfMemory(); } - display.driverdata = (void *)CFBridgingRetain(data); + display.driverdata = data; SDL_AddVideoDisplay(&display, send_event); return 0; @@ -366,16 +366,22 @@ int UIKit_AddDisplay(UIScreen *uiscreen, SDL_bool send_event) void UIKit_DelDisplay(UIScreen *uiscreen) { + SDL_DisplayID *displays; int i; - for (i = 0; i < SDL_GetNumVideoDisplays(); ++i) { - SDL_DisplayData *data = (__bridge SDL_DisplayData *)SDL_GetDisplayDriverData(i); + displays = SDL_GetDisplays(NULL); + if (displays) { + for (i = 0; displays[i]; ++i) { + SDL_VideoDisplay *display = SDL_GetVideoDisplay(displays[i]); + SDL_DisplayData *data = display->driverdata; - if (data && data.uiscreen == uiscreen) { - CFRelease(SDL_GetDisplayDriverData(i)); - SDL_DelVideoDisplay(i); - return; + if (data && data.uiscreen == uiscreen) { + display->driverdata = nil; + SDL_DelVideoDisplay(displays[i]); + return; + } } + SDL_free(displays); } } @@ -414,7 +420,7 @@ int UIKit_InitModes(_THIS) void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { @autoreleasepool { - SDL_DisplayData *data = (__bridge SDL_DisplayData *)display->driverdata; + SDL_DisplayData *data = display->driverdata; SDL_bool isLandscape = UIKit_IsDisplayLandscape(data.uiscreen); SDL_bool addRotation = (data.uiscreen == [UIScreen mainScreen]); @@ -447,7 +453,7 @@ void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay *display) int UIKit_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi) { @autoreleasepool { - SDL_DisplayData *data = (__bridge SDL_DisplayData *)display->driverdata; + SDL_DisplayData *data = display->driverdata; float dpi = data.screenDPI; if (ddpi) { @@ -467,7 +473,7 @@ int UIKit_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, f int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { @autoreleasepool { - SDL_DisplayData *data = (__bridge SDL_DisplayData *)display->driverdata; + SDL_DisplayData *data = display->driverdata; #if !TARGET_OS_TV SDL_DisplayModeData *modedata = (__bridge SDL_DisplayModeData *)mode->driverdata; @@ -496,13 +502,12 @@ int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { @autoreleasepool { - int displayIndex = (int)(display - _this->displays); - SDL_DisplayData *data = (__bridge SDL_DisplayData *)display->driverdata; + SDL_DisplayData *data = display->driverdata; CGRect frame = data.uiscreen.bounds; /* the default function iterates displays to make a fake offset, as if all the displays were side-by-side, which is fine for iOS. */ - if (SDL_GetDisplayBounds(displayIndex, rect) < 0) { + if (SDL_GetDisplayBounds(display->id, rect) < 0) { return -1; } @@ -531,9 +536,8 @@ void UIKit_QuitModes(_THIS) UIKit_FreeDisplayModeData(mode); } - if (display->driverdata != NULL) { - CFRelease(display->driverdata); - display->driverdata = NULL; + if (display->driverdata) { + display->driverdata = nil; } } } @@ -543,7 +547,7 @@ void UIKit_QuitModes(_THIS) void SDL_OnApplicationDidChangeStatusBarOrientation() { BOOL isLandscape = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation); - SDL_VideoDisplay *display = SDL_GetDisplay(0); + SDL_VideoDisplay *display = SDL_GetVideoDisplay(SDL_GetPrimaryDisplay()); if (display) { SDL_DisplayMode *desktopmode = &display->desktop_mode; diff --git a/src/video/uikit/SDL_uikitopengles.m b/src/video/uikit/SDL_uikitopengles.m index b1411c7b3..f540856a5 100644 --- a/src/video/uikit/SDL_uikitopengles.m +++ b/src/video/uikit/SDL_uikitopengles.m @@ -113,7 +113,7 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window *window) @autoreleasepool { SDLEAGLContext *context = nil; SDL_uikitopenglview *view; - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; CGRect frame = UIKit_ComputeViewFrame(window, data.uiwindow.screen); EAGLSharegroup *sharegroup = nil; CGFloat scale = 1.0; diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index d0ab9f82f..de6300f9f 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -52,7 +52,7 @@ static void UIKit_VideoQuit(_THIS); static void UIKit_DeleteDevice(SDL_VideoDevice *device) { @autoreleasepool { - CFRelease(device->driverdata); + device->driverdata = nil; SDL_free(device); } } @@ -73,7 +73,7 @@ static SDL_VideoDevice *UIKit_CreateDevice(void) return (0); } - device->driverdata = (void *)CFBridgingRetain(data); + device->driverdata = data; /* Set the function pointers */ device->VideoInit = UIKit_VideoInit; @@ -184,7 +184,7 @@ UIKit_IsSystemVersionAtLeast(double version) CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen) { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; CGRect frame = screen.bounds; /* Use the UIWindow bounds instead of the UIScreen bounds, when possible. @@ -225,7 +225,7 @@ void UIKit_ForceUpdateHomeIndicator() /* Force the main SDL window to re-evaluate home indicator state */ SDL_Window *focus = SDL_GetFocusWindow(); if (focus) { - SDL_WindowData *data = (__bridge SDL_WindowData *)focus->driverdata; + SDL_WindowData *data = focus->driverdata; if (data != nil) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunguarded-availability-new" diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 5e9e23767..59bd9e1b8 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -103,7 +103,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; /* Remove ourself from the old window. */ if (sdlwindow) { SDL_uikitview *view = nil; - data = (__bridge SDL_WindowData *)sdlwindow->driverdata; + data = sdlwindow->driverdata; [data.views removeObject:self]; @@ -122,7 +122,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick; /* Add ourself to the new window. */ if (window) { - data = (__bridge SDL_WindowData *)window->driverdata; + data = window->driverdata; /* Make sure the SDL window has a strong reference to this view. */ [data.views addObject:self]; diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index 54a250558..092616959 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -156,7 +156,7 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(doLoop:)]; #ifdef __IPHONE_10_3 - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if ([displayLink respondsToSelector:@selector(preferredFramesPerSecond)] && data != nil && data.uiwindow != nil && [data.uiwindow.screen respondsToSelector:@selector(maximumFramesPerSecond)]) { displayLink.preferredFramesPerSecond = data.uiwindow.screen.maximumFramesPerSecond / animationInterval; @@ -513,7 +513,7 @@ static SDL_uikitviewcontroller *GetWindowViewController(SDL_Window *window) return nil; } - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; return data.viewcontroller; } diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index fa7882b3d..c3b631bdf 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -81,8 +81,8 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *)display->driverdata; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); + SDL_DisplayData *displaydata = display->driverdata; SDL_uikitview *view; CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen); @@ -94,7 +94,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo return SDL_OutOfMemory(); } - window->driverdata = (void *)CFBridgingRetain(data); + window->driverdata = data; data.uiwindow = uiwindow; @@ -152,13 +152,13 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo int UIKit_CreateWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *data = (__bridge SDL_DisplayData *)display->driverdata; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); + SDL_DisplayData *data = display->driverdata; SDL_Window *other; /* We currently only handle a single window per display on iOS */ for (other = _this->windows; other; other = other->next) { - if (other != window && SDL_GetDisplayForWindow(other) == display) { + if (other != window && SDL_GetVideoDisplayForWindow(other) == display) { return SDL_SetError("Only one window allowed per display."); } } @@ -222,7 +222,7 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window) void UIKit_SetWindowTitle(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; data.viewcontroller.title = @(window->title); } } @@ -230,12 +230,12 @@ void UIKit_SetWindowTitle(_THIS, SDL_Window *window) void UIKit_ShowWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; [data.uiwindow makeKeyAndVisible]; /* Make this window the current mouse focus for touch input */ - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *displaydata = (__bridge SDL_DisplayData *)display->driverdata; + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); + SDL_DisplayData *displaydata = display->driverdata; if (displaydata.uiscreen == [UIScreen mainScreen]) { SDL_SetMouseFocus(window); SDL_SetKeyboardFocus(window); @@ -246,7 +246,7 @@ void UIKit_ShowWindow(_THIS, SDL_Window *window) void UIKit_HideWindow(_THIS, SDL_Window *window) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; data.uiwindow.hidden = YES; } } @@ -262,7 +262,7 @@ void UIKit_RaiseWindow(_THIS, SDL_Window *window) static void UIKit_UpdateWindowBorder(_THIS, SDL_Window *window) { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SDL_uikitviewcontroller *viewcontroller = data.viewcontroller; #if !TARGET_OS_TV @@ -313,7 +313,7 @@ void UIKit_UpdatePointerLock(_THIS, SDL_Window *window) #if !TARGET_OS_TV #if defined(__IPHONE_14_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0 @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SDL_uikitviewcontroller *viewcontroller = data.viewcontroller; if (@available(iOS 14.0, *)) { [viewcontroller setNeedsUpdateOfPrefersPointerLocked]; @@ -327,7 +327,7 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window) { @autoreleasepool { if (window->driverdata != NULL) { - SDL_WindowData *data = (SDL_WindowData *)CFBridgingRelease(window->driverdata); + SDL_WindowData *data = window->driverdata; NSArray *views = nil; [data.viewcontroller stopAnimation]; @@ -346,15 +346,16 @@ void UIKit_DestroyWindow(_THIS, SDL_Window *window) * SDL window. */ data.uiwindow.rootViewController = nil; data.uiwindow.hidden = YES; + + window->driverdata = nil; } } - window->driverdata = NULL; } void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) { @autoreleasepool { - SDL_WindowData *windata = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *windata = window->driverdata; UIView *view = windata.viewcontroller.view; CGSize size = view.bounds.size; CGFloat scale = 1.0; @@ -373,7 +374,7 @@ void UIKit_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) int UIKit_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) { @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; info->subsystem = SDL_SYSWM_UIKIT; info->info.uikit.window = data.uiwindow; @@ -399,7 +400,7 @@ UIKit_GetSupportedOrientations(SDL_Window *window) NSUInteger orientationMask = 0; @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; UIApplication *app = [UIApplication sharedApplication]; /* Get all possible valid orientations. If the app delegate doesn't tell @@ -465,7 +466,7 @@ int SDL_iPhoneSetAnimationCallback(SDL_Window *window, int interval, void (*call } @autoreleasepool { - SDL_WindowData *data = (__bridge SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; [data.viewcontroller setAnimationCallback:interval callback:callback callbackParam:callbackParam]; diff --git a/src/video/vita/SDL_vitaframebuffer.c b/src/video/vita/SDL_vitaframebuffer.c index 31028cce5..3833009fc 100644 --- a/src/video/vita/SDL_vitaframebuffer.c +++ b/src/video/vita/SDL_vitaframebuffer.c @@ -65,7 +65,7 @@ void vita_gpu_free(SceUID uid) int VITA_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SceDisplayFrameBuf framebuf; *format = SDL_PIXELFORMAT_ABGR8888; @@ -101,7 +101,7 @@ int VITA_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rect void VITA_DestroyWindowFramebuffer(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data == NULL) { /* The window wasn't fully initialized */ diff --git a/src/video/vita/SDL_vitagl_pvr.c b/src/video/vita/SDL_vitagl_pvr.c index 6a2467752..c58d93883 100644 --- a/src/video/vita/SDL_vitagl_pvr.c +++ b/src/video/vita/SDL_vitagl_pvr.c @@ -94,7 +94,7 @@ VITA_GL_CreateContext(_THIS, SDL_Window *window) _this->gl_config.minor_version = 0; _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES; - context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); + context = SDL_EGL_CreateContext(_this, window->driverdata->egl_surface); if (context != NULL) { FB_WIDTH = window->w; diff --git a/src/video/vita/SDL_vitagles.c b/src/video/vita/SDL_vitagles.c index 7ed9eb0fb..0f5d448c4 100644 --- a/src/video/vita/SDL_vitagles.c +++ b/src/video/vita/SDL_vitagles.c @@ -80,7 +80,7 @@ static EGLint height = 544; SDL_GLContext VITA_GLES_CreateContext(_THIS, SDL_Window *window) { - SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *wdata = window->driverdata; EGLint attribs[32]; EGLDisplay display; @@ -193,7 +193,7 @@ int VITA_GLES_SwapWindow(_THIS, SDL_Window *window) void VITA_GLES_DeleteContext(_THIS, SDL_GLContext context) { - SDL_VideoData *phdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *phdata = _this->driverdata; EGLBoolean status; if (phdata->egl_initialized != SDL_TRUE) { diff --git a/src/video/vita/SDL_vitagles_pvr.c b/src/video/vita/SDL_vitagles_pvr.c index 1076fe9e6..fd3277540 100644 --- a/src/video/vita/SDL_vitagles_pvr.c +++ b/src/video/vita/SDL_vitagles_pvr.c @@ -40,8 +40,8 @@ int VITA_GLES_LoadLibrary(_THIS, const char *path) char *default_path = "app0:module"; char target_path[MAX_PATH]; - if (skip_init == NULL) { // we don't care about actual value - + if (skip_init == NULL) { // we don't care about actual value + if (override != NULL) { default_path = override; } @@ -70,13 +70,13 @@ int VITA_GLES_LoadLibrary(_THIS, const char *path) SDL_GLContext VITA_GLES_CreateContext(_THIS, SDL_Window *window) { - return SDL_EGL_CreateContext(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); + return SDL_EGL_CreateContext(_this, window->driverdata->egl_surface); } int VITA_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) { if (window && context) { - return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *)window->driverdata)->egl_surface, context); + return SDL_EGL_MakeCurrent(_this, window->driverdata->egl_surface, context); } else { return SDL_EGL_MakeCurrent(_this, NULL, NULL); } @@ -84,11 +84,11 @@ int VITA_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) int VITA_GLES_SwapWindow(_THIS, SDL_Window *window) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; if (videodata->ime_active) { sceImeUpdate(); } - return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); + return SDL_EGL_SwapBuffers(_this, window->driverdata->egl_surface); } #endif /* SDL_VIDEO_DRIVER_VITA && SDL_VIDEO_VITA_PVR */ diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c index cf21ae097..84e7c67c1 100644 --- a/src/video/vita/SDL_vitavideo.c +++ b/src/video/vita/SDL_vitavideo.c @@ -56,13 +56,8 @@ SDL_Window *Vita_Window; static void VITA_Destroy(SDL_VideoDevice *device) { - /* SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata; */ - SDL_free(device->driverdata); SDL_free(device); - // if (device->driverdata != NULL) { - // device->driverdata = NULL; - // } } static SDL_VideoDevice *VITA_Create() @@ -352,7 +347,6 @@ void VITA_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void VITA_DestroyWindow(_THIS, SDL_Window *window) { - // SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; SDL_WindowData *data; data = window->driverdata; @@ -441,7 +435,7 @@ void VITA_ImeEventHandler(void *arg, const SceImeEventData *e) void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SceInt32 res; #if defined(SDL_VIDEO_VITA_PVR) @@ -503,7 +497,7 @@ void VITA_ShowScreenKeyboard(_THIS, SDL_Window *window) void VITA_HideScreenKeyboard(_THIS, SDL_Window *window) { #if !defined(SDL_VIDEO_VITA_PVR) - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus(); @@ -524,7 +518,7 @@ void VITA_HideScreenKeyboard(_THIS, SDL_Window *window) SDL_bool VITA_IsScreenKeyboardShown(_THIS, SDL_Window *window) { #if defined(SDL_VIDEO_VITA_PVR) - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; return videodata->ime_active; #else SceCommonDialogStatus dialogStatus = sceImeDialogGetStatus(); @@ -535,7 +529,7 @@ SDL_bool VITA_IsScreenKeyboardShown(_THIS, SDL_Window *window) void VITA_PumpEvents(_THIS) { #if !defined(SDL_VIDEO_VITA_PVR) - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; #endif if (_this->suspend_screensaver) { diff --git a/src/video/vita/SDL_vitavideo.h b/src/video/vita/SDL_vitavideo.h index 497947be0..de265f4b5 100644 --- a/src/video/vita/SDL_vitavideo.h +++ b/src/video/vita/SDL_vitavideo.h @@ -31,21 +31,16 @@ #include #include -typedef struct SDL_VideoData +struct SDL_VideoData { SDL_bool egl_initialized; /* OpenGL device initialization status */ uint32_t egl_refcount; /* OpenGL reference count */ SceWChar16 ime_buffer[SCE_IME_DIALOG_MAX_TEXT_LENGTH]; SDL_bool ime_active; -} SDL_VideoData; +}; -typedef struct SDL_DisplayData -{ - -} SDL_DisplayData; - -typedef struct SDL_WindowData +struct SDL_WindowData { SDL_bool uses_gles; SceUID buffer_uid; @@ -54,7 +49,7 @@ typedef struct SDL_WindowData EGLSurface egl_surface; EGLContext egl_context; #endif -} SDL_WindowData; +}; extern SDL_Window *Vita_Window; diff --git a/src/video/vivante/SDL_vivanteopengles.c b/src/video/vivante/SDL_vivanteopengles.c index 8170567b8..190831116 100644 --- a/src/video/vivante/SDL_vivanteopengles.c +++ b/src/video/vivante/SDL_vivanteopengles.c @@ -29,9 +29,7 @@ int VIVANTE_GLES_LoadLibrary(_THIS, const char *path) { - SDL_DisplayData *displaydata; - - displaydata = SDL_GetDisplayDriverData(0); + SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(SDL_GetPrimaryDisplay()); return SDL_EGL_LoadLibrary(_this, path, displaydata->native_display, 0); } diff --git a/src/video/vivante/SDL_vivantevideo.c b/src/video/vivante/SDL_vivantevideo.c index fe8ecd63b..31590ce48 100644 --- a/src/video/vivante/SDL_vivantevideo.c +++ b/src/video/vivante/SDL_vivantevideo.c @@ -39,10 +39,8 @@ static void VIVANTE_Destroy(SDL_VideoDevice *device) { - if (device->driverdata != NULL) { - SDL_free(device->driverdata); - device->driverdata = NULL; - } + SDL_free(device->driverdata); + SDL_free(device); } static SDL_VideoDevice *VIVANTE_Create() @@ -169,7 +167,7 @@ static int VIVANTE_AddVideoDisplays(_THIS) int VIVANTE_VideoInit(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; #if SDL_VIDEO_DRIVER_VIVANTE_VDK videodata->vdk_private = vdkInitialize(); @@ -221,7 +219,7 @@ int VIVANTE_VideoInit(_THIS) void VIVANTE_VideoQuit(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; #ifdef SDL_INPUT_LINUXEV SDL_EVDEV_Quit(); @@ -255,7 +253,7 @@ int VIVANTE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mo int VIVANTE_CreateWindow(_THIS, SDL_Window *window) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_DisplayData *displaydata; SDL_WindowData *data; @@ -296,7 +294,7 @@ int VIVANTE_CreateWindow(_THIS, SDL_Window *window) void VIVANTE_DestroyWindow(_THIS, SDL_Window *window) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_WindowData *data; data = window->driverdata; @@ -361,7 +359,7 @@ void VIVANTE_HideWindow(_THIS, SDL_Window *window) /*****************************************************************************/ int VIVANTE_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(0); info->subsystem = SDL_SYSWM_VIVANTE; diff --git a/src/video/vivante/SDL_vivantevideo.h b/src/video/vivante/SDL_vivantevideo.h index 83aa0bef6..0e9496940 100644 --- a/src/video/vivante/SDL_vivantevideo.h +++ b/src/video/vivante/SDL_vivantevideo.h @@ -34,7 +34,7 @@ #include #endif -typedef struct SDL_VideoData +struct SDL_VideoData { #if SDL_VIDEO_DRIVER_VIVANTE_VDK vdkPrivate vdk_private; @@ -50,18 +50,18 @@ typedef struct SDL_VideoData void(EGLAPIENTRY *fbGetWindowInfo)(EGLNativeWindowType Window, int *X, int *Y, int *Width, int *Height, int *BitsPerPixel, unsigned int *Offset); void(EGLAPIENTRY *fbDestroyWindow)(EGLNativeWindowType Window); #endif -} SDL_VideoData; +}; -typedef struct SDL_DisplayData +struct SDL_DisplayData { EGLNativeDisplayType native_display; -} SDL_DisplayData; +}; -typedef struct SDL_WindowData +struct SDL_WindowData { EGLNativeWindowType native_window; EGLSurface egl_surface; -} SDL_WindowData; +}; /****************************************************************************/ /* SDL_VideoDevice functions declaration */ diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c index d295c21ca..feb1616f2 100644 --- a/src/video/wayland/SDL_waylandmouse.c +++ b/src/video/wayland/SDL_waylandmouse.c @@ -330,7 +330,7 @@ static int create_buffer_from_shm(Wayland_CursorData *d, uint32_t format) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); - SDL_VideoData *data = (SDL_VideoData *)vd->driverdata; + SDL_VideoData *data = vd->driverdata; struct wl_shm_pool *shm_pool; int stride = width * 4; @@ -381,7 +381,7 @@ static SDL_Cursor *Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot cursor = SDL_calloc(1, sizeof(*cursor)); if (cursor) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); - SDL_VideoData *wd = (SDL_VideoData *)vd->driverdata; + SDL_VideoData *wd = vd->driverdata; Wayland_CursorData *data = SDL_calloc(1, sizeof(Wayland_CursorData)); if (data == NULL) { SDL_OutOfMemory(); @@ -554,7 +554,7 @@ static void Wayland_WarpMouse(SDL_Window *window, float x, float y) static int Wayland_SetRelativeMouseMode(SDL_bool enabled) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); - SDL_VideoData *data = (SDL_VideoData *)vd->driverdata; + SDL_VideoData *data = vd->driverdata; if (enabled) { /* Disable mouse warp emulation if it's enabled. */ diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c index de8045d5e..8807b72a4 100644 --- a/src/video/wayland/SDL_waylandopengles.c +++ b/src/video/wayland/SDL_waylandopengles.c @@ -37,7 +37,7 @@ int Wayland_GLES_LoadLibrary(_THIS, const char *path) { int ret; - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)data->display, _this->gl_config.egl_platform); @@ -50,8 +50,8 @@ int Wayland_GLES_LoadLibrary(_THIS, const char *path) SDL_GLContext Wayland_GLES_CreateContext(_THIS, SDL_Window *window) { SDL_GLContext context; - context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *)window->driverdata)->egl_surface); - WAYLAND_wl_display_flush(((SDL_VideoData *)_this->driverdata)->display); + context = SDL_EGL_CreateContext(_this, window->driverdata->egl_surface); + WAYLAND_wl_display_flush(_this->driverdata->display); return context; } @@ -104,7 +104,7 @@ int Wayland_GLES_GetSwapInterval(_THIS, int *interval) int Wayland_GLES_SwapWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; const int swap_interval = _this->egl_data->egl_swapinterval; /* For windows that we know are hidden, skip swaps entirely, if we don't do @@ -121,9 +121,9 @@ int Wayland_GLES_SwapWindow(_THIS, SDL_Window *window) /* Control swap interval ourselves. See comments on Wayland_GLES_SetSwapInterval */ if (swap_interval != 0) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; struct wl_display *display = videodata->display; - SDL_VideoDisplay *sdldisplay = SDL_GetDisplayForWindow(window); + SDL_VideoDisplay *sdldisplay = SDL_GetVideoDisplayForWindow(window); /* ~10 frames (or 1 sec), so we'll progress even if throttled to zero. */ const Uint64 max_wait = SDL_GetTicksNS() + (sdldisplay->current_mode.refresh_rate ? ((SDL_NS_PER_SECOND * 10 * 100) / (int)(sdldisplay->current_mode.refresh_rate * 100)) : SDL_NS_PER_SECOND); while (SDL_AtomicGet(&data->swap_interval_ready) == 0) { @@ -176,12 +176,12 @@ int Wayland_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) int ret; if (window && context) { - ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *)window->driverdata)->egl_surface, context); + ret = SDL_EGL_MakeCurrent(_this, window->driverdata->egl_surface, context); } else { ret = SDL_EGL_MakeCurrent(_this, NULL, NULL); } - WAYLAND_wl_display_flush(((SDL_VideoData *)_this->driverdata)->display); + WAYLAND_wl_display_flush(_this->driverdata->display); _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, 0); /* see comments on Wayland_GLES_SetSwapInterval. */ @@ -191,12 +191,12 @@ int Wayland_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) void Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context) { SDL_EGL_DeleteContext(_this, context); - WAYLAND_wl_display_flush(((SDL_VideoData *)_this->driverdata)->display); + WAYLAND_wl_display_flush(_this->driverdata->display); } EGLSurface Wayland_GLES_GetEGLSurface(_THIS, SDL_Window *window) { - SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windowdata = window->driverdata; return windowdata->egl_surface; } diff --git a/src/video/wayland/SDL_waylandtouch.c b/src/video/wayland/SDL_waylandtouch.c index 3aaf831a5..e301fa50d 100644 --- a/src/video/wayland/SDL_waylandtouch.c +++ b/src/video/wayland/SDL_waylandtouch.c @@ -71,7 +71,7 @@ static void touch_handle_touch(void *data, * (src/compositor/wayland_wrapper/qwltouch.cpp) **/ - SDL_VideoData *viddata = (SDL_VideoData *)data; + SDL_VideoData *viddata = data; float FIXED_TO_FLOAT = 1. / 10000.; float xf = FIXED_TO_FLOAT * normalized_x; diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index c2db92e5b..932569ee7 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -67,8 +67,7 @@ static void display_handle_done(void *data, struct wl_output *output); static int Wayland_VideoInit(_THIS); static int Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect); - -static int Wayland_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *sdl_display, float *ddpi, float *hdpi, float *vdpi); +static int Wayland_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi); static void Wayland_VideoQuit(_THIS); @@ -151,7 +150,7 @@ SDL_bool SDL_WAYLAND_own_output(struct wl_output *output) static void Wayland_DeleteDevice(SDL_VideoDevice *device) { - SDL_VideoData *data = (SDL_VideoData *)device->driverdata; + SDL_VideoData *data = device->driverdata; if (data->display) { WAYLAND_wl_display_flush(data->display); WAYLAND_wl_display_disconnect(data->display); @@ -286,7 +285,7 @@ VideoBootStrap Wayland_bootstrap = { static void xdg_output_handle_logical_position(void *data, struct zxdg_output_v1 *xdg_output, int32_t x, int32_t y) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (SDL_DisplayData *)data; driverdata->x = x; driverdata->y = y; @@ -296,7 +295,7 @@ static void xdg_output_handle_logical_position(void *data, struct zxdg_output_v1 static void xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xdg_output, int32_t width, int32_t height) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (SDL_DisplayData *)data; if (driverdata->screen_width != 0 && driverdata->screen_height != 0) { /* FIXME: GNOME has a bug where the logical size does not account for @@ -323,7 +322,7 @@ static void xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xd static void xdg_output_handle_done(void *data, struct zxdg_output_v1 *xdg_output) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (void *)data; /* * xdg-output.done events are deprecated and only apply below version 3 of the protocol. @@ -342,9 +341,9 @@ static void xdg_output_handle_name(void *data, struct zxdg_output_v1 *xdg_output static void xdg_output_handle_description(void *data, struct zxdg_output_v1 *xdg_output, const char *description) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (SDL_DisplayData *)data; - if (driverdata->index == -1) { + if (driverdata->display == 0) { /* xdg-output descriptions, if available, supersede wl-output model names. */ if (driverdata->placeholder.name != NULL) { SDL_free(driverdata->placeholder.name); @@ -452,19 +451,19 @@ static void display_handle_geometry(void *data, int transform) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (SDL_DisplayData *)data; SDL_VideoDisplay *display; int i; if (driverdata->wl_output_done_count) { /* Clear the wl_output ref so Reset doesn't free it */ - display = SDL_GetDisplay(driverdata->index); - for (i = 0; i < display->num_display_modes; i += 1) { + display = SDL_GetVideoDisplay(driverdata->display); + for (i = 0; i < display->num_display_modes; ++i) { display->display_modes[i].driverdata = NULL; } /* Okay, now it's safe to reset */ - SDL_ResetDisplayModes(driverdata->index); + SDL_ResetDisplayModes(display); /* The display has officially started over. */ driverdata->wl_output_done_count = 0; @@ -479,7 +478,7 @@ static void display_handle_geometry(void *data, driverdata->physical_height = physical_height; /* The output name is only set if xdg-output hasn't provided a description. */ - if (driverdata->index == -1 && driverdata->placeholder.name == NULL) { + if (driverdata->display == 0 && driverdata->placeholder.name == NULL) { driverdata->placeholder.name = SDL_strdup(model); } @@ -521,7 +520,7 @@ static void display_handle_mode(void *data, int height, int refresh) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (SDL_DisplayData *)data; if (flags & WL_OUTPUT_MODE_CURRENT) { driverdata->pixel_width = width; @@ -543,7 +542,7 @@ static void display_handle_mode(void *data, static void display_handle_done(void *data, struct wl_output *output) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (SDL_DisplayData *)data; SDL_VideoData *video = driverdata->videodata; SDL_DisplayMode native_mode, desktop_mode; SDL_VideoDisplay *dpy; @@ -603,8 +602,8 @@ static void display_handle_done(void *data, desktop_mode.refresh_rate = ((100 * driverdata->refresh) / 1000) / 100.0f; /* mHz to Hz */ desktop_mode.driverdata = driverdata->output; - if (driverdata->index > -1) { - dpy = SDL_GetDisplay(driverdata->index); + if (driverdata->display > 0) { + dpy = SDL_GetVideoDisplay(driverdata->display); } else { dpy = &driverdata->placeholder; } @@ -658,12 +657,12 @@ static void display_handle_done(void *data, ((float)driverdata->physical_height) / 25.4f); } - if (driverdata->index == -1) { + if (driverdata->display == 0) { /* First time getting display info, create the VideoDisplay */ SDL_bool send_event = driverdata->videodata->initializing ? SDL_FALSE : SDL_TRUE; driverdata->placeholder.orientation = driverdata->orientation; driverdata->placeholder.driverdata = driverdata; - driverdata->index = SDL_AddVideoDisplay(&driverdata->placeholder, send_event); + driverdata->display = SDL_AddVideoDisplay(&driverdata->placeholder, send_event); SDL_free(driverdata->placeholder.name); SDL_zero(driverdata->placeholder); } else { @@ -675,7 +674,7 @@ static void display_handle_scale(void *data, struct wl_output *output, int32_t factor) { - SDL_WaylandOutputData *driverdata = data; + SDL_DisplayData *driverdata = (SDL_DisplayData *)data; driverdata->scale_factor = factor; } @@ -689,35 +688,33 @@ static const struct wl_output_listener output_listener = { static void Wayland_add_display(SDL_VideoData *d, uint32_t id) { struct wl_output *output; - SDL_WaylandOutputData *data; + SDL_DisplayData *data; output = wl_registry_bind(d->registry, id, &wl_output_interface, 2); if (output == NULL) { SDL_SetError("Failed to retrieve output."); return; } - data = SDL_malloc(sizeof *data); - SDL_zerop(data); + data = (SDL_DisplayData *)SDL_calloc(1, sizeof(*data)); data->videodata = d; data->output = output; data->registry_id = id; data->scale_factor = 1.0f; - data->index = -1; wl_output_add_listener(output, &output_listener, data); SDL_WAYLAND_register_output(output); /* Keep a list of outputs for deferred xdg-output initialization. */ if (d->output_list != NULL) { - SDL_WaylandOutputData *node = d->output_list; + SDL_DisplayData *node = d->output_list; while (node->next != NULL) { node = node->next; } - node->next = (struct SDL_WaylandOutputData *)data; + node->next = data; } else { - d->output_list = (struct SDL_WaylandOutputData *)data; + d->output_list = data; } if (data->videodata->xdg_output_manager) { @@ -728,51 +725,46 @@ static void Wayland_add_display(SDL_VideoData *d, uint32_t id) static void Wayland_free_display(SDL_VideoData *d, uint32_t id) { - int num_displays = SDL_GetNumVideoDisplays(); + SDL_DisplayID *displays; SDL_VideoDisplay *display; - SDL_WaylandOutputData *data; + SDL_DisplayData *data; int i; - for (i = 0; i < num_displays; i += 1) { - display = SDL_GetDisplay(i); - data = (SDL_WaylandOutputData *)display->driverdata; - if (data->registry_id == id) { - if (d->output_list != NULL) { - SDL_WaylandOutputData *node = d->output_list; - if (node == data) { - d->output_list = node->next; - } else { - while (node->next != data && node->next != NULL) { - node = node->next; - } - if (node->next != NULL) { - node->next = node->next->next; + displays = SDL_GetDisplays(NULL); + if (displays) { + for (i = 0; displays[i]; ++i) { + display = SDL_GetVideoDisplay(displays[i]); + data = display->driverdata; + if (data->registry_id == id) { + if (d->output_list != NULL) { + SDL_DisplayData *node = d->output_list; + if (node == data) { + d->output_list = node->next; + } else { + while (node->next != data && node->next != NULL) { + node = node->next; + } + if (node->next != NULL) { + node->next = node->next->next; + } } } + SDL_DelVideoDisplay(displays[i]); + if (data->xdg_output) { + zxdg_output_v1_destroy(data->xdg_output); + } + wl_output_destroy(data->output); + SDL_free(data); + break; } - SDL_DelVideoDisplay(i); - if (data->xdg_output) { - zxdg_output_v1_destroy(data->xdg_output); - } - wl_output_destroy(data->output); - SDL_free(data); - - /* Update the index for all remaining displays */ - num_displays -= 1; - for (; i < num_displays; i += 1) { - display = SDL_GetDisplay(i); - data = (SDL_WaylandOutputData *)display->driverdata; - data->index -= 1; - } - - return; } + SDL_free(displays); } } static void Wayland_init_xdg_output(SDL_VideoData *d) { - SDL_WaylandOutputData *node; + SDL_DisplayData *node; for (node = d->output_list; node != NULL; node = node->next) { node->xdg_output = zxdg_output_manager_v1_get_xdg_output(node->videodata->xdg_output_manager, node->output); zxdg_output_v1_add_listener(node->xdg_output, &xdg_output_listener, node); @@ -941,7 +933,7 @@ SDL_bool Wayland_LoadLibdecor(SDL_VideoData *data, SDL_bool ignore_xdg) int Wayland_VideoInit(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; data->xkb_context = WAYLAND_xkb_context_new(0); if (!data->xkb_context) { @@ -981,7 +973,7 @@ int Wayland_VideoInit(_THIS) static int Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { - SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *)display->driverdata; + SDL_DisplayData *driverdata = display->driverdata; rect->x = driverdata->x; rect->y = driverdata->y; rect->w = display->current_mode.screen_w; @@ -989,9 +981,9 @@ static int Wayland_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect * return 0; } -static int Wayland_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *sdl_display, float *ddpi, float *hdpi, float *vdpi) +static int Wayland_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi) { - SDL_WaylandOutputData *driverdata = (SDL_WaylandOutputData *)sdl_display->driverdata; + SDL_DisplayData *driverdata = display->driverdata; if (ddpi) { *ddpi = driverdata->ddpi; @@ -1017,11 +1009,11 @@ static void Wayland_VideoCleanup(_THIS) for (i = _this->num_displays - 1; i >= 0; --i) { SDL_VideoDisplay *display = &_this->displays[i]; - if (((SDL_WaylandOutputData *)display->driverdata)->xdg_output) { - zxdg_output_v1_destroy(((SDL_WaylandOutputData *)display->driverdata)->xdg_output); + if (display->driverdata->xdg_output) { + zxdg_output_v1_destroy(display->driverdata->xdg_output); } - wl_output_destroy(((SDL_WaylandOutputData *)display->driverdata)->output); + wl_output_destroy(display->driverdata->output); SDL_free(display->driverdata); display->driverdata = NULL; diff --git a/src/video/wayland/SDL_waylandvideo.h b/src/video/wayland/SDL_waylandvideo.h index 62f1f6a1f..12530ad49 100644 --- a/src/video/wayland/SDL_waylandvideo.h +++ b/src/video/wayland/SDL_waylandvideo.h @@ -47,9 +47,7 @@ typedef struct int size; } SDL_WaylandCursorTheme; -typedef struct SDL_WaylandOutputData SDL_WaylandOutputData; - -typedef struct +struct SDL_VideoData { SDL_bool initializing; struct wl_display *display; @@ -88,7 +86,7 @@ typedef struct struct xkb_context *xkb_context; struct SDL_WaylandInput *input; struct SDL_WaylandTabletManager *tablet_manager; - SDL_WaylandOutputData *output_list; + SDL_DisplayData *output_list; #ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH struct SDL_WaylandTouch *touch; @@ -100,9 +98,9 @@ typedef struct int relative_mouse_mode; SDL_bool egl_transparency_enabled; -} SDL_VideoData; +}; -struct SDL_WaylandOutputData +struct SDL_DisplayData { SDL_VideoData *videodata; struct wl_output *output; @@ -115,10 +113,10 @@ struct SDL_WaylandOutputData int physical_width, physical_height; float ddpi, hdpi, vdpi; SDL_bool has_logical_position, has_logical_size; - int index; + SDL_DisplayID display; SDL_VideoDisplay placeholder; int wl_output_done_count; - SDL_WaylandOutputData *next; + SDL_DisplayData *next; }; /* Needed here to get wl_surface declaration, fixes GitHub#4594 */ diff --git a/src/video/wayland/SDL_waylandvulkan.c b/src/video/wayland/SDL_waylandvulkan.c index c498ee46d..bce6fab94 100644 --- a/src/video/wayland/SDL_waylandvulkan.c +++ b/src/video/wayland/SDL_waylandvulkan.c @@ -136,7 +136,7 @@ SDL_bool Wayland_Vulkan_CreateSurface(_THIS, VkInstance instance, VkSurfaceKHR *surface) { - SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windowData = window->driverdata; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr; PFN_vkCreateWaylandSurfaceKHR vkCreateWaylandSurfaceKHR = diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index 8a3d20f99..9207d0386 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -55,9 +55,9 @@ SDL_FORCE_INLINE SDL_bool FloatEqual(float a, float b) static void GetFullScreenDimensions(SDL_Window *window, int *width, int *height, int *drawable_width, int *drawable_height) { - SDL_WindowData *wind = (SDL_WindowData *)window->driverdata; - SDL_VideoDisplay *disp = SDL_GetDisplayForWindow(window); - SDL_WaylandOutputData *output = (SDL_WaylandOutputData *)disp->driverdata; + SDL_WindowData *wind = window->driverdata; + SDL_VideoDisplay *disp = SDL_GetVideoDisplayForWindow(window); + SDL_DisplayData *output = disp->driverdata; int fs_width, fs_height; int buf_width, buf_height; @@ -126,7 +126,7 @@ static SDL_bool WindowNeedsViewport(SDL_Window *window) { SDL_WindowData *wind = window->driverdata; SDL_VideoData *video = wind->waylandData; - SDL_WaylandOutputData *output = ((SDL_WaylandOutputData *)SDL_GetDisplayForWindow(window)->driverdata); + SDL_DisplayData *output = SDL_GetDisplayDriverDataForWindow(window); const int output_width = wind->fs_output_width ? wind->fs_output_width : output->screen_width; const int output_height = wind->fs_output_height ? wind->fs_output_height : output->screen_height; int fs_width, fs_height; @@ -205,7 +205,7 @@ static void ConfigureWindowGeometry(SDL_Window *window) { SDL_WindowData *data = window->driverdata; SDL_VideoData *viddata = data->waylandData; - SDL_WaylandOutputData *output = (SDL_WaylandOutputData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_DisplayData *output = SDL_GetDisplayDriverDataForWindow(window); struct wl_region *region; const int old_dw = data->drawable_width; const int old_dh = data->drawable_height; @@ -303,7 +303,7 @@ static void ConfigureWindowGeometry(SDL_Window *window) static void CommitLibdecorFrame(SDL_Window *window) { #ifdef HAVE_LIBDECOR_H - SDL_WindowData *wind = (SDL_WindowData *)window->driverdata; + SDL_WindowData *wind = window->driverdata; if (wind->shell_surface_type == WAYLAND_SURFACE_LIBDECOR && wind->shell_surface.libdecor.frame) { struct libdecor_state *state = libdecor_state_new(wind->window_width, wind->window_height); @@ -438,7 +438,7 @@ static void SetFullscreen(SDL_Window *window, struct wl_output *output) static void UpdateWindowFullscreen(SDL_Window *window, SDL_bool fullscreen) { - SDL_WindowData *wind = (SDL_WindowData *)window->driverdata; + SDL_WindowData *wind = window->driverdata; if (fullscreen) { if ((window->flags & SDL_WINDOW_FULLSCREEN_MASK) == 0) { @@ -724,7 +724,7 @@ static void handle_configure_zxdg_decoration(void *data, uint32_t mode) { SDL_Window *window = (SDL_Window *)data; - SDL_WindowData *driverdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *driverdata = window->driverdata; SDL_VideoDevice *device = SDL_GetVideoDevice(); /* If the compositor tries to force CSD anyway, bail on direct XDG support @@ -992,7 +992,7 @@ static void update_scale_factor(SDL_WindowData *window) /* Check every display's factor, use the highest */ new_factor = 0.0f; for (i = 0; i < window->num_outputs; i++) { - SDL_WaylandOutputData *driverdata = window->outputs[i]; + SDL_DisplayData *driverdata = window->outputs[i]; new_factor = SDL_max(new_factor, driverdata->scale_factor); } } else { @@ -1010,36 +1010,41 @@ static void update_scale_factor(SDL_WindowData *window) * what monitor we're on, so let's send move events that put the window at the * center of the whatever display the wl_surface_listener events give us. */ -static void Wayland_move_window(SDL_Window *window, - SDL_WaylandOutputData *driverdata) +static void Wayland_move_window(SDL_Window *window, SDL_DisplayData *driverdata) { - int i, numdisplays = SDL_GetNumVideoDisplays(); - for (i = 0; i < numdisplays; i += 1) { - if (SDL_GetDisplay(i)->driverdata == driverdata) { - /* We want to send a very very specific combination here: - * - * 1. A coordinate that tells the application what display we're on - * 2. Exactly (0, 0) - * - * Part 1 is useful information but is also really important for - * ensuring we end up on the right display for fullscreen, while - * part 2 is important because numerous applications use a specific - * combination of GetWindowPosition and GetGlobalMouseState, and of - * course neither are supported by Wayland. Since global mouse will - * fall back to just GetMouseState, we need the window position to - * be zero so the cursor math works without it going off in some - * random direction. See UE5 Editor for a notable example of this! - * - * This may be an issue some day if we're ever able to implement - * SDL_GetDisplayUsableBounds! - * - * -flibit - */ - SDL_Rect bounds; - SDL_GetDisplayBounds(i, &bounds); - SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, bounds.x, bounds.y); - break; + SDL_DisplayID *displays; + int i; + + displays = SDL_GetDisplays(NULL); + if (displays) { + for (i = 0; displays[i]; ++i) { + if (SDL_GetDisplayDriverData(displays[i]) == driverdata) { + /* We want to send a very very specific combination here: + * + * 1. A coordinate that tells the application what display we're on + * 2. Exactly (0, 0) + * + * Part 1 is useful information but is also really important for + * ensuring we end up on the right display for fullscreen, while + * part 2 is important because numerous applications use a specific + * combination of GetWindowPosition and GetGlobalMouseState, and of + * course neither are supported by Wayland. Since global mouse will + * fall back to just GetMouseState, we need the window position to + * be zero so the cursor math works without it going off in some + * random direction. See UE5 Editor for a notable example of this! + * + * This may be an issue some day if we're ever able to implement + * SDL_GetDisplayUsableBounds! + * + * -flibit + */ + SDL_Rect bounds; + SDL_GetDisplayBounds(displays[i], &bounds); + SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, bounds.x, bounds.y); + break; + } } + SDL_free(displays); } } @@ -1047,14 +1052,14 @@ static void handle_surface_enter(void *data, struct wl_surface *surface, struct wl_output *output) { SDL_WindowData *window = data; - SDL_WaylandOutputData *driverdata = wl_output_get_user_data(output); + SDL_DisplayData *driverdata = wl_output_get_user_data(output); if (!SDL_WAYLAND_own_output(output) || !SDL_WAYLAND_own_surface(surface)) { return; } window->outputs = SDL_realloc(window->outputs, - sizeof(SDL_WaylandOutputData *) * (window->num_outputs + 1)); + sizeof(SDL_DisplayData *) * (window->num_outputs + 1)); window->outputs[window->num_outputs++] = driverdata; /* Update the scale factor after the move so that fullscreen outputs are updated. */ @@ -1070,7 +1075,7 @@ static void handle_surface_leave(void *data, struct wl_surface *surface, { SDL_WindowData *window = data; int i, send_move_event = 0; - SDL_WaylandOutputData *driverdata = wl_output_get_user_data(output); + SDL_DisplayData *driverdata = wl_output_get_user_data(output); if (!SDL_WAYLAND_own_output(output) || !SDL_WAYLAND_own_surface(surface)) { return; @@ -1084,7 +1089,7 @@ static void handle_surface_leave(void *data, struct wl_surface *surface, } else { SDL_memmove(&window->outputs[i], &window->outputs[i + 1], - sizeof(SDL_WaylandOutputData *) * ((window->num_outputs - i) - 1)); + sizeof(SDL_DisplayData *) * ((window->num_outputs - i) - 1)); } window->num_outputs--; i--; @@ -1111,8 +1116,8 @@ static const struct wl_surface_listener surface_listener = { int Wayland_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_VideoData *viddata = _this->driverdata; + SDL_WindowData *data = window->driverdata; info->subsystem = SDL_SYSWM_WAYLAND; info->info.wl.display = data->waylandData->display; @@ -1147,7 +1152,7 @@ int Wayland_SetWindowHitTest(SDL_Window *window, SDL_bool enabled) int Wayland_SetWindowModalFor(_THIS, SDL_Window *modal_window, SDL_Window *parent_window) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; SDL_WindowData *modal_data = modal_window->driverdata; SDL_WindowData *parent_data = parent_window->driverdata; @@ -1657,11 +1662,11 @@ static void QtExtendedSurface_Unsubscribe(struct qt_extended_surface *surface, c #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ void Wayland_SetWindowFullscreen(_THIS, SDL_Window *window, - SDL_VideoDisplay *_display, SDL_bool fullscreen) + SDL_VideoDisplay *display, SDL_bool fullscreen) { - SDL_WindowData *wind = (SDL_WindowData *)window->driverdata; - struct wl_output *output = ((SDL_WaylandOutputData *)_display->driverdata)->output; - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; + SDL_WindowData *wind = window->driverdata; + struct wl_output *output = display->driverdata->output; /* Called from within a configure event or the window is a popup, drop it. */ if (wind->in_fullscreen_transition || wind->shell_surface_type == WAYLAND_SURFACE_XDG_POPUP) { @@ -1696,8 +1701,8 @@ void Wayland_SetWindowFullscreen(_THIS, SDL_Window *window, void Wayland_RestoreWindow(_THIS, SDL_Window *window) { + SDL_VideoData *viddata = _this->driverdata; SDL_WindowData *wind = window->driverdata; - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; if (wind->shell_surface_type == WAYLAND_SURFACE_XDG_POPUP) { return; @@ -1772,8 +1777,8 @@ void Wayland_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) void Wayland_MaximizeWindow(_THIS, SDL_Window *window) { + SDL_VideoData *viddata = _this->driverdata; SDL_WindowData *wind = window->driverdata; - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; if (wind->shell_surface_type == WAYLAND_SURFACE_XDG_POPUP) { return; @@ -1808,8 +1813,8 @@ void Wayland_MaximizeWindow(_THIS, SDL_Window *window) void Wayland_MinimizeWindow(_THIS, SDL_Window *window) { + SDL_VideoData *viddata = _this->driverdata; SDL_WindowData *wind = window->driverdata; - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; if (wind->shell_surface_type == WAYLAND_SURFACE_XDG_POPUP) { return; @@ -1835,7 +1840,7 @@ void Wayland_MinimizeWindow(_THIS, SDL_Window *window) void Wayland_SetWindowMouseRect(_THIS, SDL_Window *window) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; /* This may look suspiciously like SetWindowGrab, despite SetMouseRect not * implicitly doing a grab. And you're right! Wayland doesn't let us mess @@ -1854,7 +1859,7 @@ void Wayland_SetWindowMouseRect(_THIS, SDL_Window *window) void Wayland_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (grabbed) { Wayland_input_confine_pointer(data->input, window); @@ -1865,7 +1870,7 @@ void Wayland_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void Wayland_SetWindowKeyboardGrab(_THIS, SDL_Window *window, SDL_bool grabbed) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (grabbed) { Wayland_input_grab_keyboard(window, data->input); @@ -1908,8 +1913,8 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) { int i; - for (i = 0; i < SDL_GetVideoDevice()->num_displays; i++) { - float scale = ((SDL_WaylandOutputData *)SDL_GetVideoDevice()->displays[i].driverdata)->scale_factor; + for (i = 0; i < _this->num_displays; i++) { + float scale = _this->displays[i].driverdata->scale_factor; data->windowed_scale_factor = SDL_max(data->windowed_scale_factor, scale); } } @@ -2014,7 +2019,7 @@ int Wayland_CreateWindow(_THIS, SDL_Window *window) static void Wayland_HandleResize(SDL_Window *window, int width, int height) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; const int old_w = window->w, old_h = window->h; /* Update the window geometry. */ @@ -2077,7 +2082,7 @@ void Wayland_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) { SDL_WindowData *data; if (window->driverdata) { - data = (SDL_WindowData *)window->driverdata; + data = window->driverdata; *w = data->drawable_width; *h = data->drawable_height; } @@ -2113,7 +2118,7 @@ void Wayland_SetWindowTitle(_THIS, SDL_Window *window) void Wayland_SuspendScreenSaver(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; #if SDL_USE_LIBDBUS if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) { @@ -2220,7 +2225,7 @@ static void EGLTransparencyChangedCallback(void *userdata, const char *name, con /* Iterate over all windows and update the surface opaque regions */ for (window = dev->windows; window != NULL; window = window->next) { - SDL_WindowData *wind = (SDL_WindowData *)window->driverdata; + SDL_WindowData *wind = window->driverdata; if (!newval) { struct wl_region *region = wl_compositor_create_region(wind->waylandData->compositor); diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h index f17f8dd33..560dee10d 100644 --- a/src/video/wayland/SDL_waylandwindow.h +++ b/src/video/wayland/SDL_waylandwindow.h @@ -33,7 +33,7 @@ struct SDL_WaylandInput; -typedef struct +struct SDL_WindowData { SDL_Window *sdlwindow; SDL_VideoData *waylandData; @@ -100,7 +100,7 @@ typedef struct struct qt_extended_surface *extended_surface; #endif /* SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH */ - SDL_WaylandOutputData **outputs; + SDL_DisplayData **outputs; int num_outputs; float windowed_scale_factor; @@ -117,7 +117,7 @@ typedef struct SDL_bool is_fullscreen; SDL_bool in_fullscreen_transition; Uint32 fullscreen_flags; -} SDL_WindowData; +}; extern void Wayland_ShowWindow(_THIS, SDL_Window *window); extern void Wayland_HideWindow(_THIS, SDL_Window *window); diff --git a/src/video/windows/SDL_windowsclipboard.c b/src/video/windows/SDL_windowsclipboard.c index 8fea9e65d..cb66bcac7 100644 --- a/src/video/windows/SDL_windowsclipboard.c +++ b/src/video/windows/SDL_windowsclipboard.c @@ -39,14 +39,14 @@ static HWND GetWindowHandle(_THIS) window = _this->windows; if (window) { - return ((SDL_WindowData *)window->driverdata)->hwnd; + return window->driverdata->hwnd; } return NULL; } int WIN_SetClipboardText(_THIS, const char *text) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; int result = 0; if (OpenClipboard(GetWindowHandle(_this))) { diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index 8eac1acb8..964fea7e8 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -483,7 +483,7 @@ static void WIN_CheckAsyncMouseRelease(SDL_WindowData *data) static void WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; SDL_bool had_focus = (SDL_GetKeyboardFocus() == window) ? SDL_TRUE : SDL_FALSE; SDL_bool has_focus = (GetForegroundWindow() == hwnd) ? SDL_TRUE : SDL_FALSE; @@ -636,7 +636,7 @@ static SDL_WindowData *WIN_GetWindowDataFromHWND(HWND hwnd) if (_this) { for (window = _this->windows; window; window = window->next) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data && data->hwnd == hwnd) { return data; } @@ -1241,7 +1241,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) RECT rect; int x, y; int w, h; - int display_index = data->window->display_index; + SDL_DisplayID displayID = data->window->displayID; if (data->initializing || data->in_border_change) { break; @@ -1294,7 +1294,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) /* Forces a WM_PAINT event */ InvalidateRect(hwnd, NULL, FALSE); - if (data->window->display_index != display_index) { + if (data->window->displayID != displayID) { /* Display changed, check ICC profile */ WIN_UpdateWindowICCProfile(data->window, SDL_TRUE); } @@ -1752,7 +1752,7 @@ static void WIN_UpdateClipCursorForWindows() if (_this) { for (window = _this->windows; window; window = window->next) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data) { if (data->skip_update_clipcursor) { data->skip_update_clipcursor = SDL_FALSE; @@ -1770,7 +1770,7 @@ static void WIN_UpdateMouseCapture() SDL_Window *focusWindow = SDL_GetKeyboardFocus(); if (focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE)) { - SDL_WindowData *data = (SDL_WindowData *)focusWindow->driverdata; + SDL_WindowData *data = focusWindow->driverdata; if (!data->mouse_tracked) { POINT cursorPos; @@ -1840,7 +1840,7 @@ int WIN_WaitEventTimeout(_THIS, Sint64 timeoutNS) void WIN_SendWakeupEvent(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; PostMessage(data->hwnd, data->videodata->_SDL_WAKEUP, 0, 0); } diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index 925d2c640..678353f32 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -26,7 +26,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SDL_bool isstack; size_t size; LPBITMAPINFO info; @@ -100,7 +100,7 @@ int WIN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; int i; for (i = 0; i < numrects; ++i) { @@ -112,7 +112,7 @@ int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data == NULL) { /* The window wasn't fully initialized */ diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index 2bd0785d0..e66b42044 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -52,7 +52,7 @@ static SDL_bool IME_IsTextInputShown(SDL_VideoData *videodata); void WIN_InitKeyboard(_THIS) { #ifndef SDL_DISABLE_WINDOWS_IME - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; data->ime_com_initialized = SDL_FALSE; data->ime_threadmgr = 0; @@ -155,7 +155,7 @@ void WIN_UpdateKeymap(SDL_bool send_event) void WIN_QuitKeyboard(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; #ifndef SDL_DISABLE_WINDOWS_IME IME_Quit(data); @@ -207,8 +207,8 @@ void WIN_StartTextInput(_THIS) #ifndef SDL_DISABLE_WINDOWS_IME window = SDL_GetKeyboardFocus(); if (window) { - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + HWND hwnd = window->driverdata->hwnd; + SDL_VideoData *videodata = _this->driverdata; SDL_GetWindowSize(window, &videodata->ime_winwidth, &videodata->ime_winheight); IME_Init(videodata, hwnd); IME_Enable(videodata, hwnd); @@ -227,8 +227,8 @@ void WIN_StopTextInput(_THIS) #ifndef SDL_DISABLE_WINDOWS_IME window = SDL_GetKeyboardFocus(); if (window) { - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + HWND hwnd = window->driverdata->hwnd; + SDL_VideoData *videodata = _this->driverdata; IME_Init(videodata, hwnd); IME_Disable(videodata, hwnd); } @@ -237,7 +237,7 @@ void WIN_StopTextInput(_THIS) void WIN_SetTextInputRect(_THIS, const SDL_Rect *rect) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; HIMC himc = 0; if (rect == NULL) { @@ -1727,13 +1727,13 @@ void IME_Present(SDL_VideoData *videodata) SDL_bool WIN_IsTextInputShown(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; return IME_IsTextInputShown(videodata); } void WIN_ClearComposition(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; IME_ClearComposition(videodata); } diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index 6bd3254c8..00a17bd73 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -871,7 +871,7 @@ static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int * /* If we have a parent window, get the Instance and HWND for them * so that our little dialog gets exclusive focus at all times. */ if (messageboxdata->window) { - ParentWindow = ((SDL_WindowData *)messageboxdata->window->driverdata)->hwnd; + ParentWindow = messageboxdata->window->driverdata->hwnd; } result = DialogBoxIndirectParam(NULL, (DLGTEMPLATE *)dialog->lpDialog, ParentWindow, MessageBoxDialogProc, (LPARAM)messageboxdata); @@ -952,7 +952,7 @@ int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) /* If we have a parent window, get the Instance and HWND for them so that our little dialog gets exclusive focus at all times. */ if (messageboxdata->window) { - ParentWindow = ((SDL_WindowData *)messageboxdata->window->driverdata)->hwnd; + ParentWindow = messageboxdata->window->driverdata->hwnd; } wmessage = WIN_UTF8ToStringW(messageboxdata->message); diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index f206aa585..ad8d51c34 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -303,6 +303,7 @@ WIN_GetDisplayNameVista_failed: static void WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, int *display_index, SDL_bool send_event) { int i, index = *display_index; + SDL_DisplayID displayID; SDL_VideoDisplay display; SDL_DisplayData *displaydata; SDL_DisplayMode mode; @@ -320,7 +321,7 @@ static void WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, // ready to be added to allow any displays that we can't fully query to be // removed for (i = 0; i < _this->num_displays; ++i) { - SDL_DisplayData *driverdata = (SDL_DisplayData *)_this->displays[i].driverdata; + SDL_DisplayData *driverdata = _this->displays[i].driverdata; if (SDL_wcscmp(driverdata->DeviceName, info->szDevice) == 0) { SDL_bool moved = (index != i); @@ -338,17 +339,18 @@ static void WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, driverdata->IsValid = SDL_TRUE; if (!_this->setting_display_mode) { + SDL_VideoDisplay *existing_display = &_this->displays[i]; SDL_Rect bounds; - SDL_ResetDisplayModes(i); - SDL_SetCurrentDisplayMode(&_this->displays[i], &mode); - SDL_SetDesktopDisplayMode(&_this->displays[i], &mode); - if (WIN_GetDisplayBounds(_this, &_this->displays[i], &bounds) == 0) { + SDL_ResetDisplayModes(existing_display); + SDL_SetCurrentDisplayMode(existing_display, &mode); + SDL_SetDesktopDisplayMode(existing_display, &mode); + if (WIN_GetDisplayBounds(_this, existing_display, &bounds) == 0) { if (SDL_memcmp(&driverdata->bounds, &bounds, sizeof(bounds)) != 0 || moved) { - SDL_SendDisplayEvent(&_this->displays[i], SDL_EVENT_DISPLAY_MOVED, 0); + SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_MOVED, 0); } } - SDL_SendDisplayEvent(&_this->displays[i], SDL_EVENT_DISPLAY_ORIENTATION, orientation); + SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_ORIENTATION, orientation); } goto done; } @@ -379,8 +381,8 @@ static void WIN_AddDisplay(_THIS, HMONITOR hMonitor, const MONITORINFOEXW *info, display.device = _this; display.driverdata = displaydata; WIN_GetDisplayBounds(_this, &display, &displaydata->bounds); - index = SDL_AddVideoDisplay(&display, send_event); - SDL_assert(index == *display_index); + displayID = SDL_AddVideoDisplay(&display, send_event); + SDL_assert(SDL_GetDisplayIndex(displayID) == *display_index); SDL_free(display.name); done: @@ -478,8 +480,8 @@ static void WIN_MonitorInfoToSDL(const SDL_VideoData *videodata, HMONITOR monito int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { - const SDL_DisplayData *data = (const SDL_DisplayData *)display->driverdata; - const SDL_VideoData *videodata = (SDL_VideoData *)display->device->driverdata; + const SDL_DisplayData *data = display->driverdata; + const SDL_VideoData *videodata = display->device->driverdata; MONITORINFO minfo; BOOL rc; @@ -502,8 +504,8 @@ int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) int WIN_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi_out, float *hdpi_out, float *vdpi_out) { - const SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; - const SDL_VideoData *videodata = (SDL_VideoData *)display->device->driverdata; + const SDL_DisplayData *displaydata = display->driverdata; + const SDL_VideoData *videodata = display->device->driverdata; float hdpi = 0, vdpi = 0, ddpi = 0; if (videodata->GetDpiForMonitor) { @@ -560,8 +562,8 @@ int WIN_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *display, float *ddpi_out, int WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect) { - const SDL_DisplayData *data = (const SDL_DisplayData *)display->driverdata; - const SDL_VideoData *videodata = (SDL_VideoData *)display->device->driverdata; + const SDL_DisplayData *data = display->driverdata; + const SDL_VideoData *videodata = display->device->driverdata; MONITORINFO minfo; BOOL rc; @@ -602,7 +604,7 @@ void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int * { const SDL_VideoDevice *videodevice = SDL_GetVideoDevice(); const SDL_VideoData *videodata; - int displayIndex; + SDL_DisplayID displayID; SDL_Rect bounds; float ddpi, hdpi, vdpi; SDL_Point point; @@ -618,19 +620,18 @@ void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int * goto passthrough; } - videodata = (SDL_VideoData *)videodevice->driverdata; + videodata = videodevice->driverdata; if (!videodata->dpi_scaling_enabled) { goto passthrough; } /* Can't use MonitorFromPoint for this because we currently have SDL coordinates, not pixels */ - displayIndex = SDL_GetDisplayIndexForPoint(&point); - - if (displayIndex < 0) { + displayID = SDL_GetDisplayForPoint(&point); + if (displayID == 0) { goto passthrough; } - if (SDL_GetDisplayBounds(displayIndex, &bounds) < 0 || SDL_GetDisplayPhysicalDPI(displayIndex, &ddpi, &hdpi, &vdpi) < 0) { + if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || SDL_GetDisplayPhysicalDPI(displayID, &ddpi, &hdpi, &vdpi) < 0) { goto passthrough; } @@ -673,7 +674,8 @@ void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut) const SDL_VideoData *videodata; POINT point; HMONITOR monitor; - int i, displayIndex; + int i; + SDL_DisplayID displayID; SDL_Rect bounds; float ddpi, hdpi, vdpi; @@ -681,7 +683,7 @@ void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut) return; } - videodata = (SDL_VideoData *)videodevice->driverdata; + videodata = videodevice->driverdata; if (!videodata->dpi_scaling_enabled) { *xOut = (float)x; *yOut = (float)y; @@ -693,19 +695,19 @@ void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut) monitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST); /* Search for the corresponding SDL monitor */ - displayIndex = -1; + displayID = 0; for (i = 0; i < videodevice->num_displays; ++i) { - SDL_DisplayData *driverdata = (SDL_DisplayData *)videodevice->displays[i].driverdata; + SDL_DisplayData *driverdata = videodevice->displays[i].driverdata; if (driverdata->MonitorHandle == monitor) { - displayIndex = i; + displayID = videodevice->displays[i].id; } } - if (displayIndex == -1) { + if (displayID == 0) { return; } /* Get SDL display properties */ - if (SDL_GetDisplayBounds(displayIndex, &bounds) < 0 || SDL_GetDisplayPhysicalDPI(displayIndex, &ddpi, &hdpi, &vdpi) < 0) { + if (SDL_GetDisplayBounds(displayID, &bounds) < 0 || SDL_GetDisplayPhysicalDPI(displayID, &ddpi, &hdpi, &vdpi) < 0) { return; } @@ -721,7 +723,7 @@ void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut) void WIN_GetDisplayModes(_THIS, SDL_VideoDisplay *display) { - SDL_DisplayData *data = (SDL_DisplayData *)display->driverdata; + SDL_DisplayData *data = display->driverdata; DWORD i; SDL_DisplayMode mode; @@ -776,8 +778,8 @@ static void WIN_LogMonitor(_THIS, HMONITOR mon) int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { - SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; - SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->driverdata; + SDL_DisplayData *displaydata = display->driverdata; + SDL_DisplayModeData *data = mode->driverdata; LONG status; #ifdef DEBUG_MODES @@ -842,7 +844,7 @@ void WIN_RefreshDisplays(_THIS) // Mark all displays as potentially invalid to detect // entries that have actually been removed for (i = 0; i < _this->num_displays; ++i) { - SDL_DisplayData *driverdata = (SDL_DisplayData *)_this->displays[i].driverdata; + SDL_DisplayData *driverdata = _this->displays[i].driverdata; driverdata->IsValid = SDL_FALSE; } @@ -853,7 +855,7 @@ void WIN_RefreshDisplays(_THIS) // Delete any entries still marked as invalid, iterate // in reverse as each delete takes effect immediately for (i = _this->num_displays - 1; i >= 0; --i) { - SDL_DisplayData *driverdata = (SDL_DisplayData *)_this->displays[i].driverdata; + SDL_DisplayData *driverdata = _this->displays[i].driverdata; if (driverdata->IsValid == SDL_FALSE) { SDL_DelVideoDisplay(i); } diff --git a/src/video/windows/SDL_windowsmodes.h b/src/video/windows/SDL_windowsmodes.h index be813f3aa..54faebc2b 100644 --- a/src/video/windows/SDL_windowsmodes.h +++ b/src/video/windows/SDL_windowsmodes.h @@ -23,18 +23,18 @@ #ifndef SDL_windowsmodes_h_ #define SDL_windowsmodes_h_ -typedef struct +struct SDL_DisplayData { WCHAR DeviceName[32]; HMONITOR MonitorHandle; SDL_bool IsValid; SDL_Rect bounds; -} SDL_DisplayData; +}; -typedef struct +struct SDL_DisplayModeData { DEVMODE DeviceMode; -} SDL_DisplayModeData; +}; extern int WIN_InitModes(_THIS); extern int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect); diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index f73869921..e93d57c3a 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -279,7 +279,7 @@ void WIN_SetCursorPos(int x, int y) static void WIN_WarpMouse(SDL_Window *window, float x, float y) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; POINT pt; @@ -313,13 +313,13 @@ static int WIN_SetRelativeMouseMode(SDL_bool enabled) static int WIN_CaptureMouse(SDL_Window *window) { if (window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SetCapture(data->hwnd); } else { SDL_Window *focus_window = SDL_GetMouseFocus(); if (focus_window) { - SDL_WindowData *data = (SDL_WindowData *)focus_window->driverdata; + SDL_WindowData *data = focus_window->driverdata; if (!data->mouse_tracked) { SDL_SetMouseFocus(NULL); } diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index c52a71a3c..7b5b3fdf4 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -561,7 +561,7 @@ static int WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs) /* actual work of WIN_GL_SetupWindow() happens here. */ static int WIN_GL_SetupWindowInternal(_THIS, SDL_Window *window) { - HDC hdc = ((SDL_WindowData *)window->driverdata)->hdc; + HDC hdc = window->driverdata->hdc; PIXELFORMATDESCRIPTOR pfd; int pixel_format = 0; int iAttribs[64]; @@ -698,7 +698,7 @@ SDL_bool WIN_GL_UseEGL(_THIS) SDL_GLContext WIN_GL_CreateContext(_THIS, SDL_Window *window) { - HDC hdc = ((SDL_WindowData *)window->driverdata)->hdc; + HDC hdc = window->driverdata->hdc; HGLRC context, share_context; if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES && WIN_GL_UseEGL(_this)) { @@ -844,7 +844,7 @@ int WIN_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) } } - hdc = ((SDL_WindowData *)window->driverdata)->hdc; + hdc = window->driverdata->hdc; if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC)context)) { return WIN_SetError("wglMakeCurrent()"); } @@ -877,7 +877,7 @@ int WIN_GL_GetSwapInterval(_THIS, int *interval) int WIN_GL_SwapWindow(_THIS, SDL_Window *window) { - HDC hdc = ((SDL_WindowData *)window->driverdata)->hdc; + HDC hdc = window->driverdata->hdc; if (!SwapBuffers(hdc)) { return WIN_SetError("SwapBuffers()"); @@ -895,8 +895,8 @@ void WIN_GL_DeleteContext(_THIS, SDL_GLContext context) SDL_bool WIN_GL_SetPixelFormatFrom(_THIS, SDL_Window *fromWindow, SDL_Window *toWindow) { - HDC hfromdc = ((SDL_WindowData *)fromWindow->driverdata)->hdc; - HDC htodc = ((SDL_WindowData *)toWindow->driverdata)->hdc; + HDC hfromdc = fromWindow->driverdata->hdc; + HDC htodc = toWindow->driverdata->hdc; BOOL result; /* get the pixel format of the fromWindow */ diff --git a/src/video/windows/SDL_windowsopengles.c b/src/video/windows/SDL_windowsopengles.c index be88defc6..dd89ffd11 100644 --- a/src/video/windows/SDL_windowsopengles.c +++ b/src/video/windows/SDL_windowsopengles.c @@ -64,7 +64,7 @@ SDL_GLContext WIN_GLES_CreateContext(_THIS, SDL_Window *window) { SDL_GLContext context; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; #if SDL_VIDEO_OPENGL_WGL if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES && @@ -106,7 +106,7 @@ SDL_EGL_SwapWindow_impl(WIN) int WIN_GLES_SetupWindow(_THIS, SDL_Window *window) { /* The current context is lost in here; save it and reset it. */ - SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windowdata = window->driverdata; SDL_Window *current_win = SDL_GL_GetCurrentWindow(); SDL_GLContext current_ctx = SDL_GL_GetCurrentContext(); @@ -135,7 +135,7 @@ SDL_EGL_SwapWindow_impl(WIN) EGLSurface WIN_GLES_GetEGLSurface(_THIS, SDL_Window *window) { - SDL_WindowData *windowdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windowdata = window->driverdata; return windowdata->egl_surface; } diff --git a/src/video/windows/SDL_windowsshape.c b/src/video/windows/SDL_windowsshape.c index 9293d2778..dbf197d4c 100644 --- a/src/video/windows/SDL_windowsshape.c +++ b/src/video/windows/SDL_windowsshape.c @@ -95,7 +95,7 @@ int Win32_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_Windo SDL_TraverseShapeTree(data->mask_tree, &CombineRectRegions, &mask_region); SDL_assert(mask_region != NULL); - SetWindowRgn(((SDL_WindowData *)(shaper->window->driverdata))->hwnd, mask_region, TRUE); + SetWindowRgn(shaper->window->driverdata->hwnd, mask_region, TRUE); return 0; } diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 43fbc8545..d010ce139 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -76,7 +76,7 @@ extern void D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height); static void WIN_DeleteDevice(SDL_VideoDevice *device) { - SDL_VideoData *data = (SDL_VideoData *)device->driverdata; + SDL_VideoData *data = device->driverdata; SDL_UnregisterApp(); #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) @@ -104,7 +104,7 @@ static SDL_VideoDevice *WIN_CreateDevice(void) /* Initialize all variables that we clean on shutdown */ device = (SDL_VideoDevice *)SDL_calloc(1, sizeof(SDL_VideoDevice)); if (device) { - data = (struct SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); + data = (SDL_VideoData *)SDL_calloc(1, sizeof(SDL_VideoData)); } else { data = NULL; } @@ -270,7 +270,7 @@ VideoBootStrap WINDOWS_bootstrap = { static BOOL WIN_DeclareDPIAwareUnaware(_THIS) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data->SetProcessDpiAwarenessContext) { return data->SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE); @@ -285,7 +285,7 @@ static BOOL WIN_DeclareDPIAwareUnaware(_THIS) static BOOL WIN_DeclareDPIAwareSystem(_THIS) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data->SetProcessDpiAwarenessContext) { /* Windows 10, version 1607 */ @@ -304,7 +304,7 @@ static BOOL WIN_DeclareDPIAwareSystem(_THIS) static BOOL WIN_DeclareDPIAwarePerMonitor(_THIS) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data->SetProcessDpiAwarenessContext) { /* Windows 10, version 1607 */ @@ -325,7 +325,7 @@ static BOOL WIN_DeclareDPIAwarePerMonitorV2(_THIS) #if defined(__XBOXONE__) || defined(__XBOXSERIES__) return FALSE; #else - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; /* Declare DPI aware (may have been done in external code or a manifest, as well) */ if (data->SetProcessDpiAwarenessContext) { @@ -361,7 +361,7 @@ static BOOL WIN_DeclareDPIAwarePerMonitorV2(_THIS) #ifdef HIGHDPI_DEBUG static const char *WIN_GetDPIAwareness(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data->GetThreadDpiAwarenessContext && data->AreDpiAwarenessContextsEqual) { DPI_AWARENESS_CONTEXT context = data->GetThreadDpiAwarenessContext(); @@ -400,7 +400,7 @@ static void WIN_InitDPIAwareness(_THIS) static void WIN_InitDPIScaling(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (SDL_GetHintBoolean("SDL_WINDOWS_DPI_SCALING", SDL_TRUE)) { WIN_DeclareDPIAwarePerMonitorV2(_this); @@ -411,7 +411,7 @@ static void WIN_InitDPIScaling(_THIS) int WIN_VideoInit(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; WIN_InitDPIAwareness(_this); WIN_InitDPIScaling(_this); @@ -525,7 +525,7 @@ D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface) return SDL_FALSE; } -int SDL_Direct3D9GetAdapterIndex(int displayIndex) +int SDL_Direct3D9GetAdapterIndex(SDL_DisplayID displayID) { void *pD3DDLL; IDirect3D9 *pD3D; @@ -533,7 +533,7 @@ int SDL_Direct3D9GetAdapterIndex(int displayIndex) SDL_SetError("Unable to create Direct3D interface"); return D3DADAPTER_DEFAULT; } else { - SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex); + SDL_DisplayData *pData = SDL_GetDisplayDriverData(displayID); int adapterIndex = D3DADAPTER_DEFAULT; if (pData == NULL) { @@ -599,8 +599,7 @@ static SDL_bool DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory) } #endif -SDL_bool -SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex) +SDL_bool SDL_DXGIGetOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex) { #if !HAVE_DXGI_H if (adapterIndex) { @@ -612,7 +611,7 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex) SDL_SetError("SDL was compiled without DXGI support due to missing dxgi.h header"); return SDL_FALSE; #else - SDL_DisplayData *pData = (SDL_DisplayData *)SDL_GetDisplayDriverData(displayIndex); + SDL_DisplayData *pData = SDL_GetDisplayDriverData(displayID); void *pDXGIDLL; char *displayName; int nAdapter, nOutput; @@ -681,7 +680,7 @@ SDL_bool WIN_IsPerMonitorV2DPIAware(_THIS) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data->AreDpiAwarenessContextsEqual && data->GetThreadDpiAwarenessContext) { /* Windows 10, version 1607 */ diff --git a/src/video/windows/SDL_windowsvideo.h b/src/video/windows/SDL_windowsvideo.h index ab795b100..27484a9f8 100644 --- a/src/video/windows/SDL_windowsvideo.h +++ b/src/video/windows/SDL_windowsvideo.h @@ -364,7 +364,7 @@ typedef struct tagINPUTCONTEXT2 /* Private display data */ -typedef struct SDL_VideoData +struct SDL_VideoData { int render; @@ -457,7 +457,7 @@ typedef struct SDL_VideoData BYTE pre_hook_key_state[256]; UINT _SDL_WAKEUP; -} SDL_VideoData; +}; extern SDL_bool g_WindowsEnableMessageLoop; extern SDL_bool g_WindowsEnableMenuMnemonics; diff --git a/src/video/windows/SDL_windowsvulkan.c b/src/video/windows/SDL_windowsvulkan.c index 5fa3d367e..77015866f 100644 --- a/src/video/windows/SDL_windowsvulkan.c +++ b/src/video/windows/SDL_windowsvulkan.c @@ -131,7 +131,7 @@ SDL_bool WIN_Vulkan_CreateSurface(_THIS, VkInstance instance, VkSurfaceKHR *surface) { - SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windowData = window->driverdata; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr; PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR = diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index a3b5ab9e2..90a13d3e4 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -194,7 +194,7 @@ static void WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, BOOL static void WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_bool use_current) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; DWORD style; BOOL menu; @@ -210,7 +210,7 @@ static void WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, static void WIN_SetWindowPositionInternal(_THIS, SDL_Window *window, UINT flags) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; HWND top; int x, y; @@ -278,7 +278,7 @@ static int WIN_GetScalingDPIForHWND(const SDL_VideoData *videodata, HWND hwnd) static int SetupWindowData(_THIS, SDL_Window *window, HWND hwnd, HWND parent, SDL_bool created) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_WindowData *data; /* Allocate the window data */ @@ -438,7 +438,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, HWND hwnd, HWND parent, SD static void CleanupWindowData(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data) { SDL_DelHintCallback(SDL_HINT_MOUSE_RELATIVE_MODE_CENTER, WIN_MouseRelativeModeCenterChanged, data); @@ -613,7 +613,7 @@ int WIN_CreateWindowFrom(_THIS, SDL_Window *window, const void *data) void WIN_SetWindowTitle(_THIS, SDL_Window *window) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + HWND hwnd = window->driverdata->hwnd; LPTSTR title = WIN_UTF8ToString(window->title); SetWindowText(hwnd, title); SDL_free(title); @@ -623,7 +623,7 @@ void WIN_SetWindowTitle(_THIS, SDL_Window *window) void WIN_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + HWND hwnd = window->driverdata->hwnd; HICON hicon = NULL; BYTE *icon_bmp; int icon_len, mask_len, row_len, y; @@ -693,7 +693,7 @@ void WIN_SetWindowSize(_THIS, SDL_Window *window) int WIN_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right) { #if defined(__XBOXONE__) || defined(__XBOXSERIES__) - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + HWND hwnd = window->driverdata->hwnd; RECT rcClient; /* rcClient stores the size of the inner window, while rcWindow stores the outer size relative to the top-left @@ -707,7 +707,7 @@ int WIN_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int return 0; #else /*!defined(__XBOXONE__) && !defined(__XBOXSERIES__)*/ - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + HWND hwnd = window->driverdata->hwnd; RECT rcClient, rcWindow; POINT ptDiff; @@ -759,7 +759,7 @@ int WIN_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int void WIN_GetWindowSizeInPixels(_THIS, SDL_Window *window, int *w, int *h) { - const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata); + const SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; RECT rect; @@ -778,7 +778,7 @@ void WIN_ShowWindow(_THIS, SDL_Window *window) HWND hwnd; int nCmdShow; - hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + hwnd = window->driverdata->hwnd; nCmdShow = SDL_GetHintBoolean(SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN, SDL_FALSE) ? SW_SHOWNA : SW_SHOW; style = GetWindowLong(hwnd, GWL_EXSTYLE); if (style & WS_EX_NOACTIVATE) { @@ -789,7 +789,7 @@ void WIN_ShowWindow(_THIS, SDL_Window *window) void WIN_HideWindow(_THIS, SDL_Window *window) { - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + HWND hwnd = window->driverdata->hwnd; ShowWindow(hwnd, SW_HIDE); } @@ -810,7 +810,7 @@ void WIN_RaiseWindow(_THIS, SDL_Window *window) DWORD dwMyID = 0u; DWORD dwCurID = 0u; - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + HWND hwnd = window->driverdata->hwnd; if (bForce) { hCurWnd = GetForegroundWindow(); dwMyID = GetCurrentThreadId(); @@ -831,7 +831,7 @@ void WIN_RaiseWindow(_THIS, SDL_Window *window) void WIN_MaximizeWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; data->expected_resize = SDL_TRUE; ShowWindow(hwnd, SW_MAXIMIZE); @@ -840,13 +840,13 @@ void WIN_MaximizeWindow(_THIS, SDL_Window *window) void WIN_MinimizeWindow(_THIS, SDL_Window *window) { - HWND hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + HWND hwnd = window->driverdata->hwnd; ShowWindow(hwnd, SW_MINIMIZE); } void WIN_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; DWORD style; @@ -862,7 +862,7 @@ void WIN_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered) void WIN_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; DWORD style; @@ -875,7 +875,7 @@ void WIN_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) void WIN_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; if (on_top) { SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); @@ -886,7 +886,7 @@ void WIN_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) void WIN_RestoreWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; data->expected_resize = SDL_TRUE; ShowWindow(hwnd, SW_RESTORE); @@ -899,8 +899,8 @@ void WIN_RestoreWindow(_THIS, SDL_Window *window) void WIN_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) { #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) - SDL_DisplayData *displaydata = (SDL_DisplayData *)display->driverdata; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_DisplayData *displaydata = display->driverdata; + SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; MONITORINFO minfo; DWORD style; @@ -983,9 +983,8 @@ void WIN_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *displa #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) void WIN_UpdateWindowICCProfile(SDL_Window *window, SDL_bool send_event) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); - SDL_DisplayData *displaydata = display ? (SDL_DisplayData *)display->driverdata : NULL; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); if (displaydata) { HDC hdc = CreateDCW(displaydata->DeviceName, NULL, NULL, NULL); @@ -1013,7 +1012,7 @@ void WIN_UpdateWindowICCProfile(SDL_Window *window, SDL_bool send_event) void * WIN_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; char *filename_utf8; void *iccProfileData = NULL; @@ -1032,7 +1031,7 @@ WIN_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size) static void WIN_GrabKeyboard(SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; HMODULE module; if (data->keyboard_hook) { @@ -1066,7 +1065,7 @@ static void WIN_GrabKeyboard(SDL_Window *window) void WIN_UngrabKeyboard(SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data->keyboard_hook) { UnhookWindowsHookEx(data->keyboard_hook); @@ -1192,7 +1191,7 @@ void SDL_HelperWindowDestroy(void) #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) void WIN_OnWindowEnter(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data == NULL || !data->hwnd) { /* The window wasn't fully initialized */ @@ -1206,7 +1205,7 @@ void WIN_OnWindowEnter(_THIS, SDL_Window *window) void WIN_UpdateClipCursor(SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; SDL_Mouse *mouse = SDL_GetMouse(); RECT rect, clipped_rect; @@ -1307,7 +1306,7 @@ int WIN_SetWindowOpacity(_THIS, SDL_Window *window, float opacity) #if defined(__XBOXONE__) || defined(__XBOXSERIES__) return -1; #else - const SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + const SDL_WindowData *data = window->driverdata; HWND hwnd = data->hwnd; const LONG style = GetWindowLong(hwnd, GWL_EXSTYLE); @@ -1345,7 +1344,7 @@ int WIN_SetWindowOpacity(_THIS, SDL_Window *window, float opacity) */ void WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y) { - const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata); + const SDL_WindowData *data = window->driverdata; const SDL_VideoData *videodata = data->videodata; if (!videodata->dpi_scaling_enabled) { @@ -1358,7 +1357,7 @@ void WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y) void WIN_ClientPointToSDLFloat(const SDL_Window *window, LONG x, LONG y, float *xOut, float *yOut) { - const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata); + const SDL_WindowData *data = window->driverdata; const SDL_VideoData *videodata = data->videodata; if (videodata->dpi_scaling_enabled) { @@ -1377,7 +1376,7 @@ void WIN_ClientPointToSDLFloat(const SDL_Window *window, LONG x, LONG y, float * */ void WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y) { - const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata); + const SDL_WindowData *data = window->driverdata; const SDL_VideoData *videodata = data->videodata; if (!videodata->dpi_scaling_enabled) { @@ -1390,7 +1389,7 @@ void WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y) void WIN_ClientPointFromSDLFloat(const SDL_Window *window, float x, float y, LONG *xOut, LONG *yOut) { - const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata); + const SDL_WindowData *data = window->driverdata; const SDL_VideoData *videodata = data->videodata; if (videodata->dpi_scaling_enabled) { @@ -1405,7 +1404,7 @@ void WIN_ClientPointFromSDLFloat(const SDL_Window *window, float x, float y, LON #if !defined(__XBOXONE__) && !defined(__XBOXSERIES__) void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept) { - const SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + const SDL_WindowData *data = window->driverdata; DragAcceptFiles(data->hwnd, accept ? TRUE : FALSE); } @@ -1415,7 +1414,7 @@ int WIN_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation) SDL_zero(desc); desc.cbSize = sizeof(desc); - desc.hwnd = ((SDL_WindowData *)window->driverdata)->hwnd; + desc.hwnd = window->driverdata->hwnd; switch (operation) { case SDL_FLASH_CANCEL: desc.dwFlags = FLASHW_STOP; diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index 4490f48d7..9f263bed3 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -34,7 +34,7 @@ extern "C" { #endif -typedef struct +struct SDL_WindowData { SDL_Window *window; HWND hwnd; @@ -72,7 +72,7 @@ typedef struct * between dpi-scaled points and pixels. Only used if videodata->dpi_scaling_enabled. */ int scaling_dpi; -} SDL_WindowData; +}; extern int WIN_CreateWindow(_THIS, SDL_Window *window); extern int WIN_CreateWindowFrom(_THIS, SDL_Window *window, const void *data); diff --git a/src/video/winrt/SDL_winrtgamebar.cpp b/src/video/winrt/SDL_winrtgamebar.cpp index fba7eefed..a2c87bc02 100644 --- a/src/video/winrt/SDL_winrtgamebar.cpp +++ b/src/video/winrt/SDL_winrtgamebar.cpp @@ -144,7 +144,7 @@ static void WINRT_HandleGameBarIsInputRedirected_NonMainThread(Platform::Object void WINRT_InitGameBar(_THIS) { - SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *driverdata = _this->driverdata; IGameBarStatics_ *gameBar = WINRT_GetGameBar(); if (gameBar) { /* GameBar.IsInputRedirected events can come in via something other than @@ -173,7 +173,7 @@ void WINRT_QuitGameBar(_THIS) if (gameBar == NULL) { return; } - driverdata = (SDL_VideoData *)_this->driverdata; + driverdata = _this->driverdata; if (driverdata->gameBarIsInputRedirectedToken.Value) { gameBar->remove_IsInputRedirectedChanged(driverdata->gameBarIsInputRedirectedToken); driverdata->gameBarIsInputRedirectedToken.Value = 0; diff --git a/src/video/winrt/SDL_winrtopengles.cpp b/src/video/winrt/SDL_winrtopengles.cpp index cdda759ad..3ce746b5e 100644 --- a/src/video/winrt/SDL_winrtopengles.cpp +++ b/src/video/winrt/SDL_winrtopengles.cpp @@ -54,7 +54,7 @@ static const int ANGLE_D3D_FEATURE_LEVEL_ANY = 0; extern "C" int WINRT_GLES_LoadLibrary(_THIS, const char *path) { - SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *video_data = _this->driverdata; if (SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0) != 0) { return -1; @@ -186,7 +186,7 @@ WINRT_GLES_LoadLibrary(_THIS, const char *path) extern "C" void WINRT_GLES_UnloadLibrary(_THIS) { - SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *video_data = _this->driverdata; /* Release SDL's own COM reference to the ANGLE/WinRT IWinrtEglWindow */ if (video_data->winrtEglWindow) { diff --git a/src/video/winrt/SDL_winrtpointerinput.cpp b/src/video/winrt/SDL_winrtpointerinput.cpp index 44e8b8100..c4030dde4 100644 --- a/src/video/winrt/SDL_winrtpointerinput.cpp +++ b/src/video/winrt/SDL_winrtpointerinput.cpp @@ -57,7 +57,7 @@ WINRT_TransformCursorPosition(SDL_Window *window, return rawPosition; } - SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata; + SDL_WindowData *windowData = window->driverdata; if (windowData->coreWindow == nullptr) { // For some reason, the window isn't associated with a CoreWindow. // This might end up being the case as XAML support is extended. diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index 768eda633..3d6216ab6 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -94,7 +94,7 @@ SDL_Window *WINRT_GlobalSDLWindow = NULL; static void WINRT_DeleteDevice(SDL_VideoDevice *device) { if (device->driverdata) { - SDL_VideoData *video_data = (SDL_VideoData *)device->driverdata; + SDL_VideoData *video_data = device->driverdata; if (video_data->winrtEglWindow) { video_data->winrtEglWindow->Release(); } @@ -229,7 +229,7 @@ static void SDLCALL WINRT_SetDisplayOrientationsPreference(void *userdata, const int WINRT_VideoInit(_THIS) { - SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *driverdata = _this->driverdata; if (WINRT_InitModes(_this) < 0) { return -1; } @@ -483,7 +483,7 @@ static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMod void WINRT_VideoQuit(_THIS) { - SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *driverdata = _this->driverdata; if (driverdata && driverdata->displayRequest) { driverdata->displayRequest->Release(); driverdata->displayRequest = NULL; @@ -498,7 +498,7 @@ extern "C" Uint32 WINRT_DetectWindowFlags(SDL_Window *window) { Uint32 latestFlags = 0; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; bool is_fullscreen = false; #if SDL_WINRT_USE_APPLICATIONVIEW @@ -511,7 +511,7 @@ WINRT_DetectWindowFlags(SDL_Window *window) if (data->coreWindow.Get()) { if (is_fullscreen) { - SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window); + SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); int w = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Width); int h = WINRT_DIPS_TO_PHYSICAL_PIXELS(data->coreWindow->Bounds.Height); @@ -638,7 +638,7 @@ int WINRT_CreateWindow(_THIS, SDL_Window *window) data->egl_surface = EGL_NO_SURFACE; } else { /* OpenGL ES 2 was reuqested. Set up an EGL surface. */ - SDL_VideoData *video_data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *video_data = _this->driverdata; /* Call SDL_EGL_ChooseConfig and eglCreateWindowSurface directly, * rather than via SDL_EGL_CreateSurface, as older versions of @@ -753,7 +753,7 @@ int WINRT_CreateWindow(_THIS, SDL_Window *window) void WINRT_SetWindowSize(_THIS, SDL_Window *window) { #if NTDDI_VERSION >= NTDDI_WIN10 - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; const Windows::Foundation::Size size(window->w, window->h); data->appView->TryResizeView(size); // TODO, WinRT: return failure (to caller?) from TryResizeView() #endif @@ -762,7 +762,7 @@ void WINRT_SetWindowSize(_THIS, SDL_Window *window) void WINRT_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen) { #if NTDDI_VERSION >= NTDDI_WIN10 - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; bool isWindowActive = WINRT_IsCoreWindowActive(data->coreWindow.Get()); if (isWindowActive) { if (fullscreen) { @@ -780,7 +780,7 @@ void WINRT_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *disp void WINRT_DestroyWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (WINRT_GlobalSDLWindow == window) { WINRT_GlobalSDLWindow = NULL; @@ -796,7 +796,7 @@ void WINRT_DestroyWindow(_THIS, SDL_Window *window) int WINRT_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; info->subsystem = SDL_SYSWM_WINRT; info->info.winrt.window = reinterpret_cast(data->coreWindow.Get()); @@ -849,7 +849,7 @@ done: void WINRT_SuspendScreenSaver(_THIS) { - SDL_VideoData *driverdata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *driverdata = _this->driverdata; if (driverdata && driverdata->displayRequest) { ABI::Windows::System::Display::IDisplayRequest *displayRequest = (ABI::Windows::System::Display::IDisplayRequest *)driverdata->displayRequest; if (_this->suspend_screensaver) { diff --git a/src/video/winrt/SDL_winrtvideo_cpp.h b/src/video/winrt/SDL_winrtvideo_cpp.h index 069ecec2c..069fff4fb 100644 --- a/src/video/winrt/SDL_winrtvideo_cpp.h +++ b/src/video/winrt/SDL_winrtvideo_cpp.h @@ -39,7 +39,7 @@ extern "C" { } /* Private display data */ -typedef struct SDL_VideoData +struct SDL_VideoData { /* An object created by ANGLE/WinRT (OpenGL ES 2 for WinRT) that gets * passed to eglGetDisplay and eglCreateWindowSurface: @@ -56,7 +56,7 @@ typedef struct SDL_VideoData * It's casted to 'IUnknown *', to help with building SDL. */ IUnknown *displayRequest; -} SDL_VideoData; +}; /* The global, WinRT, SDL Window. For now, SDL/WinRT only supports one window (due to platform limitations of diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c index de3626709..92c31e061 100644 --- a/src/video/x11/SDL_x11clipboard.c +++ b/src/video/x11/SDL_x11clipboard.c @@ -30,7 +30,7 @@ /* Get any application owned window handle for clipboard association */ static Window GetWindow(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; /* We create an unmapped window that exists just to manage the clipboard, since X11 selection data is tied to a specific window and dies with it. @@ -115,7 +115,7 @@ Atom X11_GetSDLCutBufferClipboardInternalFormat(Display *display, enum ESDLX11Cl static int SetSelectionText(_THIS, const char *text, Atom selection_type) { - Display *display = ((SDL_VideoData *)_this->driverdata)->display; + Display *display = _this->driverdata->display; Window window; /* Get the SDL window that will own the selection */ @@ -139,7 +139,7 @@ static int SetSelectionText(_THIS, const char *text, Atom selection_type) static char *GetSlectionText(_THIS, Atom selection_type) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Display *display = videodata->display; Atom format; Window window; @@ -216,7 +216,7 @@ static char *GetSlectionText(_THIS, Atom selection_type) int X11_SetClipboardText(_THIS, const char *text) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Atom XA_CLIPBOARD = X11_XInternAtom(videodata->display, "CLIPBOARD", 0); if (XA_CLIPBOARD == None) { return SDL_SetError("Couldn't access X clipboard"); @@ -232,7 +232,7 @@ int X11_SetPrimarySelectionText(_THIS, const char *text) char * X11_GetClipboardText(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Atom XA_CLIPBOARD = X11_XInternAtom(videodata->display, "CLIPBOARD", 0); if (XA_CLIPBOARD == None) { SDL_SetError("Couldn't access X clipboard"); diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 32a5f8ee2..a01af29b0 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -349,7 +349,7 @@ static void X11_HandleGenericEvent(SDL_VideoData *videodata, XEvent *xev) static unsigned X11_GetNumLockModifierMask(_THIS) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; Display *display = viddata->display; unsigned num_mask = 0; int i, j; @@ -374,7 +374,7 @@ static unsigned X11_GetNumLockModifierMask(_THIS) static unsigned X11_GetScrollLockModifierMask(_THIS) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; Display *display = viddata->display; unsigned num_mask = 0; int i, j; @@ -399,7 +399,7 @@ static unsigned X11_GetScrollLockModifierMask(_THIS) void X11_ReconcileKeyboardState(_THIS) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; Display *display = viddata->display; char keys[32]; int keycode; @@ -506,7 +506,7 @@ static void X11_DispatchUnmapNotify(SDL_WindowData *data) static void InitiateWindowMove(_THIS, const SDL_WindowData *data, const SDL_Point *point) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; SDL_Window *window = data->window; Display *display = viddata->display; XEvent evt; @@ -531,7 +531,7 @@ static void InitiateWindowMove(_THIS, const SDL_WindowData *data, const SDL_Poin static void InitiateWindowResize(_THIS, const SDL_WindowData *data, const SDL_Point *point, int direction) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *viddata = _this->driverdata; SDL_Window *window = data->window; Display *display = viddata->display; XEvent evt; @@ -614,7 +614,7 @@ static void X11_UpdateUserTime(SDL_WindowData *data, const unsigned long latest) static void X11_HandleClipboardEvent(_THIS, const XEvent *xevent) { int i; - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Display *display = videodata->display; SDL_assert(videodata->clipboard_window != None); @@ -755,7 +755,7 @@ static int XLookupStringAsUTF8(XKeyEvent *event_struct, char *buffer_return, int static void X11_DispatchEvent(_THIS, XEvent *xevent) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Display *display; SDL_WindowData *data; int orig_event_type; @@ -923,7 +923,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent) #if SDL_VIDEO_DRIVER_X11_XFIXES { /* Only create the barriers if we have input focus */ - SDL_WindowData *windowdata = (SDL_WindowData *)data->window->driverdata; + SDL_WindowData *windowdata = data->window->driverdata; if ((data->pointer_barrier_active == SDL_TRUE) && windowdata->window->flags & SDL_WINDOW_INPUT_FOCUS) { X11_ConfineCursorWithFlags(_this, windowdata->window, &windowdata->barrier_rect, X11_BARRIER_HANDLED_BY_EVENT); } @@ -1569,7 +1569,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent) static void X11_HandleFocusChanges(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; int i; if (videodata && videodata->windowlist) { @@ -1606,9 +1606,9 @@ static SDL_bool X11_PollEvent(Display *display, XEvent *event) void X11_SendWakeupEvent(_THIS, SDL_Window *window) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Display *req_display = data->request_display; - Window xwindow = ((SDL_WindowData *)window->driverdata)->xwindow; + Window xwindow = window->driverdata->xwindow; XClientMessageEvent event; SDL_memset(&event, 0, sizeof(XClientMessageEvent)); @@ -1626,7 +1626,7 @@ void X11_SendWakeupEvent(_THIS, SDL_Window *window) int X11_WaitEventTimeout(_THIS, Sint64 timeoutNS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Display *display; XEvent xevent; display = videodata->display; @@ -1676,7 +1676,7 @@ int X11_WaitEventTimeout(_THIS, Sint64 timeoutNS) void X11_PumpEvents(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; XEvent xevent; int i; @@ -1729,7 +1729,7 @@ void X11_PumpEvents(_THIS) void X11_SuspendScreenSaver(_THIS) { #if SDL_VIDEO_DRIVER_X11_XSCRNSAVER - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; int dummy; int major_version, minor_version; #endif /* SDL_VIDEO_DRIVER_X11_XSCRNSAVER */ diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c index 466ded849..fa0617556 100644 --- a/src/video/x11/SDL_x11framebuffer.c +++ b/src/video/x11/SDL_x11framebuffer.c @@ -51,7 +51,7 @@ static SDL_bool have_mitshm(Display *dpy) int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; XGCValues gcv; XVisualInfo vinfo; @@ -146,7 +146,7 @@ int X11_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, int X11_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; int i; int x, y, w, h; @@ -224,7 +224,7 @@ int X11_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects void X11_DestroyWindowFramebuffer(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display; if (data == NULL) { diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index 3a711654d..2dc5d8190 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -70,7 +70,7 @@ static Uint32 X11_KeyCodeToUcs4(_THIS, KeyCode keycode, unsigned char group) KeySym X11_KeyCodeToSym(_THIS, KeyCode keycode, unsigned char group) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; KeySym keysym; #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM @@ -106,7 +106,7 @@ X11_KeyCodeToSym(_THIS, KeyCode keycode, unsigned char group) int X11_InitKeyboard(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; int i = 0; int j = 0; int min_keycode, max_keycode; @@ -312,7 +312,7 @@ int X11_InitKeyboard(_THIS) void X11_UpdateKeymap(_THIS, SDL_bool send_event) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; int i; SDL_Scancode scancode; SDL_Keycode keymap[SDL_NUM_SCANCODES]; @@ -374,7 +374,7 @@ void X11_UpdateKeymap(_THIS, SDL_bool send_event) void X11_QuitKeyboard(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM if (data->xkb) { @@ -391,7 +391,7 @@ void X11_QuitKeyboard(_THIS) static void X11_ResetXIM(_THIS) { #ifdef X_HAVE_UTF8_STRING - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; int i; if (videodata && videodata->windowlist) { @@ -437,13 +437,13 @@ void X11_SetTextInputRect(_THIS, const SDL_Rect *rect) SDL_bool X11_HasScreenKeyboardSupport(_THIS) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; return videodata->is_steam_deck; } void X11_ShowScreenKeyboard(_THIS, SDL_Window *window) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; if (videodata->is_steam_deck) { /* For more documentation of the URL parameters, see: @@ -460,7 +460,7 @@ void X11_ShowScreenKeyboard(_THIS, SDL_Window *window) void X11_HideScreenKeyboard(_THIS, SDL_Window *window) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; if (videodata->is_steam_deck) { SDL_OpenURL("steam://close/keyboard"); @@ -471,7 +471,7 @@ void X11_HideScreenKeyboard(_THIS, SDL_Window *window) SDL_bool X11_IsScreenKeyboardShown(_THIS, SDL_Window *window) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; return videodata->steam_keyboard_open; } diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index 468e06a97..ac8fedda0 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -403,9 +403,8 @@ static int X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data) const SDL_MessageBoxData *messageboxdata = data->messageboxdata; if (messageboxdata->window) { - SDL_DisplayData *displaydata = - (SDL_DisplayData *)SDL_GetDisplayForWindow(messageboxdata->window)->driverdata; - windowdata = (SDL_WindowData *)messageboxdata->window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(messageboxdata->window); + windowdata = messageboxdata->window->driverdata; data->screen = displaydata->screen; } else { data->screen = DefaultScreen(display); @@ -470,7 +469,7 @@ static int X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data) const SDL_VideoDevice *dev = SDL_GetVideoDevice(); if ((dev) && (dev->displays) && (dev->num_displays > 0)) { const SDL_VideoDisplay *dpy = &dev->displays[0]; - const SDL_DisplayData *dpydata = (SDL_DisplayData *)dpy->driverdata; + const SDL_DisplayData *dpydata = dpy->driverdata; x = dpydata->x + ((dpy->current_mode.pixel_w - data->dialog_width) / 2); y = dpydata->y + ((dpy->current_mode.pixel_h - data->dialog_height) / 3); } else { /* oh well. This will misposition on a multi-head setup. Init first next time. */ diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index c1b368a92..5cf0801e3 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -393,30 +393,30 @@ static int X11_AddXRandRDisplay(_THIS, Display *dpy, int screen, RROutput output static void X11_HandleXRandROutputChange(_THIS, const XRROutputChangeNotifyEvent *ev) { - const int num_displays = SDL_GetNumVideoDisplays(); + SDL_DisplayID *displays; SDL_VideoDisplay *display = NULL; - int displayidx = -1; int i; #if 0 printf("XRROutputChangeNotifyEvent! [output=%u, crtc=%u, mode=%u, rotation=%u, connection=%u]", (unsigned int) ev->output, (unsigned int) ev->crtc, (unsigned int) ev->mode, (unsigned int) ev->rotation, (unsigned int) ev->connection); #endif - for (i = 0; i < num_displays; i++) { - SDL_VideoDisplay *thisdisplay = SDL_GetDisplay(i); - const SDL_DisplayData *displaydata = (const SDL_DisplayData *)thisdisplay->driverdata; - if (displaydata->xrandr_output == ev->output) { - display = thisdisplay; - displayidx = i; - break; + displays = SDL_GetDisplays(NULL); + if (displays) { + for (i = 0; displays[i]; ++i) { + SDL_VideoDisplay *thisdisplay = SDL_GetVideoDisplay(displays[i]); + const SDL_DisplayData *displaydata = thisdisplay->driverdata; + if (displaydata->xrandr_output == ev->output) { + display = thisdisplay; + break; + } } + SDL_free(displays); } - SDL_assert((displayidx == -1) == (display == NULL)); - if (ev->connection == RR_Disconnected) { /* output is going away */ if (display != NULL) { - SDL_DelVideoDisplay(displayidx); + SDL_DelVideoDisplay(display->id); } } else if (ev->connection == RR_Connected) { /* output is coming online */ if (display != NULL) { @@ -445,7 +445,7 @@ static void X11_HandleXRandROutputChange(_THIS, const XRROutputChangeNotifyEvent void X11_HandleXRandREvent(_THIS, const XEvent *xevent) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_assert(xevent->type == (videodata->xrandr_event_base + RRNotify)); switch (((const XRRNotifyEvent *)xevent)->subtype) { @@ -459,7 +459,7 @@ void X11_HandleXRandREvent(_THIS, const XEvent *xevent) static int X11_InitModes_XRandR(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Display *dpy = data->display; const int screencount = ScreenCount(dpy); const int default_screen = DefaultScreen(dpy); @@ -549,7 +549,7 @@ static int GetXftDPI(Display *dpy) static int X11_InitModes_StdXlib(_THIS) { /* !!! FIXME: a lot of copy/paste from X11_InitModes_XRandR in this function. */ - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Display *dpy = data->display; const int default_screen = DefaultScreen(dpy); Screen *screen = ScreenOfDisplay(dpy, default_screen); @@ -640,7 +640,7 @@ int X11_InitModes(_THIS) desktop size. */ #if SDL_VIDEO_DRIVER_X11_XRANDR { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; int xrandr_major, xrandr_minor; /* require at least XRandR v1.3 */ if (CheckXRandR(data->display, &xrandr_major, &xrandr_minor) && @@ -656,7 +656,7 @@ int X11_InitModes(_THIS) void X11_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display) { - SDL_DisplayData *data = (SDL_DisplayData *)sdl_display->driverdata; + SDL_DisplayData *data = sdl_display->driverdata; SDL_DisplayMode mode; /* Unfortunately X11 requires the window to be created with the correct @@ -670,7 +670,7 @@ void X11_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display) #if SDL_VIDEO_DRIVER_X11_XRANDR if (data->use_xrandr) { - Display *display = ((SDL_VideoData *)_this->driverdata)->display; + Display *display = _this->driverdata->display; XRRScreenResources *res; res = X11_XRRGetScreenResources(display, RootWindow(display, data->screen)); @@ -734,8 +734,8 @@ static int SDL_XRRSetScreenSizeErrHandler(Display *d, XErrorEvent *e) int X11_SetDisplayMode(_THIS, SDL_VideoDisplay *sdl_display, SDL_DisplayMode *mode) { - SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; - SDL_DisplayData *data = (SDL_DisplayData *)sdl_display->driverdata; + SDL_VideoData *viddata = _this->driverdata; + SDL_DisplayData *data = sdl_display->driverdata; viddata->last_mode_change_deadline = SDL_GetTicks() + (PENDING_FOCUS_TIME * 2); @@ -827,7 +827,7 @@ void X11_QuitModes(_THIS) int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect) { - SDL_DisplayData *data = (SDL_DisplayData *)sdl_display->driverdata; + SDL_DisplayData *data = sdl_display->driverdata; rect->x = data->x; rect->y = data->y; @@ -839,7 +839,7 @@ int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect) int X11_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *sdl_display, float *ddpi, float *hdpi, float *vdpi) { - SDL_DisplayData *data = (SDL_DisplayData *)sdl_display->driverdata; + SDL_DisplayData *data = sdl_display->driverdata; if (ddpi) { *ddpi = data->ddpi; @@ -856,7 +856,7 @@ int X11_GetDisplayPhysicalDPI(_THIS, SDL_VideoDisplay *sdl_display, float *ddpi, int X11_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *sdl_display, SDL_Rect *rect) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Display *display = data->display; Atom _NET_WORKAREA; int status, real_format; diff --git a/src/video/x11/SDL_x11modes.h b/src/video/x11/SDL_x11modes.h index 1e48bccf4..0dcc9c592 100644 --- a/src/video/x11/SDL_x11modes.h +++ b/src/video/x11/SDL_x11modes.h @@ -23,7 +23,7 @@ #ifndef SDL_x11modes_h_ #define SDL_x11modes_h_ -typedef struct +struct SDL_DisplayData { int screen; Visual *visual; @@ -40,16 +40,16 @@ typedef struct #if SDL_VIDEO_DRIVER_X11_XRANDR RROutput xrandr_output; #endif -} SDL_DisplayData; +}; -typedef struct +struct SDL_DisplayModeData { #if SDL_VIDEO_DRIVER_X11_XRANDR RRMode xrandr_mode; #else int unused; /* just so struct isn't empty. */ #endif -} SDL_DisplayModeData; +}; extern int X11_InitModes(_THIS); extern void X11_GetDisplayModes(_THIS, SDL_VideoDisplay *display); diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c index 0c5b2fec0..03ba8d376 100644 --- a/src/video/x11/SDL_x11mouse.c +++ b/src/video/x11/SDL_x11mouse.c @@ -33,7 +33,7 @@ static Cursor x11_empty_cursor = None; static Display *GetDisplay(void) { - return ((SDL_VideoData *)SDL_GetVideoDevice()->driverdata)->display; + return SDL_GetVideoDevice()->driverdata->display; } static Cursor X11_CreateEmptyCursor() @@ -310,7 +310,7 @@ static int X11_ShowCursor(SDL_Cursor *cursor) SDL_Window *window; for (window = video->windows; window; window = window->next) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (data) { if (x11_cursor != None) { X11_XDefineCursor(display, data->xwindow, x11_cursor); @@ -326,7 +326,7 @@ static int X11_ShowCursor(SDL_Cursor *cursor) static void X11_WarpMouseInternal(Window xwindow, float x, float y) { - SDL_VideoData *videodata = (SDL_VideoData *)SDL_GetVideoDevice()->driverdata; + SDL_VideoData *videodata = SDL_GetVideoDevice()->driverdata; Display *display = videodata->display; #if SDL_VIDEO_DRIVER_X11_XINPUT2 int deviceid = 0; @@ -349,7 +349,7 @@ static void X11_WarpMouseInternal(Window xwindow, float x, float y) static void X11_WarpMouse(SDL_Window *window, float x, float y) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; #if SDL_VIDEO_DRIVER_X11_XFIXES /* If we have no barrier, we need to warp */ @@ -385,7 +385,7 @@ static int X11_CaptureMouse(SDL_Window *window) SDL_Window *mouse_focus = SDL_GetMouseFocus(); if (window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; const unsigned int mask = ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask; Window confined = (data->mouse_grabbed ? data->xwindow : None); const int rc = X11_XGrabPointer(display, data->xwindow, False, @@ -407,9 +407,9 @@ static int X11_CaptureMouse(SDL_Window *window) static Uint32 X11_GetGlobalMouseState(float *x, float *y) { - SDL_VideoData *videodata = (SDL_VideoData *)SDL_GetVideoDevice()->driverdata; + SDL_VideoData *videodata = SDL_GetVideoDevice()->driverdata; + SDL_DisplayID *displays; Display *display = GetDisplay(); - const int num_screens = SDL_GetNumVideoDisplays(); int i; /* !!! FIXME: should we XSync() here first? */ @@ -421,32 +421,36 @@ static Uint32 X11_GetGlobalMouseState(float *x, float *y) /* check if we have this cached since XInput last saw the mouse move. */ /* !!! FIXME: can we just calculate this from XInput's events? */ if (videodata->global_mouse_changed) { - for (i = 0; i < num_screens; i++) { - SDL_DisplayData *data = (SDL_DisplayData *)SDL_GetDisplayDriverData(i); - if (data != NULL) { - Window root, child; - int rootx, rooty, winx, winy; - unsigned int mask; - if (X11_XQueryPointer(display, RootWindow(display, data->screen), &root, &child, &rootx, &rooty, &winx, &winy, &mask)) { - XWindowAttributes root_attrs; - Uint32 buttons = 0; - buttons |= (mask & Button1Mask) ? SDL_BUTTON_LMASK : 0; - buttons |= (mask & Button2Mask) ? SDL_BUTTON_MMASK : 0; - buttons |= (mask & Button3Mask) ? SDL_BUTTON_RMASK : 0; - /* Use the SDL state for the extended buttons - it's better than nothing */ - buttons |= (SDL_GetMouseState(NULL, NULL) & (SDL_BUTTON_X1MASK | SDL_BUTTON_X2MASK)); - /* SDL_DisplayData->x,y point to screen origin, and adding them to mouse coordinates relative to root window doesn't do the right thing - * (observed on dual monitor setup with primary display being the rightmost one - mouse was offset to the right). - * - * Adding root position to root-relative coordinates seems to be a better way to get absolute position. */ - X11_XGetWindowAttributes(display, root, &root_attrs); - videodata->global_mouse_position.x = root_attrs.x + rootx; - videodata->global_mouse_position.y = root_attrs.y + rooty; - videodata->global_mouse_buttons = buttons; - videodata->global_mouse_changed = SDL_FALSE; - break; + displays = SDL_GetDisplays(NULL); + if (displays) { + for (i = 0; displays[i]; ++i) { + SDL_DisplayData *data = SDL_GetDisplayDriverData(displays[i]); + if (data != NULL) { + Window root, child; + int rootx, rooty, winx, winy; + unsigned int mask; + if (X11_XQueryPointer(display, RootWindow(display, data->screen), &root, &child, &rootx, &rooty, &winx, &winy, &mask)) { + XWindowAttributes root_attrs; + Uint32 buttons = 0; + buttons |= (mask & Button1Mask) ? SDL_BUTTON_LMASK : 0; + buttons |= (mask & Button2Mask) ? SDL_BUTTON_MMASK : 0; + buttons |= (mask & Button3Mask) ? SDL_BUTTON_RMASK : 0; + /* Use the SDL state for the extended buttons - it's better than nothing */ + buttons |= (SDL_GetMouseState(NULL, NULL) & (SDL_BUTTON_X1MASK | SDL_BUTTON_X2MASK)); + /* SDL_DisplayData->x,y point to screen origin, and adding them to mouse coordinates relative to root window doesn't do the right thing + * (observed on dual monitor setup with primary display being the rightmost one - mouse was offset to the right). + * + * Adding root position to root-relative coordinates seems to be a better way to get absolute position. */ + X11_XGetWindowAttributes(display, root, &root_attrs); + videodata->global_mouse_position.x = root_attrs.x + rootx; + videodata->global_mouse_position.y = root_attrs.y + rooty; + videodata->global_mouse_buttons = buttons; + videodata->global_mouse_changed = SDL_FALSE; + break; + } } } + SDL_free(displays); } } @@ -476,7 +480,7 @@ void X11_InitMouse(_THIS) void X11_QuitMouse(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; SDL_XInput2DeviceInfo *i; SDL_XInput2DeviceInfo *next; diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index 15a10d2a3..ac94f3a6d 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -232,7 +232,7 @@ int X11_GL_LoadLibrary(_THIS, const char *path) return SDL_SetError("Could not retrieve OpenGL functions"); } - display = ((SDL_VideoData *)_this->driverdata)->display; + display = _this->driverdata->display; if (!_this->gl_data->glXQueryExtension(display, &_this->gl_data->errorBase, &_this->gl_data->eventBase)) { return SDL_SetError("GLX is not supported"); } @@ -335,7 +335,7 @@ static SDL_bool HasExtension(const char *extension, const char *extensions) static void X11_GL_InitExtensions(_THIS) { - Display *display = ((SDL_VideoData *)_this->driverdata)->display; + Display *display = _this->driverdata->display; const int screen = DefaultScreen(display); XVisualInfo *vinfo = NULL; Window w = 0; @@ -689,10 +689,9 @@ SDL_bool X11_GL_UseEGL(_THIS) SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; - int screen = - ((SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata)->screen; + int screen = SDL_GetDisplayDriverDataForWindow(window)->screen; XWindowAttributes xattr; XVisualInfo v, *vinfo; int n; @@ -822,9 +821,9 @@ SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window *window) int X11_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context) { - Display *display = ((SDL_VideoData *)_this->driverdata)->display; + Display *display = _this->driverdata->display; Window drawable = - (context ? ((SDL_WindowData *)window->driverdata)->xwindow : None); + (context ? window->driverdata->xwindow : None); GLXContext glx_context = (GLXContext)context; int rc; @@ -866,10 +865,8 @@ int X11_GL_SetSwapInterval(_THIS, int interval) if ((interval < 0) && (!_this->gl_data->HAS_GLX_EXT_swap_control_tear)) { SDL_SetError("Negative swap interval unsupported in this GL"); } else if (_this->gl_data->glXSwapIntervalEXT) { - Display *display = ((SDL_VideoData *)_this->driverdata)->display; - const SDL_WindowData *windowdata = (SDL_WindowData *) - SDL_GL_GetCurrentWindow() - ->driverdata; + Display *display = _this->driverdata->display; + const SDL_WindowData *windowdata = SDL_GL_GetCurrentWindow()->driverdata; Window drawable = windowdata->xwindow; @@ -911,10 +908,8 @@ int X11_GL_SetSwapInterval(_THIS, int interval) int X11_GL_GetSwapInterval(_THIS, int *interval) { if (_this->gl_data->glXSwapIntervalEXT) { - Display *display = ((SDL_VideoData *)_this->driverdata)->display; - const SDL_WindowData *windowdata = (SDL_WindowData *) - SDL_GL_GetCurrentWindow() - ->driverdata; + Display *display = _this->driverdata->display; + const SDL_WindowData *windowdata = SDL_GL_GetCurrentWindow()->driverdata; Window drawable = windowdata->xwindow; unsigned int allow_late_swap_tearing = 0; unsigned int val = 0; @@ -950,7 +945,7 @@ int X11_GL_GetSwapInterval(_THIS, int *interval) int X11_GL_SwapWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; _this->gl_data->glXSwapBuffers(display, data->xwindow); @@ -959,7 +954,7 @@ int X11_GL_SwapWindow(_THIS, SDL_Window *window) void X11_GL_DeleteContext(_THIS, SDL_GLContext context) { - Display *display = ((SDL_VideoData *)_this->driverdata)->display; + Display *display = _this->driverdata->display; GLXContext glx_context = (GLXContext)context; if (!_this->gl_data) { diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c index 41923966a..ffa68869b 100644 --- a/src/video/x11/SDL_x11opengles.c +++ b/src/video/x11/SDL_x11opengles.c @@ -30,7 +30,7 @@ int X11_GLES_LoadLibrary(_THIS, const char *path) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; /* If the profile requested is not GL ES, switch over to X11_GL functions */ if ((_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) && @@ -92,7 +92,7 @@ SDL_GLContext X11_GLES_CreateContext(_THIS, SDL_Window *window) { SDL_GLContext context; - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; X11_XSync(display, False); @@ -105,7 +105,7 @@ X11_GLES_CreateContext(_THIS, SDL_Window *window) SDL_EGLSurface X11_GLES_GetEGLSurface(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; return data->egl_surface; } diff --git a/src/video/x11/SDL_x11shape.c b/src/video/x11/SDL_x11shape.c index b3edd7327..dfebceb8e 100644 --- a/src/video/x11/SDL_x11shape.c +++ b/src/video/x11/SDL_x11shape.c @@ -115,7 +115,7 @@ int X11_SetWindowShape(SDL_WindowShaper *shaper, SDL_Surface *shape, SDL_WindowS /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */ SDL_CalculateShapeBitmap(shaper->mode, shape, data->bitmap, 8); - windowdata = (SDL_WindowData *)(shaper->window->driverdata); + windowdata = shaper->window->driverdata; shapemask = X11_XCreateBitmapFromData(windowdata->videodata->display, windowdata->xwindow, data->bitmap, shaper->window->w, shaper->window->h); X11_XShapeCombineMask(windowdata->videodata->display, windowdata->xwindow, ShapeBounding, 0, 0, shapemask, ShapeSet); diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index 5a3fb4fcd..02465c49b 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -91,7 +91,7 @@ static int (*orig_x11_errhandler)(Display *, XErrorEvent *) = NULL; static void X11_DeleteDevice(SDL_VideoDevice *device) { - SDL_VideoData *data = (SDL_VideoData *)device->driverdata; + SDL_VideoData *data = device->driverdata; if (device->vulkan_config.loader_handle) { device->Vulkan_UnloadLibrary(device); } @@ -338,7 +338,7 @@ static int X11_CheckWindowManagerErrorHandler(Display *d, XErrorEvent *e) static void X11_CheckWindowManager(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Display *display = data->display; Atom _NET_SUPPORTING_WM_CHECK; int status, real_format; @@ -398,7 +398,7 @@ static void X11_CheckWindowManager(_THIS) int X11_VideoInit(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; /* Get the window class name, usually the name of the application */ data->classname = get_classname(); @@ -476,7 +476,7 @@ int X11_VideoInit(_THIS) void X11_VideoQuit(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (data->clipboard_window) { X11_XDestroyWindow(data->display, data->clipboard_window); diff --git a/src/video/x11/SDL_x11video.h b/src/video/x11/SDL_x11video.h index 858399ce4..f14794c60 100644 --- a/src/video/x11/SDL_x11video.h +++ b/src/video/x11/SDL_x11video.h @@ -64,7 +64,7 @@ /* Private display data */ -typedef struct SDL_VideoData +struct SDL_VideoData { Display *display; Display *request_display; @@ -154,7 +154,7 @@ typedef struct SDL_VideoData SDL_bool is_steam_deck; SDL_bool steam_keyboard_open; -} SDL_VideoData; +}; extern SDL_bool X11_UseDirectColorVisuals(void); diff --git a/src/video/x11/SDL_x11vulkan.c b/src/video/x11/SDL_x11vulkan.c index 5f4153c41..dc85a78b5 100644 --- a/src/video/x11/SDL_x11vulkan.c +++ b/src/video/x11/SDL_x11vulkan.c @@ -42,7 +42,7 @@ typedef uint32_t xcb_visualid_t; int X11_Vulkan_LoadLibrary(_THIS, const char *path) { - SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videoData = _this->driverdata; VkExtensionProperties *extensions = NULL; Uint32 extensionCount = 0; SDL_bool hasSurfaceExtension = SDL_FALSE; @@ -130,7 +130,7 @@ fail: void X11_Vulkan_UnloadLibrary(_THIS) { - SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videoData = _this->driverdata; if (_this->vulkan_config.loader_handle) { if (videoData->vulkan_xlib_xcb_library) { SDL_UnloadObject(videoData->vulkan_xlib_xcb_library); @@ -144,7 +144,7 @@ SDL_bool X11_Vulkan_GetInstanceExtensions(_THIS, unsigned *count, const char **names) { - SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videoData = _this->driverdata; if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); return SDL_FALSE; @@ -171,8 +171,8 @@ SDL_bool X11_Vulkan_CreateSurface(_THIS, VkInstance instance, VkSurfaceKHR *surface) { - SDL_VideoData *videoData = (SDL_VideoData *)_this->driverdata; - SDL_WindowData *windowData = (SDL_WindowData *)window->driverdata; + SDL_VideoData *videoData = _this->driverdata; + SDL_WindowData *windowData = window->driverdata; PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr; if (!_this->vulkan_config.loader_handle) { SDL_SetError("Vulkan is not loaded"); diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 7ff5368bd..d9493079a 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -74,8 +74,8 @@ static Bool X11_XIfEventTimeout(Display *display, XEvent *event_return, Bool (*p static SDL_bool X11_IsWindowMapped(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_VideoData *videodata = _this->driverdata; XWindowAttributes attr; X11_XGetWindowAttributes(videodata->display, data->xwindow, &attr); @@ -89,7 +89,7 @@ static SDL_bool X11_IsWindowMapped(_THIS, SDL_Window *window) #if 0 static SDL_bool X11_IsActionAllowed(SDL_Window *window, Atom action) { - SDL_WindowData *data = (SDL_WindowData *) window->driverdata; + SDL_WindowData *data = window->driverdata; Atom _NET_WM_ALLOWED_ACTIONS = data->videodata->_NET_WM_ALLOWED_ACTIONS; Atom type; Display *display = data->videodata->display; @@ -114,7 +114,7 @@ static SDL_bool X11_IsActionAllowed(SDL_Window *window, Atom action) void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Display *display = videodata->display; /* !!! FIXME: just dereference videodata below instead of copying to locals. */ Atom _NET_WM_STATE = videodata->_NET_WM_STATE; @@ -169,7 +169,7 @@ void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags) Uint32 X11_GetNetWMState(_THIS, SDL_Window *window, Window xwindow) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; Display *display = videodata->display; Atom _NET_WM_STATE = videodata->_NET_WM_STATE; Atom _NET_WM_STATE_HIDDEN = videodata->_NET_WM_STATE_HIDDEN; @@ -255,7 +255,7 @@ X11_GetNetWMState(_THIS, SDL_Window *window, Window xwindow) static int SetupWindowData(_THIS, SDL_Window *window, Window w, BOOL created) { - SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *videodata = _this->driverdata; SDL_WindowData *data; int numwindows = videodata->numwindows; int windowlistlength = videodata->windowlistlength; @@ -286,11 +286,7 @@ static int SetupWindowData(_THIS, SDL_Window *window, Window w, BOOL created) windowlist[numwindows] = data; videodata->numwindows++; } else { - windowlist = - (SDL_WindowData **)SDL_realloc(windowlist, - (numwindows + - 1) * - sizeof(*windowlist)); + windowlist = (SDL_WindowData **)SDL_realloc(windowlist, (numwindows + 1) * sizeof(*windowlist)); if (windowlist == NULL) { SDL_free(data); return SDL_OutOfMemory(); @@ -375,9 +371,8 @@ static void SetWindowBordered(Display *display, int screen, Window window, SDL_b int X11_CreateWindow(_THIS, SDL_Window *window) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; - SDL_DisplayData *displaydata = - (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_VideoData *data = _this->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); const SDL_bool force_override_redirect = SDL_GetHintBoolean(SDL_HINT_X11_FORCE_OVERRIDE_REDIRECT, SDL_FALSE); SDL_WindowData *windowdata; Display *display = data->display; @@ -639,7 +634,7 @@ int X11_CreateWindow(_THIS, SDL_Window *window) X11_XDestroyWindow(display, w); return -1; } - windowdata = (SDL_WindowData *)window->driverdata; + windowdata = window->driverdata; #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2 || SDL_VIDEO_OPENGL_EGL if ((window->flags & SDL_WINDOW_OPENGL) && @@ -704,7 +699,7 @@ int X11_CreateWindowFrom(_THIS, SDL_Window *window, const void *data) char * X11_GetWindowTitle(_THIS, Window xwindow) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; Display *display = data->display; int status, real_format; Atom real_type; @@ -736,7 +731,7 @@ X11_GetWindowTitle(_THIS, Window xwindow) void X11_SetWindowTitle(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Window xwindow = data->xwindow; Display *display = data->videodata->display; char *title = window->title ? window->title : ""; @@ -746,7 +741,7 @@ void X11_SetWindowTitle(_THIS, SDL_Window *window) void X11_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; Atom _NET_WM_ICON = data->videodata->_NET_WM_ICON; @@ -794,7 +789,7 @@ static int X11_CatchAnyError(Display *d, XErrorEvent *e) void X11_SetWindowPosition(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; int (*prev_handler)(Display *, XErrorEvent *) = NULL; unsigned int childCount; @@ -851,7 +846,7 @@ void X11_SetWindowPosition(_THIS, SDL_Window *window) void X11_SetWindowMinimumSize(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; if (window->flags & SDL_WINDOW_RESIZABLE) { @@ -879,7 +874,7 @@ void X11_SetWindowMinimumSize(_THIS, SDL_Window *window) void X11_SetWindowMaximumSize(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; if (window->flags & SDL_WINDOW_RESIZABLE) { @@ -907,7 +902,7 @@ void X11_SetWindowMaximumSize(_THIS, SDL_Window *window) void X11_SetWindowSize(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; int (*prev_handler)(Display *, XErrorEvent *) = NULL; XWindowAttributes attrs; @@ -995,7 +990,7 @@ void X11_SetWindowSize(_THIS, SDL_Window *window) int X11_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int *bottom, int *right) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; *left = data->border_left; *right = data->border_right; @@ -1007,7 +1002,7 @@ int X11_GetWindowBordersSize(_THIS, SDL_Window *window, int *top, int *left, int int X11_SetWindowOpacity(_THIS, SDL_Window *window, float opacity) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; Atom _NET_WM_WINDOW_OPACITY = data->videodata->_NET_WM_WINDOW_OPACITY; @@ -1025,8 +1020,8 @@ int X11_SetWindowOpacity(_THIS, SDL_Window *window, float opacity) int X11_SetWindowModalFor(_THIS, SDL_Window *modal_window, SDL_Window *parent_window) { - SDL_WindowData *data = (SDL_WindowData *)modal_window->driverdata; - SDL_WindowData *parent_data = (SDL_WindowData *)parent_window->driverdata; + SDL_WindowData *data = modal_window->driverdata; + SDL_WindowData *parent_data = parent_window->driverdata; Display *display = data->videodata->display; X11_XSetTransientForHint(display, data->xwindow, parent_data->xwindow); @@ -1036,7 +1031,7 @@ int X11_SetWindowModalFor(_THIS, SDL_Window *modal_window, SDL_Window *parent_wi int X11_SetWindowInputFocus(_THIS, SDL_Window *window) { if (X11_IsWindowMapped(_this, window)) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; X11_XSetInputFocus(display, data->xwindow, RevertToNone, CurrentTime); X11_XFlush(display); @@ -1049,9 +1044,8 @@ void X11_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered) { const SDL_bool focused = ((window->flags & SDL_WINDOW_INPUT_FOCUS) != 0); const SDL_bool visible = ((window->flags & SDL_WINDOW_HIDDEN) == 0); - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = - (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); Display *display = data->videodata->display; XEvent event; @@ -1082,7 +1076,7 @@ void X11_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered) void X11_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; XSizeHints *sizehints = X11_XAllocSizeHints(); @@ -1119,8 +1113,8 @@ void X11_SetWindowResizable(_THIS, SDL_Window *window, SDL_bool resizable) void X11_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); Display *display = data->videodata->display; Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE; Atom _NET_WM_STATE_ABOVE = data->videodata->_NET_WM_STATE_ABOVE; @@ -1148,7 +1142,7 @@ void X11_SetWindowAlwaysOnTop(_THIS, SDL_Window *window, SDL_bool on_top) void X11_ShowWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; XEvent event; @@ -1173,8 +1167,8 @@ void X11_ShowWindow(_THIS, SDL_Window *window) void X11_HideWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); Display *display = data->videodata->display; XEvent event; @@ -1190,9 +1184,8 @@ void X11_HideWindow(_THIS, SDL_Window *window) static void X11_SetWindowActive(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = - (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); Display *display = data->videodata->display; Atom _NET_ACTIVE_WINDOW = data->videodata->_NET_ACTIVE_WINDOW; @@ -1219,7 +1212,7 @@ static void X11_SetWindowActive(_THIS, SDL_Window *window) void X11_RaiseWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; X11_XRaiseWindow(display, data->xwindow); @@ -1229,9 +1222,8 @@ void X11_RaiseWindow(_THIS, SDL_Window *window) static void X11_SetWindowMaximized(_THIS, SDL_Window *window, SDL_bool maximized) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = - (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); Display *display = data->videodata->display; Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE; Atom _NET_WM_STATE_MAXIMIZED_VERT = data->videodata->_NET_WM_STATE_MAXIMIZED_VERT; @@ -1280,9 +1272,8 @@ void X11_MaximizeWindow(_THIS, SDL_Window *window) void X11_MinimizeWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = - (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); Display *display = data->videodata->display; X11_XIconifyWindow(display, data->xwindow, displaydata->screen); @@ -1299,8 +1290,8 @@ void X11_RestoreWindow(_THIS, SDL_Window *window) /* This asks the Window Manager to handle fullscreen for us. This is the modern way. */ static void X11_SetWindowFullscreenViaWM(_THIS, SDL_Window *window, SDL_VideoDisplay *_display, SDL_bool fullscreen) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = (SDL_DisplayData *)_display->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = _display->driverdata; Display *display = data->videodata->display; Atom _NET_WM_STATE = data->videodata->_NET_WM_STATE; Atom _NET_WM_STATE_FULLSCREEN = data->videodata->_NET_WM_STATE_FULLSCREEN; @@ -1484,7 +1475,7 @@ static void X11_ReadProperty(SDL_x11Prop *p, Display *disp, Window w, Atom prop) void * X11_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; XWindowAttributes attributes; Atom icc_profile_atom; @@ -1533,7 +1524,7 @@ X11_GetWindowICCProfile(_THIS, SDL_Window *window, size_t *size) void X11_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display; if (data == NULL) { @@ -1588,7 +1579,7 @@ void X11_SetWindowMouseGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void X11_SetWindowKeyboardGrab(_THIS, SDL_Window *window, SDL_bool grabbed) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display; if (data == NULL) { @@ -1615,7 +1606,7 @@ void X11_SetWindowKeyboardGrab(_THIS, SDL_Window *window, SDL_bool grabbed) void X11_DestroyWindow(_THIS, SDL_Window *window) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; if (window->shaper) { SDL_ShapeData *shapedata = (SDL_ShapeData *)window->shaper->driverdata; @@ -1628,7 +1619,7 @@ void X11_DestroyWindow(_THIS, SDL_Window *window) } if (data) { - SDL_VideoData *videodata = (SDL_VideoData *)data->videodata; + SDL_VideoData *videodata = data->videodata; Display *display = videodata->display; int numwindows = videodata->numwindows; SDL_WindowData **windowlist = videodata->windowlist; @@ -1667,8 +1658,8 @@ void X11_DestroyWindow(_THIS, SDL_Window *window) int X11_GetWindowWMInfo(_THIS, SDL_Window *window, SDL_SysWMinfo *info) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; - SDL_DisplayData *displaydata = (SDL_DisplayData *)SDL_GetDisplayForWindow(window)->driverdata; + SDL_WindowData *data = window->driverdata; + SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); if (data == NULL) { /* This sometimes happens in SDL_IBus_UpdateTextRect() while creating the window */ @@ -1689,7 +1680,7 @@ int X11_SetWindowHitTest(SDL_Window *window, SDL_bool enabled) void X11_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; Atom XdndAware = X11_XInternAtom(display, "XdndAware", False); @@ -1704,7 +1695,7 @@ void X11_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept) int X11_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation) { - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; XWMHints *wmhints; diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h index 97756b815..05a263685 100644 --- a/src/video/x11/SDL_x11window.h +++ b/src/video/x11/SDL_x11window.h @@ -40,7 +40,7 @@ typedef enum PENDING_FOCUS_OUT } PendingFocusEnum; -typedef struct +struct SDL_WindowData { SDL_Window *window; Window xwindow; @@ -78,7 +78,7 @@ typedef struct PointerBarrier barrier[4]; SDL_Rect barrier_rect; #endif /* SDL_VIDEO_DRIVER_X11_XFIXES */ -} SDL_WindowData; +}; extern void X11_SetNetWMState(_THIS, Window xwindow, Uint32 flags); extern Uint32 X11_GetNetWMState(_THIS, SDL_Window *window, Window xwindow); diff --git a/src/video/x11/SDL_x11xfixes.c b/src/video/x11/SDL_x11xfixes.c index dec607986..7e1748aca 100644 --- a/src/video/x11/SDL_x11xfixes.c +++ b/src/video/x11/SDL_x11xfixes.c @@ -44,7 +44,7 @@ static SDL_bool xfixes_version_atleast(const int version, const int wantmajor, c void X11_InitXfixes(_THIS) { - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; int version = 0; int event, error; @@ -78,7 +78,7 @@ void X11_SetWindowMouseRect(_THIS, SDL_Window *window) X11_ConfineCursorWithFlags(_this, window, &window->mouse_rect, 0); } else { /* Save the state for when we get focus again */ - SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *wdata = window->driverdata; SDL_memcpy(&wdata->barrier_rect, &window->mouse_rect, sizeof(wdata->barrier_rect)); @@ -93,7 +93,7 @@ int X11_ConfineCursorWithFlags(_THIS, SDL_Window *window, const SDL_Rect *rect, * edges exactly match, a rectangle the cursor 'slips' out of the barrier. * To prevent that the lines for the barriers will span the whole screen. */ - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; SDL_WindowData *wdata; if (!X11_XfixesIsInitialized()) { @@ -106,7 +106,7 @@ int X11_ConfineCursorWithFlags(_THIS, SDL_Window *window, const SDL_Rect *rect, } SDL_assert(window != NULL); - wdata = (SDL_WindowData *)window->driverdata; + wdata = window->driverdata; /* If user did not specify an area to confine, destroy the barrier that was/is assigned to * this window it was assigned */ @@ -130,7 +130,7 @@ int X11_ConfineCursorWithFlags(_THIS, SDL_Window *window, const SDL_Rect *rect, } /* Use the display bounds to ensure the barriers don't have corner gaps */ - SDL_GetDisplayBounds(SDL_GetWindowDisplayIndex(window), &bounds); + SDL_GetDisplayBounds(SDL_GetDisplayForWindow(window), &bounds); /** Create the left barrier */ wdata->barrier[0] = X11_XFixesCreatePointerBarrier(data->display, wdata->xwindow, @@ -179,9 +179,9 @@ int X11_ConfineCursorWithFlags(_THIS, SDL_Window *window, const SDL_Rect *rect, void X11_DestroyPointerBarrier(_THIS, SDL_Window *window) { int i; - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; if (window) { - SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata; + SDL_WindowData *wdata = window->driverdata; for (i = 0; i < 4; i++) { if (wdata->barrier[i] > 0) { diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index ba509d4fb..80f5c60da 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -113,7 +113,7 @@ static void xinput2_normalize_touch_coordinates(SDL_Window *window, double in_x, void X11_InitXinput2(_THIS) { #if SDL_VIDEO_DRIVER_X11_XINPUT2 - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; int version = 0; XIEventMask eventmask; @@ -391,7 +391,7 @@ int X11_HandleXinput2Event(SDL_VideoData *videodata, XGenericEventCookie *cookie void X11_InitXinput2Multitouch(_THIS) { #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH - SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; + SDL_VideoData *data = _this->driverdata; XIDeviceInfo *info; int ndevices, i, j; @@ -440,8 +440,8 @@ void X11_Xinput2SelectTouch(_THIS, SDL_Window *window) return; } - data = (SDL_VideoData *)_this->driverdata; - window_data = (SDL_WindowData *)window->driverdata; + data = _this->driverdata; + window_data = window->driverdata; eventmask.deviceid = XIAllMasterDevices; eventmask.mask_len = sizeof(mask); @@ -477,7 +477,7 @@ int X11_Xinput2IsMultitouchSupported() void X11_Xinput2GrabTouch(_THIS, SDL_Window *window) { #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; unsigned char mask[4] = { 0, 0, 0, 0 }; @@ -507,7 +507,7 @@ void X11_Xinput2GrabTouch(_THIS, SDL_Window *window) void X11_Xinput2UngrabTouch(_THIS, SDL_Window *window) { #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH - SDL_WindowData *data = (SDL_WindowData *)window->driverdata; + SDL_WindowData *data = window->driverdata; Display *display = data->videodata->display; XIGrabModifiers mods; diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 8ad17dd86..b09bf8163 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -343,110 +343,83 @@ int video_getWindowFlags(void *arg) */ int video_getNumDisplayModes(void *arg) { + SDL_DisplayID *displays; int result; - int displayNum; int i; /* Get number of displays */ - displayNum = SDL_GetNumVideoDisplays(); - SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); + displays = SDL_GetDisplays(NULL); + if (displays) { + SDLTest_AssertPass("Call to SDL_GetDisplays()"); - /* Make call for each display */ - for (i = 0; i < displayNum; i++) { - result = SDL_GetNumDisplayModes(i); - SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i); - SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result); + /* Make call for each display */ + for (i = 0; displays[i]; ++i) { + result = SDL_GetNumDisplayModes(displays[i]); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i); + SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result); + } + SDL_free(displays); } return TEST_COMPLETED; } -/** - * @brief Tests negative call to SDL_GetNumDisplayModes function - */ -int video_getNumDisplayModesNegative(void *arg) -{ - int result; - int displayNum; - int displayIndex; - - /* Get number of displays */ - displayNum = SDL_GetNumVideoDisplays(); - SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); - - /* Invalid boundary values */ - displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE); - result = SDL_GetNumDisplayModes(displayIndex); - SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex); - SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); - - /* Large (out-of-bounds) display index */ - displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000); - result = SDL_GetNumDisplayModes(displayIndex); - SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex); - SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); - - displayIndex = SDLTest_RandomIntegerInRange(1000, 2000); - result = SDL_GetNumDisplayModes(displayIndex); - SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex); - SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); - - return TEST_COMPLETED; -} - /** * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution */ int video_getClosestDisplayModeCurrentResolution(void *arg) { int result; + SDL_DisplayID *displays; SDL_DisplayMode current; SDL_DisplayMode target; SDL_DisplayMode closest; SDL_DisplayMode *dResult; - int displayNum; int i; int variation; /* Get number of displays */ - displayNum = SDL_GetNumVideoDisplays(); - SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); + displays = SDL_GetDisplays(NULL); + if (displays) { + SDLTest_AssertPass("Call to SDL_GetDisplays()"); - /* Make calls for each display */ - for (i = 0; i < displayNum; i++) { - SDLTest_Log("Testing against display: %d", i); + /* Make calls for each display */ + for (i = 0; displays[i]; ++i) { + SDLTest_Log("Testing against display: %" SDL_PRIu32 "", displays[i]); - /* Get first display mode to get a sane resolution; this should always work */ - result = SDL_GetDisplayMode(i, 0, ¤t); - SDLTest_AssertPass("Call to SDL_GetDisplayMode()"); - SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result); - if (result != 0) { - return TEST_ABORTED; - } - - /* Set the desired resolution equals to current resolution */ - SDL_zero(target); - target.pixel_w = current.pixel_w; - target.pixel_h = current.pixel_h; - for (variation = 0; variation < 8; variation++) { - /* Vary constraints on other query parameters */ - target.format = (variation & 1) ? current.format : 0; - target.refresh_rate = (variation & 2) ? current.refresh_rate : 0.0f; - target.driverdata = (variation & 4) ? current.driverdata : 0; - - /* Make call */ - dResult = SDL_GetClosestDisplayMode(i, &target, &closest); - SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation); - SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL"); - - /* Check that one gets the current resolution back again */ - SDLTest_AssertCheck(closest.pixel_w == current.pixel_w, "Verify returned width matches current width; expected: %d, got: %d", current.pixel_w, closest.pixel_w); - SDLTest_AssertCheck(closest.pixel_h == current.pixel_h, "Verify returned height matches current height; expected: %d, got: %d", current.pixel_h, closest.pixel_h); - /* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */ - SDLTest_AssertCheck(closest.pixel_w == dResult->pixel_w, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_w, dResult->pixel_w); - SDLTest_AssertCheck(closest.pixel_h == dResult->pixel_h, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_h, dResult->pixel_h); - /* NOLINTEND(clang-analyzer-core.NullDereference) */ + /* Get first display mode to get a sane resolution; this should always work */ + result = SDL_GetDisplayMode(displays[i], 0, ¤t); + SDLTest_AssertPass("Call to SDL_GetDisplayMode()"); + SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result); + if (result != 0) { + return TEST_ABORTED; + } + + /* Set the desired resolution equals to current resolution */ + SDL_zero(target); + target.pixel_w = current.pixel_w; + target.pixel_h = current.pixel_h; + for (variation = 0; variation < 8; variation++) { + /* Vary constraints on other query parameters */ + target.format = (variation & 1) ? current.format : 0; + target.refresh_rate = (variation & 2) ? current.refresh_rate : 0.0f; + target.driverdata = (variation & 4) ? current.driverdata : 0; + + /* Make call */ + dResult = SDL_GetClosestDisplayMode(displays[i], &target, &closest); + SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation); + SDLTest_Assert(dResult != NULL, "Verify returned value is not NULL"); + + /* Check that one gets the current resolution back again */ + SDLTest_AssertCheck(closest.pixel_w == current.pixel_w, "Verify returned width matches current width; expected: %d, got: %d", current.pixel_w, closest.pixel_w); + SDLTest_AssertCheck(closest.pixel_h == current.pixel_h, "Verify returned height matches current height; expected: %d, got: %d", current.pixel_h, closest.pixel_h); + /* NOLINTBEGIN(clang-analyzer-core.NullDereference): Checked earlier for NULL */ + SDLTest_AssertCheck(closest.pixel_w == dResult->pixel_w, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_w, dResult->pixel_w); + SDLTest_AssertCheck(closest.pixel_h == dResult->pixel_h, "Verify return value matches assigned value; expected: %d, got: %d", closest.pixel_h, dResult->pixel_h); + /* NOLINTEND(clang-analyzer-core.NullDereference) */ + } } + SDL_free(displays); } return TEST_COMPLETED; @@ -457,33 +430,36 @@ int video_getClosestDisplayModeCurrentResolution(void *arg) */ int video_getClosestDisplayModeRandomResolution(void *arg) { + SDL_DisplayID *displays; SDL_DisplayMode target; SDL_DisplayMode closest; - int displayNum; int i; int variation; /* Get number of displays */ - displayNum = SDL_GetNumVideoDisplays(); - SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays()"); + displays = SDL_GetDisplays(NULL); + if (displays) { + SDLTest_AssertPass("Call to SDL_GetDisplays()"); - /* Make calls for each display */ - for (i = 0; i < displayNum; i++) { - SDLTest_Log("Testing against display: %d", i); + /* Make calls for each display */ + for (i = 0; displays[i]; ++i) { + SDLTest_Log("Testing against display: %" SDL_PRIu32 "", displays[i]); - for (variation = 0; variation < 16; variation++) { + for (variation = 0; variation < 16; variation++) { - /* Set random constraints */ - SDL_zero(target); - target.pixel_w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; - target.pixel_h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; - target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0; - target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f; + /* Set random constraints */ + SDL_zero(target); + target.pixel_w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; + target.pixel_h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0; + target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0; + target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f; - /* Make call; may or may not find anything, so don't validate any further */ - SDL_GetClosestDisplayMode(i, &target, &closest); - SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation); + /* Make call; may or may not find anything, so don't validate any further */ + SDL_GetClosestDisplayMode(displays[i], &target, &closest); + SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation); + } } + SDL_free(displays); } return TEST_COMPLETED; @@ -1055,7 +1031,7 @@ int video_getSetWindowSize(void *arg) int desiredW, desiredH; /* Get display bounds for size range */ - result = SDL_GetDisplayBounds(0, &display); + result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); if (result != 0) { @@ -1222,7 +1198,7 @@ int video_getSetWindowMinimumSize(void *arg) int desiredH = 1; /* Get display bounds for size range */ - result = SDL_GetDisplayBounds(0, &display); + result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); if (result != 0) { @@ -1364,7 +1340,7 @@ int video_getSetWindowMaximumSize(void *arg) int desiredW, desiredH; /* Get display bounds for size range */ - result = SDL_GetDisplayBounds(0, &display); + result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); if (result != 0) { @@ -1710,6 +1686,7 @@ cleanup: */ int video_setWindowCenteredOnDisplay(void *arg) { + SDL_DisplayID *displays; SDL_Window *window; const char *title = "video_setWindowCenteredOnDisplay Test Window"; int x, y, w, h; @@ -1718,110 +1695,114 @@ int video_setWindowCenteredOnDisplay(void *arg) int result; SDL_Rect display0, display1; - displayNum = SDL_GetNumVideoDisplays(); + displays = SDL_GetDisplays(&displayNum); + if (displays) { - /* Get display bounds */ - result = SDL_GetDisplayBounds(0 % displayNum, &display0); - SDLTest_AssertPass("SDL_GetDisplayBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) { - return TEST_ABORTED; - } - - result = SDL_GetDisplayBounds(1 % displayNum, &display1); - SDLTest_AssertPass("SDL_GetDisplayBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) { - return TEST_ABORTED; - } - - for (xVariation = 0; xVariation < 2; xVariation++) { - for (yVariation = 0; yVariation < 2; yVariation++) { - int currentX = 0, currentY = 0; - int currentW = 0, currentH = 0; - int expectedX = 0, expectedY = 0; - int currentDisplay; - int expectedDisplay; - SDL_Rect expectedDisplayRect; - - /* xVariation is the display we start on */ - expectedDisplay = xVariation % displayNum; - x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); - y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); - w = SDLTest_RandomIntegerInRange(640, 800); - h = SDLTest_RandomIntegerInRange(400, 600); - expectedDisplayRect = (xVariation == 0) ? display0 : display1; - expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); - expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); - - window = SDL_CreateWindow(title, x, y, w, h, 0); - SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); - SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - - /* Check the window is centered on the requested display */ - currentDisplay = SDL_GetWindowDisplayIndex(window); - SDL_GetWindowSize(window, ¤tW, ¤tH); - SDL_GetWindowPosition(window, ¤tX, ¤tY); - - SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); - SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); - SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); - SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); - SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); - - /* Enter fullscreen desktop */ - result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - - /* Check we are filling the full display */ - currentDisplay = SDL_GetWindowDisplayIndex(window); - SDL_GetWindowSize(window, ¤tW, ¤tH); - SDL_GetWindowPosition(window, ¤tX, ¤tY); - - SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); - SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w); - SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h); - SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x); - SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y); - - /* Leave fullscreen desktop */ - result = SDL_SetWindowFullscreen(window, 0); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - - /* Check window was restored correctly */ - currentDisplay = SDL_GetWindowDisplayIndex(window); - SDL_GetWindowSize(window, ¤tW, ¤tH); - SDL_GetWindowPosition(window, ¤tX, ¤tY); - - SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); - SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); - SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); - SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); - SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); - - /* Center on display yVariation, and check window properties */ - - expectedDisplay = yVariation % displayNum; - x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); - y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); - expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1; - expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); - expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); - SDL_SetWindowPosition(window, x, y); - - currentDisplay = SDL_GetWindowDisplayIndex(window); - SDL_GetWindowSize(window, ¤tW, ¤tH); - SDL_GetWindowPosition(window, ¤tX, ¤tY); - - SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); - SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); - SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); - SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); - SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); - - /* Clean up */ - destroyVideoSuiteTestWindow(window); + /* Get display bounds */ + result = SDL_GetDisplayBounds(displays[0 % displayNum], &display0); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) { + return TEST_ABORTED; } + + result = SDL_GetDisplayBounds(displays[1 % displayNum], &display1); + SDLTest_AssertPass("SDL_GetDisplayBounds()"); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + if (result != 0) { + return TEST_ABORTED; + } + + for (xVariation = 0; xVariation < 2; xVariation++) { + for (yVariation = 0; yVariation < 2; yVariation++) { + int currentX = 0, currentY = 0; + int currentW = 0, currentH = 0; + int expectedX = 0, expectedY = 0; + int currentDisplay; + int expectedDisplay; + SDL_Rect expectedDisplayRect; + + /* xVariation is the display we start on */ + expectedDisplay = xVariation % displayNum; + x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); + y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); + w = SDLTest_RandomIntegerInRange(640, 800); + h = SDLTest_RandomIntegerInRange(400, 600); + expectedDisplayRect = (xVariation == 0) ? display0 : display1; + expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); + expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); + + window = SDL_CreateWindow(title, x, y, w, h, 0); + SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); + SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); + + /* Check the window is centered on the requested display */ + currentDisplay = SDL_GetDisplayForWindow(window); + SDL_GetWindowSize(window, ¤tW, ¤tH); + SDL_GetWindowPosition(window, ¤tX, ¤tY); + + SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); + SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); + SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); + SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); + SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); + + /* Enter fullscreen desktop */ + result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + + /* Check we are filling the full display */ + currentDisplay = SDL_GetDisplayForWindow(window); + SDL_GetWindowSize(window, ¤tW, ¤tH); + SDL_GetWindowPosition(window, ¤tX, ¤tY); + + SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); + SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w); + SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h); + SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x); + SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y); + + /* Leave fullscreen desktop */ + result = SDL_SetWindowFullscreen(window, 0); + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + + /* Check window was restored correctly */ + currentDisplay = SDL_GetDisplayForWindow(window); + SDL_GetWindowSize(window, ¤tW, ¤tH); + SDL_GetWindowPosition(window, ¤tX, ¤tY); + + SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); + SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); + SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); + SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); + SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); + + /* Center on display yVariation, and check window properties */ + + expectedDisplay = yVariation % displayNum; + x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); + y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay); + expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1; + expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2)); + expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2)); + SDL_SetWindowPosition(window, x, y); + + currentDisplay = SDL_GetDisplayForWindow(window); + SDL_GetWindowSize(window, ¤tW, ¤tH); + SDL_GetWindowPosition(window, ¤tX, ¤tY); + + SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay); + SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w); + SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h); + SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX); + SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY); + + /* Clean up */ + destroyVideoSuiteTestWindow(window); + } + } + + SDL_free(displays); } return TEST_COMPLETED; @@ -1855,58 +1836,54 @@ static const SDLTest_TestCaseReference videoTest6 = { }; static const SDLTest_TestCaseReference videoTest7 = { - (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED -}; - -static const SDLTest_TestCaseReference videoTest8 = { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest9 = { +static const SDLTest_TestCaseReference videoTest8 = { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest10 = { +static const SDLTest_TestCaseReference videoTest9 = { (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode", "Get window display mode", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest11 = { +static const SDLTest_TestCaseReference videoTest10 = { (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative", "Get window display mode with invalid input", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest12 = { +static const SDLTest_TestCaseReference videoTest11 = { (SDLTest_TestCaseFp)video_getSetWindowGrab, "video_getSetWindowGrab", "Checks SDL_GetWindowGrab and SDL_SetWindowGrab positive and negative cases", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest13 = { +static const SDLTest_TestCaseReference videoTest12 = { (SDLTest_TestCaseFp)video_getWindowId, "video_getWindowId", "Checks SDL_GetWindowID and SDL_GetWindowFromID", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest14 = { +static const SDLTest_TestCaseReference videoTest13 = { (SDLTest_TestCaseFp)video_getWindowPixelFormat, "video_getWindowPixelFormat", "Checks SDL_GetWindowPixelFormat", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest15 = { +static const SDLTest_TestCaseReference videoTest14 = { (SDLTest_TestCaseFp)video_getSetWindowPosition, "video_getSetWindowPosition", "Checks SDL_GetWindowPosition and SDL_SetWindowPosition positive and negative cases", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest16 = { +static const SDLTest_TestCaseReference videoTest15 = { (SDLTest_TestCaseFp)video_getSetWindowSize, "video_getSetWindowSize", "Checks SDL_GetWindowSize and SDL_SetWindowSize positive and negative cases", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest17 = { +static const SDLTest_TestCaseReference videoTest16 = { (SDLTest_TestCaseFp)video_getSetWindowMinimumSize, "video_getSetWindowMinimumSize", "Checks SDL_GetWindowMinimumSize and SDL_SetWindowMinimumSize positive and negative cases", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest18 = { +static const SDLTest_TestCaseReference videoTest17 = { (SDLTest_TestCaseFp)video_getSetWindowMaximumSize, "video_getSetWindowMaximumSize", "Checks SDL_GetWindowMaximumSize and SDL_SetWindowMaximumSize positive and negative cases", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest19 = { +static const SDLTest_TestCaseReference videoTest18 = { (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED }; -static const SDLTest_TestCaseReference videoTest20 = { +static const SDLTest_TestCaseReference videoTest19 = { (SDLTest_TestCaseFp)video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED }; @@ -1915,7 +1892,7 @@ static const SDLTest_TestCaseReference *videoTests[] = { &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, &videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, &videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17, - &videoTest18, &videoTest19, &videoTest20, NULL + &videoTest18, &videoTest19, NULL }; /* Video test suite (global) */ diff --git a/test/testbounds.c b/test/testbounds.c index e52a21a04..6481df66b 100644 --- a/test/testbounds.c +++ b/test/testbounds.c @@ -15,22 +15,26 @@ int main(int argc, char **argv) { - int total, i; + SDL_DisplayID *displays; + int i; if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDL_Log("SDL_Init(SDL_INIT_VIDEO) failed: %s", SDL_GetError()); return 1; } - total = SDL_GetNumVideoDisplays(); - for (i = 0; i < total; i++) { - SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 }; - SDL_GetDisplayBounds(i, &bounds); - SDL_GetDisplayUsableBounds(i, &usable); - SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}", - i, SDL_GetDisplayName(i), - bounds.x, bounds.y, bounds.w, bounds.h, - usable.x, usable.y, usable.w, usable.h); + displays = SDL_GetDisplays(NULL); + if (displays) { + for (i = 0; displays[i]; i++) { + SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 }; + SDL_GetDisplayBounds(displays[i], &bounds); + SDL_GetDisplayUsableBounds(displays[i], &usable); + SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}", + i, SDL_GetDisplayName(displays[i]), + bounds.x, bounds.y, bounds.w, bounds.h, + usable.x, usable.y, usable.w, usable.h); + } + SDL_free(displays); } SDL_Quit(); diff --git a/test/testdisplayinfo.c b/test/testdisplayinfo.c index 5b10aa4f3..0c77154a6 100644 --- a/test/testdisplayinfo.c +++ b/test/testdisplayinfo.c @@ -31,8 +31,9 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode) int main(int argc, char *argv[]) { + SDL_DisplayID *displays; SDL_DisplayMode mode; - int num_displays, dpy; + int num_displays, i; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); @@ -44,18 +45,19 @@ int main(int argc, char *argv[]) } SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver()); - num_displays = SDL_GetNumVideoDisplays(); + displays = SDL_GetDisplays(&num_displays); SDL_Log("See %d displays.\n", num_displays); - for (dpy = 0; dpy < num_displays; dpy++) { + for (i = 0; i < num_displays; i++) { + SDL_DisplayID dpy = displays[i]; const int num_modes = SDL_GetNumDisplayModes(dpy); SDL_Rect rect = { 0, 0, 0, 0 }; float ddpi, hdpi, vdpi; int m; SDL_GetDisplayBounds(dpy, &rect); - SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes); + SDL_Log("%" SDL_PRIu32 ": \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes); if (SDL_GetDisplayPhysicalDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError()); @@ -87,6 +89,7 @@ int main(int argc, char *argv[]) SDL_Log("\n"); } + SDL_free(displays); SDL_Quit(); return 0; diff --git a/test/testgl.c b/test/testgl.c index de98b7473..1146dcc7f 100644 --- a/test/testgl.c +++ b/test/testgl.c @@ -293,7 +293,7 @@ int main(int argc, char *argv[]) swap_interval = 0; } - SDL_GetCurrentDisplayMode(0, &mode); + SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode); SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format)); ret_interval = SDL_GL_GetSwapInterval(&interval); diff --git a/test/testgles.c b/test/testgles.c index 6c5d075eb..5df605653 100644 --- a/test/testgles.c +++ b/test/testgles.c @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) SDL_GL_SetSwapInterval(0); } - SDL_GetCurrentDisplayMode(0, &mode); + SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode); SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); SDL_Log("\n"); SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR)); diff --git a/test/testgles2.c b/test/testgles2.c index dd32a76c2..9280cc4bc 100644 --- a/test/testgles2.c +++ b/test/testgles2.c @@ -714,7 +714,7 @@ int main(int argc, char *argv[]) SDL_GL_SetSwapInterval(0); } - SDL_GetCurrentDisplayMode(0, &mode); + SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode); SDL_Log("Threaded : %s\n", threaded ? "yes" : "no"); SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); SDL_Log("\n"); diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c index 419e5f7b7..f51dd0b69 100644 --- a/test/testgles2_sdf.c +++ b/test/testgles2_sdf.c @@ -602,7 +602,7 @@ int main(int argc, char *argv[]) SDL_GL_SetSwapInterval(0); } - SDL_GetCurrentDisplayMode(0, &mode); + SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode); SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format)); SDL_Log("\n"); SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR)); diff --git a/test/testvulkan.c b/test/testvulkan.c index a03147e19..191b4b5f6 100644 --- a/test/testvulkan.c +++ b/test/testvulkan.c @@ -1104,7 +1104,7 @@ int main(int argc, char **argv) return 1; } - SDL_GetCurrentDisplayMode(0, &mode); + SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay(), &mode); SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format)); SDL_GetWindowSize(state->windows[0], &dw, &dh); SDL_Log("Window Size : %d,%d\n", dw, dh); diff --git a/test/testwm.c b/test/testwm.c index 73c1e0667..d0642f78d 100644 --- a/test/testwm.c +++ b/test/testwm.c @@ -57,8 +57,8 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport) SDL_DisplayMode mode; char text[1024]; const int lineHeight = 10; - const int display_index = SDL_GetWindowDisplayIndex(window); - const int num_modes = SDL_GetNumDisplayModes(display_index); + const SDL_DisplayID displayID = SDL_GetDisplayForWindow(window); + const int num_modes = SDL_GetNumDisplayModes(displayID); int i; int column_chars = 0; int text_length; @@ -103,7 +103,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport) for (i = 0; i < num_modes; ++i) { SDL_FRect cell_rect; - if (0 != SDL_GetDisplayMode(display_index, i, &mode)) { + if (0 != SDL_GetDisplayMode(displayID, i, &mode)) { return; } @@ -167,7 +167,7 @@ void loop() event.window.windowID, event.window.data1, event.window.data2, - SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window))); + SDL_GetDisplayName(SDL_GetDisplayForWindow(window))); } } if (event.type == SDL_EVENT_WINDOW_FOCUS_LOST) { @@ -207,9 +207,9 @@ void loop() if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) { SDL_Window *window = SDL_GetMouseFocus(); if (highlighted_mode != -1 && window != NULL) { - const int display_index = SDL_GetWindowDisplayIndex(window); + SDL_DisplayID displayID = SDL_GetDisplayForWindow(window); SDL_DisplayMode mode; - if (0 != SDL_GetDisplayMode(display_index, highlighted_mode, &mode)) { + if (0 != SDL_GetDisplayMode(displayID, highlighted_mode, &mode)) { SDL_Log("Couldn't get display mode"); } else { SDL_SetWindowDisplayMode(window, &mode);