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.