Recently I was looking for some examples of using gaction and gmenu with GTK builder. Found

Well that is not really an example, but only a test. But got it to compile with

gcc -Wall gaction.c -o gaction pkg-config --cflags --libs gtk4

I assumed that it is a GTK4 example as widget.show() is used, not widget.showAll(). Changing show() to showAll() makes it compile with GTK3.

First observation. When I click the x at top right window corner, then window will not close. Not surprising, as there is no signal connect to destroy. It that not necessary for GTK4? Next observation: While it works fine for GTK3 with showAll(), for unchanged source text compiled for GTK4 all menu items are grey and can not be activated. Button works ok. I have installed GTK4 on /opt/gtk recently, all paths seems to be OK, there are no error messages when compiling or running. So I an a bit confused. Is this example intended for GTK3 or GTK4? Do I miss something, or do menu items not work in GTK4 at all?

Well not a real problem, I just shipped the Nim version, and at least for GTK3 that modified version seems to work. But as I provide bindings for GTK4 as well, I was going to ship a GTK4 version as well, but that would have grey disabled menus too, so I did ship only the GTK3 version for now:

The master branch is GTK 4:


You can try to find GTK 3 equivalent files in gtk-3.24 branch, or tag
for specific release like 3.24.12. GitLab allows changing the git
revision using the select box on the top of the page.

When I try to do that, I see:

“tests/testgaction.c” did not exist on “3.24.13”

Looking at the commit history of the file, I can see it was added in

I can click the three dots buble next to master bubble to reveal
branches and tags this commit is included in. It looks like the first
tag it appeared in was 3.89.1.

We can try to look into the directoty to see if there is not something


We notice


but that appears to use the deprecated GtkUIManager API.

By grepping for <menu, I found
which appears to use GAction with GMenu.

Thanks for your explanations.

I looked into gtk-3.24 branch before, but there lives legacy stuff, no testgaction.c.

testgaction.c from gitlab master is identical to testgaction.c from github mainline – so when that is for GTK4 I still wonder why the menuitems are grey and disabled when I compile it for GTK4.

As I already said no real problem, as it works fine with GTK3. But it may be a good idea to show people at least one working example for GTK4, otherwise people may tell me: Well you provide bindings for GTK4 already, but what is the benefit? I do provide an empty app demo for GTK4 in https://github.com/StefanSalewski/gintro/blob/master/examples/gtk4/app0.nim but that is really weak, so I will try to find some other C code working with GTK4. Or maybe I can fix testgaction, maybe there is a hidden trick to enable items in GTK4.

testgaction.c from gitlab master is identical to testgaction.c from github mainline

Yeah, master is renamed to mainline on GitHub to make Google ignore it, see https://gitlab.gnome.org/Infrastructure/Infrastructure/issues/192

As I already said no real problem, as it works fine with Gtk3. But it may be a good idea to show people at least one working example for GTK4

Sorry, I misread the OP and thought it was the other way round. I have not played with GTK 4 yet so I will not be able to help you there. Maybe try asking on IRC about the changes in GAction binding.

Just found a working GTK4 example:

Compiled with

gcc -Wall headerbar.c -o headerbar `pkg-config --cflags --libs gtk4`

and works, so I think my /opt/gtk install is OK. Will see if I can create a Nim version on weekend. Interesting is the new destroy call for mainwindow. there is no signalconnect() any more:

  gtk_main ();

  gtk_widget_destroy (window);

  return 0;

Because the window has a custom GtkHeaderBar widget in place of the usual system decorations. When the “Close” button in the header bar is clicked, it will quit the main loop; control will be returned to the main() function at that point, which will proceed to destroy the window.

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