Commit Graph

6275 Commits (2c518747b9cf45c1b94c570c19912e04476e8eed)

Author SHA1 Message Date
Ozkan Sezer 887ae0c6eb fix build failure after commit 2a8d00634d if strtod isn't available. 2022-09-20 18:20:00 +03:00
Sam Lantinga 2a8d00634d Fixed scanning a negative number as an unsigned value
e.g. sscanf("-1", "%zu", &v)

Thanks to @sezero for the test case
2022-09-20 07:25:49 -07:00
Ozkan Sezer 3f5c46663e SDL_vsscanf: fix an uninitialized warning 2022-09-20 11:56:40 +03:00
Sam Lantinga 216e3f10bb Implemented size_t format specifiers for SDL_snprintf() and SDL_sscanf()
Fixes https://github.com/libsdl-org/SDL/issues/6264
2022-09-19 15:42:11 -07:00
Sam Lantinga 101306edcf Do case insensitive matching on test cases 2022-09-19 14:37:10 -07:00
Cameron Cawley 8598f05b47 Support loading 2bpp .bmp files 2022-09-17 16:50:45 -07:00
Cameron Cawley 1f7a7fd931 haiku: Combine HAIKU_ColorSpaceToBitsPerPixel and HAIKU_BPPToSDLPxFormat 2022-09-17 18:13:08 -04:00
Cameron Cawley 43fc6d593f Fix incorrect return value in X11_GetPixelFormatFromVisualInfo 2022-09-17 13:17:42 -07:00
Ivan Epifanov 7115ceb775 Vita: restore sceClibMemcmp 2022-09-17 10:12:46 -07:00
Sam Lantinga 2e9f5b5989 Added support for the HORI Fighting Commander OCTA (Xbox Series X and PS versions) 2022-09-16 15:41:35 -07:00
Ozkan Sezer 5fba31f6fb SDL_HasPrimarySelectionText: fix -Wunreachable-code-return warning. 2022-09-17 00:51:00 +03:00
Sam Lantinga efe01faa8e Replaced Blit4to4CopyAlpha() with optimized SDL_BlitCopy()
Fixes https://github.com/libsdl-org/SDL/issues/6241
2022-09-16 10:09:13 -07:00
Ozkan Sezer c0baa6bf5e move SDL_windowstaskdialog.h contents into SDL_windowsmessagebox.c
Silences clang -Wpragma warnings:

D:/a/SDL/SDL/src/video/windows/SDL_windowstaskdialog.h:21:10: warning: the current #pragma pack alignment value is modified in the included file [-Wpragma-pack]
#include <pshpack1.h>
         ^
D:/a/_temp/msys64/clang64/include/pshpack1.h:7:9: note: previous '#pragma pack' directive that modifies alignment is here
#pragma pack(push,1)
        ^

In file included from D:/a/SDL/SDL/src/video/windows/SDL_windowsmessagebox.c:35:

D:/a/SDL/SDL/src/video/windows/SDL_windowstaskdialog.h:156:10: warning: the current #pragma pack alignment value is modified in the included file [-Wpragma-pack]

#include <poppack.h>

         ^

note: previous '#pragma pack' directive that modifies alignment is here

2 warnings generated.

Closes: https://github.com/libsdl-org/SDL/issues/6240
2022-09-16 20:03:50 +03:00
Sam Lantinga 82b40f097b Fixed runaway CPU usage in the metal renderer when the window is minimized 2022-09-16 09:55:20 -07:00
Sam Lantinga 5892ed4373 Fixed Xcode warnings on macOS 2022-09-16 09:44:39 -07:00
Sam Lantinga 910d499c54 Fixed comment typo 2022-09-16 09:19:20 -07:00
Sam Lantinga 172865ff13 Don't enumerate HID devices on macOS if we don't have input monitoring permissions
Unfortunately the only way to detect this is to actually try opening a device, so we wait until the application tries, and then stop enumerating afterwards.

