Commit Graph

159 Commits

Author SHA1 Message Date
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 3cbfd75d0f Re-added the CRC to the joystick guid
This is now used as a crc field in the mapping rather than directly in mapping guids, for better mapping compatibility between versions of SDL.

Added SDL_GetJoystickGUIDInfo() to get device information encoded in a joystick GUID, so that mapping programs can clear the CRC from the GUID when generating mappings.

sort_controllers.py has been updated to extract the CRC from mappings created by older mapping programs and convert it into the new crc field. It will also take the CRC into account when checking for duplicate mappings.

Also regenerated the GUIDs for the PS2/PSP/Vita controller mappings, fixing https://github.com/libsdl-org/SDL/issues/6151
2022-08-27 19:00:31 -07:00
Noel Berry 00452e47fa
Adding SDL_GetWindowSizeInPixels for window size in pixels (#6112) 2022-08-24 11:25:13 -07:00
Sam Lantinga b4c4dd84c2 Added SDL_crc16() to be used in joystick GUIDs after 2.24.0 2022-08-11 09:53:25 -07:00
Sam Lantinga d4192850c1 Added SDL_ResetHint() to reset a hint to the default value
Resolves question of how to clear an override hint raised by @pionere in https://github.com/libsdl-org/SDL/pull/5309
2022-08-10 08:01:24 -07:00
Sam Lantinga 98bac00dcc Add `SDL_GetPointDisplayIndex` and `SDL_GetRectDisplayIndex` and re-implement `SDL_GetWindowDisplayIndex` in terms of `SDL_GetRectDisplayIndex`
- This allows looking up the display index for an arbitrary location rather than requiring an active window to do so.

- This change also reimplements the fallback display lookup that found the display with center closest to the window's center to instead find the display rect edge
  closest to the window center (this was done in the almost identical display lookup used in SDL_windowsmodes.c, which now uses `SDL_GetPointDisplayIndex`). In
  practice this should almost never be hit as it requires the window's center to not be enclosed by any display rect.
2022-08-08 11:26:52 -07:00
Ethan Lee 2f0816adb7 Add SDL_GetDefaultAudioInfo.
This API is supported on pipewire, pulseaudio, wasapi, and directsound.

Co-authored-by: Frank Praznik <frank.praznik@gmail.com>
2022-07-11 13:34:35 -04:00
Sam Lantinga 2373da5d94 Exposed SDL_ResetKeyboard() as a public function
This will be used by Source 2 titles to reset keyboard state before showing assertion dialogs
2022-07-11 09:49:00 -07:00
Sam Lantinga cbd0187475 Removed the limit on the size of the SDL error message
Also added SDL_GetOriginalMemoryFunctions()

Fixes https://github.com/libsdl-org/SDL/issues/5795
2022-06-27 16:59:50 -07:00
chalonverse 3b191580c3
Windows GDK Support (#5830)
* Added GDK

* Simplfied checks in SDL_config_wingdk.h

* Added testgdk sample

* Added GDK readme

* Fixed error in merge of SDL_windows.h

* Additional GDK fixes

* OpenWatcom should not export _SDL_GDKGetTaskQueue

* Formatting fixes

* Moved initialization code into SDL_GDKRunApp
2022-06-27 10:19:39 -07:00
Guldoman 74bcc5a0a3 stdlib: Add `SDL_utf8strnlen` 2022-06-09 15:18:50 -07:00
chalonverse 4082821822
DirectX 12 Renderer (#5761)
* DirectX 12 Renderer (27 squashed commits)

* Add missing SDL_hidapi.h of merge of SDL.vcxproj.filters

* Fixed OpenWatcom build failure

* Dynapi fix

Co-authored-by: Ryan C. Gordon <icculus@icculus.org>
2022-06-06 17:42:30 -07:00
Ozkan Sezer 61115aebd3 update dynapi after the loongarch support patch 2022-06-06 19:29:56 +03:00
Christoph Reichenbach 3a20274ddf Refactoring: move GUID operations out of Joystick
- SDL_JoystickGUID -> SDL_GUID (though we retain a type alias)
- Operations for GUID <-> String ops are now in
  src/SDL_guid.c and include/SDL_guid.h
- The corresponding Joystick operations delegate to SDL_guid.c
- Added test/testguid.c
2022-06-04 17:22:13 -07:00
Sam Lantinga 423141bfca Added a function to get the controller firmware version 2022-06-03 18:50:00 -07:00
Cameron Cawley f5cf0e37f7 Remove unused and duplicate defines from SDL_dynapi_overrides.h 2022-05-19 17:23:24 +03:00
Sam Lantinga 94eeb587c1 First pass at extending virtual controller functionality
Added the ability to specify a name and the product VID/PID for a virtual controller

Also added a test case to testgamecontroller, if you pass --virtual as a parameter
2022-05-15 20:01:12 -07:00
Sam Lantinga e551384a99 Added functions to get the platform dependent name for a joystick or game controller 2022-04-26 14:54:14 -07:00
Ozkan Sezer e9ff4fdd49 add SDL_bsearch 2022-04-26 04:03:25 +03:00
Sylvain Becker c23a7ad38a
Add SDL_RenderGetWindow() API to get the window associated with a renderer (#5440)
Add SDL_RenderGetWindow() API to get the window associated with a renderer
2022-03-23 17:07:56 +01:00
Ryan C. Gordon d81fee7623
SDL_Rect: Added floating point versions of all the rectangle APIs.
Fixes #5110.
2022-03-19 10:35:24 -04:00
Zach Reedy d14a126383
IME Composition Truncation + SDL_IsTextInputShown + SDL_ClearComposition (#5398)
* Fixes for IME Composition Truncation + Addition of SDL_ClearComposition, SDL_IsTextInputShown

* Fixed: Documentation and code style issues raised during code review.
2022-03-11 14:45:17 -08:00
Sylvain e7e44df039
Dynapi: add SDL_GetTouchName() entry 2022-02-08 11:34:41 +01:00
Sylvain fe2ed6cf6f
Fixed bug #5221 - Add SDL_AndroidSendMessage() 2022-02-01 11:30:43 +01:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Sam Lantinga c97b721868 Added SDL_PremultiplyAlpha() to premultiply alpha on a block of SDL_PIXELFORMAT_ARGB8888 pixels 2021-11-21 12:18:10 -08:00
Sam Lantinga 9c3bcf8e8a Added SDL_hid_ble_scan() for pairing Steam Controllers on iOS and tvOS 2021-11-11 17:31:14 -08:00
Sam Lantinga 36b2690e40 Moved SDL HIDAPI functions into a single block for the ABI 2021-11-11 15:48:56 -08:00
Cameron Gutman fe09a4930a joystick: Add APIs to query rumble support 2021-11-11 15:10:08 -08:00
Sam Lantinga b15e880e73 Fixed open functions in the SDL_hidapi.h header 2021-11-11 13:50:16 -08:00
Sam Lantinga c9ada1c142 Made HIDAPI device change notifications available via SDL_hid_device_change_count() 2021-11-11 12:46:10 -08:00
Eric Wasylishen 0d98793693
testwm2: Fix video modes menu hit detection when highdpi or logical size used (#4936)
* SDLTest_CommonDrawWindowInfo: log SDL_RenderGetScale, SDL_RenderGetLogicalSize

* testwm2: fix video modes menu hit detection in High DPI cases

- also when logical size is specified, e.g.
  `--logical 640x480 --resizable --allow-highdpi`

* add function to determine logical coordinates of renderer point when given window point

* change since to the targeted milestone

* fix typo

* rename for consistency

* Change logical coordinate type to float, since we can render with floating point precision.

* add function to convert logical to window coordinates

* testwm2: use new SDL_RenderWindowToLogical

* SDL_render.c: alternate SDL_RenderWindowToLogical/SDL_RenderLogicalToWindow

Co-authored-by: John Blat <johnblat64@protonmail.com>
Co-authored-by: John Blat <47202511+johnblat64@users.noreply.github.com>
2021-11-09 21:03:42 -08:00
Sam Lantinga fd79607eb0 Added SDL_GetWindowMouseRect()
Also guarantee that we won't get mouse movement outside the confining area, even if the OS implementation allows it (e.g. macOS)
2021-11-08 21:34:48 -08:00
Ethan Lee 4b42c05ba1 video: Add SDL_SetWindowMouseRect.
This API and implementation comes from the Unreal Engine branch of SDL, which
originally called this "SDL_ConfineCursor".

Some minor cleanup and changes for consistency with the rest of SDL_video, but
there are two major changes:

1. The coordinate system has been changed so that `rect` is _window_ relative
   and not _screen_ relative, making it easier to implement without having
   global access to the display.
2. The UE version unset all rects when passing `NULL` as a parameter for
   `window`, this has been removed as it was an unused feature anyhow.

Currently this is only implemented for X, but can be supported on Wayland and
Windows at minimum too.
2021-11-08 14:16:54 -08:00
Sam Lantinga 5b646cd19e Build hidapi code into SDL as a new public API
This prevents conflicts with hidapi linked with applications, as well as allowing applications to make use of HIDAPI on Android and other platforms that might not normally have an implementation available.
2021-11-07 23:00:59 -08:00
Sam Lantinga e14358265e Cleanup sfSymbolName support and add them to the dynamic API functions 2021-11-07 11:16:48 -08:00
Frank Praznik 43ddc59fa8
Export SDL_LinuxSetThreadPriorityAndPolicy() function (#4877)
It's marked as being a public symbol internally, however, it was missing from the header files and not visible in the shared library.  This adds it to the necessary headers and to the DynAPI list to expose it for use by applications.

Co-authored-by: Frank Praznik <frank.praznik@oh.rr.com>
2021-11-02 13:56:14 -07:00
Ryan C. Gordon 99c9727dc0 timer: Added SDL_GetTicks64(), for a timer that doesn't wrap every ~49 days.
Note that this removes the timeGetTime() fallback on Windows; it is a
32-bit counter and SDL2 should never choose to use it, as it only is needed
if QueryPerformanceCounter() isn't available, and QPC is _always_ available
on Windows XP and later.

OS/2 has a similar situation, but since it isn't clear to me that similar
promises can be made about DosTmrQueryTime() even in modern times, I decided
to leave the fallback in, with some heroic measures added to try to provide a
true 64-bit tick counter despite the 49-day wraparound. That approach can
migrate to Windows too, if we discover some truly broken install that doesn't
have QPC and still depends on timeGetTime().

Fixes #4870.
2021-11-01 14:28:00 -04:00
Cacodemon345 19dee1cd16
Add SDL_GetWindowICCProfile(). (#4314)
* Add SDL_GetWindowICCProfile

* Add new SDL display events

* Implement ICC profile change event for macOS

* Implement ICC profile notification for Windows

* Fix SDL_GetWindowICCProfile() for X11

* Fix compile errors
2021-10-21 17:37:20 -07:00
Sylvain 8b1a2fe860
backout SDL_AndroidSetInputType() 2021-10-17 23:47:59 +02:00
Sylvain 6ef3bc5688
Add Dynapi for SDL_AndroidSetInputType() 2021-10-17 23:40:36 +02:00
Cameron Cawley 25a614bc3e Add SDL_asprintf and SDL_vasprintf 2021-09-22 11:53:46 -07:00
Misa 4549769d7d Add `SDL_RenderSetVSync()`
Currently, if an application wants to toggle VSync, they'd have to tear
down the renderer and recreate it. This patch fixes that by letting
applications call SDL_RenderSetVSync().

This is the same as the patch in #3673, except it applies to all
renderers (including PSP, even thought it seems that the VSync flag is
disabled for that renderer). Furthermore, the renderer flags also change
as well, which #3673 didn't do. It is also an API instead of using hint
callbacks (which could be potentially dangerous).

Closes #3673.
2021-09-14 09:56:29 -07:00
Sylvain 08d6a4653e Fix dynapi prototypes 2021-08-19 00:10:59 +02:00
Sylvain cc37c38e30 Add SDL_RenderGeometry based on SDL_RenderGeometryRaw 2021-08-19 00:10:59 +02:00
Sylvain e481261173 Move to SDL_RenderGeometryRaw prototype with separate xy/uv/color pointer parameters 2021-08-19 00:10:59 +02:00
Sylvain 9eab5195fe Update dynapi files 2021-08-19 00:10:59 +02:00
Sam Lantinga f5794f9eeb Added SDL_SetTextureUserData() and SDL_GetTextureUserData() to associate a user-specified pointer with an SDL texture 2021-08-10 15:17:59 -07:00
Sam Lantinga a186a503e7 Added SDL_GameControllerGetSensorDataRate() to get the sensor update rate for a controller. 2021-07-29 06:43:39 -07:00
Sam Lantinga d135c0762f Added SDL_GameControllerSendEffect() and SDL_JoystickSendEffect() to allow applications to send custom effects to the PS4 and PS5 controllers
See testgamecontroller.c for an example of a custom PS5 trigger effect
2021-07-08 13:22:41 -07:00