1 /* CSS Theming/Custom CSS
3 * GTK+ uses CSS for theming. If required, applications can
4 * install their own custom CSS style provider to achieve
7 * Doing this has the downside that your application will no
8 * longer react to the users theme preferences, so this should
14 static GtkWidget *window = NULL;
17 do_theming_custom_css (GtkWidget *do_widget)
21 GtkCssProvider *provider;
26 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
27 gtk_window_set_screen (GTK_WINDOW (window),
28 gtk_widget_get_screen (do_widget));
29 gtk_window_set_title (GTK_WINDOW (window), "Custom CSS");
30 gtk_container_set_border_width (GTK_CONTAINER (window), 18);
31 g_signal_connect (window, "destroy",
32 G_CALLBACK (gtk_widget_destroyed), &window);
33 box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
34 gtk_container_add (GTK_CONTAINER (window), box);
35 button = gtk_button_new_with_label ("Plain");
36 gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
37 button = gtk_button_new_with_label ("Fancy");
38 gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
39 gtk_widget_set_name (button, "fancy");
41 provider = gtk_css_provider_new ();
42 bytes = g_resources_lookup_data ("/theming_custom_css/fancy.css", 0, NULL);
43 gtk_css_provider_load_from_data (provider, g_bytes_get_data (bytes, NULL),
44 g_bytes_get_size (bytes), NULL);
45 gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (do_widget),
46 GTK_STYLE_PROVIDER (provider),
47 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
48 g_object_unref (provider);
49 g_bytes_unref (bytes);
51 gtk_widget_show_all (box);
54 if (!gtk_widget_get_visible (window))
56 gtk_widget_show (window);
60 gtk_widget_destroy (window);