#include <gtk/gtk.h>

static GtkWindow *
create_scrolled_window (gboolean overlay, GtkPolicyType policy)
{
  GtkWidget *grid = gtk_grid_new ();

  for (unsigned i = 0; i < 8; ++i) {
    for (unsigned j = 0; j < 8; ++j) {
      char *string = g_strdup_printf ("%u, %u", i, j);
      GtkWidget *button = gtk_button_new_with_label (string);
      g_free (string);

      gtk_grid_attach (GTK_GRID (grid), button, i, j, 1, 1);
    }
  }

  GtkWidget *scroller = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_overlay_scrolling (GTK_SCROLLED_WINDOW (scroller), overlay);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller), policy, policy);
  gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (scroller), TRUE);
  gtk_scrolled_window_set_propagate_natural_width  (GTK_SCROLLED_WINDOW (scroller), TRUE);
  gtk_container_add (GTK_CONTAINER (scroller), grid);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  char *title = g_strdup_printf ("%s / %s",
                                 overlay ? "overlay" : "fixed",
                                 policy == GTK_POLICY_AUTOMATIC ? "auto" : "always");
  gtk_window_set_title (GTK_WINDOW (window), title);
  g_free (title);

  gtk_container_add (GTK_CONTAINER (window), scroller);
  gtk_widget_show_all (window);
}

int
main(int argc, char** argv)
{
  gtk_init (&argc, &argv);

  create_scrolled_window (TRUE, GTK_POLICY_AUTOMATIC);
  create_scrolled_window (FALSE, GTK_POLICY_AUTOMATIC);
  create_scrolled_window (TRUE, GTK_POLICY_ALWAYS);
  create_scrolled_window (FALSE, GTK_POLICY_ALWAYS);

  gtk_main ();

  return 0;
}
