SDL/src/video
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
..
android Android: understand HAL_PIXEL_FORMAT_BGR_565 as a returned value from ANativeWindow_getFormat() (see #6016) 2022-09-03 23:40:14 +02:00
arm ARM: NEON assembly optimization for SDL_FillRect 2019-10-24 21:17:52 -04:00
cocoa Adding SDL_GetWindowSizeInPixels for window size in pixels (#6112) 2022-08-24 11:25:13 -07:00
directfb keyboard: Remove no-op calls to SDL_SetKeymap() 2022-07-31 15:46:35 -07:00
dummy video: dummy: Support evdev psuedo-device with no video. 2022-08-08 08:31:04 -07:00
emscripten Adding SDL_GetWindowSizeInPixels for window size in pixels (#6112) 2022-08-24 11:25:13 -07:00
haiku video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
khronos Updated to the latest version of OpenGL and Vulkan headers from the Khronos registry 2022-09-14 09:14:47 -07:00
kmsdrm Fixed spacing 2022-08-24 10:10:49 -07:00
nacl video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
ngage video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
offscreen video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
os2 video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
pandora video: Only check major version in SDL_GetWindowWMInfo 2022-05-24 08:56:23 -07:00
ps2 Implement create windows method 2022-08-04 15:41:43 -07:00
psp Remove unused internal header SDL_sysevents.h 2022-07-01 07:39:48 -07:00
qnx QNX: use SDL_malloc 2021-11-22 08:38:46 -08:00
raspberry Remove unused internal header SDL_sysevents.h 2022-07-01 07:39:48 -07:00
riscos video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
uikit cocoa/uikit: Use VK_EXT_metal_surface in Vulkan_GetInstanceExtensions 2022-08-19 09:48:22 -07:00
vita video: Only check major version in SDL_GetWindowWMInfo 2022-05-24 08:56:23 -07:00
vivante video: Only check major version in SDL_GetWindowWMInfo 2022-05-24 08:56:23 -07:00
wayland Add support for X11 primary selection (#6132) 2022-09-14 09:28:35 -07:00
windows Update SDL_windowswindow.c (#6225) 2022-09-13 12:43:16 -07:00
winrt video: removed unused devindex argument from bootstrap's create method. 2022-07-26 00:19:52 -04:00
x11 Add support for X11 primary selection (#6132) 2022-09-14 09:28:35 -07:00
yuv2rgb Add optimiztion function with LSX in LoongArch 2022-06-06 08:49:09 -07:00
SDL_RLEaccel.c Don't use SDL_SIMDFree() if the pixels haven't been allocated with SDL_SIMDAlloc() 2022-05-11 08:40:17 -07:00
SDL_RLEaccel_c.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_blit.c Fixed bug #2199: make SDL_blit_slow handles SDL_PIXELFORMAT_ARGB2101010, storing as RGBA 2022-03-15 17:46:12 +01:00
SDL_blit.h fixed SDL_BlitMap typedef redefinition errors 2022-06-22 01:37:00 +03:00
SDL_blit_0.c Fixed bug #2140: basic support to convert 16 colors palette PIXELFORMAT_INDEX4, to allow conversion to SDL_Texture 2022-02-10 13:44:59 +01:00
SDL_blit_1.c Add clang-format on/off comments where necessary. 2022-05-19 01:31:29 -07:00
SDL_blit_A.c Add clang-format on/off comments where necessary. 2022-05-19 01:31:29 -07:00
SDL_blit_N.c Add clang-format on/off comments where necessary. 2022-05-19 01:31:29 -07:00
SDL_blit_auto.c Add clang-format on/off comments where necessary. 2022-05-19 01:31:29 -07:00
SDL_blit_auto.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_blit_copy.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_blit_copy.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_blit_slow.c SDL_blit_slow: remove one nested 'if()' because of ARGB2101010 handling 2022-03-16 18:08:20 +01:00
SDL_blit_slow.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_bmp.c Fixed loading 32-bit BMP files 2022-03-31 16:15:51 -07:00
SDL_clipboard.c Add support for X11 primary selection (#6132) 2022-09-14 09:28:35 -07:00
SDL_egl.c egl: Add support for SDL_GL_FLOATBUFFERS. 2022-08-09 15:41:02 -04:00
SDL_egl_c.h Rename variables in SDL_egl.c to be more intuitive 2022-06-11 14:20:18 -07:00
SDL_fillrect.c Add clang-format on/off comments where necessary. 2022-05-19 01:31:29 -07:00
SDL_pixels.c Handle SDL_PIXELFORMAT_EXTERNAL_OES in SDL_GetPixelFormatName() 2022-08-16 07:29:45 -07:00
SDL_pixels_c.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_rect.c SDL_Rect: Added floating point versions of all the rectangle APIs. 2022-03-19 10:35:24 -04:00
SDL_rect_c.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_rect_impl.h SDL_Rect: Added floating point versions of all the rectangle APIs. 2022-03-19 10:35:24 -04:00
SDL_shape.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_shape_internals.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_stretch.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_surface.c video: Note unused SDL_surface creation parameters for removal in SDL 3 2022-06-13 11:53:53 -07:00
SDL_sysvideo.h Add support for X11 primary selection (#6132) 2022-09-14 09:28:35 -07:00
SDL_video.c video: Make the mode switching function a NOP if mode switching is disabled 2022-09-09 08:17:27 -07:00
SDL_vulkan_internal.h cocoa/uikit: Support VK_EXT_metal_surface 2022-08-19 09:48:22 -07:00
SDL_vulkan_utils.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
SDL_yuv.c Add optimiztion function with LSX in LoongArch 2022-06-06 08:49:09 -07:00
SDL_yuv_c.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
sdlgenblit.pl Add clang-format on/off comments where necessary. 2022-05-19 01:31:29 -07:00