Commit graph

323 commits

Author SHA1 Message Date
Frank Praznik d6a19c8cc6 video: Use the explicit fullscreen display for a window unless the window was moved
When an exclusive fullscreen display is specified, it overrides any positioning, including from driver specific functions. Allows for the proper placement of fullscreen windows on macOS and Windows when the floating window is on a display that differs from the one specified by the exclusive fullscreen mode.

 A specific position-only function has been split out for use when a window has been moved.
2023-02-11 14:44:02 -05:00
Bruce Mitchener a8e89f2567 emscripten: Update deprecated calls to EM_ASM*.
`EM_ASM_` and `EM_ASM_INT_V` are calls that have been deprecated
for a long time.

Since the return value isn't used for the call to `EM_ASM_`, it
can be replaced with `EM_ASM`.

`EM_ASM_INT_V` is now (for the last few years) `EM_ASM_INT`.
2023-02-09 23:10:17 -08:00
Sylvain cee245b6a9 SDL_*SceenSaver(): change return value to int. // add SDL_Unsupported() errors 2023-02-09 08:16:46 -08:00
Sylvain e2e5e670bf Remove returns int from Destroy/Close/Unlock functions 2023-02-09 07:57:14 -08:00
Sam Lantinga 824b9b0a58 Removed SDL_GetDisplayDPI()
This function wasn't consistently correct across platforms and devices.

If you want the UI scale factor, you can use display_scale in the structure returned by SDL_GetDesktopDisplayMode(). If you need an approximate DPI, you can multiply this value times 160 on iPhone and Android, and 96 on other platforms.
2023-02-08 17:35:54 -08:00
Sylvain c5c94a6be6 Change return type from void to int, for functions that set an error
(SDL_SetError(), SDL_OutOfMemory(), SDL_Unsupported(), SDL_InvalidParam())

Update prototype to forward errors to generic layer, for the functions:
MoveCursor, WarpMouse, GL_DeleteContext, GetDisplayModes.

