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);
gtk_widget_show(window);
}
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);
g_object_unref(app);
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