Programmatically opening a sub-menu of a menu

I am curious about whether there is capability to open a sub-menu of a parent menu, or even a sub-menu, of a sub-menu, of the parent menu (or possibly deeper), using gtk3 with gjs.

For context, I have code that I use with mpv to generate menu’s and send the menu structure to a sub-process to popup a menu on screen above the mpv window. These sub-processes “build” the menu and display it on screen, and for one of the menu “builders” using the Tcl language with the Tk graphical toolkit, it’s possible to open a menu with the cascaded sub-menus already open.

This allows a pseudo-toggle capability where the menu appears where it was originally opened from (originally triggered by a right-click of the mouse) and the sub-menu is reopened with the mouse is hovering over the menu item that was previously clicked.

All this explanation is to ask if it is possible to reproduce this sort of behavior with gjs and gtk3. The code I’m using currently is this menu builder file. I have asked ChatGPT which suggested that I could do this by getting the a sub-menu via something like:

let subMenu = baseMenu.get_child().get_submenu();

baseMenu.popup([arguments go here]);
subMenu.show_all();

And I tried that amongst a number of other suggested variations, but could not seem to get the intended functionality to work.

Is this actually something that’s possible? I am not expecting it to be possible, but thought it was worth asking actual humans!

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