GApplication – Part II

#include <gtk/gtk.h>

static void activate ( GtkApplication *application, G_GNUC_UNUSED gpointer data )
{
    GtkWidget *window;

    /// ***
    window = gtk_application_window_new   ( application );

    /// ***
    gtk_window_set_default_size ( GTK_WINDOW ( window ), 200, 200 );

    /// ***
    g_print ( "Running the Aplication\n" );

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

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

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

    /// ***
    GError* error = NULL;
    if ( !g_application_register ( G_APPLICATION ( application ), NULL, &error ) )
    {
        g_warning ( "Cannot register %s", error->message );
        g_error_free ( error );
        error = NULL;
    }

    /// ***
    if ( g_application_get_is_registered ( G_APPLICATION ( application ) ) )
    {
        /// ***
        g_print ( "The application was registered\n" );

        /// ***
        if ( g_application_get_is_remote ( G_APPLICATION ( application ) ) )
        {
            /// ***
            g_message ( "The GApplication is already running." );
        }
    }
    else
    {
        /// ***
        g_print ( "Not registered\n" );
    }

    /// ***
    g_signal_connect ( application, "activate", G_CALLBACK ( activate ), 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.