#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkStyleContext *context;
  GtkCssProvider *red_provider;
  GtkCssProvider *blue_provider;

  red_provider = gtk_css_provider_new ();
  blue_provider = gtk_css_provider_new ();

  gtk_css_provider_load_from_data (red_provider, ".blue-window { background: blue; }", -1, NULL);
  gtk_css_provider_load_from_data (blue_provider, "window { background: red; }", -1, NULL);

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  context = gtk_widget_get_style_context (window);

  gtk_style_context_add_class (context, "blue-window");

#if 1
  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (blue_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (red_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
#else
  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (red_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (blue_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
#endif

  gtk_widget_show_all (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}
