2013-04-22 16:03:07 +00:00
|
|
|
/* Revealer
|
|
|
|
*
|
|
|
|
* GtkRevealer is a container that animates showing and hiding
|
|
|
|
* of its sole child with nice transitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static gint count = 0;
|
2015-06-28 13:23:28 +00:00
|
|
|
static guint timeout = 0;
|
2013-04-22 16:03:07 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
change_direction (GtkRevealer *revealer)
|
|
|
|
{
|
2016-05-07 20:22:13 +00:00
|
|
|
if (gtk_widget_get_mapped (GTK_WIDGET (revealer)))
|
|
|
|
{
|
|
|
|
gboolean revealed;
|
2013-04-22 16:03:07 +00:00
|
|
|
|
2016-05-07 20:22:13 +00:00
|
|
|
revealed = gtk_revealer_get_child_revealed (revealer);
|
|
|
|
gtk_revealer_set_reveal_child (revealer, !revealed);
|
|
|
|
}
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
reveal_one (gpointer data)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
GtkWidget *window = data;
|
|
|
|
GtkBuilder *builder;
|
2013-04-22 16:03:07 +00:00
|
|
|
gchar *name;
|
|
|
|
GtkRevealer *revealer;
|
|
|
|
|
2015-06-28 13:23:28 +00:00
|
|
|
builder = GTK_BUILDER (g_object_get_data (G_OBJECT (window), "builder"));
|
2013-04-22 16:03:07 +00:00
|
|
|
name = g_strdup_printf ("revealer%d", count);
|
|
|
|
revealer = (GtkRevealer *)gtk_builder_get_object (builder, name);
|
|
|
|
|
|
|
|
gtk_revealer_set_reveal_child (revealer, TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (revealer, "notify::child-revealed",
|
|
|
|
G_CALLBACK (change_direction), NULL);
|
|
|
|
count++;
|
|
|
|
|
2014-04-12 17:35:19 +00:00
|
|
|
if (count >= 9)
|
|
|
|
{
|
|
|
|
timeout = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return TRUE;
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
2013-04-22 16:03:07 +00:00
|
|
|
static void
|
2015-06-28 13:23:28 +00:00
|
|
|
on_destroy (gpointer data)
|
2013-04-22 16:03:07 +00:00
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
window = NULL;
|
2013-07-04 21:52:09 +00:00
|
|
|
if (timeout != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (timeout);
|
|
|
|
timeout = 0;
|
|
|
|
}
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_revealer (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
if (!window)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
GtkBuilder *builder;
|
|
|
|
|
|
|
|
builder = gtk_builder_new_from_resource ("/revealer/revealer.ui");
|
|
|
|
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2013-04-22 16:03:07 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2015-06-28 13:23:28 +00:00
|
|
|
G_CALLBACK (on_destroy), NULL);
|
|
|
|
g_object_set_data_full (G_OBJECT (window), "builder", builder, g_object_unref);
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
|
|
|
{
|
|
|
|
count = 0;
|
2015-06-28 13:23:28 +00:00
|
|
|
timeout = g_timeout_add (690, reveal_one, window);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2013-04-22 16:03:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|