Compare commits

...

1 Commits

Author SHA1 Message Date
Emmanuele Bassi
bb54bc7d14 Add a "devel" CSS theme for our demos
It's useful to know if you're running the demos from an unstable version
of GTK+, so we should use a CSS fragment that updates the visual
identity of gtk-demo and gtk-widget-factory depending on the version of
GTK+ they are running against.
2018-05-08 09:16:53 +01:00
5 changed files with 99 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
<gresource prefix="/ui">
<file preprocess="xml-stripblanks">main.ui</file>
<file preprocess="xml-stripblanks">appmenu.ui</file>
<file>theme.css</file>
</gresource>
<gresource prefix="/application_demo">
<file>application.c</file>

View File

@@ -997,6 +997,41 @@ scrollbar_popup (GtkWidget *scrollbar, GtkWidget *menu)
return TRUE;
}
static void
settings__notify_gtk_theme_name (GObject *gobject,
GParamSpec *pspec,
gpointer data)
{
static GtkCssProvider *css_provider;
GtkWidget *window = data;
char *theme_name;
g_object_get (gobject, "gtk-theme-name", &theme_name, NULL);
if (g_strcmp0 (theme_name, "Adwaita") == 0)
{
if (css_provider == NULL)
{
css_provider = gtk_css_provider_new ();
gtk_css_provider_load_from_resource (css_provider, "/ui/theme.css");
gtk_style_context_add_provider_for_display (gtk_widget_get_display (window),
GTK_STYLE_PROVIDER (css_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
}
else
{
if (css_provider != NULL)
{
gtk_style_context_remove_provider_for_display (gtk_widget_get_display (window),
GTK_STYLE_PROVIDER (css_provider));
g_clear_object (&css_provider);
}
}
g_free (theme_name);
}
static void
activate (GApplication *app)
{
@@ -1029,6 +1064,20 @@ activate (GApplication *app)
win_entries, G_N_ELEMENTS (win_entries),
window);
g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",
G_CALLBACK (settings__notify_gtk_theme_name),
window);
if (gtk_get_minor_version () % 2 != 0)
{
GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (window));
gtk_style_context_add_class (context, "devel");
}
settings__notify_gtk_theme_name (G_OBJECT (gtk_widget_get_settings (GTK_WIDGET (window))),
NULL,
window);
notebook = (GtkWidget *)gtk_builder_get_object (builder, "notebook");
info_view = (GtkWidget *)gtk_builder_get_object (builder, "info-textview");

10
demos/gtk-demo/theme.css Normal file
View File

@@ -0,0 +1,10 @@
window.devel headerbar {
background: #cbd2d9 -gtk-icontheme("system-run-symbolic") 70% 0/64px 64px no-repeat, linear-gradient(to left, #a5b1bd 0%, #a5b1bd 8%, @theme_bg_color 25%);
box-shadow: inset 0 1px #f1f3f5;
border-color: #909fae;
color: rgba(46, 52, 54, 0.2);
}
window.devel headerbar label {
color: @theme_fg_color;
}

View File

@@ -1605,6 +1605,27 @@ adjustment3_value_changed (GtkAdjustment *adj, GtkProgressBar *pbar)
gtk_progress_bar_set_fraction (pbar, fraction);
}
static void
settings__notify_gtk_theme_name (GObject *gobject,
GParamSpec *pspec,
gpointer data)
{
GtkWidget *window = data;
char *theme_name = NULL;
g_object_get (gobject, "gtk-theme-name", &theme_name, NULL);
if (g_strcmp0 (theme_name, "Adwaita") == 0)
{
if (gtk_get_minor_version () % 2 != 0)
gtk_style_context_add_class (gtk_widget_get_style_context (window), "devel");
}
else
gtk_style_context_remove_class (gtk_widget_get_style_context (window), "devel");
g_free (theme_name);
}
static void
activate (GApplication *app)
{
@@ -1680,6 +1701,13 @@ activate (GApplication *app)
win_entries, G_N_ELEMENTS (win_entries),
window);
g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",
G_CALLBACK (settings__notify_gtk_theme_name),
window);
settings__notify_gtk_theme_name (G_OBJECT (gtk_settings_get_default ()),
NULL,
window);
for (i = 0; i < G_N_ELEMENTS (accels); i++)
gtk_application_set_accels_for_action (GTK_APPLICATION (app), accels[i].action_and_target, accels[i].accelerators);

View File

@@ -24,3 +24,14 @@
.border-ridge {
border-width: 2px;
}
window.devel headerbar {
background: #cbd2d9 -gtk-icontheme("system-run-symbolic") 70% 0/64px 64px no-repeat, linear-gradient(to left, #a5b1bd 0%, #a5b1bd 8%, @theme_bg_color 25%);
box-shadow: inset 0 1px #f1f3f5;
border-color: #909fae;
color: rgba(46, 52, 54, 0.2);
}
window.devel headerbar label {
color: @theme_fg_color;
}