-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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 Extensible Clipboard Data Loading #86021
base: master
Are you sure you want to change the base?
Conversation
Nice to see you're working on this, some comments: Perhaps a bit of a nitpick, but for me the naming
Regarding this there's also the case of custom types, one of the more important usecases for expanding the clipboard functionality in my mind. In other words getting and setting data to the clipboard in propriety formats used only in your own application. So for cases where the type isn't a MIME type that can be translated to something appropriate for the local platform the type string should be used as is. And finally, regarding the image specific versions like |
I agree the naming of the functions is a bit awkward, I was aiming for consistency with the existing functions without being overly verbose. I don't love |
Regarding naming, perhaps the current I also agree that the To me I think the most important thing is to allow getting and setting custom and multiple specified types of data on the clipboard instead of the current just getting and setting single standard bitmap image or text string. For example if I copy a graphical element in the graphics app I'm working on I'd like to place a bitmap image, an svg vector representation and my own custom format data structure all on the pasteboard. The two first for exporting to other apps that might prefer a bitmap images or vector svg graphics, and the third custom format data for internal use if the user pastes it in somewhere in my own app. Similarly when pasting something into the app I'd like to be able to check if there is data of different such supported types on the clipboard to determine which one should be used and pasted in. So for these types of situations I imagined there would be need for something like this to access this data from the clipboard when pasting:
And to set multiple format data on the clipboard when copying:
|
I think removing the type handler callback system entirely and just providing engine methods for text and images solves the common use cases, and then an additional method to get arbitrary types as a |
@Setadokalo any progress on this? Anything I can do to help? I've got a use case now in the project I'm working on where I'm copying graphical layer and I'd like to put both a string SVG representation and my own internal data format on the clipboard at the same time, and conversely also then examine the clipboard and see if there is data there in my internal format when pasting in. Currently this is very tricky and doesn't really work as expected in all cases as I can only actually put strings on the clipboard with the current clipboard functionality and have to rely on my own faked internal clipboard for the custom data. So getting this functionality to put multiple data formats on the clipboard and look for and get specific custom formats would be very useful! |
sorry, the thing that stopped me from progressing last time was actually a bug I noticed in the current implementation; when I get an image from the clipboard and it triggers the multipart mechanism, it also for some reason makes the window unable to receive focus anymore. I've meant to try to track that bug down, but haven't had the time. |
I see, I assume this input issue is on Windows, where the Clipboard seems more closely tied to windows? But still it seems unexpected that getting data from the clipboard should affect input. Could it be related to an unbalanced And also, does getting an image need to trigger a "multipart mechanism" of some kind? On Windows there seems to be a dedicated Clipboard.GetImage method that will allow getting an image from the Clipboard without needing to know what format it is in. On macOS there is a similar method via NSImage initWithPasteboard that can be used to create an NSImage (that we can then turn into PNG data for example) from the clipboard, without needing to know what formats images are stored on the clipboard. Is the code updated with this latest version in this pr draft? If you update that I could take a look at the code there and see if I can find anything that looks like it could cause issues. |
it's actually a linux issue - and increment transfer is chosen by the owner of the clipboard data, not the requesting client. I'm not sure if it's a godot, xwayland, or kde bug at this point - I haven't had the time and motivation to investigate it enough. |
I see, that's unfortunate. But that sounds like it wouldn't be a new issue or specific to this new extended multi-format clipboard support. But rather something more general with linux clipboard access in Godot? Does the current |
I don't know how helpful it can be, but since SDL 3 now has support for mime types in its clipboard implementation, maybe you could have a look there for inspiration? https://wiki.libsdl.org/SDL3/SDL_SetClipboardData Edit: Direct link to clipboard.c: https://github.com/libsdl-org/SDL/blob/main/src/video/SDL_clipboard.c |
(Note: This is very freshly written, so I haven't even implemented it on Windows yet.)
This mostly addresses godotengine/godot-proposals#7899 by adding several functions to DisplayServer:
clipboard_has_type
, implemented per-platform, to test if a given type is available on the clipboard.clipboard_add_type_handler
andclipboard_remove_type_handler
, for adding and removing type handlers (Callable
s which map the raw data to the correct type) from the internal list.clipboard_get_raw_type
, implemented per-platform, which is not exposed outside the engine and simply produces the raw bytes of a type from the clipboard in a PackedByteArray.clipboard_get_type
, implemented for all platforms, which takes the raw data fromclipboard_get_raw_type
and converts it using the appropriate Callable from the handler map to produce the correct type.Something not explicit in the code is that
p_type
, the type name being requested by the user, is a MIME type, which should be directly supported on Linux and (as far as I can tell) Windows, and which should be convertable to the correct representation on Mac.I still want to implement this for windows, and I don't know if the API is really what we'd want to expose for this, but I'm making this draft PR to let anyone who'd like to leave feedback on it.