Fixes https://github.com/libsdl-org/SDL/issues/5781
2022-09-16 09:16:18 -07:00
Sam Lantinga eb046958da Fixed build warning 2022-09-16 08:19:45 -07:00
Sam Lantinga e2753e19e8 Calculate simulated vsync interval based on display refresh rate 2022-09-16 07:44:40 -07:00
Sam Lantinga 208964f038 Reset the simulated vsync presentation timeline if it's been too long since the last present 2022-09-16 07:44:40 -07:00
Sam Lantinga 1663cb4196 Reset simulated presentation timeline when vsync status changes 2022-09-16 07:44:40 -07:00
Sam Lantinga d744aafb05 Added support for simulated vsync in the renderer
This kicks in if the platform doesn't support vsync directly, or if the present fails for some reason (e.g. minimized on some platforms)

Fixes https://github.com/libsdl-org/SDL/issues/5134
2022-09-16 07:44:40 -07:00
Ozkan Sezer 339f7a2f6b SDL_windows.h: guard WIN32_LEAN_AND_MEAN and STRICT macro defines.
also define them as 1, instead of empty.
Reference issue: https://github.com/libsdl-org/SDL/issues/6239
2022-09-16 17:28:20 +03:00
Ozkan Sezer c23fb235c8 SDL_render_d3d12.c: Fix uninitialized warning for CreateEventExFunc 2022-09-16 17:20:56 +03:00
Ozkan Sezer d86cb8ec9e SDL_offscreenwindow.c: swap include order of SDL_egl_c.h/SDL_sysvideo.h
Fixes redefinition warnings from windows builds.
Reference issue: https://github.com/libsdl-org/SDL/issues/6239
2022-09-16 17:05:02 +03:00
Sam Lantinga 5bc85d6788 Only advertise the SDL_PIXELFORMAT_EXTERNAL_OES format if we can build the shader for it 2022-09-16 06:15:45 -07:00
Sam Lantinga 6de15ffcd6 Fixed building offscreen video driver without EGL support
Also did miscellaneous style cleanup for consistency with other code
2022-09-15 12:04:08 -07:00
Sam Lantinga 2970710b5d Pretty print shaders for debugging purposes 2022-09-15 07:41:29 -07:00
Sam Lantinga bc57d3e35c Fixed OpenGL ES shader compilation on Linux 2022-09-15 06:57:41 -07:00
Sam Lantinga 8a15a738f3 Fixed uninitialized variable warning 2022-09-15 06:21:19 -07:00
DS ac5b9bc4ee
Add support for X11 primary selection (#6132)
X11 has a so-called primary selection, which you can use by marking text and middle-clicking elsewhere to copy the marked text.

There are 3 new API functions in `SDL_clipboard.h`, which work exactly like their clipboard equivalents.

## Test Instructions

* Run the tests (just a copy of the clipboard tests): `$ ./test/testautomation --filter Clipboard`
* Build and run this small application:
<details>
```C
#include <SDL.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void print_error(const char *where)
{
	const char *errstr = SDL_GetError();
	if (errstr == NULL || errstr[0] == '\0')
		return;
	fprintf(stderr, "SDL Error after '%s': %s\n", where, errstr);
	SDL_ClearError();
}

int main()
{
	char text_buf[256];

	srand(time(NULL));

	SDL_Init(SDL_INIT_VIDEO);
	print_error("SDL_INIT()");
	SDL_Window *window = SDL_CreateWindow("Primary Selection Test", SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED, 400, 400, SDL_WINDOW_SHOWN);
	print_error("SDL_CreateWindow()");
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
	print_error("SDL_CreateRenderer()");

	bool quit = false;
	unsigned int do_render = 0;
	while (!quit) {
		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			print_error("SDL_PollEvent()");
			switch (event.type) {
			case SDL_QUIT: {
				quit = true;
				break;
			} case SDL_KEYDOWN: {
				switch (event.key.keysym.sym) {
				case SDLK_ESCAPE:
				case SDLK_q:
					quit = true;
					break;
				case SDLK_c:
					snprintf(text_buf, sizeof(text_buf), "foo%d", rand());
					SDL_SetClipboardText(text_buf);
					print_error("SDL_SetClipboardText()");
					printf("clipboard: set_to=\"%s\"\n", text_buf);
					break;
				case SDLK_v: {
					printf("clipboard: has=%d, ", SDL_HasClipboardText());
					print_error("SDL_HasClipboardText()");
					char *text = SDL_GetClipboardText();
					print_error("SDL_GetClipboardText()");
					printf("text=\"%s\"\n", text);
					SDL_free(text);
					break;
				} case SDLK_d:
					snprintf(text_buf, sizeof(text_buf), "bar%d", rand());
					SDL_SetPrimarySelectionText(text_buf);
					print_error("SDL_SetPrimarySelectionText()");
					printf("primselec: set_to=\"%s\"\n", text_buf);
					break;
				case SDLK_f: {
					printf("primselec: has=%d, ", SDL_HasPrimarySelectionText());
					print_error("SDL_HasPrimarySelectionText()");
					char *text = SDL_GetPrimarySelectionText();
					print_error("SDL_GetPrimarySelectionText()");
					printf("text=\"%s\"\n", text);
					SDL_free(text);
					break;
				} default:
					break;
				}
				break;
			} default: {
				break;
			}}
		}
		// create less noise with WAYLAND_DEBUG=1
		if (do_render == 0) {
			SDL_RenderPresent(renderer);
			print_error("SDL_RenderPresent()");
		}
		do_render += 1;
		usleep(12000);
	}

	SDL_DestroyRenderer(renderer);
	SDL_DestroyWindow(window);
	SDL_Quit();
	print_error("quit");
	return 0;
}
```
</details>

* Use c,v,d,f to get and set the clipboard and primary selection.
* Mark text and middle-click also in other applications.
* For wayland under x:
  * `$ mutter --wayland --no-x11 --nested`
  * `$ XDG_SESSION_TYPE=wayland SDL_VIDEODRIVER=wayland ./<path_to_test_appl_binary>`
2022-09-14 09:28:35 -07:00
Sam Lantinga 72fe6cc8f1 Updated to the latest version of OpenGL and Vulkan headers from the Khronos registry
Fixes https://github.com/libsdl-org/SDL/issues/6193
2022-09-14 09:14:47 -07:00
Sam Lantinga b5102a551b Fixed OpenGLES shaders failing after renderer has been created
Cache all the shaders up front, so we can verify that they won't silently fail at runtime.

If compiling the fragment shaders with the precision hint fails, try again without specifying precision.

Fixes https://github.com/libsdl-org/SDL/issues/6166
Fixes https://github.com/libsdl-org/SDL/issues/6174
2022-09-14 08:03:46 -07:00
xeonmc 228b9fb517
Update SDL_windowswindow.c (#6225)
Clip rectangle set to int(left+width/2) , int(top+height/2) , int(left+width/2)+1 , int(top+height/2)+1
a 1x1 box
On even-valued resolution, cursor is stable at bottom-right central pixel
On odd-valued resolution, cursor is stable at exact central pixel.
this is the desired behaviour
2022-09-13 12:43:16 -07:00
Frank Praznik 929d5b80c6 wayland: Use the backbuffer size for determining if a resize event is required
In some cases, a backbuffer size update may not be accompanied by a resize event if the window size and/or scale were updated before the new backbuffer size was recomputed. Instead of the scale, use the old/new backbuffer sizes to determine if a resize event is required so that a backbuffer size change will always be followed by a resize event.
2022-09-13 10:54:35 -07:00
Sam Lantinga 4f1b408a72 Fixed button mapping for PS5 controllers 2022-09-12 18:19:02 -07:00
Amir 7f415ce587 android: fix some compiler warnings 2022-09-12 10:06:08 -07:00
Frank Praznik edfb00c25e wayland: Only commit on move if the display was changed
Only commit on a move event if the display was changed for a fullscreen window and the compositor has returned bad dimensions.
2022-09-09 17:14:49 -07:00
Frank Praznik 97a5e74449 wayland: Remove duplicate code
Wayland_SetWindowSize() can be simplified with the common CommitWindowGeometry() function.
2022-09-09 08:17:27 -07:00
Frank Praznik 78f843f741 wayland: Remove unnecessary function parameter
SetFullscreen() is never called in a case where the commit parameter is false anymore, so the parameter is unnecessary.
2022-09-09 08:17:27 -07:00
Frank Praznik 69e4c770f3 video: Make the mode switching function a NOP if mode switching is disabled
Instead of wrapping individual calls to SDL_SetDisplayModeForDisplay(), just check the flag in the function itself and make it a NOP that cannot fail if the flag is set. Silences some errant "SDL video driver doesn't support changing display mode" log errors.
2022-09-09 08:17:27 -07:00
Frank Praznik 768b6728bd wayland: Compare against the old scale when resizing
Compare against the old scale instead of the new or the conditional will always be true.
2022-09-09 08:17:27 -07:00
Frank Praznik 07aea476ba wayland: Ignore content sizes from libdecor when hiding a window
When hiding a window, libdecor can report bogus content region sizes that are +/- the height of the title bar. Ignore any size values from libdecor when hiding a window, or the size may be incorrect when restored.
2022-09-09 08:17:27 -07:00
Frank Praznik 6de12b4a0d wayland: Update the internal state when the compositor moves a fullscreen window
The compositor can arbitrarily move windows between displays, including fullscreen windows. Update the internal state when a fullscreen window is moved so the internal SDL state accurately reflects the window location, and resize the window to fit the new display.

This also fixes an edge case where the compositor can make a window fullscreen on a different display than SDL thinks it will be on (usually when a window is made fullscreen by the compositor while straddling multiple displays), which can result in the window being incorrectly sized.
2022-09-09 08:17:27 -07:00
Frank Praznik a7d345958d wayland: Trigger a commit on fullscreen update
If additional fullscreen requests are received when the window is already fullscreen, it is typically due to the fullscreen flags or emulated video mode being changed. A commit must be explicitly triggered or the requested changes won't take effect until some other event, such as a resize or focus change, causes the changes to be committed.
2022-09-09 08:17:27 -07:00
Frank Praznik 707b561f97 wayland: Enable compositor fullscreen toggling
The compositor can toggle the fullscreen state (via a hotkey or otherwise), so the internal SDL state must be updated accordingly when it does.

When toggling fullscreen via the compositor, SDL will attempt to use the last fullscreen flag explicitly set. If no flag was previously set, SDL_WINDOW_FULLSCREEN will be used if a window video mode was set, otherwise SDL_WINDOW_FULLSCREEN_DESKTOP will be used. If the previous flag was SDL_WINDOW_FULLSCREEN and the window video mode was cleared, it will revert to SDL_WINDOW_FULLSCREEN_DESKTOP.
2022-09-09 08:17:27 -07:00
Frank Praznik 31979e2d98 wayland: Add missing static qualifiers 2022-09-09 08:17:27 -07:00
Taiko2k 1c88a0522f Update Wayland cursors to match X11 cursors 2022-09-09 08:59:37 -04:00
Sam Lantinga 9f4baeea53 Clean up thread local storage when quitting SDL
SDL_Quit() should be the last SDL API that you call before exiting your application, and is intended to clean up all internal state.

If real-life applications are relying on thread-local storage after SDL_Quit() we could potentially add a hint to control this behavior.

Fixes https://github.com/libsdl-org/SDL/issues/6200
2022-09-08 20:08:20 -07:00
Sam Lantinga a3900a751e Lock joysticks when removing a controller on the WGI thread 2022-09-08 13:59:25 -07:00
Sam Lantinga 12413ab31f Lock joysticks while attaching a virtual one 2022-09-08 13:33:21 -07:00
Ozkan Sezer 787cd580ee silence unused function warning for SDL_endswith() on non-linux. 2022-09-08 23:00:04 +03:00
Sam Lantinga 4071573241 Don't try to second guess DS4Windows, let it remap things as expected.
DS4Windows can create both emulated Xbox and emulated PS4 controllers, and we don't know which the user has it doing, so don't try to second guess it, just let it do it's thing. Users should follow the remapping software recommendations on when to enable/disable it for various situations.

Fixes https://github.com/libsdl-org/SDL/issues/6167
2022-09-08 11:50:56 -07:00
Sam Lantinga a0f169603d Fixed the CRC in the mappings for PS2, PSP, and Vita controllers 2022-09-08 09:53:51 -07:00
Sylvain 90a480a100
Fixed bug #6199 - Broken clip behaviour on a render target (metal) 2022-09-08 05:44:39 +02:00
Sam Lantinga 0ad8d9d292 SDL_IsXInputDevice() shouldn't return true if XInput isn't enabled 2022-09-07 15:31:24 -07:00
Sam Lantinga d93f9a778b The new Wii Remote shares the same VID/PID as the Wii U Pro controller 2022-09-07 12:33:43 -07:00
Sam Lantinga f398d8a424 Note that the Logitech Extreme 3D is a flight stick 2022-09-07 11:53:13 -07:00
Sam Lantinga 0a05b281f2 Make sure we hold the joystick lock when updating the device state while opening it 2022-09-07 11:51:51 -07:00
Sam Lantinga d4e0d27c1c Added Wii Remote controller mappings for Linux 2022-09-07 02:02:04 -07:00
Sam Lantinga 42cf6d6c56 Don't treat the Wii extension controls as a separate game controller on Linux 2022-09-07 01:41:11 -07:00
Sam Lantinga 87f8b6ff0f Don't mess with the state of the Motion Plus extension on Linux 2022-09-07 01:21:01 -07:00
Sam Lantinga c28da4892a Fixed build 2022-09-07 00:52:40 -07:00
Sam Lantinga 638452ecf7 Assert that continuous reporting is enabled, so input timeout is a reliable way of detecting Bluetooth connection problems. 2022-09-07 00:44:13 -07:00
Sam Lantinga 8dfe0e4beb Removed checks not needed for the Wii U Pro Controller 2022-09-07 00:41:29 -07:00
Sam Lantinga 4018f35ef2 Added left and right sensors for Nintendo Joy-Con and Wii controllers 2022-09-07 00:00:27 -07:00
Sam Lantinga 30f55a5d59 Added initial support for the Wii Motion Plus extension
This adds a gyro sensor to the Wii controller, and is enabled in standalone and nunchuk mode
2022-09-06 23:33:55 -07:00
Sam Lantinga 29f4a5ba0e Add GLES2 shader prologue infrastructure. (by @eloj)
There is supposedly an OpenGL ES2 target that does not support precision specifiers. However, the existing logic to detect this is currently broken in two ways:

1) There's a typo of the `#ifdef` as `#if`.
2) Checking for `GL_FRAGMENT_PRECISION_HIGH` can not be the correct way to detect this platform. Other targets, including some desktops, will also not have this defined (for various reasons).

