css: Add -gtk-dpi CSS property hack

This property is necessary to ensure widgets automatically update after
the text scale factor is changed desktop-wide.

And if I'm already doing a property like this, I can make it
overridable. So now you can override the dpi per-widget with CSS like
GtkSwitch {
  -gtk-dpi: 48;
}
if you want to debug things.

Long-term, we want to get rid of this property and insist on dpi being
96 everywhere and people can change the font size to get larger fonts.
This commit is contained in:
Benjamin Otte
2015-02-05 18:52:59 +01:00
parent 7eecb16404
commit 89f635fee1
4 changed files with 37 additions and 3 deletions

View File

@ -731,6 +731,13 @@ background_image_value_assign (GtkCssStyleProperty *property,
return _gtk_css_array_value_new (css_image_value_assign (property, value));
}
static GtkCssValue *
dpi_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
return _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_NUMBER);
}
static GtkCssValue *
font_size_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
@ -959,7 +966,7 @@ icon_theme_value_parse (GtkCssStyleProperty *property,
void
_gtk_css_style_property_init_properties (void)
{
/* Initialize "color" and "font-size" first,
/* Initialize "color", "-gtk-dpi" and "font-size" first,
* so that when computing values later they are
* done first. That way, 'currentColor' and font
* sizes in em can be looked up properly */
@ -972,6 +979,15 @@ _gtk_css_style_property_init_properties (void)
color_query,
color_assign,
_gtk_css_color_value_new_rgba (1, 1, 1, 1));
gtk_css_style_property_register ("-gtk-dpi",
GTK_CSS_PROPERTY_DPI,
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
GTK_CSS_AFFECTS_FONT | GTK_CSS_AFFECTS_TEXT | GTK_CSS_AFFECTS_SIZE,
dpi_parse,
NULL,
NULL,
_gtk_css_number_value_new (96.0, GTK_CSS_NUMBER));
gtk_css_style_property_register ("font-size",
GTK_CSS_PROPERTY_FONT_SIZE,
G_TYPE_DOUBLE,