SDL/src
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
..
atomic Proposing exposing as public api the various arch dependent 2022-08-04 08:47:39 -07:00
audio Add more valid configurations to PS2 audio driver 2022-08-27 18:34:33 -07:00
core Assume that stdint.h is available on Windows with compilers other than MSVC <= 2008 2022-09-05 09:01:31 -07:00
cpuinfo Use proper header for OpenBSD PPC CPU detection 2022-06-27 11:01:34 -07:00
dynapi Add support for X11 primary selection (#6132) 2022-09-14 09:28:35 -07:00
events Added a hint SDL_HINT_MOUSE_RELATIVE_SYSTEM_SCALE to control whether to use system mouse acceleration on raw relative motion. 2022-08-22 16:48:09 -07:00
file Xbox GDKX support (#5869) 2022-07-01 13:59:14 -07:00
filesystem Fixed some Xcode warnings 2022-07-17 09:07:04 -07:00
haptic Xbox GDKX support (#5869) 2022-07-01 13:59:14 -07:00
hidapi hidapi: really fix dynamic / non-dynamic libusb loading. 2022-09-01 22:55:00 +03:00
joystick Fixed button mapping for PS5 controllers 2022-09-12 18:19:02 -07:00
libm Add some PS2 flags 2022-06-15 15:15:26 -07:00
loadso use SDL_InvalidParamError or SDL_assert instead of custom SDL_SetError 2022-01-28 20:40:19 -05:00
locale Vita: add SDL_GetPreferredLocales support 2022-03-29 15:02:21 -07:00
main Disable fileXio and patch fio 2022-08-24 12:23:56 -07:00
misc Xbox GDKX support (#5869) 2022-07-01 13:59:14 -07:00
power Don't fail to get battery status if the upower refresh call fails 2022-02-04 14:02:44 -08:00
render Fixed OpenGLES shaders failing after renderer has been created 2022-09-14 08:03:46 -07:00
sensor Removed problematic call to ISensor_SetEventSink() 2022-03-17 10:01:13 -07:00
stdlib Fixed potential uninitialized variable usage 2022-08-12 20:51:28 -07:00
test test: Fixed wrong arguments to SDL_SetWindowFullscreen. 2022-08-09 09:29:30 -04:00
thread Xbox GDKX support (#5869) 2022-07-01 13:59:14 -07:00
timer Xbox GDKX support (#5869) 2022-07-01 13:59:14 -07:00
video Add support for X11 primary selection (#6132) 2022-09-14 09:28:35 -07:00
SDL.c Clean up thread local storage when quitting SDL 2022-09-08 20:08:20 -07:00
SDL_assert.c hide SDL_GenerateAssertionReport in case SDL_ASSERT_LEVEL is 0 2022-07-25 14:26:46 -07:00
SDL_assert_c.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_dataqueue.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_dataqueue.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_error.c Fix SIGSEV in SDL_error (After removing the limit on the size of the SDL error message) (see #5795) 2022-06-28 09:46:12 +02:00
SDL_error_c.h Removed the limit on the size of the SDL error message 2022-06-27 16:59:50 -07:00
SDL_guid.c Refactoring: move GUID operations out of Joystick 2022-06-04 17:22:13 -07:00
SDL_hints.c Added SDL_ResetHint() to reset a hint to the default value 2022-08-10 08:01:24 -07:00
SDL_hints_c.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_internal.h Fix enabling SDL_DYNAMIC_API in OpenWatcom builds 2022-05-19 20:11:10 +03:00
SDL_list.c Add SDL_list.c/h 2022-04-01 08:01:44 +02:00
SDL_list.h Add SDL_list.c/h 2022-04-01 08:01:44 +02:00
SDL_log.c android: Add missing entries to SDL_category_prefixes table. 2022-07-05 17:50:19 -07:00
SDL_log_c.h Added declaration of SDL_LogInit() and SDL_LogQuit() 2022-04-28 15:01:34 -07:00
SDL_utils.c Fixed declaration-after-statement warning 2022-07-18 07:31:23 -07:00
SDL_utils_c.h Fixed comment (thanks @pionere!) 2022-07-18 07:18:56 -07:00