// gcc $(pkg-config --cflags --libs gtk+-3.0) -o cluebar ./test-notebook-infobar.c

#include <gtk/gtk.h>

static GtkWidget *create_window(gboolean create_infobar)
{
        GtkWidget *window;
        GtkWidget *widget;

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

        if (create_infobar) {
            GtkWidget *infobar_label;
            widget = gtk_info_bar_new ();

            infobar_label = gtk_label_new ("infobar label");
            gtk_container_add (GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (widget))),
                               infobar_label);

#ifdef WORKAROUND
            GObject *revealer = gtk_widget_get_template_child (GTK_WIDGET (widget),
                                               GTK_TYPE_INFO_BAR, "revealer");
            if (revealer) {
                    g_warning("revealer");
                    gtk_revealer_set_transition_type (GTK_REVEALER (revealer),
                                    GTK_REVEALER_TRANSITION_TYPE_NONE);
                    gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 0);
            }

#endif
        } else {
            widget = gtk_label_new("foo");
        }


        gtk_container_add (GTK_CONTAINER (window), widget);

        gtk_widget_show_all(window);

        return widget;
}

typedef struct {
        GtkWidget *widget;
        guint state;
} ShowHideData;

static gboolean show_hide_widget(gpointer user_data)
{
        ShowHideData *data = user_data;

        switch (data->state) {
        case 0:
                g_warning("hide %p", data->widget);
                gtk_widget_hide(data->widget);
                break;
        case 1:
                g_warning("show %p", data->widget);
                gtk_widget_show(data->widget);
                break;
        }
        data->state++;
        if (data->state > 1)
                return G_SOURCE_REMOVE;
        else
                return G_SOURCE_CONTINUE;
}

int main(int argc, char **argv)
{
        ShowHideData infobar_data = { 0, };
        ShowHideData label_data = { 0, };

        gtk_init(&argc, &argv);

        /* 1st window - reference infobar */
        create_window(TRUE);

        /* 2nd window - show/hide infobar */
        infobar_data.widget = create_window(TRUE);
        g_timeout_add_seconds(2, show_hide_widget, &infobar_data);

        /* 1st window - reference label */
        create_window(FALSE);

        /* 2nd window - show/hide label */
        label_data.widget = create_window(FALSE);
        g_timeout_add_seconds(2, show_hide_widget, &label_data);

        gtk_main();

        return 0;
}
