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

Clipboard API missing temporal order #8338

Closed
Green-Sky opened this issue Oct 2, 2023 · 8 comments
Closed

Clipboard API missing temporal order #8338

Green-Sky opened this issue Oct 2, 2023 · 8 comments
Assignees
Milestone

Comments

@Green-Sky
Copy link
Contributor

Green-Sky commented Oct 2, 2023

The current, new clipboard api with added support for types other than text is a really good thing.
But, it lacks info on what was set last. eg:
(assume set is externally)

  1. text is set
    -> no issue yet, we only know of text
  2. file is set (like an image)
    -> now both, text and file are set, with no way to know what was the last copy, so we cant know , whether we should paste the file or the text.
  3. i set text again
    -> same issue, but now text would be the correct answer.
@Green-Sky
Copy link
Contributor Author

Green-Sky commented Oct 2, 2023

Ideas on how to solve this:

  1. add mime type to the SDL_EVENT_CLIPBOARD_UPDATE event
  2. add some way to query the timestamp of last set for a mimetype -> since most clipboard copy operations on files set multiple mimetypes

@slouken slouken added this to the 3.2.0 milestone Nov 8, 2023
@slouken
Copy link
Collaborator

slouken commented Nov 8, 2023

Good point, thanks for the feedback!

@Green-Sky
Copy link
Contributor Author

Green-Sky commented Jan 20, 2024

Took a deeper look, because the primary selection feature is somewhat broken on X11.
The reason for the clipboard to not update is indeed because we loop over the list of known text mime-types until we find one, without looking at any timestamps.

Further, primary selection does not work for most apps I care about (terminals like xterm and alacritty), because only the first text mime-type in the list is looked at. Converting this to a loop would only fix this partially, same as current clipboard behavior.

@Susko3
Copy link
Contributor

Susko3 commented Apr 20, 2024

You mention that all the sets are external. Isn't it the operating systems's job to clear out stale clipboard data? On Windows, this is delegated to applications: they must call EmptyClipboard to empty and take ownership of the clipboard.

Unless SDL is somehow caching the clipboard content (that would be really inefficient).

@Green-Sky
Copy link
Contributor Author

Green-Sky commented Apr 20, 2024

External applications, and also SDL can and will set different data for different mimetypes for what the user sees as a single clip on the board. Copying image data usually sets png, jpg, bmp and other formats, each technically being their own. Now you can mix in text in there, on linux there is also a selection clipboard, that works the same but should not be touched and continue to be valid when other mimetypes are set.

@Susko3
Copy link
Contributor

Susko3 commented Apr 20, 2024

Everything you said is correct and makes sense (and helped me understand what the primary selection text is), but it doesn't address my question.

@c-smile
Copy link

c-smile commented Apr 26, 2024

The current, new clipboard api with added support for types other than text is a really good thing.

Yes, but mime types are not that portable for these purposes.

Take images for example, Windows and MacOS have their own internal formats for clipboard and DnD (CF_DIB and NSImage serialization). MSPaint will put CF_DIB into clipboard. What mime type you will use to get that?

Check this

@icculus icculus modified the milestones: 3.2.0, 3.0 ABI May 18, 2024
@slouken slouken modified the milestones: 3.0 ABI, 3.2.0 Aug 16, 2024
@slouken slouken self-assigned this Oct 6, 2024
slouken added a commit to slouken/SDL that referenced this issue Dec 31, 2024
@slouken slouken closed this as completed in 6575b81 Jan 1, 2025
@slouken
Copy link
Collaborator

slouken commented Jan 1, 2025

Fixed!

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

5 participants