/* gcc -g titlebar-buttons.c $(pkg-config --cflags --libs gtk+-3.0
   gio-2.0 glib-2.0) */

#include <gtk/gtk.h>

static void
clickme_clicked (GtkWidget *widget)
{
  gboolean sensitive = gtk_widget_get_sensitive (widget);
  gtk_widget_set_sensitive (widget, !sensitive);
}

static gboolean
change_headerbar (GtkWidget *headerbar)
{
  GtkWidget *clickme;
  GtkWidget *lookme;

  clickme = gtk_button_new_with_label ("Click Me");
  lookme = gtk_button_new_with_label ("Look Me");

  g_signal_connect_swapped (clickme,
                            "clicked",
                            G_CALLBACK (clickme_clicked),
                            lookme);
  gtk_header_bar_pack_start (GTK_HEADER_BAR (headerbar), clickme);
  gtk_header_bar_pack_end (GTK_HEADER_BAR (headerbar), lookme);

  // to make it works, just swap the following two lines:
  gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), FALSE);
  gtk_widget_show_all (headerbar);
  return FALSE;
}

gint
main (gint argc, gchar *argv[])
{
  GtkWidget *grid;
  GtkWidget *header_bar;
  GtkWidget *label;
  GtkWidget *window;

  gtk_init (NULL, NULL);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (window, 500, -1);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  header_bar = gtk_header_bar_new ();
  gtk_header_bar_set_title (GTK_HEADER_BAR (header_bar), "titlebar-buttons");
  gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), TRUE);
  gtk_widget_show_all (header_bar);
  gtk_window_set_titlebar (GTK_WINDOW (window), header_bar);

  label = gtk_label_new ("wait the buttons in the header bar");
  gtk_container_add (GTK_CONTAINER (window), label);

  g_timeout_add (1000, (GSourceFunc) change_headerbar, header_bar);

  gtk_widget_show_all (window);
  gtk_main ();

  return 0;
}

