#include <gtk/gtk.h>
#include <libsexy/sexy-tooltip.h>

gboolean
enter (GtkWidget *widget, GdkEventCrossing *event, GtkWidget *tooltip)
{
	GdkScreen *screen;
	gint x, y;
	GdkRectangle rect;

	screen = gtk_widget_get_screen(widget);
	gdk_window_get_origin(widget->window, &x, &y);

	rect.x = widget->allocation.x + x;
	rect.y = widget->allocation.y + y;
	rect.width  = widget->allocation.width;
	rect.height = widget->allocation.height;

	sexy_tooltip_position_to_rect (SEXY_TOOLTIP (tooltip), &rect, screen);
	sexy_tooltip_position_to_widget (SEXY_TOOLTIP (tooltip), widget);
	gtk_widget_show (tooltip);
	return FALSE;
}

gboolean
leave (GtkWidget *widget, GdkEventCrossing *event, GtkWidget *tooltip)
{
	gtk_widget_hide (tooltip);
	return FALSE;
}

int main() {
	gtk_init (NULL, NULL);
	GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        GtkWidget *button = gtk_button_new_with_label ("button");
        gtk_container_add (GTK_CONTAINER (window), button);
        gtk_widget_show_all (window);
	GtkWidget *tooltip = sexy_tooltip_new ();
	GtkWidget *l = gtk_label_new ("Hello world!");
	gtk_widget_show (l);
	gtk_container_add (GTK_CONTAINER (tooltip), l);
	g_signal_connect_object (button, "enter-notify-event", (GCallback) enter, tooltip, 0);
	g_signal_connect_object (button, "leave-notify-event", (GCallback) leave, tooltip, 0);
        gtk_main ();
}