Because some of the shader code is missing precision specifiers, and because a default is ONLY provided if `GL_FRAGMENT_PRECISION_HIGH` is set, these other targets break.

Instead of 'hard-coding' the prologue string into shaders in the C source, use our ability to provide a list of strings to `glShaderSource` instead, leaving the determination to run-time.

This commit closes https://github.com/libsdl-org/SDL/pull/6182
2022-09-06 15:55:27 -07:00
Sam Lantinga 4fd6bba257 Refactored for similarity to surrounding code 2022-09-06 12:29:42 -07:00
Ozkan Sezer 5ffede35d9 Fix https://github.com/libsdl-org/SDL/issues/6191 2022-09-06 19:56:29 +03:00
Cameron Cawley 10e1ef00e2 Fix compatibility with Windows XP 2022-09-06 08:55:35 -04:00
Sam Lantinga d1fea10c0f Added support for the accelerometer in the Wii Remote 2022-09-05 16:08:15 -07:00
Sam Lantinga a61b823da8 Added support for the Wii Remote with the Classic Controller Pro extension
Also changed event order to: buttons, triggers, axes, for consistency with other drivers
2022-09-05 14:32:45 -07:00
Ozkan Sezer 612a86ebad HIDAPI_DriverPS3_UpdateEffects: kill bad use of & operator on effects[] 2022-09-05 20:47:00 +03:00
Sam Lantinga b00e1b1b62 Added support for a ShanWan PS2 -> PS3 USB converter to the HIDAPI driver 2022-09-05 10:01:51 -07:00
Cameron Cawley fd93f817ba Assume that stdint.h is available on Windows with compilers other than MSVC <= 2008 2022-09-05 09:01:31 -07:00
Sylvain 03485db0a3
Android: understand HAL_PIXEL_FORMAT_BGR_565 as a returned value from ANativeWindow_getFormat() (see #6016) 2022-09-03 23:40:14 +02:00
Sam Lantinga 1b4e08b89e Added an entry for the Hori Fighting Stick mini 4 kai
This is a PS3/PS4 arcade stick which becomes an Xbox 360 controller on PC
2022-09-02 17:04:53 -07:00
Sam Lantinga 47f2373dc1 Added locking for Android joystick events 2022-09-02 16:52:55 -07:00
Sam Lantinga e8f6b7503a Added mappings for the ASUS ROG Kunai 3 Gamepad 2022-09-02 15:06:13 -07:00
Sam Lantinga 5770e87cb2 Fixed regression handling touchpad input with PS5 controllers using the original shipping firmware 2022-09-02 13:57:59 -07:00
Sam Lantinga 253f6a913d Variable renaming for consistency 2022-09-02 11:49:06 -07:00
Sam Lantinga 5002624e8a Fixed crash when extension controllers are hotplugged 2022-09-02 11:41:19 -07:00
Sam Lantinga 7df571ffc6 HIDAPI_DumpPacket() takes a const memory pointer 2022-09-02 11:37:16 -07:00
Sam Lantinga b6d23d21db Fixed interactions with the Linux Wiimote driver 2022-09-02 11:21:51 -07:00
Ozkan Sezer 0c984360d1 SDL_hidapi_wii.c: fix a -Wshadow warning 2022-09-02 20:02:56 +03:00
Sam Lantinga b6b3fb0023 This was intended to be Uint8 2022-09-02 09:59:32 -07:00
Ozkan Sezer 5be157b3a2 SDL_hidapi_wii.c: fix -Wpointer-sign warnings 2022-09-02 19:33:40 +03:00
Sam Lantinga 54356f41a9 Wii: fixed trigger axis reporting for the Wii U Pro Controller 2022-09-02 09:03:44 -07:00
Sam Lantinga a35642fa3e Wii: don't bother reading the extension type for the Wii U Pro controller, we already know what it is 2022-09-02 08:58:52 -07:00
Sam Lantinga c3ecb9d099 Wii: re-request the status if we get a communication error 2022-09-02 08:58:52 -07:00
Ozkan Sezer 0c24b46e9f SDL_hidapi_wii.c: fix build in c89 mode. 2022-09-02 18:55:00 +03:00
Sam Lantinga 9874fc4e6a Reconnect as a different controller if the Wii extension hardware changes 2022-09-02 08:47:15 -07:00
Sam Lantinga 5f3cb54972 Updated Wii support with @tellowkrinkle's changes in 2f288e9d5b 2022-09-02 08:28:28 -07:00
Sam Lantinga 785d784a93 Set the output value for ParseExtensionResponse() in all return cases 2022-09-01 22:30:05 -07:00
Sam Lantinga 046aaa2d21 Use auto calibration for the Wii Nunchuk thumbstick axis values 2022-09-01 21:37:26 -07:00
Sam Lantinga 8381e008ea Handle hotplugging of Wii controller extensions 2022-09-01 21:13:16 -07:00
Sam Lantinga 396411c090 Added mapping for the Wii Nunchuk extension 2022-09-01 20:27:34 -07:00
Sam Lantinga e19b36d871 Initial support for the Wii Remote with Nunchuk extension 2022-09-01 19:29:20 -07:00
Sam Lantinga c887cb02af Added the hint SDL_HINT_JOYSTICK_HIDAPI_WII_PLAYER_LED to control whether the player LED should be lit on the Nintendo Wii controllers
Also fixed the Y axes on the Wii U Pro controller, and various formatting cleanup
2022-09-01 16:30:55 -07:00