static void xfce_xkb_construct (XfcePanelPlugin *plugin) { GtkWidget *configure_layouts; GtkIconTheme *theme; GtkWidget *image; GdkPixbuf *pixbuf; t_xkb *xkb = xkb_new (plugin); xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); xfce_panel_plugin_set_small (plugin, TRUE); g_signal_connect (plugin, "orientation-changed", G_CALLBACK (xfce_xkb_orientation_changed), xkb); g_signal_connect (plugin, "size-changed", G_CALLBACK (xfce_xkb_set_size), xkb); g_signal_connect (plugin, "free-data", G_CALLBACK (xfce_xkb_free_data), xkb); g_signal_connect (plugin, "save", G_CALLBACK (xfce_xkb_save_config), xkb); xfce_panel_plugin_menu_show_configure (plugin); g_signal_connect (plugin, "configure-plugin", G_CALLBACK (xfce_xkb_configure), xkb); xfce_panel_plugin_menu_show_about (plugin); g_signal_connect (plugin, "about", G_CALLBACK (xfce_xkb_about), xkb); configure_layouts = gtk_menu_item_new_with_label (_("Keyboard settings")); theme = gtk_icon_theme_get_for_screen (gdk_screen_get_default()); pixbuf = gtk_icon_theme_load_icon (theme, "preferences-desktop-keyboard", GTK_ICON_SIZE_MENU, 0, NULL); if (pixbuf != NULL) { image = gtk_image_new (); gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (configure_layouts), image); g_object_unref (pixbuf); } gtk_widget_show (configure_layouts); xfce_panel_plugin_menu_insert_item (plugin, GTK_MENU_ITEM (configure_layouts)); g_signal_connect (G_OBJECT (configure_layouts), "activate", G_CALLBACK (xfce_xkb_configure_layout), NULL); }
static gboolean xkb_control_new(Control *ctrl) { t_xkb *xkb; xkb = xkb_new(); gtk_container_add(GTK_CONTAINER(ctrl->base), xkb->ebox); ctrl->data = (gpointer)xkb; ctrl->with_popup = FALSE; gtk_widget_set_size_request(ctrl->base, -1, -1); return(TRUE); }
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; }