Usage of Gtk.EventControllerLegacy in GJS

The EventBox has been deprecated in Gtk4 and EventController is recommended as its replacement. I have a problem with the usage: = "4.0";
const { Gtk, GObject } =;

var ExampleApp = GObject.registerClass(
class ExampleApp extends Gtk.Application {
    vfunc_activate() {
        let appWindow = new Gtk.ApplicationWindow({ application: this, });
        let add = new Gtk.Box({ halign: Gtk.Align.CENTER });
        add.append(new Gtk.Image({ icon_name: 'list-add-symbolic' }));
        let ctl = new Gtk.EventControllerLegacy({});
        ctl.connect('event', () => { /* do sth. */ });
new ExampleApp().run([imports.system.programInvocationName].concat(ARGV));

I got this when hovering on the box:

(gjs:119912): Gjs-WARNING **: 09:49:20.415: JS ERROR: Error: Failed to convert GValue to a fundamental instance

What’s the right way to get a widget similar to the EventBox?

This looks like a bug in GJS, possibly related to #365. Please report :slight_smile:

That being said, you probably don’t need to use Gtk.EventControllerLegacy and should instead use Gtk.GestureClick or Gtk.EventControllerMotion for pointer stuff, and so on.

1 Like

Thanks. I’ve reported it . Gtk.GestureClick works as expected.


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