Hi All,
Showing a submenu in a popovermenu in Gtk4 results in app accelerators not working. If a submenu is dismissed by choosing an action, or by clicking outside the menu to dismiss it, all app accelerator keyboard shortcuts stop working.
If the main menu is shown again, the accelerators work again. Choosing an item in the main menu or dismissing the main menu with escape or outside click does not cause the app accelerators to stop working, only showing, dismissing, or choosing an item in the submenu does.
A sample app is attached. Once the submenu is chosen and dismissed, keyboard shortcuts will not log any messages. Once the main menu is shown and dismissed, the keyboard shortcuts work again.
Is there something wrong with the program I am writing, gjs or gtk4?
#!/usr/bin/env gjs
imports.gi.versions.Gtk = "4.0";
const { Gio, Gtk } = imports.gi;
class ImageViewerWindow {
constructor(app) {
this._app = app;
this._window = null;
this._box = null;
this._fileChooserButton = null;
}
_buildUI() {
this._window = new Gtk.ApplicationWindow({
application: this._app,
defaultHeight: 600,
defaultWidth: 800
});
this._box = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL
});
this._fileChooserButton = Gtk.Button.new_with_label('Menu');
this._fileChooserButton.connect('clicked', (button) => {
log('activated')
let popupmenu = Gtk.PopoverMenu.new_from_model(this.desktopBackgroundGioMenu);
//this.popupmenu = Gtk.PopoverMenu.new_from_model_full(this.desktopBackgroundGioMenu, Gtk.PopoverMenuFlags.NESTED);
popupmenu.set_parent(this._fileChooserButton);
popupmenu.popup();
});
this._box.append(this._fileChooserButton);
this._box.show();
this._window.set_child(this._box);
this.desktopBackgroundGioMenu = Gio.Menu.new();
this.desktopBackgroundGioMenu.append("New Folder", "app.doNewFolder");
this.pasteUndoRedoMenu = Gio.Menu.new();
this.pasteUndoRedoMenu.append("Paste", "app.doPaste");
this.pasteUndoRedoMenu.append("Undo", "app.doUndo");
this.pasteUndoRedoMenu.append("Redo", "app.doRedo");
this.desktopBackgroundGioMenu.append_submenu("Paste Menu", this.pasteUndoRedoMenu);
let newFolder = Gio.SimpleAction.new('doNewFolder', null);
newFolder.connect('activate', () => {
log('Creating New Folder');
});
this._app.add_action(newFolder);
this._app.set_accels_for_action('app.doNewFolder', ['<Control><Shift>N']);
this.doPasteSimpleAction = Gio.SimpleAction.new('doPaste', null);
this.doPasteSimpleAction.connect('activate', () => {
log('Pasting');
});
this._app.add_action(this.doPasteSimpleAction);
this._app.set_accels_for_action('app.doPaste', ['<Control>V'])
this.doUndoSimpleAction = Gio.SimpleAction.new('doUndo', null);
this.doUndoSimpleAction.connect('activate', () => {
log('Undoing');
});
this._app.add_action(this.doUndoSimpleAction);
this._app.set_accels_for_action('app.doUndo', ['<Control>Z'])
this.doRedoSimpleAction = Gio.SimpleAction.new('doRedo', null);
this.doRedoSimpleAction.connect('activate', () => {
log('Redoing');
});
this._app.add_action(this.doRedoSimpleAction);
this._app.set_accels_for_action('app.doRedo', ['<Control><Shift>Z'])
}
getWidget() {
this._buildUI();
return this._window;
}
}
const application = new Gtk.Application({
application_id: 'org.gnome.Sandbox.MenuExample',
flags: Gio.ApplicationFlags.FLAGS_NONE
});
application.connect('activate', app => {
let activeWindow = app.activeWindow;
if (!activeWindow) {
let imageViewerWindow = new ImageViewerWindow(app);
activeWindow = imageViewerWindow.getWidget();
}
activeWindow.present();
});
application.run(null);