GApplication – Part III

#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 );

    /// ***
    /* the inactivity timeout can only be set while the application is held */
    /// *** Calling hold function will prevent the application to terminate.
    g_application_hold ( G_APPLICATION    ( application ) );

    /// *** If this is called, there release will be called after 5 seconds
    g_application_set_inactivity_timeout  ( G_APPLICATION ( application ), 5 * 1000 );

    /// *** Calling release function will terminate the application.
    g_application_release ( G_APPLICATION ( application ) );

    /// ***
    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 );

    /// ***
    g_application_register ( G_APPLICATION ( application ), NULL, NULL );

    /// ***
    GDBusConnection *connection = g_application_get_dbus_connection ( G_APPLICATION ( application ) );
    if ( connection )
    {
        const gchar *const get_unique_name = g_dbus_connection_get_unique_name ( connection );
        const gchar *const get_path        = g_application_get_dbus_object_path ( G_APPLICATION ( application ) );

        /// ***
        g_print ( "Unique Name: %s\n", get_unique_name );
        g_print ( "Path: %s\n", get_path );
    }

    /// ***
    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.