#include <glib.h>
#include <gtk/gtk.h>

/* Hover over the button to show the tooltip. The tooltip
 * will disappear when timeout_func gets called. */

gboolean timeout_func()
{
    GtkWidget *window;
    GtkWidget *alignment;

    printf("timeout_func called\n");

    alignment = gtk_alignment_new(0, 0, 0, 0);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_add(GTK_CONTAINER(window), alignment);

    return G_SOURCE_CONTINUE;
}

void quit_func(G_GNUC_UNUSED GtkWidget *widget)
{
    gtk_main_quit();
}

int main(int argc, char **argv)
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *button;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

    button = gtk_button_new_with_label("Hover to get a tooltip");
    gtk_widget_set_tooltip_text(button, "I am a tooltip, watch me disappear");

    gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), box);

    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(quit_func), NULL);
    g_timeout_add(2000, timeout_func, NULL);
    gtk_widget_show_all(window);

    gtk_main();

    return 0;
}
