2019-06-05 03:23:13 +00:00
|
|
|
/* Benchmark/Themes
|
|
|
|
*
|
2020-12-08 23:02:03 +00:00
|
|
|
* This demo continuously switches themes, like some of you.
|
2020-08-09 20:36:00 +00:00
|
|
|
*
|
|
|
|
* Warning: This demo involves rapidly flashing changes and may
|
|
|
|
* be hazardous to photosensitive viewers.
|
2019-06-05 03:23:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static guint tick_cb;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
gboolean dark;
|
|
|
|
} Theme;
|
|
|
|
|
|
|
|
static Theme themes[] = {
|
|
|
|
{ "Adwaita", FALSE },
|
|
|
|
{ "Adwaita", TRUE },
|
|
|
|
{ "HighContrast", FALSE },
|
|
|
|
{ "HighContrastInverse", FALSE }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int theme;
|
|
|
|
|
|
|
|
static gboolean
|
2020-06-07 00:09:42 +00:00
|
|
|
change_theme (GtkWidget *widget,
|
2019-06-05 03:23:13 +00:00
|
|
|
GdkFrameClock *frame_clock,
|
2020-06-07 00:09:42 +00:00
|
|
|
gpointer data)
|
2019-06-05 03:23:13 +00:00
|
|
|
{
|
2020-06-07 00:09:42 +00:00
|
|
|
GtkWidget *label = data;
|
2019-06-05 03:23:13 +00:00
|
|
|
Theme next = themes[theme++ % G_N_ELEMENTS (themes)];
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
g_object_set (gtk_settings_get_default (),
|
|
|
|
"gtk-theme-name", next.name,
|
|
|
|
"gtk-application-prefer-dark-theme", next.dark,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
name = g_strconcat (next.name, next.dark ? " (dark)" : NULL, NULL);
|
2020-04-30 23:04:08 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (widget), name);
|
2019-06-05 03:23:13 +00:00
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
if (frame_clock)
|
|
|
|
{
|
|
|
|
char *fps;
|
|
|
|
|
2020-09-14 03:42:13 +00:00
|
|
|
fps = g_strdup_printf ("%.2f fps", gdk_frame_clock_get_fps (frame_clock));
|
2019-06-05 03:23:13 +00:00
|
|
|
gtk_label_set_label (GTK_LABEL (label), fps);
|
|
|
|
g_free (fps);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), "");
|
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2020-06-05 22:39:08 +00:00
|
|
|
static void
|
|
|
|
toggle_cycle (GObject *button,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2020-08-09 20:36:00 +00:00
|
|
|
GtkWidget *warning = data;
|
2020-06-05 22:39:08 +00:00
|
|
|
gboolean active;
|
|
|
|
GtkWidget *window;
|
|
|
|
|
|
|
|
g_object_get (button, "active", &active, NULL);
|
|
|
|
|
|
|
|
window = gtk_widget_get_ancestor (GTK_WIDGET (button), GTK_TYPE_WINDOW);
|
|
|
|
|
|
|
|
if (active && !tick_cb)
|
|
|
|
{
|
2020-08-09 20:36:00 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (warning));
|
2020-06-05 22:39:08 +00:00
|
|
|
}
|
|
|
|
else if (!active && tick_cb)
|
|
|
|
{
|
|
|
|
gtk_widget_remove_tick_callback (window, tick_cb);
|
|
|
|
tick_cb = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:36:00 +00:00
|
|
|
static void
|
|
|
|
warning_closed (GtkDialog *warning,
|
|
|
|
int response_id,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
gtk_widget_hide (GTK_WIDGET (warning));
|
|
|
|
|
|
|
|
window = gtk_widget_get_ancestor (GTK_WIDGET (data), GTK_TYPE_WINDOW);
|
|
|
|
button = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "button"));
|
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
tick_cb = gtk_widget_add_tick_callback (window, change_theme, data, NULL);
|
|
|
|
else
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
|
|
|
|
}
|
|
|
|
|
2019-06-05 03:23:13 +00:00
|
|
|
GtkWidget *
|
|
|
|
do_themes (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkBuilder *builder;
|
2020-06-05 22:39:08 +00:00
|
|
|
GtkWidget *button;
|
2020-06-07 00:09:42 +00:00
|
|
|
GtkWidget *label;
|
2020-08-09 20:36:00 +00:00
|
|
|
GtkWidget *warning;
|
2019-06-05 03:23:13 +00:00
|
|
|
|
|
|
|
builder = gtk_builder_new_from_resource ("/themes/themes.ui");
|
|
|
|
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2019-06-05 03:23:13 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2020-05-09 16:03:11 +00:00
|
|
|
|
2020-06-07 00:09:42 +00:00
|
|
|
label = GTK_WIDGET (gtk_builder_get_object (builder, "fps"));
|
2020-08-09 20:36:00 +00:00
|
|
|
warning = GTK_WIDGET (gtk_builder_get_object (builder, "warning"));
|
|
|
|
g_signal_connect (warning, "response", G_CALLBACK (warning_closed), label);
|
2019-06-05 03:23:13 +00:00
|
|
|
|
2020-06-05 22:39:08 +00:00
|
|
|
button = GTK_WIDGET (gtk_builder_get_object (builder, "toggle"));
|
2020-08-09 20:36:00 +00:00
|
|
|
g_object_set_data (G_OBJECT (window), "button", button);
|
|
|
|
g_signal_connect (button, "notify::active", G_CALLBACK (toggle_cycle), warning);
|
2019-06-05 03:23:13 +00:00
|
|
|
gtk_widget_realize (window);
|
2020-06-07 00:09:42 +00:00
|
|
|
|
|
|
|
g_object_unref (builder);
|
2019-06-05 03:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
|
|
|
gtk_widget_show (window);
|
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2019-06-05 03:23:13 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|