/* Compile with: gcc `pkg-config --cflags --libs gtk+-3.0` testcss.c -g -o testcss */
#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *grid, *vbox, *label;
  GtkStyleProvider *provider;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  grid = gtk_grid_new ();
  gtk_widget_set_name (grid, "grid");
  gtk_container_add (GTK_CONTAINER (window), grid);

  label = gtk_label_new ("Label 1\n");
  gtk_widget_set_name (label, "label1");
  gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
  gtk_grid_attach (GTK_GRID (grid), vbox, 1, 0, 1, 1);
  gtk_widget_set_name (vbox, "vbox");

  label = gtk_label_new ("Label 2\n");
  gtk_widget_set_name (label, "label2");
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  label = gtk_label_new ("Label 3\n");
  gtk_widget_set_name (label, "label3");
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

  provider = (GtkStyleProvider *)gtk_css_provider_new ();
  gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
				   /* This shouldn't (IMHO) affect the labels, since it matches *only* the toplevel, but it does */
                                   "GtkWindow {\n"
                                   "  color: #ff0000;\n"
                                   "}\n"
                                   "GtkBox {\n"
                                   "  color: #00ff00;\n"
                                   "}\n"
				   /* This should select the second label to the right, but doesn't */
                                   "GtkLabel #label3 {\n"
                                   "  color: #0000ff;\n"
                                   "}\n",
				   -1, NULL);
  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (), provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}

