You can check chapter 30.20 Window System Selections and chapter 30.21 Drag and Drop of the Emacs Lisp manual for the details, but Emacs mostly only supports text for both pastes and drag and drop actions. However, it may be possible for you to do what you want.
For pastes, you can see the list of formats Emacs knows about in the selection-converter-alist
variable. These are mostly all different kinds of text, and some things that are very similar to text such as file names and user names, but the one called TARGETS is the most interesting. If you call gui-get-selection
with a type of TARGETS, you will be sent not the data but a list of data types that are available. You can then pick the type you prefer and call gui-get-selection
again with that type.
Handling drag–and–drop is similar, except that you want to set the x-dnd-test-function
in the buffer to a function of your own. It will be called any time a drop is initiated, and it gets a list of data types that it can choose from. The default test function looks at the value of x-dnd-known-types
; if any type from the drop is in that list, it will use the corresponding function to accept the drop. By default those are all various types of text.
Here is a random article I found online with related information and some simple examples: https://www.uninformativ.de/blog/postings/2017-04-02/0/POSTING-en.html