2016-11-05 02:31:10 +00:00
|
|
|
/* Benchmark/Fishbowl
|
|
|
|
*
|
|
|
|
* This demo models the fishbowl demos seen on the web in a GTK way.
|
|
|
|
* It's also a neat little tool to see how fast your computer (or
|
|
|
|
* your GTK version) is.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2017-01-07 00:59:23 +00:00
|
|
|
#include "gtkfishbowl.h"
|
2016-11-05 02:31:10 +00:00
|
|
|
|
2018-04-24 18:32:57 +00:00
|
|
|
char **icon_names = NULL;
|
|
|
|
gsize n_icon_names = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_icon_names (GtkIconTheme *theme)
|
|
|
|
{
|
|
|
|
GPtrArray *icons;
|
|
|
|
GList *l, *icon_list;
|
|
|
|
|
|
|
|
if (icon_names)
|
|
|
|
return;
|
|
|
|
|
|
|
|
icon_list = gtk_icon_theme_list_icons (theme, NULL);
|
|
|
|
icons = g_ptr_array_new ();
|
|
|
|
|
|
|
|
for (l = icon_list; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (g_str_has_suffix (l->data, "symbolic"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
g_ptr_array_add (icons, g_strdup (l->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
n_icon_names = icons->len;
|
|
|
|
g_ptr_array_add (icons, NULL); /* NULL-terminate the array */
|
|
|
|
icon_names = (char **) g_ptr_array_free (icons, FALSE);
|
|
|
|
|
|
|
|
/* don't free strings, we assigned them to the array */
|
|
|
|
g_list_free_full (icon_list, g_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
get_random_icon_name (GtkIconTheme *theme)
|
|
|
|
{
|
|
|
|
init_icon_names (theme);
|
|
|
|
|
|
|
|
return icon_names[g_random_int_range(0, n_icon_names)];
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
create_icon (void)
|
|
|
|
{
|
|
|
|
GtkWidget *image;
|
|
|
|
|
|
|
|
image = gtk_image_new_from_icon_name (get_random_icon_name (gtk_icon_theme_get_default ()));
|
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2016-11-05 02:31:10 +00:00
|
|
|
GtkWidget *
|
|
|
|
do_fishbowl (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
2018-03-30 14:47:52 +00:00
|
|
|
GtkWidget *bowl;
|
2016-11-05 02:31:10 +00:00
|
|
|
|
2017-01-07 00:59:23 +00:00
|
|
|
g_type_ensure (GTK_TYPE_FISHBOWL);
|
|
|
|
|
2016-11-05 02:31:10 +00:00
|
|
|
builder = gtk_builder_new_from_resource ("/fishbowl/fishbowl.ui");
|
|
|
|
gtk_builder_connect_signals (builder, NULL);
|
|
|
|
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
|
|
|
bowl = GTK_WIDGET (gtk_builder_get_object (builder, "bowl"));
|
2018-04-24 18:32:57 +00:00
|
|
|
gtk_fishbowl_set_creation_func (GTK_FISHBOWL (bowl), create_icon);
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2016-11-05 02:31:10 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
|
|
|
|
|
|
|
gtk_widget_realize (window);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
2016-11-20 04:29:03 +00:00
|
|
|
gtk_widget_show (window);
|
2016-11-05 02:31:10 +00:00
|
|
|
else
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|