Gtk4: GtkShortcuts cause segfaults
Triggering a shortcut created via Gtk.Shortcut causes a segfault.
Sample code:
int main (string[] argv) {
var app = new Gtk.Application("org.tavmjong.example.shortcuts_simple",
GLib.ApplicationFlags.DEFAULT_FLAGS);
app.activate.connect (() => {
var window = new Gtk.ApplicationWindow (app);
var action1 = new GLib.SimpleAction ("test1", null);
action1.activate.connect (() => { print ("Action1\n"); });
window.add_action(action1);
var shortcut_action1 = new Gtk.NamedAction("win.test1");
var shortcut1 = new Gtk.Shortcut (Gtk.ShortcutTrigger.parse_string("<Control>A"), shortcut_action1);
var liststore = new GLib.ListStore(typeof (Gtk.Shortcut));
liststore.append(shortcut1);
var shortcut_controller = new Gtk.ShortcutController.for_model(liststore);
shortcut_controller.set_propagation_phase(Gtk.PropagationPhase.BUBBLE);
shortcut_controller.set_scope(Gtk.ShortcutScope.GLOBAL);
window.add_controller(shortcut_controller);
window.present();
});
return app.run (argv);
}
Generating 'C' code, changing the line starting with G_TYPE_INSTANCE_GET_INTERFACE...
to gtk_widget_add_controller ((GtkWidget*) window, (GtkEventController*) shortcut_controller);
, then compiling the 'C' code fixes the problem.