How does gtk application window set help overlay Works?

I am trying to understand how gtk_application_window_set_help_overlay works and I just can not figure out how!

Could you please point me to an example?
I have a dummy code where I created a GtkShortcutsWindow which looks like this:

#include <gtk/gtk.h>

GtkShortcutsWindow *create_shortcuts_window ( void );
void startup_clbk_signal  ( GtkApplication *application );
void activate_clbk_signal ( GtkApplication *application );

int main ( void )
{
    GtkApplication *application;
    gint status;
    
    /// ***
    application = gtk_application_new ( "this.is.an.app", G_APPLICATION_FLAGS_NONE );

    /// ***
    g_signal_connect ( application, "startup",  G_CALLBACK ( startup_clbk_signal ),  NULL );
    g_signal_connect ( application, "activate", G_CALLBACK ( activate_clbk_signal ), NULL );

    /// ***
    status = g_application_run ( G_APPLICATION ( application ), FALSE, NULL );

    /// ***
    g_object_unref ( application );
    return status;
}

void activate_clbk_signal ( GtkApplication *application )
{
    GtkWidget          *window;
    GtkShortcutsWindow *shortcuts_window;

    /// ***
    window = gtk_application_window_new   ( application );
    g_signal_connect ( window, "destroy", gtk_main_quit, NULL );

    /// ***
    shortcuts_window  = create_shortcuts_window();

    /// ***
    ///gtk_application_add_window ( application, GTK_WINDOW ( shortcuts_window ) );
    gtk_application_window_set_help_overlay ( GTK_APPLICATION_WINDOW ( window ), shortcuts_window );

    /// ***
    gtk_window_present ( GTK_WINDOW ( shortcuts_window ) );
    gtk_window_present ( GTK_WINDOW ( window ) );
}

void startup_clbk_signal  ( GtkApplication *application )
{
    ( void ) application;
    /// ***
}

GtkShortcutsWindow *create_shortcuts_window ( void )
{
    /// ***
    GtkShortcutsWindow  *shrt_window = g_object_new ( GTK_TYPE_SHORTCUTS_WINDOW,
                                       "modal",         TRUE,
                                       "section-name",  "Section",
                                       "view-name",     "view",
                                       NULL );

    /// ***
    GtkShortcutsSection *shrt_section = g_object_new ( GTK_TYPE_SHORTCUTS_SECTION,
                                        "max-height",   10,
                                        "visible",      TRUE,
                                        "section-name", "Section",
                                        "title",        "What ever",
                                        "parent",       shrt_window,
                                        NULL );

    /// ***
    GtkShortcutsGroup *shrt_group = g_object_new ( GTK_TYPE_SHORTCUTS_GROUP,
                                    "visible",  1,
                                    "title",    "The Accelerator",
                                    "view",     "View",
                                    "parent",   shrt_section,
                                    NULL );

    /// ***
    GIcon *icon = g_themed_icon_new ( "computer" );
    GtkShortcutsShortcut *shrt_shortcut = g_object_new ( GTK_TYPE_SHORTCUTS_SHORTCUT,
                                          "visible",       TRUE,
                                          "icon-set",      TRUE,
                                          "icon",          icon,
                                          "shortcut-type", GTK_SHORTCUT_ACCELERATOR,
                                          "accelerator",   "<ctl><alt>G",
                                          "title",         "Take a Look",
                                          "subtitle",      "Did you?",
                                          "subtitle-set",  TRUE,
                                          "direction",     GTK_TEXT_DIR_LTR,
                                          NULL );

    /// ***
    g_object_set ( shrt_shortcut, "parent", shrt_group, NULL );

    return shrt_window;
}

which looks like this:
GtkShortcutsWindow

Where should I use this Function exactly ?

Like many other things in GTK, you should look at gtk-demo.

The shortcuts dialog is meant to be used to document your existing keyboard shortcuts. How you handle keyboard shortcuts is entirely up to you:

Once you wrote the keyboard shortcut code for your application, you document them by creating a GtkShortcutsWindow with all the shortcuts.

1 Like

I did that already and I did not found that function there.
Thank you for your help.

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