Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about checking SDL_CLIPBOARDUPDATE in Wiki CategoryClipboard before calling SDL_GetClipboardText() #12063

Open
inflex opened this issue Jan 23, 2025 · 1 comment
Milestone

Comments

@inflex
Copy link

inflex commented Jan 23, 2025

Happy to do this myself if possible but thought I'd bring this issue up, if nothing else for anyone else who gets a head-scratching "bug" here (manifests as stalling/stuttering/loss-of-fps due to time consumption);

At the time of writing, SDL_GetClipboardText() is a time-expensive call under linux and it's poor usage by oneself would have potentially been avoided if it was noted in the Wiki CategoryClipboard that it may be worth checking for SDL_CLIPBOARDUPDATE in the event structure before needlessly calling SDL_GetClipboardText().

I was running around lookin for a SDL_IsClipboardChanged() or similar function, so that was my bad assumption there.

			if (event.type == SDL_CLIPBOARDUPDATE) {
				if (SDL_HasClipboardText()) {
					char *cbt = SDL_GetClipboardText();
					if (cbt) {
                                                // Do something with the text
					}
					SDL_free(cbt);
				}
			}

Very likely the use of SDL_HasClipboardText() may be redundant here for my use case but I added it for thoroughness.

@slouken
Copy link
Collaborator

slouken commented Jan 23, 2025

Sure, feel free to submit a PR for this.

Thanks!

@slouken slouken added this to the 3.2.2 milestone Jan 23, 2025
@slouken slouken modified the milestones: 3.2.2, 3.x Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants