Can't make work Enter and Leave events for Gtk.EventControllerMotion in Gtk3

I want to migrate some Gtk3 code from “classic” events to event controllers, to simplify a future Gtk4 migration. I noticed that the Gtk.EventControllerMotion has Enter and Leave events, but I’m unable to make them work (but the Motion event works fine). I tried with this piece of code, both in a Gtk.Window and a Gtk.EventBox, but no luck:

let motionController = Gtk.EventControllerMotion.new(this._eventBox);
motionController.set_propagation_phase(Gtk.PropagationPhase.BUBBLE);
this.connect(motionController, 'motion', (controller, x, y) => {
    console.log(`Motion 2 ${x},${y}`);
});
this.connect(motionController, 'enter', (controller, x, y) => {
    console.log(`Enter 2 ${x},${y}`);
});
this.connect(motionController, 'leave', (controller) => {
    console.log("Leave 2");
});

Instead, the old code does work like a charm:

this.connect(this._eventBox, 'enter-notify-event', (actor, event) => {this._onEnter(this._eventBox);});
this.connect(this._eventBox, 'leave-notify-event', (actor, event) => {this._onLeave(this._eventBox);});

I tried to add the ENTER_NOTIFY_MASK and LEAVE_NOTIFY_MASK with add_events, but didn’t work.

I did some tests directly in C, and added some debug printfs in Gtk, and I think that the problem is really in Gtk, not in my code. I filled a bug report. Gtk.EventControllerMotion doesn't emit neither enter nor leave signals in Gtk3 (#7225) · Issues · GNOME / gtk · GitLab

1 Like

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