clinuxgtkx11ubuntu-unity

Adding items to Unity's global menu bar for a pure X11 application


My application is written using pure X11 APIs only, i.e. no GTK, qt or any other middleware. Everything is done via the low-level Xlib API, e.g. XCreateWindow() and so on. Is it possible to add items to Unity's global menu bar from a pure X11 application or would this force me to do all window and event loop handling using a toolkit like GTK? I'd really like to stick with my current pure X11-based implementation but it would be nice if it was somehow possible to add a few menu items to Unity's global menu bar for my application.


Solution

  • To display menu each time some toplevel window is focused you need to call com.canonical.AppMenu.Registrar.RegisterWindow method of /com/canonical/AppMenu/Registrar passing window id and your menu path ( your string id, which is also a service name - usually build using some path and win id ). Then you need to implement com.canonical.dbusmenu interface on that service name - namely, GetLayout, GetGroupProperties, Event, AboutToShow and LayoutUpdated methods.

    I did simple library to implement all this in JavaScript using node-dbus and node-x11 libraries. See example which creates toplevel window and unity menu for it ( no glib / libdbus / libx11 dependencies here, pure networking )