]> Pileus Git - ~andy/gtk/blob - tests/visuals/visuals.c
stylecontext: Do invalidation on first resize container
[~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  *
18  * Author: Cosimo Cecchi <cosimoc@gnome.org>
19  *
20  */
21
22 #include <gtk/gtk.h>
23
24 static void
25 dark_button_toggled_cb (GtkToggleButton *button,
26                         gpointer user_data)
27 {
28   gboolean active = gtk_toggle_button_get_active (button);
29   GtkSettings *settings = gtk_settings_get_default ();
30
31   g_object_set (settings,
32                 "gtk-application-prefer-dark-theme", active,
33                 NULL);
34 }
35
36 static void
37 create_dark_popup (GtkWidget *parent)
38 {
39   GtkWidget *popup = gtk_window_new (GTK_WINDOW_TOPLEVEL);
40   GtkWidget *button = gtk_toggle_button_new_with_label ("Dark");
41
42   gtk_window_set_decorated (GTK_WINDOW (popup), FALSE);
43   gtk_widget_set_size_request (popup, 100, 100);
44   gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
45
46   g_signal_connect (popup, "delete-event",
47                     G_CALLBACK (gtk_true), NULL);
48
49   gtk_container_add (GTK_CONTAINER (popup), button);
50   g_signal_connect (button, "toggled",
51                     G_CALLBACK (dark_button_toggled_cb), NULL);
52
53   gtk_window_set_transient_for (GTK_WINDOW (popup), GTK_WINDOW (parent));
54
55   gtk_widget_show_all (popup);
56 }
57
58 int
59 main (int argc, char *argv[])
60 {
61   GtkBuilder *builder;
62   GtkWidget  *window;
63   const gchar *filename;
64
65   gtk_init (&argc, &argv);
66
67   if (argc < 2)
68     return 1;
69   filename = argv[1];
70
71   builder = gtk_builder_new ();
72   gtk_builder_add_from_file (builder, filename, NULL);
73
74   window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
75   g_object_unref (G_OBJECT (builder));
76   g_signal_connect (window, "destroy",
77                     G_CALLBACK (gtk_main_quit), NULL);
78   gtk_widget_show_all (window);
79
80   create_dark_popup (window);
81   gtk_main ();
82
83   return 0;
84 }