Beispiel #1
0
int main( int argc, char *argv[] )
{
    // Initialize GTK+
    gtk_init( &argc, &argv );
    g_set_application_name( PACKAGE_NAME );
    g_log_set_handler( "Wnck", G_LOG_LEVEL_WARNING, (GLogFunc)gtk_false  , NULL );

    const struct option longopts[] =
    {
        { 0, 0, 0, 'v' },
        { 0, 0, 0, 'h' },
        { 0, 0, 0,  0  },
    };

    int index = 0;
    int iarg  = 0;

    // turn off getopt error message
    opterr = 0;

    while( iarg != -1 )
    {
        iarg = getopt_long( argc, argv, "s:vh", longopts, &index );

        switch( iarg )
        {
        case 'v':
            g_fprintf( stderr, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION );
            g_fprintf( stderr, "Features:\n" );
            #ifdef HAVE_APPINDICATOR
                g_fprintf( stderr, "AppIndicator support - Yes\n" );
            #else
                g_fprintf( stderr, "AppIndicator support - No\n" );
            #endif
            g_fprintf( stderr, "Icon cache - Yes\n" );
            return 0;
            break;

        case 'h':
            g_fprintf( stderr, "%s\n\n%s\n%s\n%s\n",
                       "Usage: gxkb [arguments]",
                       "Options:",
                       "-v \t Display gxkb's version number.",
                       "-h \t Show this help." );
            return 0;
            break;
        }
    }

    gchar *config_file = xkb_util_get_config_file();

    gboolean first_run = FALSE;
    t_xkb_settings *xkb = xkb_new();
    if( !xkb_load_config( xkb, config_file ) )
    {
        first_run = TRUE;
        xkb->group_policy = GROUP_POLICY_PER_APPLICATION;
    }

    if( !xkb_config_initialize( xkb, xkb_state_changed, xkb ) )
    {
        g_fprintf( stderr, "Can't get instance of the X display.\n" );
        return 1;
    }

    if( first_run )
        xkb_save_config( xkb, config_file );

    statusicon_new();

    // Save original config
    t_xkb_settings *orig_config = g_new0( t_xkb_settings, 1 );
    xkb_load_config( orig_config, config_file );

    /* Enter the main loop */
    gtk_main();

    // Load config and check if it was not changed
    t_xkb_settings *last_config = g_new0( t_xkb_settings, 1 );
    xkb_load_config( last_config, config_file );
    gboolean is_diff = xkb_is_config_changed( orig_config, last_config );

    if( is_diff )
        g_warning("Config file was changed. Saving skipped.\n");
    else if( xkb->never_modify_config )
        g_warning("Saving skipped by your configuration.\n");
    else
        xkb_save_config( xkb, config_file );

    g_free( orig_config );
    g_free( last_config );
    g_free( config_file );
    xkb_free( xkb );
    statusicon_free();

    return 0;
}
static void
xfce_xkb_free_data (XfcePanelPlugin *plugin, t_xkb *xkb)
{
    xkb_free (xkb);
}