GtkApplication – Part III

#include <gtk/gtk.h>

static void activate_clbk ( GtkApplication *application )
{
    GtkWidget *first_window;
    GtkWidget *second_window;

    GList *list;

    /// ***
    first_window = gtk_application_window_new   ( application );
    gtk_window_set_title ( GTK_WINDOW ( first_window ), "First Window" );
    gtk_window_set_default_size ( GTK_WINDOW ( first_window ), 200, 200 );

    /// ***
    second_window = gtk_window_new();
    gtk_window_set_title ( GTK_WINDOW ( second_window ), "Second Window" );

    /// ***
    gtk_application_add_window ( application, GTK_WINDOW ( second_window ) );

    /// ***
    list = gtk_application_get_windows ( application );

    /// ***
    while ( list != NULL )
    {
        GtkWindow *window = GTK_WINDOW ( list->data );

        /// ***
        if ( GTK_IS_WINDOW ( window ) )
        {
            g_print ( "The window found is: %s\n", gtk_widget_get_name ( list->data ) );
            
            /// ***
            gtk_window_present ( window );

            /// ***
            ///gtk_application_remove_window( application, window );
        }

        list = g_list_next ( list );
    }

    /// ***
    ///gtk_window_present ( GTK_WINDOW ( first_window ) );

    /// ***
    ///gtk_window_present ( GTK_WINDOW ( second_window ) );

    /// ***
}

int main ( void )
{
    GtkApplication *application;
    gint status;

    /// ***
    application = gtk_application_new ( "this.is.my-nice.app", G_APPLICATION_FLAGS_NONE );

    /// ***
    g_signal_connect ( application, "activate", G_CALLBACK ( activate_clbk ), NULL );

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

    /// ***
    g_object_unref ( application );
    return status;
}
Author: MichaelB

Leave a Reply

Your email address will not be published.