If what you are looking for is the DPI scale (usually set by the GDK_DPI_SCALE
environment variable), I would use a variant the following code snippet:
static gdouble get_dpi_scale(GdkScreen *screen)
{
gdouble dpi = gdk_screen_get_resolution(screen);
GtkSettings *settings = gtk_settings_get_default();
gint xft_dpi = 0;
g_object_get(settings, "gtk-xft-dpi", &xft_dpi, NULL);
g_return_val_if_fail(xft_dpi > 0, 0);
return dpi / xft_dpi;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…