mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 14:30:15 +00:00
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:
parent
7eecb16404
commit
89f635fee1
@ -23,6 +23,7 @@
|
||||
#include "gtkcssnumbervalueprivate.h"
|
||||
#include "gtkcssstringvalueprivate.h"
|
||||
#include "gtkcssstylepropertyprivate.h"
|
||||
#include "gtksettingsprivate.h"
|
||||
#include "gtkstyleproviderprivate.h"
|
||||
|
||||
struct _GtkCssValue {
|
||||
@ -49,6 +50,18 @@ gtk_css_value_initial_compute (GtkCssValue *value,
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case GTK_CSS_PROPERTY_DPI:
|
||||
settings = _gtk_style_provider_private_get_settings (provider);
|
||||
if (settings)
|
||||
{
|
||||
GdkScreen *screen = _gtk_settings_get_screen (settings);
|
||||
double resolution = gdk_screen_get_resolution (screen);
|
||||
|
||||
if (resolution > 0.0)
|
||||
return _gtk_css_number_value_new (resolution, GTK_CSS_NUMBER);
|
||||
}
|
||||
break;
|
||||
|
||||
case GTK_CSS_PROPERTY_FONT_FAMILY:
|
||||
settings = _gtk_style_provider_private_get_settings (provider);
|
||||
if (settings)
|
||||
|
@ -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,
|
||||
|
@ -110,6 +110,7 @@ typedef enum {
|
||||
|
||||
enum { /*< skip >*/
|
||||
GTK_CSS_PROPERTY_COLOR,
|
||||
GTK_CSS_PROPERTY_DPI,
|
||||
GTK_CSS_PROPERTY_FONT_SIZE,
|
||||
GTK_CSS_PROPERTY_ICON_THEME,
|
||||
GTK_CSS_PROPERTY_BACKGROUND_COLOR,
|
||||
|
@ -10286,6 +10286,12 @@ update_pango_context (GtkWidget *widget,
|
||||
PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
|
||||
|
||||
pango_font_description_free (font_desc);
|
||||
|
||||
pango_cairo_context_set_resolution (context,
|
||||
_gtk_css_number_value_get (
|
||||
_gtk_style_context_peek_property (style_context,
|
||||
GTK_CSS_PROPERTY_DPI),
|
||||
100));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -10302,8 +10308,6 @@ gtk_widget_update_pango_context (GtkWidget *widget)
|
||||
screen = gtk_widget_get_screen_unchecked (widget);
|
||||
if (screen)
|
||||
{
|
||||
pango_cairo_context_set_resolution (context,
|
||||
gdk_screen_get_resolution (screen));
|
||||
pango_cairo_context_set_font_options (context,
|
||||
gdk_screen_get_font_options (screen));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user