Commit graph

7041 commits

Author SHA1 Message Date
Sam Lantinga 00e02de77b Fixed mis-detecting the share button on the Xbox controller over NDIS 2023-02-08 14:16:21 -08:00
Sam Lantinga d1c72bb0bc Dynamically update the serial number if it isn't available at first
This happens for Xbox One controllers using newer firmware connected over NDIS
2023-02-08 14:16:17 -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 6c37d5b57f x11: Cast the dot clock value to 64-bit when calculating the refresh rate
The Xrandr dot clock value is declared as an unsigned long and the result when multiplying by 100 can overflow on a 32-bit system. Explicitly cast it to Sint64 to ensure that no overflow will occur.
2023-02-07 13:39:38 -05:00
Sam Lantinga 20a4e31a12 Re-added the internal hint SDL_BORDERLESS_WINDOWED_STYLE
sdl2-compat should set this to "0"
2023-02-07 09:47:17 -08:00
Pierre Wendling fa8fba3812 Add clang-tidy config and CMake/CI support. 2023-02-06 21:02:25 -08:00
Sam Lantinga 5fded632d6 Added support for the Turtle Beach REACT-R and Recon Xbox controllers 2023-02-06 20:14:12 -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
Sam Lantinga 0208a0eeb3 Added support for the Logitech ChillStream 2023-02-06 13:28:59 -08:00
Ozkan Sezer b82a8b76b1 windows/SDL_systhread.c: remove some dead code. 2023-02-07 00:22:20 +03:00
Sam Lantinga 22bafe8729 Removed debug code accidentally committed 2023-02-06 11:23:53 -08:00
Sam Lantinga f8b41919da Fixed warning running a command queue without any vertex operations 2023-02-06 11:22:00 -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
Sam Lantinga 9d8f98c735 Don't change presentation modes when resizing the logical target
Fixes https://github.com/libsdl-org/SDL/issues/7251
2023-02-06 08:51:58 -08:00
Sylvain 6f0acca8bd Return the SDL_SetError value 2023-02-06 11:42:38 +01:00
Sean Ridenour a077cc8e4d
[SDL3] macOS SetCursor performance fix (fixes #7151) (#7249)
* Setting the same mouse cursor twice is a no-op

* Cocoa: Call [NSCursor set] to change mouse cursor

The previous way, changing the mouse cursor was handled by invalidating
the mouse cursor rectangles and then recreating them (with the new
cursor) the next event loop. This is extremely slow; sometimes it can
take over a millisecond! With [NSCursor set] it happens instantly and
very quick performance-wise.

The downside is that it sets the cursor for the whole screen, so we
have some guards in place to change it to the system cursor if
the mouse moves outside the window or the window loses focus.

* Cocoa: Remove unneeded resetCursorRects: function
2023-02-05 17:58:33 -08:00
Sylvain fbe0352764 SDL_DestroyRenderer: drop all commands first
and don't queue new command from SDL_DestroyTexture() (memory leak)
2023-02-05 13:35:08 -08:00
Sam Lantinga ec1b42557f Fixed memory leak at shutdown (thanks @1bsyl!)
Clean up the textures first, as destroying the current render target will queue viewport and clip rectangle commands
2023-02-05 09:10:21 -08:00
Leonardo Brondani Schenkel 6f06e4bc80 Add Linux mapping for 8BitDo Pro 2 Wired Controller for Xbox
Without these mappings, this controller "kinda" works out of the box:
- `SDL_GameControllerMapping()` works because it will notice "Xbox" in
  the name and use the default XInput mappings
- `SDL_GameControllerMappingForGUID()` will not find any mapping

lsusb:
```
ID 2dc8:2000 8BitDo 8BitDo Pro 2 Wired Controller for Xbox
```

In Linux this controller is supported by two drivers:
- `xpad` (built-in to the kernel), exposes the controller name from the
  USB descriptor and the GUID starts with 03 (0x03 = BUS_USB)
- `xone` (https://github.com/medusalix/xone), exposes a virtual
  controller which is always named "Microsoft X-Box One pad" and the
  GUID starts with 06 (0x06 = BUS_VIRTUAL)

This commit adds the 2 GUIDs from both drivers so mappings will always
be found and the real controller name will always be reported.

(cherry picked from commit 4266cf8504)
2023-02-05 08:45:24 -08:00
Sam Lantinga 1c03ddefc3 Sorted controller list 2023-02-05 08:43:26 -08:00
Antonis Geralis 52cd9fcbb0 Added Elecom 8button gamepad 2023-02-05 08:41:07 -08:00
Frank Praznik b2d8a1a58c wayland: Transform mode values for native portrait displays
Portrait displays may have native, physical resolutions that are taller than wide. Reverse the mode dimensions when dealing with these displays as well as those rotated via software means.
2023-02-04 11:40:55 -05:00
Sam Lantinga 2a83093b36 Use a reasonable upper bound on the number of pixels we'll try to draw when traversing a line
Fixes https://github.com/libsdl-org/SDL/issues/6116
2023-02-03 20:53:30 -08:00
Alynne 4dea13e02f Adds Stadia BT mapping 2023-02-03 15:01:49 -08:00
Sam Lantinga 14a4ce8b59 Fixed SDL_ScaleMode values for consistency 2023-02-03 14:20:51 -08:00
Sam Lantinga e5edce8e75
Fixed permissions on src/render/SDL_render.c (#7232) 2023-02-03 13:14:48 -08:00
Sylvain Becker cb6b8b0132
Simplify flags testing (#7220) 2023-02-03 13:08:42 -08:00
Sam Lantinga dcd17f5473 Renderer logical size is now implemented as a render target
This fixes rounding errors with coordinate scaling and gives more flexibility in the presentation, as well as making it easy to maintain device independent resolution as windows move between different pixel density displays.

By default when a renderer is created, it will match the window size so window coordinates and render coordinates are 1-1.

Mouse and touch events are no longer filtered to change their coordinates, instead you can call SDL_ConvertEventToRenderCoordinates() to explicitly map event coordinates into the rendering viewport.

SDL_RenderWindowToLogical() and SDL_RenderLogicalToWindow() have been renamed SDL_RenderCoordinatesFromWindow() and SDL_RenderCoordinatesToWindow() and take floating point coordinates in both directions.

The viewport, clipping state, and scale for render targets are now persistent and will remain set whenever they are active.
2023-02-03 12:57:37 -08:00
Frank Praznik 0bf91e16b7 wayland: Fix non-floating libdecor window sizing 2023-02-03 11:07:31 -05:00
Ozkan Sezer 9f21bed729 dynapi: cast GetProcAddress() result to void* 2023-02-03 17:40:40 +03: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 7def1438c3 wayland: Refactor for video core changes
Accommodate the new video core changes.

The new video core changes allow for some window geometry calculation refactoring that simplify the system:

- Removal of helper functions
- Eliminate some discrepancies between the libdecor and xdg-toplevel paths
- No need to short-circuit the video core window size event deduplication check
- Exclusive fullscreen windows will always end up on the correct output, even when fullscreen is initiated from the compositor
- Better handling of cases where the desktop is scaled, but does not expose the viewport protocol
- Return the display bounds for the emulated mode if an exclusive fullscreen window has focus
- Fixed cases where changing display properties during runtime wouldn't update the display mode lists
- General cleanup
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
Sam Lantinga 673bc57649 Don't accept official mappings for controllers that aren't unique
For example, the DragonRise Inc. Generic USB Joystick
See https://github.com/gabomdq/SDL_GameControllerDB/issues/202 for details
2023-02-02 08:39:54 -08:00
Sam Lantinga 917607c335 Fixed sort_controllers.py and resorted game controller database 2023-02-02 08:38:22 -08:00
Sam Lantinga d29e1f3632 Added gamepad mappings for the Xin-Mo Dual Arcade Fightstick 2023-02-01 23:09:53 -08:00
Sasha Szpakowski baca26d727 macOS: fix initial Metal drawable size in certain multi-display setups 2023-02-01 22:38:55 -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
Anonymous Maarten d8f0715385 Revert "Remove unused SDL_GetCPUName"
This reverts commit 4e6ab13d6f.
2023-02-02 00:49:09 +01:00
Anonymous Maarten 69aede6c9e Add missing _ in SDL_EVENT_LOCALECHANGED and SSDL_EVENT_TEXTEDITING_EXT 2023-02-02 00:49:09 +01:00
Anonymous Maarten 08bcee8570 test: don't use wiki urls for documentation comments
Also make consistent use of \ as documentation escape character.
2023-02-02 00:49:09 +01:00
Anonymous Maarten 4e6ab13d6f Remove unused SDL_GetCPUName 2023-02-01 23:17:15 +01:00
Sam Lantinga 177a6f38e0 Only minimize the window for an assert if it's in exclusive fullscreen mode 2023-02-01 12:05:25 -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
Anonymous Maarten 048df6260c Remove disabled self test main functions in src/SDL_error.c 2023-02-01 20:14:48 +01:00
Anonymous Maarten 4af93990a9 Remove disabled self test main functions 2023-02-01 20:13:34 +01:00