]> Pileus Git - ~andy/gtk/blob - tests/visuals/visuals.c
0a6caa3b999e1618f04a86ce62187927b45b24c4
[~andy/gtk] / tests / visuals / visuals.c
1 /* visuals: UI runner for visual GtkBuilder files
2  *
3  * Copyright (C) 2012 Red Hat, Inc.
4  *
5  * This  library is free  software; you can  redistribute it and/or
6  * modify it  under  the terms  of the  GNU Lesser  General  Public
7  * License  as published  by the Free  Software  Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed  in the hope that it will be useful,
11  * but  WITHOUT ANY WARRANTY; without even  the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License  along  with  this library;  if not,  write to  the Free
17  * Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  *
20  * Author: Cosimo Cecchi <cosimoc@gnome.org>
21  *
22  */
23
24 #include <gtk/gtk.h>
25
26 static void
27 dark_button_toggled_cb (GtkToggleButton *button,
28                         gpointer user_data)
29 {
30   gboolean active = gtk_toggle_button_get_active (button);
31   GtkSettings *settings = gtk_settings_get_default ();
32
33   g_object_set (settings,
34                 "gtk-application-prefer-dark-theme", active,
35                 NULL);
36 }
37
38 static void
39 create_dark_popup (GtkWidget *parent)
40 {
41   GtkWidget *popup = gtk_window_new (GTK_WINDOW_TOPLEVEL);
42   GtkWidget *button = gtk_toggle_button_new_with_label ("Dark");
43
44   gtk_window_set_decorated (GTK_WINDOW (popup), FALSE);
45   gtk_widget_set_size_request (popup, 100, 100);
46   gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
47
48   g_signal_connect (popup, "delete-event",
49                     G_CALLBACK (gtk_true), NULL);
50
51   gtk_container_add (GTK_CONTAINER (popup), button);
52   g_signal_connect (button, "toggled",
53                     G_CALLBACK (dark_button_toggled_cb), NULL);
54
55   gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
56
57   gtk_widget_show_all (popup);
58 }
59
60 int
61 main (int argc, char *argv[])
62 {
63   GtkBuilder *builder;
64   GtkWidget  *window;
65   const gchar *filename;
66
67   gtk_init (&argc, &argv);
68
69   if (argc < 2)
70     return 1;
71   filename = argv[1];
72
73   builder = gtk_builder_new ();
74   gtk_builder_add_from_file (builder, filename, NULL);
75
76   window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
77   g_object_unref (G_OBJECT (builder));
78   g_signal_connect (window, "destroy",
79                     G_CALLBACK (gtk_main_quit), NULL);
80   gtk_widget_show_all (window);
81
82   create_dark_popup (window);
83   gtk_main ();
84
85   return 0;
86 }