Gdk-CRITICAL when dropping several times

Hi,

I’m writing an WYSIWYG editor with GTK 4 (https://github.com/mmMike/marko-editor). For this I want to handle external drops, for e.g. links, differently.

My current test (using Rust) is:

let fbuilder = gdk::ContentFormatsBuilder::new();
let formats = fbuilder.to_formats().unwrap();
let handler = gtk::DropTargetAsync::new(Some(&formats), gdk::DragAction::COPY);

handler.connect_accept({
    |_target, drop| {
        if let Some(f) = drop.get_formats() {
            return f.contain_mime_type("text/x-moz-url");
        }
        false
    }
});

handler.connect_drop(move |_target, drop, _x, _y| {
    if let Some(f) = drop.get_formats() {
        if f.contain_mime_type("text/x-moz-url") {
            // ... read async data ... 

            drop.finish(gdk::DragAction::COPY);
            return true;
        }
    }
    false
});

The code works and the data in the drop is read - also when dropping several times. However, beginning with the second time, the following critical appears each time before the ‘accept’ callback is executed:

Gdk-CRITICAL **: 20:36:18.349: gdk_drop_set_actions: assertion 'priv->state == GDK_DROP_STATE_NONE' failed

Any help, what I need to do differenly? Just handling the ‘enter’ signal didn’t do the trick. It seems the GdkDrop is reused but doesn’t get reinitialized.

My version is 4.0.3 on X11, Arch Linux.

Thank you.

I’ve created a minimal Python example to check potential problems with the Rust version, but I get the same problem. When dropping the second time (and every time afterwards), the critical message is logged:

(python:7168): Gdk-CRITICAL **: 13:13:23.500: gdk_drop_set_actions: assertion 'priv->state == GDK_DROP_STATE_NONE' failed

Example:

import gi

gi.require_version('Gtk', '4.0')
from gi.repository import Gtk, Gdk, GLib

mime = "text/plain"


def cb_accept(_target, drop):
    formats = drop.get_formats()
    if formats is not None:
        return formats.contain_mime_type(mime)
    return False


def cb_drop(_target, drop, x, y):
    formats = drop.get_formats()
    if formats is not None:
        if formats.contain_mime_type(mime):
            drop.read_value_async(GLib.String, GLib.PRIORITY_DEFAULT, None, lambda _drop, value: print(value))
            drop.finish(Gdk.DragAction.COPY)
            return True

    return False


def get_drop_handler():
    builder = Gdk.ContentFormatsBuilder()
    builder.add_mime_type(mime)
    formats = builder.to_formats()
    handler = Gtk.DropTargetAsync(formats=formats)
    handler.connect('accept', cb_accept)
    handler.connect('drop', cb_drop)
    return handler


def on_activate(app):
    window = Gtk.ApplicationWindow(application=app)
    window.set_title("Gtk4 Mime Test")
    window.set_default_size(500, 400)

    textview = Gtk.TextView()
    textview.add_controller(get_drop_handler())
    window.set_child(textview)

    window.present()


# Create a new application
app = Gtk.Application(application_id='com.example.GtkApplication')
app.connect('activate', on_activate)

# Run the application
app.run(None)

Any ideas on how to fix this?

I don’t know how that API is supposed to be used exactly, but as the critical doesn’t even happen from any of the functions you call, I would assume that this is actually a bug in GTK. And even if not, it would at least be missing documentation. Maybe report an issue here?

Thank you, let’s see: https://gitlab.gnome.org/GNOME/gtk/-/issues/3755

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