Currently, I'm trying to use GtkPopoverMenuBar widget in a GTK4 app in C, based on the tutorial listed here: https://toshiocp.github.io/Gtk4-tutorial/sec17.html
Here's the current code I have:
#include <gtk/gtk.h>
static void
quit_activated(GSimpleAction *action, GVariant *parameter, GApplication *application) {
g_application_quit (application);
}
static void
app_activate (GApplication *application) {
GtkApplication *app = GTK_APPLICATION (application);
GtkWidget *win = gtk_application_window_new (GTK_APPLICATION (app));
gtk_window_set_title (GTK_WINDOW (win), "menu1");
gtk_window_set_default_size (GTK_WINDOW (win), 400, 300);
gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (win), TRUE);
gtk_window_present (GTK_WINDOW (win));
}
static void
app_startup (GApplication *application) {
GtkApplication *app = GTK_APPLICATION (application);
//GtkWidget *win = GTK_WIDGET(gtk_application_get_active_window(app));
//GtkWidget *boxv = gtk_window_get_child(GTK_WINDOW(win));
GSimpleAction *act_quit = g_simple_action_new ("quit", NULL);
g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_quit));
g_signal_connect (act_quit, "activate", G_CALLBACK (quit_activated), application);
GMenu *menubar = g_menu_new ();
GtkPopoverMenuBar *popover_menubar = gtk_popover_menu_bar_new_from_model (menubar);
GMenuItem *menu_item_file = g_menu_item_new ("File", NULL);
GMenu *menu = g_menu_new ();
GMenuItem *menu_item_quit = g_menu_item_new ("Quit", "app.quit");
g_menu_append_item (menu, menu_item_quit);
g_object_unref (menu_item_quit);
g_menu_item_set_submenu (menu_item_file, G_MENU_MODEL (menu));
g_menu_append_item (menubar, menu_item_file);
g_object_unref (menu_item_file);
//gtk_box_pack_start(GTK_BOX(boxv), GTK_WIDGET(popover_menubar), TRUE, FALSE, 0);
gtk_application_set_menubar (GTK_APPLICATION (app), G_MENU_MODEL (menubar));
}
#define APPLICATION_ID "com.github.ToshioCP.menu1"
int
main (int argc, char **argv) {
GtkApplication *app;
int stat;
app = gtk_application_new (APPLICATION_ID, G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "startup", G_CALLBACK (app_startup), NULL);
g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL);
stat = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return stat;
}
But there's a problem: The GCC compiler won't recognise the gtk/gtkpopovermenubar.h
library.
It says: identifier "GtkPopoverMenuBar" is undefined
I'm using VSCode, with this configuration in tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"-IC:/msys64/mingw64/bin/../include/libadwaita-1",
"-IC:/msys64/mingw64/bin/../include/gtk-4.0",
"-IC:/msys64/mingw64/bin/../include/pango-1.0",
"-IC:/msys64/mingw64/bin/../include",
"-IC:/msys64/mingw64/bin/../include/glib-2.0",
"-IC:/msys64/mingw64/bin/../lib/glib-2.0/include",
"-IC:/msys64/mingw64/bin/../include/harfbuzz",
"-IC:/msys64/mingw64/bin/../include/freetype2",
"-IC:/msys64/mingw64/bin/../include/libpng16",
"-IC:/msys64/mingw64/bin/../include/fribidi",
"-IC:/msys64/mingw64/bin/../include/cairo",
"-IC:/msys64/mingw64/bin/../include/pixman-1",
"-IC:/msys64/mingw64/bin/../include/gdk-pixbuf-2.0",
"-IC:/msys64/mingw64/bin/../include/webp",
"-IC:/msys64/mingw64/bin/../include/graphene-1.0",
"-IC:/msys64/mingw64/bin/../lib/graphene-1.0/include",
"${file}",
"-LC:/msys64/mingw64/bin/../lib",
"-ladwaita-1",
"-lgtk-4",
"-lpangowin32-1.0",
"-lpangocairo-1.0",
"-lpango-1.0",
"-lharfbuzz",
"-lgdk_pixbuf-2.0",
"-lcairo-gobject",
"-lcairo",
"-lgraphene-1.0",
"-lgio-2.0",
"-lgobject-2.0",
"-lglib-2.0",
"-lintl",
"-o",
"${fileDirname}\\..\\bin\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
gtk.h
is in the includes and in the linker. And it links to gtkpopovermenubar.h
, yet it doesn't show up when typing, nor does it compile.
What do I need to do to get GtkPopoverMenuBar function working? Any help would be greatly appreciated!