Gtk.PopoverMenu GTK4 - Keyboard and app accelerators stop working after a submenu is opened and closed.
Steps to reproduce
- Build and create a Gio.Menu with a submenu in the application
- Add Gio.Menu to a Gtk.PopoverMenu in the application
- Run application
- Pop up and display the popover
- Choose and display a submenu
- Close the popover by either choosing an item, using application shortcut or clicking out of the menu structure
Attaching a vala program demonstrating the behaviour. After compiling and running, output logging in the Terminal demonstrates the problem. Problem also occurs if using GJS to write a similar program.
compile with valac --pkg gtk4 --pkg gio-2.0 test_submenu.vala
` using Gtk; int main() {
Gtk.Application application = new Gtk.Application("com.rastersoft.menutest", GLib.ApplicationFlags.FLAGS_NONE);
application.startup.connect(() => {
});
application.activate.connect(() => {
Gtk.ApplicationWindow window = new Gtk.ApplicationWindow(application);
Gtk.Button menubutton = new Gtk.Button.from_icon_name("open-menu-symbolic");
GLib.SimpleAction action1 = new GLib.SimpleAction("actiona", null);
action1.activate.connect(()=>{print("Action1\n");});
action1.set_enabled(true);
application.add_action(action1);
string[] key1 = {"a"};
application.set_accels_for_action("app.actiona", key1);
GLib.SimpleAction action2 = new GLib.SimpleAction("actionb", null);
action2.activate.connect(()=>{print("Action2\n");});
action2.set_enabled(true);
application.add_action(action2);
string[] key2 = {"b"};
application.set_accels_for_action("app.actionb", key2);
Gtk.EventControllerKey eventKey = new Gtk.EventControllerKey();
eventKey.key_pressed.connect((keyval, keycode, state) => {
print("%u %u\n", keyval, keycode);
print("Key Pressed\n");
return true;
});
(window as Gtk.Widget).add_controller(eventKey);
GLib.Menu popupmenu = new GLib.Menu();
GLib.Menu submenu = new GLib.Menu();
GLib.MenuItem item1 = new GLib.MenuItem("Action 1", "app.actiona");
popupmenu.append_item(item1);
GLib.MenuItem item2 = new GLib.MenuItem("Sub Menu Action 2", "app.actionb");
submenu.append_item(item2);
popupmenu.append_submenu("submenu", submenu);
Gtk.PopoverMenu popup = new Gtk.PopoverMenu.from_model(popupmenu);
popup.set_parent(menubutton);
menubutton.clicked.connect(() => {
popup.popup();
});
window.set_child(menubutton);
window.show();
});
application.run();
return 0;
} `
Current behavior
All keyboard entry to the application stops working including keyboard app accelerators. If you open the Menu again (not the submenu), and close the menu, Keyboard entry resumes normally.
Expected outcome
Keyboard Entry should continue to work normally after a submenu is closed.
Version information
Importing Gtk-4 to build the app. Linux, Ubuntu 22.04, Archlinux rolling latest Stock Gtk4 from the distribution
Additional information
No messages in the Terminal.
Originally caught the bug in a GJS program I wrote importing gi.Gtk-4 bindings.