// gcc -Wall -g -o test test.c  `pkg-config --libs --cflags clutter-gtk-1.0`

#include <clutter-gtk/clutter-gtk.h>

static gboolean
button_press_cb (GtkWidget *widget, GdkEventButton *event, ClutterStage *stage)
{
  ClutterActor *actor;

  actor = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), CLUTTER_PICK_ALL,
					  event->x, event->y);
  g_message ("button press on %s (pick all)", clutter_actor_get_name (actor));
  actor = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), CLUTTER_PICK_REACTIVE,
					  event->x, event->y);
  g_message ("button press on %s (pick reactive)", clutter_actor_get_name (actor));
  return FALSE;
}

/* Works as expected with just the label
 * Breaks with the toolbar */
#define BROKEN 1

int main (int argc, char **argv)
{
	ClutterActor *stage;
	ClutterActor *controls;
	ClutterActor *layout;
	GtkWidget *embed;
	GtkWidget *window;
	GtkWidget *toolbar;
	GtkWidget *toolitem;

	gtk_clutter_init (NULL, NULL);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	embed = gtk_clutter_embed_new ();
	gtk_container_add (GTK_CONTAINER (window), embed);
	stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (embed));
	clutter_actor_set_name (stage, "stage");
#ifdef BROKEN
	toolbar = gtk_toolbar_new ();
	toolitem = GTK_WIDGET (gtk_tool_item_new ());
	gtk_container_add (GTK_CONTAINER (toolitem), gtk_label_new ("TEST TEXT"));
	gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
	gtk_container_add (GTK_CONTAINER (toolbar), toolitem);
	gtk_widget_show_all (toolbar);
	controls = gtk_clutter_actor_new_with_contents (toolbar);
#else
	controls = gtk_clutter_actor_new_with_contents (gtk_label_new ("TEST TEXT"));
#endif
	clutter_actor_set_x_expand (controls, TRUE);
	clutter_actor_set_name (controls, "controls");
	layout = g_object_new (CLUTTER_TYPE_ACTOR,
			       "layout-manager", clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END),
			       NULL);
	clutter_actor_set_name (layout, "layout");
	clutter_actor_add_child (layout, controls);

	clutter_actor_add_child (stage, layout);

	ClutterConstraint *constraint = clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0);
	clutter_actor_add_constraint_with_name (layout, "size", constraint);

	g_signal_connect (embed, "button-press-event",
			  G_CALLBACK (button_press_cb), stage);

	gtk_widget_show_all (window);

	clutter_main ();
	return 0;
}
