inspector: Avoid writing settings back needlessly
We were a bit careless and were writing some values back to the GtkSettings on init, possibly with rounding errors. Avoid that.
This commit is contained in:
@@ -110,6 +110,7 @@ struct _GtkInspectorVisual
|
||||
GtkInspectorOverlay *subsurface_overlay;
|
||||
|
||||
GdkDisplay *display;
|
||||
GtkSettings *settings;
|
||||
};
|
||||
|
||||
typedef struct _GtkInspectorVisualClass
|
||||
@@ -197,27 +198,22 @@ get_dpi_ratio (GtkInspectorVisual *vis)
|
||||
static double
|
||||
get_font_scale (GtkInspectorVisual *vis)
|
||||
{
|
||||
double ratio = get_dpi_ratio (vis);
|
||||
int dpi_int;
|
||||
|
||||
g_object_get (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-xft-dpi", &dpi_int,
|
||||
NULL);
|
||||
g_object_get (vis->settings, "gtk-xft-dpi", &dpi_int, NULL);
|
||||
|
||||
return dpi_int / ratio;
|
||||
return dpi_int / get_dpi_ratio (vis);
|
||||
}
|
||||
|
||||
static void
|
||||
update_font_scale (GtkInspectorVisual *vis,
|
||||
double factor,
|
||||
gboolean update_adjustment,
|
||||
gboolean update_entry)
|
||||
gboolean update_entry,
|
||||
gboolean write_back)
|
||||
{
|
||||
double ratio = get_dpi_ratio (vis);
|
||||
|
||||
g_object_set (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-xft-dpi", (int)(factor * ratio),
|
||||
NULL);
|
||||
if (write_back)
|
||||
g_object_set (vis->settings, "gtk-xft-dpi", (int)(factor * get_dpi_ratio (vis)), NULL);
|
||||
|
||||
if (update_adjustment)
|
||||
gtk_adjustment_set_value (vis->font_scale_adjustment, factor);
|
||||
@@ -238,7 +234,7 @@ font_scale_adjustment_changed (GtkAdjustment *adjustment,
|
||||
double factor;
|
||||
|
||||
factor = gtk_adjustment_get_value (adjustment);
|
||||
update_font_scale (vis, factor, FALSE, TRUE);
|
||||
update_font_scale (vis, factor, FALSE, TRUE, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -246,9 +242,7 @@ get_font_aa (GtkInspectorVisual *vis)
|
||||
{
|
||||
int aa;
|
||||
|
||||
g_object_get (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-xft-antialias", &aa,
|
||||
NULL);
|
||||
g_object_get (vis->settings, "gtk-xft-antialias", &aa, NULL);
|
||||
|
||||
return aa != 0;
|
||||
}
|
||||
@@ -258,9 +252,7 @@ get_metrics_hinting (GtkInspectorVisual *vis)
|
||||
{
|
||||
gboolean hinting;
|
||||
|
||||
g_object_get (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-hint-font-metrics", &hinting,
|
||||
NULL);
|
||||
g_object_get (vis->settings, "gtk-hint-font-metrics", &hinting, NULL);
|
||||
|
||||
return hinting;
|
||||
}
|
||||
@@ -272,7 +264,7 @@ get_font_hinting (GtkInspectorVisual *vis)
|
||||
char *hint_style_str;
|
||||
unsigned int hint_style;
|
||||
|
||||
g_object_get (gtk_settings_get_for_display (vis->display),
|
||||
g_object_get (vis->settings,
|
||||
"gtk-xft-hinting", &hinting,
|
||||
"gtk-xft-hintstyle", &hint_style_str,
|
||||
NULL);
|
||||
@@ -304,11 +296,19 @@ update_font_hinting (GtkInspectorVisual *vis,
|
||||
unsigned int hint_style)
|
||||
{
|
||||
const char *styles[] = { "hintnone", "hintslight", "hintmedium", "hintfull" };
|
||||
int hinting;
|
||||
const char *style;
|
||||
|
||||
g_object_set (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-xft-hinting", hint_style != 0,
|
||||
"gtk-xft-hintstyle", styles[hint_style],
|
||||
g_object_get (vis->settings,
|
||||
"gtk-xft-hinting", &hinting,
|
||||
"gtk-xft-hintstyle", &style,
|
||||
NULL);
|
||||
|
||||
if (hinting != (hint_style != 0) || strcmp (style, styles[hint_style]) != 0)
|
||||
g_object_set (vis->settings,
|
||||
"gtk-xft-hinting", hint_style != 0,
|
||||
"gtk-xft-hintstyle", styles[hint_style],
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -316,9 +316,14 @@ font_aa_activate (GtkSwitch *sw,
|
||||
GParamSpec *pspec,
|
||||
GtkInspectorVisual *vis)
|
||||
{
|
||||
g_object_set (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-xft-antialias", gtk_switch_get_active (sw) ? 1 : 0,
|
||||
NULL);
|
||||
int val, new_val;
|
||||
|
||||
g_object_get (vis->settings, "gtk-xft-antialias", &val, NULL);
|
||||
|
||||
new_val = gtk_switch_get_active (sw) ? 1 : 0;
|
||||
|
||||
if (val != new_val)
|
||||
g_object_set (vis->settings, "gtk-xft-antialias", new_val, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -326,10 +331,16 @@ metrics_hinting_activate (GtkSwitch *sw,
|
||||
GParamSpec *pspec,
|
||||
GtkInspectorVisual *vis)
|
||||
{
|
||||
g_object_set (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-hint-font-metrics", gtk_switch_get_active (sw),
|
||||
NULL);
|
||||
gboolean val, new_val;
|
||||
|
||||
g_object_get (vis->settings, "gtk-hint-font-metrics", &val, NULL);
|
||||
|
||||
new_val = gtk_switch_get_active (sw);
|
||||
|
||||
if (val != new_val)
|
||||
g_object_set (vis->settings, "gtk-hint-font-metrics", new_val, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
font_scale_entry_activated (GtkEntry *entry,
|
||||
GtkInspectorVisual *vis)
|
||||
@@ -339,7 +350,7 @@ font_scale_entry_activated (GtkEntry *entry,
|
||||
|
||||
factor = g_strtod (gtk_editable_get_text (GTK_EDITABLE (entry)), &err);
|
||||
if (err != NULL)
|
||||
update_font_scale (vis, factor, TRUE, FALSE);
|
||||
update_font_scale (vis, factor, TRUE, FALSE, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -750,7 +761,7 @@ init_theme (GtkInspectorVisual *vis)
|
||||
|
||||
gtk_drop_down_set_model (GTK_DROP_DOWN (vis->theme_combo), G_LIST_MODEL (names));
|
||||
|
||||
g_object_bind_property_full (gtk_settings_get_for_display (vis->display), "gtk-theme-name",
|
||||
g_object_bind_property_full (vis->settings, "gtk-theme-name",
|
||||
vis->theme_combo, "selected",
|
||||
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
|
||||
theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref);
|
||||
@@ -769,8 +780,7 @@ init_theme (GtkInspectorVisual *vis)
|
||||
static void
|
||||
init_dark (GtkInspectorVisual *vis)
|
||||
{
|
||||
g_object_bind_property (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-application-prefer-dark-theme",
|
||||
g_object_bind_property (vis->settings, "gtk-application-prefer-dark-theme",
|
||||
vis->dark_switch, "active",
|
||||
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
||||
|
||||
@@ -854,7 +864,7 @@ init_icons (GtkInspectorVisual *vis)
|
||||
|
||||
gtk_drop_down_set_model (GTK_DROP_DOWN (vis->icon_combo), G_LIST_MODEL (names));
|
||||
|
||||
g_object_bind_property_full (gtk_settings_get_for_display (vis->display), "gtk-icon-theme-name",
|
||||
g_object_bind_property_full (vis->settings, "gtk-icon-theme-name",
|
||||
vis->icon_combo, "selected",
|
||||
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
|
||||
theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref);
|
||||
@@ -928,7 +938,7 @@ init_cursors (GtkInspectorVisual *vis)
|
||||
|
||||
gtk_drop_down_set_model (GTK_DROP_DOWN (vis->cursor_combo), G_LIST_MODEL (names));
|
||||
|
||||
g_object_bind_property_full (gtk_settings_get_for_display (vis->display), "gtk-cursor-theme-name",
|
||||
g_object_bind_property_full (vis->settings, "gtk-cursor-theme-name",
|
||||
vis->cursor_combo, "selected",
|
||||
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
|
||||
theme_to_pos, pos_to_theme, names, (GDestroyNotify)g_object_unref);
|
||||
@@ -940,7 +950,7 @@ cursor_size_changed (GtkAdjustment *adjustment, GtkInspectorVisual *vis)
|
||||
int size;
|
||||
|
||||
size = gtk_adjustment_get_value (adjustment);
|
||||
g_object_set (gtk_settings_get_for_display (vis->display), "gtk-cursor-theme-size", size, NULL);
|
||||
g_object_set (vis->settings, "gtk-cursor-theme-size", size, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -948,7 +958,7 @@ init_cursor_size (GtkInspectorVisual *vis)
|
||||
{
|
||||
int size;
|
||||
|
||||
g_object_get (gtk_settings_get_for_display (vis->display), "gtk-cursor-theme-size", &size, NULL);
|
||||
g_object_get (vis->settings, "gtk-cursor-theme-size", &size, NULL);
|
||||
if (size == 0)
|
||||
size = 32;
|
||||
|
||||
@@ -994,8 +1004,7 @@ name_from_desc (GBinding *binding,
|
||||
static void
|
||||
init_font (GtkInspectorVisual *vis)
|
||||
{
|
||||
g_object_bind_property_full (gtk_settings_get_for_display (vis->display),
|
||||
"gtk-font-name",
|
||||
g_object_bind_property_full (vis->settings, "gtk-font-name",
|
||||
vis->font_button, "font-desc",
|
||||
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE,
|
||||
name_to_desc,
|
||||
@@ -1009,7 +1018,7 @@ init_font_scale (GtkInspectorVisual *vis)
|
||||
double scale;
|
||||
|
||||
scale = get_font_scale (vis);
|
||||
update_font_scale (vis, scale, TRUE, TRUE);
|
||||
update_font_scale (vis, scale, TRUE, TRUE, FALSE);
|
||||
g_signal_connect (vis->font_scale_adjustment, "value-changed",
|
||||
G_CALLBACK (font_scale_adjustment_changed), vis);
|
||||
g_signal_connect (vis->font_scale_entry, "activate",
|
||||
@@ -1045,7 +1054,7 @@ init_metrics_hinting (GtkInspectorVisual *vis)
|
||||
static void
|
||||
init_animation (GtkInspectorVisual *vis)
|
||||
{
|
||||
g_object_bind_property (gtk_settings_get_for_display (vis->display), "gtk-enable-animations",
|
||||
g_object_bind_property (vis->settings, "gtk-enable-animations",
|
||||
vis->animation_switch, "active",
|
||||
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
|
||||
}
|
||||
@@ -1324,10 +1333,11 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
|
||||
}
|
||||
|
||||
void
|
||||
gtk_inspector_visual_set_display (GtkInspectorVisual *vis,
|
||||
GdkDisplay *display)
|
||||
gtk_inspector_visual_set_display (GtkInspectorVisual *vis,
|
||||
GdkDisplay *display)
|
||||
{
|
||||
vis->display = display;
|
||||
vis->settings = gtk_settings_get_for_display (display);
|
||||
|
||||
init_direction (vis);
|
||||
init_theme (vis);
|
||||
|
||||
Reference in New Issue
Block a user