Gtk.DropTargetAsync in Gtk4 not giving the drop signal

I am trying to port an app from gtk3 to gtk4, redoing drag and drop.

Using DropControllerAsync with the following code- (sorry, heavily logged for debugging)

    this.gridDropController = new Gtk.DropTargetAsync();
    this.gridDropController.set_actions(Gdk.DragAction.MOVE);
    this.dropMimeTypes = ['x-special/ding-icon-list', 'x-special/gnome-icon-list', 'text/uri-list', 'text/plain']
    let formats = Gdk.ContentFormats.new(this.dropMimeTypes);
    this.gridDropController.set_formats(formats);
    this.gridDropController.connect('accept', (actor, drop) => {
        log(drop);
        if (drop.get_formats().match(formats)) {
            log('hello')
            log(drop.get_formats().to_string());
            return true;
        }
        return true;
    });
    this.gridDropController.connect('drag-enter', (actor, drop, x, y) => {
        log('drag-entered');
        //return Gdk.DragAction.Move;
    });
    this.gridDropController.connect('drag-motion', (actor, drop, x, y) => {
        this.receiveMotion(x, y);
    });
    this.gridDropController.connect('drag-leave', (actor, drop, x, y) => {
        this.receiveLeave();
    });
    this.gridDropController.connect('drop', (drop, x, y) => {
        log(x);log(drop);log(y);
        if (drop.get_formats().match(formats)) {
            log('dropped')
            log(drop.get_formats().to_string());
            drop.read_async(this.dropMimeTypes, 1, null, (result, error) => {
                [selection, info] = drop.read_finish(result);
                log(selection);
                log(info);
                this.receiveDrop(x, y, selection, info, false);
            });
        }
    });
    this._container.add_controller(this.gridDropController);

I get and log all the signals on dragging a file to the container from nautilus, including accept, drag-motion, drag-enter, drag-leave, but dropping the file does not give the drop signal to execute the drop code.

The log from GJS clearly shows that matching formats are present in the drop from the file dragged from Nautilus -
Gjs-Message: 20:36:53.566: JS LOG: GdkFileList GFile gchararray x-special/gnome-icon-list text/uri-list UTF8_STRING COMPOUND_TEXT TEXT STRING text/plain;charset=utf-8 text/plain DELETE

What am I doing wrong here?

In answer to my own question, the dropSource wanted the Gdk.DragAction.COPY and would not accept the drop.

In Gtk3 the Gdk.DragAction.Move was working when dropping a file from Nautilus, however I guess with the newer vesions of Nautilus, a Gdk.DragAction.COPY is preferred.

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