Gtk4: Clipboard does not provide contents using custom mime type without "/" character

Hello, while porting my app from GTK3 to GTK4, I’ve discovered that the new Clipboard does not seem to provide the contents to other applications if the mime type does not contain a “/” character.
Example application:

#include <gtk/gtk.h>

static void
activate(GtkApplication *app,
         gpointer user_data)
    GtkWidget *window;

    window = gtk_application_window_new(app);
    gtk_window_set_title(GTK_WINDOW(window), "Window");
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);

    GdkDisplay *display = gdk_display_manager_get_default_display(gdk_display_manager_get());

    GdkClipboard *clipboard = gdk_display_get_clipboard(display);

    GdkContentProvider *cp = gdk_content_provider_new_for_bytes("teste", g_bytes_new_static("Teste", 5));

    gdk_clipboard_set_content(clipboard, cp);


int main(int argc,
         char **argv)
    GtkApplication *app;
    int status;

    app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
    status = g_application_run(G_APPLICATION(app), argc, argv);

    return status;

If i replace gdk_content_provider_new_for_bytes("teste", g_bytes_new_static("Teste", 5)) by gdk_content_provider_new_for_bytes("teste/", g_bytes_new_static("Teste", 5)) or gdk_content_provider_new_for_bytes("/teste", g_bytes_new_static("Teste", 5)) it works as expected, however, without the “/”, the mime type is correctly presented as a available target (tested using xclip -o -selection clipboard -t TARGETS), but when trying to get the contents, it does not work. (Tested with xclip -o -selection clipboard -t teste, that returns Error: target teste not available).
This did work on GTK3 without issues.
GTK4 version 4.2.1 on Manjaro Linux

Neither “teste” nor (arguably) “teste/” is a valid mimetype.

Mimetype strings have the general form TYPE/SUBTYPE, and if you want to have a chance to be interoperable with other software, it is best to stick to commonly recognized mimetypes such as “text/plain;charset=utf8” or “image/png”.

Thanks for the reply.
My use case is to communicate with a proprietary application that reads / writes binary data to the clipboard, and with GTK3 I’ve used the equivalent of writing to the clipboard with the format “CF_FatekRes” (Using the clipboard set_with_data function with a TargetEntry with the name "CF_FatekRes"). So sadly, i cannot change the behavior of the application.

Also, reading works fine with the gdk_clipboard_read_async() function and "CF_FatekRes" as a mime type.

Can you file an issue for handling custom types?

We don’t currently have a great answer for this, it will need some new api.

Issue opened: link

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.