/* Compile with:
 * $ gcc -g -o scroll scroll.c `pkg-config --libs --cflags clutter-1.0`
 *
 * Use the '--enable-xinput' command line flag to test with XI2 enabled.
 */
#include <clutter/clutter.h>

static gboolean
input_cb (ClutterActor *actor,
	  ClutterEvent *event,
	  gpointer      data)
{
  ClutterScrollDirection direction;
  gdouble dX = 0, dY = 0;
  gboolean emulated;
  if (event->type != CLUTTER_SCROLL)
    return FALSE;

  direction = clutter_event_get_scroll_direction (event);
  emulated = clutter_event_is_pointer_emulated (event);
  if (direction == CLUTTER_SCROLL_SMOOTH)
    {
      clutter_event_get_scroll_delta(event, &dX, &dY);
      g_print ("SCROLL (direction:smooth t:%d emulated:%s dx:%.2f dy:%.2f)\n",
          clutter_event_get_time (event),
          emulated ? "yes" : "no",
          dX, dY);
    }
  else
    g_print ("SCROLL (direction:%s t:%d emulated:%s)\n",
             direction == CLUTTER_SCROLL_UP ? "up" :
             direction == CLUTTER_SCROLL_DOWN ? "down" :
             direction == CLUTTER_SCROLL_LEFT ? "left" :
             direction == CLUTTER_SCROLL_RIGHT ? "right" :
             "?",
             clutter_event_get_time (event),
             emulated ? "yes" : "no");
  return FALSE;
}

int
main (int argc, char *argv[])
{
  ClutterActor *stage;

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  stage = clutter_stage_new ();
  g_signal_connect (stage, "event", G_CALLBACK (input_cb), "stage");
  clutter_actor_show (CLUTTER_ACTOR (stage));
  clutter_main();

  return 0;
}