Check invalid parameter in SDL_SetTextInputRect() generic layer.
2023-02-07 13:51:45 -08:00
Frank Praznik d603371848 video: Try to get the display for fullscreen windows via the window position
Attempt to retrieve the display for fullscreen windows using the window position so that the correct display ID is returned if an exclusive fullscreen window is moved to another display.
2023-02-06 17:18:35 -08:00
Linus Probert 375bde8a4f
[SDL3] Cleanup void functions (#7253)
Some functions that do call SDL_SetError but return void changed to instead return non-zero in case of errors.
2023-02-06 08:53:52 -08:00
Sylvain 6f0acca8bd Return the SDL_SetError value 2023-02-06 11:42:38 +01:00
Sylvain Becker cb6b8b0132
Simplify flags testing (#7220) 2023-02-03 13:08:42 -08:00
Frank Praznik 7d439b87b0 video: Don't switch display modes when emulating mode changes
SDL uses window minimization to determine fullscreen window visibility and hide windows before changing the video mode back to the desktop. Wayland, however, does not have the concept of a minimized window and doesn't set the minimized flag (minimization can be requested, but what actually happens to the window is implementation dependent, and if a window is minimized via a desktop shortcut or decoration control, the application is not notified of any state changes). Make the video core mode setting a no-op so that the Wayland backend can handle reporting the display dimensions using its own internal logic.
2023-02-02 18:25:18 -08:00
Frank Praznik 47cdb532f1 video: Don't rely on memcpy undefined behavior
The C specification states that passing a size of 0 to functions like memcpy is valid, but even if the size is 0 and the function is essentially a no-op, the result when passing any invalid pointers is considered undefined behavior. Don't rely on undefined behavior when copying the display or mode lists.
2023-02-02 15:11:36 -08:00
Frank Praznik 166afebcad video: Update self-referential pointers when reallocating the display list
The display list can contain self-referential pointers if the current mode pointer points to the desktop mode or a fullscreen mode array element, and reallocating the display or fullscreen mode lists without updating the current mode pointer in these cases can leave them pointing to freed memory or garbage data. Manually copy the list items and update the self-referential pointers if necessary.
2023-02-02 09:46:01 -08:00
Frank Praznik 98ae54ccc0 video: Set the ID of fullscreen modes when adding a display
When adding a display, traverse the list of added fullscreen modes and ensure the display ID is set to its final, valid value, or the modes added before calling SDL_AddVideoDisplay() will have an invalid display ID.
2023-02-01 16:37:57 -08:00
Sam Lantinga ac75fe9324 Folded SDL_WINDOW_FULLSCREEN_EXCLUSIVE and SDL_WINDOW_FULLSCREEN_DESKTOP into a single SDL_WINDOW_FULLSCREEN flag
The fullscreen video mode used by the window can be used to determine whether it's in exclusive fullscreen or fullscreen desktop mode.
2023-02-01 12:05:25 -08:00
Sam Lantinga 14338ab459 Removed display mode flags
They weren't really adding any value and added complexity to the API
2023-02-01 12:05:25 -08:00
Sam Lantinga 9ff1055489 Workaround for Visual Studio 2019 const warning
Visual Studio 2022, gcc, and clang all agree that "const SDL_DisplayMode **" is a non-const pointer to const data, but Visual Studio 2019 warns about this, so we'll just add a cast to the SDL_free() call for now.

Apparently this was a legitimate bug that has been recently fixed:
https://stackoverflow.com/questions/10403713/why-does-visual-c-warn-on-implicit-cast-from-const-void-to-void-in-c-but
2023-02-01 12:05:25 -08:00
Sam Lantinga 6b137579ea Windows default to fullscreen desktop mode if they don't pick an explicit video mode
Rather than iterating over display modes using an index, there is a new function SDL_GetFullscreenDisplayModes() to get the list of available fullscreen modes on a display.
{
    SDL_DisplayID display = SDL_GetPrimaryDisplay();
    int num_modes = 0;
    SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
    if (modes) {
        for (i = 0; i < num_modes; ++i) {
            SDL_DisplayMode *mode = modes[i];
            SDL_Log("Display %" SDL_PRIu32 " mode %d:  %dx%d@%gHz, %d%% scale\n",
                    display, i, mode->pixel_w, mode->pixel_h, mode->refresh_rate, (int)(mode->display_scale * 100.0f));
        }
        SDL_free(modes);
    }
}

SDL_GetDesktopDisplayMode() and SDL_GetCurrentDisplayMode() return pointers to display modes rather than filling in application memory.

Windows now have an explicit fullscreen mode that is set, using SDL_SetWindowFullscreenMode(). The fullscreen mode for a window can be queried with SDL_GetWindowFullscreenMode(), which returns a pointer to the mode, or NULL if the window will be fullscreen desktop. SDL_SetWindowFullscreen() just takes a boolean value, setting the correct fullscreen state based on the selected mode.
2023-02-01 12:05:25 -08:00
Frank Praznik d58693928d video: Return the display ID when the window is fully enclosed
If the window was fully enclosed, GetDisplayForRect() would return the index of the display ID in the array instead of the display ID itself. Return the display ID itself.
2023-01-31 20:23:52 +01:00
Sylvain d66f27376e Prevent setting an error "invalid display" when the parameter displayID hasn't been set. 2023-01-30 10:57:51 +01:00
Sam Lantinga 22c69bccdf Displays are now referenced by instance ID instead of index 2023-01-29 19:25:15 -08:00
Sasha Szpakowski 90795291e4 Remove SDL_GL/Metal/Vulkan_GetDrawableSize().
SDL_GetWindowSizeInPixels supersedes those functions.
2023-01-29 11:20:33 -08:00
Sam Lantinga df7639f100 Call SDL_OnWindow* handlers after the event has been delivered
This guarantees that events which trigger other events will happen in dependency order, instead of being reversed.
2023-01-28 15:56:02 -08:00
Sam Lantinga 432af82a88 Don't deliver window events while it's being destroyed 2023-01-28 15:56:02 -08:00
Sam Lantinga bf4095359c Removed duplicated window size events, and added SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED 2023-01-28 15:56:02 -08:00
Sam Lantinga e83c54f271 SDL_WINDOW_FULLSCREEN and SDL_WINDOW_FULLSCREEN_DESKTOP are now distinct flags 2023-01-28 10:56:38 -08:00
Sam Lantinga 24fec13ac1 Add full high DPI information to SDL_DisplayMode
SDL_DisplayMode now includes the pixel size, the screen size and the relationship between the two. For example, a 4K display at 200% scale could have a pixel size of 3840x2160, a screen size of 1920x1080, and a display scale of 2.0.
2023-01-27 12:38:46 -08:00
Frank Praznik fc5f363ff7 video: Send the new fullscreen size in screen coordinates
After successfully entering fullscreen, send the new fullscreen window dimensions in screen coordinates, not pixels, to avoid a unit mismatch.
2023-01-27 08:16:27 -08:00
Frank Praznik 6895e1700f video: Ensure that the closest returned video mode match always has a valid scale value 2023-01-25 20:18:45 -08:00
Sam Lantinga 9bbc402b81 Take the display scale into account in SDL_GetWindowSizeInPixels() 2023-01-25 13:06:42 -08:00
Sam Lantinga 6a27188023 SDL_DisplayMode now represents physical pixels and has added a display scaling factor
Work in progress on https://github.com/libsdl-org/SDL/issues/7134
2023-01-25 09:26:59 -08:00
Sam Lantinga 4696c9556b
SDL 3.0 is going to be high DPI aware and officially separates screen… (#7145)
* SDL 3.0 is going to be high DPI aware and officially separates screen coordinates from client pixel area

The public APIs to disable high DPI support have been removed

Work in progress on https://github.com/libsdl-org/SDL/issues/7134
2023-01-25 01:23:17 -08:00
Sylvain 78cc95e34e Rename internal GetDisplayDPI to GetDisplayPhysicalDPI 2023-01-25 00:04:00 -08:00
Sylvain 724d92fd65 Rename SDL_GetDisplayDPI to SDL_GetDisplayPhysicalDPI
to avoid confusion with logical DPI
2023-01-25 00:04:00 -08:00
Sam Lantinga 7b50bae524 Renamed SDL events for clarity
Fixes https://github.com/libsdl-org/SDL/issues/6877
2023-01-24 07:26:48 -08:00
Frank Praznik 34bb0735d8 video: Don't resize moved fullscreen windows if the display mode switch failed
If an exclusive fullscreen window is moved between displays, SDL_UpdateFullscrrenMode can kick the window out of fullscreen if the display onto which it was moved doesn't have a matching video mode. Check the return code and clear the fullscreen flag and skip the resize if the window is no longer fullscreen.
2023-01-22 14:00:54 -08:00
Frank Praznik 8f8746cc1b video: Return an error on failure to set the video mode
If SDL_UpdateFullscreenMode() fails to find a matching mode for the window, it will restore the window to its previous state, but still returns a success code of 0. Return an error code of -1 if no matching display mode can be found.
2023-01-22 14:00:54 -08:00
Frank Praznik 5d5d39b190 video: Don't resize moved, fullscreen windows when mode switching is being emulated
When a driver is emulating mode changes, the display bounds are always the native desktop size, not those of the video mode being emulated. This can result in incorrectly setting the size of fullscreen Wayland windows. Don't resize fullscreen windows to the display dimensions when mode switching is emulated.

Renames the quirk flag from VIDEO_DEVICE_QUIRK_DISABLE_DISPLAY_MODE_SWITCHING to VIDEO_DEVICE_QUIRK_MODE_SWITCHING_EMULATED to better reflect its purpose.
2023-01-19 15:07:29 -08:00
Sam Lantinga c8dfc6b475 Fixing window being incorrect size when using win+shift+arrow to move new big picture mode between displays
*When changing the display of a window, if it's a fullscreen window, resize it to the size of the new display

CR: @saml
2023-01-19 07:43:01 -08:00
Eric Wasylishen 67c91353e0 Handle DPI scaling in SDL_GetWindowSurface
Fixes DPI awareness of testdrawchessboard (previously, the surface was
being created in points instead of pixels, resulting in the demo app
only drawing in a corner of the screen on High-DPI displays)

*_CreateWindowFramebuffer()/*_UpdateWindowFramebuffer(): are updated
to use SDL_GetWindowSizeInPixels instead of SDL_GetWindowSize() or
window->w/window->h.

Most of the _CreateWindowFramebuffer backends are untested except
for Windows.

Fixes #7047
2023-01-15 12:57:42 -08:00
Sam Lantinga e9b86eebf3 Functions which return function pointers now return SDL_FunctionPointer instead of void*
This fixes the clang warning "Cast between pointer-to-function and pointer-to-object is an extension"

You can define SDL_FUNCTION_POINTER_IS_VOID_POINTER in your project to restore the previous behavior.

Fixes https://github.com/libsdl-org/SDL/issues/2866
2023-01-09 15:46:21 -08:00
Sam Lantinga fde78d12f2 Updated copyright for 2023 2023-01-09 09:41:41 -08:00
Hunter Kvalevog 0953367967 SDL_Vulkan_GetInstanceExtensions: Remove window
Remove the unused `window` parameter from
SDL_Vulkan_GetInstanceExtensions, which is never used by any of the
backends.
2023-01-08 07:55:34 -08:00
Sylvain 6863f0b2d8 Add SDL_WindowID type for SDL_Window id 2023-01-04 09:21:52 -08:00
Sam Lantinga 32c077216c Fixed warnings 2023-01-03 15:59:35 -08:00
Sylvain bf76fc6b05 Fixed bug #6816 - SDL_RenderSetVSync doesn't disable vsync for software renderer 2023-01-03 06:38:11 -08:00
Sam Lantinga e3c1749f5b The refresh rate in SDL_DisplayMode is now a float 2023-01-03 06:35:25 -08:00
Sylvain Becker 023f067903
Update GL_GetSwapInterval for backends (#6963) 2023-01-02 10:15:05 -08:00
Sylvain Becker 8a13533949
Handle error return value for SDL_GetSwapInterval 2023-01-01 08:20:41 -08:00
Sam Lantinga cefbeb582f Mouse coordinates are floating point
You can get sub-pixel mouse coordinates and motion depending on the platform and display scaling.

Fixes https://github.com/libsdl-org/SDL/issues/2999
2022-12-29 23:12:19 -08:00