1
0
Fork 0
mirror of https://github.com/Ryujinx/SDL.git synced 2025-03-08 10:00:15 +00:00
SDL/test
DS ac5b9bc4ee
Add support for X11 primary selection ()
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
..
emscripten
nacl
shapes
acinclude.m4
autogen.sh
axis.bmp
button.bmp
checkkeys.c
checkkeysthreads.c
CMakeLists.txt
configure
configure.ac
controllermap.bmp
controllermap.c Allow mapping a controller other than the first one 2022-09-07 01:58:42 -07:00
controllermap_back.bmp
COPYING
icon.bmp
loopwave.c
loopwavequeue.c
Makefile.in
Makefile.os2
Makefile.w32
moose.dat
picture.xbm
README
relative_mode.markdown
sample.bmp
sample.wav
template.test.in
testatomic.c
testaudiocapture.c
testaudiohotplug.c
testaudioinfo.c
testautomation.c
testautomation_audio.c
testautomation_clipboard.c Add support for X11 primary selection () 2022-09-14 09:28:35 -07:00
testautomation_events.c
testautomation_guid.c
testautomation_hints.c
testautomation_joystick.c
testautomation_keyboard.c
testautomation_main.c
testautomation_math.c
testautomation_mouse.c
testautomation_pixels.c
testautomation_platform.c
testautomation_rect.c
testautomation_render.c
testautomation_rwops.c
testautomation_sdltest.c
testautomation_stdlib.c
testautomation_suites.h
testautomation_surface.c
testautomation_syswm.c
testautomation_timer.c
testautomation_video.c
testbounds.c
testcustomcursor.c
testdisplayinfo.c
testdraw2.c
testdrawchessboard.c
testdropfile.c
testerror.c
testevdev.c
testfile.c
testfilesystem.c
testgamecontroller.c Added left and right sensors for Nintendo Joy-Con and Wii controllers 2022-09-07 00:00:27 -07:00
testgeometry.c
testgesture.c
testgl2.c
testgles.c
testgles2.c
testgles2_sdf.c
testgles2_sdf_img_normal.bmp
testgles2_sdf_img_sdf.bmp
testhaptic.c
testhittesting.c
testhotplug.c
testiconv.c
testime.c
testintersections.c
testjoystick.c
testkeys.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testloadso.c
testlocale.c
testlock.c
testmessage.c
testmouse.c testmouse: Allow drawing rectangles as well as lines 2022-09-05 08:51:36 -07:00
testmultiaudio.c
testnative.c
testnative.h
testnativecocoa.m
testnativeos2.c
testnativew32.c
testnativex11.c
testoffscreen.c
testoverlay2.c
testplatform.c
testpower.c
testqsort.c
testrelative.c
testrendercopyex.c
testrendertarget.c
testresample.c
testrumble.c
testscale.c
testsem.c
testsensor.c
testshader.c
testshape.c
testsprite2.c
testspriteminimal.c
teststreaming.c
testsurround.c
testthread.c
testtimer.c
testurl.c
testutils.c
testutils.h
testver.c
testviewport.c
testvulkan.c
testwm2.c
testyuv.bmp
testyuv.c
testyuv_cvt.c
testyuv_cvt.h
torturethread.c
unifont-13.0.06-license.txt
unifont-13.0.06.hex
utf8.txt
versioning.sh fix DYLIB version inconsistencies and test failures after . 2022-09-06 03:15:02 +03:00
watcom.mif

These are test programs for the SDL library:

	checkkeys	Watch the key events to check the keyboard
	loopwave	Audio test -- loop playing a WAV file
	loopwavequeue	Audio test -- loop playing a WAV file with SDL_QueueAudio
	testsurround	Audio test -- play test tone on each audio channel
	testaudioinfo	Lists audio device capabilities
	testerror	Tests multi-threaded error handling
	testfile	Tests RWops layer
	testgl2		A very simple example of using OpenGL with SDL
	testiconv	Tests international string conversion
	testjoystick	List joysticks and watch joystick events
	testkeys	List the available keyboard keys
	testloadso	Tests the loadable library layer
	testlocale  Test Locale API
	testlock	Hacked up test of multi-threading and locking
	testmouse	Tests mouse coordinates
	testmultiaudio	Tests using several audio devices
	testoverlay2	Tests the overlay flickering/scaling during playback.
	testplatform	Tests types, endianness and cpu capabilities
	testsem		Tests SDL's semaphore implementation
	testshape	Tests shaped windows
	testsprite2	Example of fast sprite movement on the screen
	testthread	Hacked up test of multi-threading
	testtimer	Test the timer facilities
	testver		Check the version and dynamic loading and endianness
	testwm2		Test window manager -- title, icon, events
	torturethread	Simple test for thread creation/destruction
	controllermap   Useful to generate Game Controller API compatible maps



This directory contains sample.wav, which is a sample from Will Provost's
song, The Living Proof:

     From the album The Living Proof
     Publisher: 5 Guys Named Will
     Copyright 1996 Will Provost

You can get a copy of the full song (and album!) from iTunes...

    https://itunes.apple.com/us/album/the-living-proof/id4153978

or Amazon...

    http://www.amazon.com/The-Living-Proof-Will-Provost/dp/B00004R8RH

Thanks to Will for permitting us to distribute this sample with SDL!