Skip to content

meta/selection-source-memory: Add multiple mimetype support

This MR will add support in MetaSelectionSourceMemory for accepting multiple mimetype values.

I maintain the most popular clipboard manager extension for GNOME (Clipboard Indicator) and an issue started popping up, reported by many users + experienced myself, where text copied in one app could not be pasted into another app or it would get pasted but slightly broken (e.g. new lines removed). After much debugging and research I realized that when a selection is copied, Mutter keeps it in a MetaSelectionSourceWayland (or ...X11) object while St.Clipboard uses MetaSelectionSourceMemory. One of the differences between the two was that MetaSelectionSourceWayland supported selections with multiple mimetypes with different values — e.g. "bla bla" for "text/plain" and "<h1>bla bla</h1>" for "text/html" — while MetaSelectionSourceMemory did not. The bug in question seems to be caused by some applications using non-"text/plain" mimetypes for some versions of content, while my extension only keeps 1 version. So for example trying to paste a "text/html" content into an app that does not support "text/html" would not work.

Adding support for multiple mimetypes should fix the issue my users have been reporting. It's hard to say until it gets tested by thousands of people, since it's one of those phantom bugs that are hard to track, but from preliminary tests I performed locally it feels like it's working better.

Implementation details:
This MR refactors MetaSelectionSourceMemory to support multiple mimetypes with different values in the same selection source. To keep the API backwards-compatible, a new constructor was added that accepts arrays of mimetypes and their corresponding values while the old constructor kept the API, but its implementation changed to creating two GList objects with a single item in each. The internal data structure changed to holding two GList instances, one for mimetypes and one for values and retrieving the values based on the index of the mimetype.

Additional notes:

  1. I consulted with @andyholmes who helped me with the code and also looked at the proposed changes prior to me opening this MR. I made an additional commit following the suggestions by Andy
  2. I am open to modifying this MR. My goal is to be able to set the clipboard content to multiple mimetype values. If there are better ways to achieve that, I will happily make those changes
  3. I was not sure if there are any tests that need to be added following this change
Edited by Yotam Bar-On

Merge request reports