settings: Add window scaling related settings

We share two settings with GDK, so we can pick the window scaling factor
and the unscaled font resolution when we initialize Clutter.

https://bugzilla.gnome.org/show_bug.cgi?id=705915
This commit is contained in:
Emmanuele Bassi 2013-08-14 11:28:39 +01:00
parent 33316ce168
commit 69eb2e5f3b
2 changed files with 74 additions and 6 deletions

View File

@ -31,6 +31,7 @@
#include "clutter-debug.h" #include "clutter-debug.h"
#include "clutter-settings-private.h" #include "clutter-settings-private.h"
#include "clutter-stage-private.h"
#include "clutter-private.h" #include "clutter-private.h"
#define DEFAULT_FONT_NAME "Sans 12" #define DEFAULT_FONT_NAME "Sans 12"
@ -61,6 +62,7 @@ struct _ClutterSettings
gdouble resolution; gdouble resolution;
gchar *font_name; gchar *font_name;
gint font_dpi;
gint xft_hinting; gint xft_hinting;
gint xft_antialias; gint xft_antialias;
@ -72,6 +74,9 @@ struct _ClutterSettings
guint last_fontconfig_timestamp; guint last_fontconfig_timestamp;
guint password_hint_time; guint password_hint_time;
gint window_scaling_factor;
gint unscaled_font_dpi;
}; };
struct _ClutterSettingsClass struct _ClutterSettingsClass
@ -104,6 +109,9 @@ enum
PROP_PASSWORD_HINT_TIME, PROP_PASSWORD_HINT_TIME,
PROP_WINDOW_SCALING_FACTOR,
PROP_UNSCALED_FONT_DPI,
PROP_LAST PROP_LAST
}; };
@ -173,14 +181,12 @@ settings_update_font_options (ClutterSettings *self)
" - antialias: %d\n" " - antialias: %d\n"
" - hinting: %d\n" " - hinting: %d\n"
" - hint-style: %s\n" " - hint-style: %s\n"
" - rgba: %s\n" " - rgba: %s\n",
" - dpi: %.2f",
self->font_name != NULL ? self->font_name : DEFAULT_FONT_NAME, self->font_name != NULL ? self->font_name : DEFAULT_FONT_NAME,
self->xft_antialias, self->xft_antialias,
self->xft_hinting, self->xft_hinting,
self->xft_hint_style != NULL ? self->xft_hint_style : "<null>", self->xft_hint_style != NULL ? self->xft_hint_style : "<null>",
self->xft_rgba != NULL ? self->xft_rgba : "<null>", self->xft_rgba != NULL ? self->xft_rgba : "<null>");
self->resolution);
clutter_backend_set_font_options (self->backend, options); clutter_backend_set_font_options (self->backend, options);
cairo_font_options_destroy (options); cairo_font_options_destroy (options);
@ -198,7 +204,16 @@ settings_update_font_name (ClutterSettings *self)
static void static void
settings_update_resolution (ClutterSettings *self) settings_update_resolution (ClutterSettings *self)
{ {
CLUTTER_NOTE (BACKEND, "New resolution: %.2f", self->resolution); if (self->unscaled_font_dpi > 0)
self->resolution = (gdouble) self->unscaled_font_dpi / 1024.0;
else if (self->font_dpi > 0)
self->resolution = (gdouble) self->font_dpi / 1024.0;
else
self->resolution = 96.0;
CLUTTER_NOTE (BACKEND, "New resolution: %.2f (%s)",
self->resolution,
self->unscaled_font_dpi > 0 ? "unscaled" : "scaled");
if (self->backend != NULL) if (self->backend != NULL)
g_signal_emit_by_name (self->backend, "resolution-changed"); g_signal_emit_by_name (self->backend, "resolution-changed");
@ -246,6 +261,22 @@ settings_update_fontmap (ClutterSettings *self,
#endif /* HAVE_PANGO_FT2 */ #endif /* HAVE_PANGO_FT2 */
} }
static void
settings_update_window_scale (ClutterSettings *self)
{
ClutterStageManager *manager;
const GSList *stages, *l;
manager = clutter_stage_manager_get_default ();
stages = clutter_stage_manager_peek_stages (manager);
for (l = stages; l != NULL; l = l->next)
{
ClutterStage *stage = l->data;
_clutter_stage_set_scale_factor (stage, self->window_scaling_factor);
}
}
static void static void
clutter_settings_finalize (GObject *gobject) clutter_settings_finalize (GObject *gobject)
{ {
@ -296,7 +327,7 @@ clutter_settings_set_property (GObject *gobject,
break; break;
case PROP_FONT_DPI: case PROP_FONT_DPI:
self->resolution = (gdouble) g_value_get_int (value) / 1024.0; self->font_dpi = g_value_get_int (value);
settings_update_resolution (self); settings_update_resolution (self);
break; break;
@ -329,6 +360,16 @@ clutter_settings_set_property (GObject *gobject,
self->password_hint_time = g_value_get_uint (value); self->password_hint_time = g_value_get_uint (value);
break; break;
case PROP_WINDOW_SCALING_FACTOR:
self->window_scaling_factor = g_value_get_int (value);
settings_update_window_scale (self);
break;
case PROP_UNSCALED_FONT_DPI:
self->unscaled_font_dpi = g_value_get_int (value);
settings_update_resolution (self);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break; break;
@ -532,6 +573,23 @@ clutter_settings_class_init (ClutterSettingsClass *klass)
-1, -1,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
/**
* ClutterSettings:unscaled-font-dpi:
*
* The DPI used when rendering unscaled text, as a value of 1024 * dots/inch.
*
* If set to -1, the system's default will be used instead
*
* Since: 1.4
*/
obj_props[PROP_UNSCALED_FONT_DPI] =
g_param_spec_int ("unscaled-font-dpi",
P_("Font DPI"),
P_("The resolution of the font, in 1024 * dots/inch, or -1 to use the default"),
-1, 1024 * 1024,
-1,
CLUTTER_PARAM_WRITABLE);
/** /**
* ClutterSettings:font-hinting: * ClutterSettings:font-hinting:
* *
@ -610,6 +668,14 @@ clutter_settings_class_init (ClutterSettingsClass *klass)
500, 500,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
obj_props[PROP_WINDOW_SCALING_FACTOR] =
g_param_spec_int ("window-scaling-factor",
P_("Window Scaling Factor"),
P_("The scaling factor to be applied to windows"),
1, G_MAXINT,
1,
CLUTTER_PARAM_WRITABLE);
obj_props[PROP_FONTCONFIG_TIMESTAMP] = obj_props[PROP_FONTCONFIG_TIMESTAMP] =
g_param_spec_uint ("fontconfig-timestamp", g_param_spec_uint ("fontconfig-timestamp",
P_("Fontconfig configuration timestamp"), P_("Fontconfig configuration timestamp"),

View File

@ -16,6 +16,8 @@ static const struct {
{ "Xft/HintStyle", "font-hint-style" }, { "Xft/HintStyle", "font-hint-style" },
{ "Xft/RGBA", "font-subpixel-order" }, { "Xft/RGBA", "font-subpixel-order" },
{ "Fontconfig/Timestamp", "fontconfig-timestamp" }, { "Fontconfig/Timestamp", "fontconfig-timestamp" },
{ "Gdk/WindowScalingFactor", "window-scaling-factor" },
{ "Gdk/UnscaledDPI", "unscaled-font-dpi" },
}; };
static const gint _n_clutter_settings_map = G_N_ELEMENTS (_clutter_settings_map); static const gint _n_clutter_settings_map = G_N_ELEMENTS (_clutter_settings_map);