mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
settings: Migrate Backend settings to a new object
Instead of storing settings inside the Backend instance we should use a separate public object.
This commit is contained in:
parent
e4e6a6dfe5
commit
437dcad86a
@ -124,6 +124,7 @@ source_h = \
|
|||||||
$(srcdir)/clutter-score.h \
|
$(srcdir)/clutter-score.h \
|
||||||
$(srcdir)/clutter-script.h \
|
$(srcdir)/clutter-script.h \
|
||||||
$(srcdir)/clutter-scriptable.h \
|
$(srcdir)/clutter-scriptable.h \
|
||||||
|
$(srcdir)/clutter-settings.h \
|
||||||
$(srcdir)/clutter-shader.h \
|
$(srcdir)/clutter-shader.h \
|
||||||
$(srcdir)/clutter-shader-effect.h \
|
$(srcdir)/clutter-shader-effect.h \
|
||||||
$(srcdir)/clutter-shader-types.h \
|
$(srcdir)/clutter-shader-types.h \
|
||||||
@ -217,6 +218,7 @@ source_c = \
|
|||||||
$(srcdir)/clutter-script.c \
|
$(srcdir)/clutter-script.c \
|
||||||
$(srcdir)/clutter-script-parser.c \
|
$(srcdir)/clutter-script-parser.c \
|
||||||
$(srcdir)/clutter-scriptable.c \
|
$(srcdir)/clutter-scriptable.c \
|
||||||
|
$(srcdir)/clutter-settings.c \
|
||||||
$(srcdir)/clutter-shader.c \
|
$(srcdir)/clutter-shader.c \
|
||||||
$(srcdir)/clutter-shader-effect.c \
|
$(srcdir)/clutter-shader-effect.c \
|
||||||
$(srcdir)/clutter-shader-types.c \
|
$(srcdir)/clutter-shader-types.c \
|
||||||
|
@ -60,24 +60,19 @@ G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT);
|
|||||||
|
|
||||||
struct _ClutterBackendPrivate
|
struct _ClutterBackendPrivate
|
||||||
{
|
{
|
||||||
/* settings */
|
|
||||||
guint double_click_time;
|
|
||||||
guint double_click_distance;
|
|
||||||
|
|
||||||
gdouble resolution;
|
|
||||||
|
|
||||||
gfloat units_per_em;
|
|
||||||
gint32 units_serial;
|
|
||||||
|
|
||||||
cairo_font_options_t *font_options;
|
cairo_font_options_t *font_options;
|
||||||
|
|
||||||
gchar *font_name;
|
gchar *font_name;
|
||||||
|
|
||||||
|
gfloat units_per_em;
|
||||||
|
gint32 units_serial;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
RESOLUTION_CHANGED,
|
RESOLUTION_CHANGED,
|
||||||
FONT_CHANGED,
|
FONT_CHANGED,
|
||||||
|
SETTINGS_CHANGED,
|
||||||
|
|
||||||
LAST_SIGNAL
|
LAST_SIGNAL
|
||||||
};
|
};
|
||||||
@ -87,7 +82,7 @@ static guint backend_signals[LAST_SIGNAL] = { 0, };
|
|||||||
static void
|
static void
|
||||||
clutter_backend_dispose (GObject *gobject)
|
clutter_backend_dispose (GObject *gobject)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = CLUTTER_BACKEND (gobject)->priv;
|
ClutterBackend *backend = CLUTTER_BACKEND (gobject);
|
||||||
ClutterMainContext *clutter_context;
|
ClutterMainContext *clutter_context;
|
||||||
|
|
||||||
clutter_context = _clutter_context_get_default ();
|
clutter_context = _clutter_context_get_default ();
|
||||||
@ -101,9 +96,9 @@ clutter_backend_dispose (GObject *gobject)
|
|||||||
clutter_context->events_queue = NULL;
|
clutter_context->events_queue = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (priv->font_name);
|
g_free (backend->priv->font_name);
|
||||||
|
|
||||||
clutter_backend_set_font_options (CLUTTER_BACKEND (gobject), NULL);
|
clutter_backend_set_font_options (backend, NULL);
|
||||||
|
|
||||||
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
|
||||||
}
|
}
|
||||||
@ -166,11 +161,22 @@ static void
|
|||||||
clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
clutter_backend_real_resolution_changed (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv = backend->priv;
|
ClutterBackendPrivate *priv = backend->priv;
|
||||||
|
ClutterMainContext *context;
|
||||||
|
ClutterSettings *settings;
|
||||||
|
gint dpi;
|
||||||
|
|
||||||
|
context = _clutter_context_get_default ();
|
||||||
|
|
||||||
|
settings = clutter_settings_get_default ();
|
||||||
|
g_object_get (settings, "font-dpi", &dpi, NULL);
|
||||||
|
|
||||||
|
if (context->font_map != NULL)
|
||||||
|
cogl_pango_font_map_set_resolution (context->font_map, dpi / 1024.0);
|
||||||
|
|
||||||
priv->units_per_em = get_units_per_em (backend, NULL);
|
priv->units_per_em = get_units_per_em (backend, NULL);
|
||||||
priv->units_serial += 1;
|
priv->units_serial += 1;
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->priv->units_per_em);
|
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", priv->units_per_em);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -181,7 +187,7 @@ clutter_backend_real_font_changed (ClutterBackend *backend)
|
|||||||
priv->units_per_em = get_units_per_em (backend, NULL);
|
priv->units_per_em = get_units_per_em (backend, NULL);
|
||||||
priv->units_serial += 1;
|
priv->units_serial += 1;
|
||||||
|
|
||||||
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", backend->priv->units_per_em);
|
CLUTTER_NOTE (BACKEND, "Units per em: %.2f", priv->units_per_em);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -211,6 +217,15 @@ clutter_backend_class_init (ClutterBackendClass *klass)
|
|||||||
_clutter_marshal_VOID__VOID,
|
_clutter_marshal_VOID__VOID,
|
||||||
G_TYPE_NONE, 0);
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
|
backend_signals[SETTINGS_CHANGED] =
|
||||||
|
g_signal_new (I_("settings-changed"),
|
||||||
|
G_TYPE_FROM_CLASS (klass),
|
||||||
|
G_SIGNAL_RUN_FIRST,
|
||||||
|
G_STRUCT_OFFSET (ClutterBackendClass, settings_changed),
|
||||||
|
NULL, NULL,
|
||||||
|
_clutter_marshal_VOID__VOID,
|
||||||
|
G_TYPE_NONE, 0);
|
||||||
|
|
||||||
klass->resolution_changed = clutter_backend_real_resolution_changed;
|
klass->resolution_changed = clutter_backend_real_resolution_changed;
|
||||||
klass->font_changed = clutter_backend_real_font_changed;
|
klass->font_changed = clutter_backend_real_font_changed;
|
||||||
}
|
}
|
||||||
@ -222,8 +237,6 @@ clutter_backend_init (ClutterBackend *backend)
|
|||||||
|
|
||||||
priv = backend->priv = CLUTTER_BACKEND_GET_PRIVATE (backend);
|
priv = backend->priv = CLUTTER_BACKEND_GET_PRIVATE (backend);
|
||||||
|
|
||||||
priv->resolution = -1.0;
|
|
||||||
|
|
||||||
priv->units_per_em = -1.0;
|
priv->units_per_em = -1.0;
|
||||||
priv->units_serial = 1;
|
priv->units_serial = 1;
|
||||||
}
|
}
|
||||||
@ -531,14 +544,16 @@ clutter_get_default_backend (void)
|
|||||||
* verify whether it's a double click event or not.
|
* verify whether it's a double click event or not.
|
||||||
*
|
*
|
||||||
* Since: 0.4
|
* Since: 0.4
|
||||||
|
*
|
||||||
|
* Deprecated: 1.4: Use #ClutterSettings:double-click-time instead
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_backend_set_double_click_time (ClutterBackend *backend,
|
clutter_backend_set_double_click_time (ClutterBackend *backend,
|
||||||
guint msec)
|
guint msec)
|
||||||
{
|
{
|
||||||
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
ClutterSettings *settings = clutter_settings_get_default ();
|
||||||
|
|
||||||
backend->priv->double_click_time = msec;
|
g_object_set (settings, "double-click-time", msec, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -551,13 +566,18 @@ clutter_backend_set_double_click_time (ClutterBackend *backend,
|
|||||||
* Return value: a time in milliseconds
|
* Return value: a time in milliseconds
|
||||||
*
|
*
|
||||||
* Since: 0.4
|
* Since: 0.4
|
||||||
|
*
|
||||||
|
* Deprecated: 1.4: Use #ClutterSettings:double-click-time instead
|
||||||
*/
|
*/
|
||||||
guint
|
guint
|
||||||
clutter_backend_get_double_click_time (ClutterBackend *backend)
|
clutter_backend_get_double_click_time (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0);
|
ClutterSettings *settings = clutter_settings_get_default ();
|
||||||
|
gint retval;
|
||||||
|
|
||||||
return backend->priv->double_click_time;
|
g_object_get (settings, "double-click-time", &retval, NULL);
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -568,14 +588,16 @@ clutter_backend_get_double_click_time (ClutterBackend *backend)
|
|||||||
* Sets the maximum distance used to verify a double click event.
|
* Sets the maximum distance used to verify a double click event.
|
||||||
*
|
*
|
||||||
* Since: 0.4
|
* Since: 0.4
|
||||||
|
*
|
||||||
|
* Deprecated: 1.4: Use #ClutterSettings:double-click-distance instead
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_backend_set_double_click_distance (ClutterBackend *backend,
|
clutter_backend_set_double_click_distance (ClutterBackend *backend,
|
||||||
guint distance)
|
guint distance)
|
||||||
{
|
{
|
||||||
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
ClutterSettings *settings = clutter_settings_get_default ();
|
||||||
|
|
||||||
backend->priv->double_click_distance = distance;
|
g_object_set (settings, "double-click-distance", distance, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -587,13 +609,18 @@ clutter_backend_set_double_click_distance (ClutterBackend *backend,
|
|||||||
* Return value: a distance, in pixels.
|
* Return value: a distance, in pixels.
|
||||||
*
|
*
|
||||||
* Since: 0.4
|
* Since: 0.4
|
||||||
|
*
|
||||||
|
* Deprecated: 1.4: Use #ClutterSettings:double-click-distance instead
|
||||||
*/
|
*/
|
||||||
guint
|
guint
|
||||||
clutter_backend_get_double_click_distance (ClutterBackend *backend)
|
clutter_backend_get_double_click_distance (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), 0);
|
ClutterSettings *settings = clutter_settings_get_default ();
|
||||||
|
gint retval;
|
||||||
|
|
||||||
return backend->priv->double_click_distance;
|
g_object_get (settings, "double-click-distance", &retval, NULL);
|
||||||
|
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -610,26 +637,25 @@ clutter_backend_get_double_click_distance (ClutterBackend *backend)
|
|||||||
* Applications should never need to call this function.
|
* Applications should never need to call this function.
|
||||||
*
|
*
|
||||||
* Since: 0.4
|
* Since: 0.4
|
||||||
|
*
|
||||||
|
* Deprecated: Use #ClutterSettings:font-dpi instead
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_backend_set_resolution (ClutterBackend *backend,
|
clutter_backend_set_resolution (ClutterBackend *backend,
|
||||||
gdouble dpi)
|
gdouble dpi)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
ClutterSettings *settings;
|
||||||
|
gint resolution;
|
||||||
|
|
||||||
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
||||||
|
|
||||||
priv = backend->priv;
|
|
||||||
|
|
||||||
if (dpi < 0)
|
if (dpi < 0)
|
||||||
dpi = -1.0;
|
resolution = -1;
|
||||||
|
else
|
||||||
|
resolution = dpi * 1024;
|
||||||
|
|
||||||
priv->resolution = dpi;
|
settings = clutter_settings_get_default ();
|
||||||
|
g_object_set (settings, "font-dpi", resolution, NULL);
|
||||||
if (CLUTTER_CONTEXT ()->font_map)
|
|
||||||
cogl_pango_font_map_set_resolution (CLUTTER_CONTEXT ()->font_map, dpi);
|
|
||||||
|
|
||||||
g_signal_emit (backend, backend_signals[RESOLUTION_CHANGED], 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -647,9 +673,15 @@ clutter_backend_set_resolution (ClutterBackend *backend,
|
|||||||
gdouble
|
gdouble
|
||||||
clutter_backend_get_resolution (ClutterBackend *backend)
|
clutter_backend_get_resolution (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
|
ClutterSettings *settings;
|
||||||
|
gint resolution;
|
||||||
|
|
||||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1.0);
|
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), -1.0);
|
||||||
|
|
||||||
return backend->priv->resolution;
|
settings = clutter_settings_get_default ();
|
||||||
|
g_object_get (settings, "font-dpi", &resolution, NULL);
|
||||||
|
|
||||||
|
return resolution / 1024.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -670,7 +702,7 @@ clutter_backend_get_resolution (ClutterBackend *backend)
|
|||||||
* Since: 0.8
|
* Since: 0.8
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_backend_set_font_options (ClutterBackend *backend,
|
clutter_backend_set_font_options (ClutterBackend *backend,
|
||||||
const cairo_font_options_t *options)
|
const cairo_font_options_t *options)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
ClutterBackendPrivate *priv;
|
||||||
@ -742,25 +774,16 @@ clutter_backend_get_font_options (ClutterBackend *backend)
|
|||||||
* be parsed by the pango_font_description_from_string() function.
|
* be parsed by the pango_font_description_from_string() function.
|
||||||
*
|
*
|
||||||
* Since: 1.0
|
* Since: 1.0
|
||||||
|
*
|
||||||
|
* Deprecated: 1.4: Use #ClutterSettings:font-name instead
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_backend_set_font_name (ClutterBackend *backend,
|
clutter_backend_set_font_name (ClutterBackend *backend,
|
||||||
const gchar *font_name)
|
const gchar *font_name)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
ClutterSettings *settings = clutter_settings_get_default ();
|
||||||
|
|
||||||
g_return_if_fail (CLUTTER_IS_BACKEND (backend));
|
g_object_set (settings, "font-name", font_name, NULL);
|
||||||
|
|
||||||
priv = backend->priv;
|
|
||||||
|
|
||||||
g_free (priv->font_name);
|
|
||||||
|
|
||||||
if (font_name == NULL || *font_name == '\0')
|
|
||||||
priv->font_name = g_strdup (DEFAULT_FONT_NAME);
|
|
||||||
else
|
|
||||||
priv->font_name = g_strdup (font_name);
|
|
||||||
|
|
||||||
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -774,25 +797,26 @@ clutter_backend_set_font_name (ClutterBackend *backend,
|
|||||||
* owned by the #ClutterBackend and should never be modified or freed
|
* owned by the #ClutterBackend and should never be modified or freed
|
||||||
*
|
*
|
||||||
* Since: 1.0
|
* Since: 1.0
|
||||||
|
*
|
||||||
|
* Deprecated: 1.4: Use #ClutterSettings:font-name instead
|
||||||
*/
|
*/
|
||||||
G_CONST_RETURN gchar *
|
G_CONST_RETURN gchar *
|
||||||
clutter_backend_get_font_name (ClutterBackend *backend)
|
clutter_backend_get_font_name (ClutterBackend *backend)
|
||||||
{
|
{
|
||||||
ClutterBackendPrivate *priv;
|
ClutterBackendPrivate *priv;
|
||||||
|
ClutterSettings *settings;
|
||||||
|
|
||||||
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
g_return_val_if_fail (CLUTTER_IS_BACKEND (backend), NULL);
|
||||||
|
|
||||||
priv = backend->priv;
|
priv = backend->priv;
|
||||||
|
|
||||||
if (G_LIKELY (priv->font_name))
|
settings = clutter_settings_get_default ();
|
||||||
return priv->font_name;
|
|
||||||
|
|
||||||
/* if we have never been called then we need to set the
|
/* XXX yuck. but we return a const pointer, so we need to
|
||||||
* default font and update everything that relies on the
|
* store it in the backend
|
||||||
* ::font-changed signal
|
|
||||||
*/
|
*/
|
||||||
priv->font_name = g_strdup (DEFAULT_FONT_NAME);
|
g_free (priv->font_name);
|
||||||
g_signal_emit (backend, backend_signals[FONT_CHANGED], 0);
|
g_object_get (settings, "font-name", &priv->font_name, NULL);
|
||||||
|
|
||||||
return priv->font_name;
|
return priv->font_name;
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,7 @@ struct _ClutterBackendClass
|
|||||||
/* signals */
|
/* signals */
|
||||||
void (* resolution_changed) (ClutterBackend *backend);
|
void (* resolution_changed) (ClutterBackend *backend);
|
||||||
void (* font_changed) (ClutterBackend *backend);
|
void (* font_changed) (ClutterBackend *backend);
|
||||||
|
void (* settings_changed) (ClutterBackend *backend);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType clutter_backend_get_type (void) G_GNUC_CONST;
|
GType clutter_backend_get_type (void) G_GNUC_CONST;
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include "clutter-id-pool.h"
|
#include "clutter-id-pool.h"
|
||||||
#include "clutter-layout-manager.h"
|
#include "clutter-layout-manager.h"
|
||||||
#include "clutter-master-clock.h"
|
#include "clutter-master-clock.h"
|
||||||
|
#include "clutter-settings.h"
|
||||||
#include "clutter-stage-manager.h"
|
#include "clutter-stage-manager.h"
|
||||||
#include "clutter-stage-window.h"
|
#include "clutter-stage-window.h"
|
||||||
#include "clutter-stage.h"
|
#include "clutter-stage.h"
|
||||||
@ -171,6 +172,8 @@ struct _ClutterMainContext
|
|||||||
gulong redraw_count;
|
gulong redraw_count;
|
||||||
|
|
||||||
GList *repaint_funcs;
|
GList *repaint_funcs;
|
||||||
|
|
||||||
|
ClutterSettings *settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CLUTTER_CONTEXT() (_clutter_context_get_default ())
|
#define CLUTTER_CONTEXT() (_clutter_context_get_default ())
|
||||||
|
401
clutter/clutter-settings.c
Normal file
401
clutter/clutter-settings.c
Normal file
@ -0,0 +1,401 @@
|
|||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "clutter-settings.h"
|
||||||
|
|
||||||
|
#include "clutter-debug.h"
|
||||||
|
#include "clutter-private.h"
|
||||||
|
|
||||||
|
#define DEFAULT_FONT_NAME "Sans 12"
|
||||||
|
|
||||||
|
#define CLUTTER_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_SETTINGS, ClutterSettingsClass))
|
||||||
|
#define CLUTTER_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_SETTINGS))
|
||||||
|
#define CLUTTER_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_SETTINGS, ClutterSettingsClass))
|
||||||
|
|
||||||
|
typedef struct _ClutterSettingsClass ClutterSettingsClass;
|
||||||
|
|
||||||
|
struct _ClutterSettings
|
||||||
|
{
|
||||||
|
GObject parent_instance;
|
||||||
|
|
||||||
|
ClutterBackend *backend;
|
||||||
|
|
||||||
|
gint double_click_time;
|
||||||
|
gint double_click_distance;
|
||||||
|
|
||||||
|
gdouble resolution;
|
||||||
|
|
||||||
|
gchar *font_name;
|
||||||
|
|
||||||
|
gint xft_hinting;
|
||||||
|
gint xft_antialias;
|
||||||
|
gchar *xft_hint_style;
|
||||||
|
gchar *xft_rgba;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _ClutterSettingsClass
|
||||||
|
{
|
||||||
|
GObjectClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
|
||||||
|
PROP_BACKEND,
|
||||||
|
|
||||||
|
PROP_DOUBLE_CLICK_TIME,
|
||||||
|
PROP_DOUBLE_CLICK_DISTANCE,
|
||||||
|
|
||||||
|
PROP_FONT_NAME,
|
||||||
|
|
||||||
|
PROP_FONT_ANTIALIAS,
|
||||||
|
PROP_FONT_DPI,
|
||||||
|
PROP_FONT_HINTING,
|
||||||
|
PROP_FONT_HINT_STYLE,
|
||||||
|
PROP_FONT_RGBA
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (ClutterSettings, clutter_settings, G_TYPE_OBJECT);
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
settings_update_font_options (ClutterSettings *self)
|
||||||
|
{
|
||||||
|
cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_NONE;
|
||||||
|
cairo_antialias_t antialias_mode = CAIRO_ANTIALIAS_GRAY;
|
||||||
|
cairo_subpixel_order_t subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
|
||||||
|
cairo_font_options_t *options;
|
||||||
|
|
||||||
|
options = cairo_font_options_create ();
|
||||||
|
|
||||||
|
cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
|
||||||
|
|
||||||
|
if (self->xft_hinting >= 0 &&
|
||||||
|
self->xft_hint_style == NULL)
|
||||||
|
{
|
||||||
|
hint_style = CAIRO_HINT_STYLE_NONE;
|
||||||
|
}
|
||||||
|
else if (self->xft_hint_style != NULL)
|
||||||
|
{
|
||||||
|
if (strcmp (self->xft_hint_style, "hintnone") == 0)
|
||||||
|
hint_style = CAIRO_HINT_STYLE_NONE;
|
||||||
|
else if (strcmp (self->xft_hint_style, "hintslight") == 0)
|
||||||
|
hint_style = CAIRO_HINT_STYLE_SLIGHT;
|
||||||
|
else if (strcmp (self->xft_hint_style, "hintmedium") == 0)
|
||||||
|
hint_style = CAIRO_HINT_STYLE_MEDIUM;
|
||||||
|
else if (strcmp (self->xft_hint_style, "hintfull") == 0)
|
||||||
|
hint_style = CAIRO_HINT_STYLE_FULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_font_options_set_hint_style (options, hint_style);
|
||||||
|
|
||||||
|
if (self->xft_rgba)
|
||||||
|
{
|
||||||
|
if (strcmp (self->xft_rgba, "rgb") == 0)
|
||||||
|
subpixel_order = CAIRO_SUBPIXEL_ORDER_RGB;
|
||||||
|
else if (strcmp (self->xft_rgba, "bgr") == 0)
|
||||||
|
subpixel_order = CAIRO_SUBPIXEL_ORDER_BGR;
|
||||||
|
else if (strcmp (self->xft_rgba, "vrgb") == 0)
|
||||||
|
subpixel_order = CAIRO_SUBPIXEL_ORDER_VRGB;
|
||||||
|
else if (strcmp (self->xft_rgba, "vbgr") == 0)
|
||||||
|
subpixel_order = CAIRO_SUBPIXEL_ORDER_VBGR;
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_font_options_set_subpixel_order (options, subpixel_order);
|
||||||
|
|
||||||
|
if (self->xft_antialias >= 0 && !self->xft_antialias)
|
||||||
|
antialias_mode = CAIRO_ANTIALIAS_NONE;
|
||||||
|
else if (subpixel_order != CAIRO_SUBPIXEL_ORDER_DEFAULT)
|
||||||
|
antialias_mode = CAIRO_ANTIALIAS_SUBPIXEL;
|
||||||
|
else if (self->xft_antialias >= 0)
|
||||||
|
antialias_mode = CAIRO_ANTIALIAS_GRAY;
|
||||||
|
|
||||||
|
cairo_font_options_set_antialias (options, antialias_mode);
|
||||||
|
|
||||||
|
clutter_backend_set_font_options (self->backend, options);
|
||||||
|
cairo_font_options_destroy (options);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
settings_update_resolution (ClutterSettings *self)
|
||||||
|
{
|
||||||
|
g_signal_emit_by_name (self->backend, "resolution-changed");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_settings_finalize (GObject *gobject)
|
||||||
|
{
|
||||||
|
ClutterSettings *self = CLUTTER_SETTINGS (gobject);
|
||||||
|
|
||||||
|
g_free (self->font_name);
|
||||||
|
g_free (self->xft_hint_style);
|
||||||
|
g_free (self->xft_rgba);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (clutter_settings_parent_class)->finalize (gobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_settings_set_property (GObject *gobject,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
ClutterSettings *self = CLUTTER_SETTINGS (gobject);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_BACKEND:
|
||||||
|
self->backend = g_value_get_object (value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_DOUBLE_CLICK_TIME:
|
||||||
|
self->double_click_time = g_value_get_int (value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_DOUBLE_CLICK_DISTANCE:
|
||||||
|
self->double_click_distance = g_value_get_int (value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_NAME:
|
||||||
|
g_free (self->font_name);
|
||||||
|
self->font_name = g_value_dup_string (value);
|
||||||
|
settings_update_font_options (self);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_ANTIALIAS:
|
||||||
|
self->xft_antialias = g_value_get_int (value);
|
||||||
|
settings_update_font_options (self);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_DPI:
|
||||||
|
self->resolution = (gdouble) g_value_get_int (value) / 1024.0;
|
||||||
|
settings_update_resolution (self);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_HINTING:
|
||||||
|
self->xft_hinting = g_value_get_int (value);
|
||||||
|
settings_update_font_options (self);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_HINT_STYLE:
|
||||||
|
g_free (self->xft_hint_style);
|
||||||
|
self->xft_hint_style = g_value_dup_string (value);
|
||||||
|
settings_update_font_options (self);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_RGBA:
|
||||||
|
g_free (self->xft_rgba);
|
||||||
|
self->xft_rgba = g_value_dup_string (value);
|
||||||
|
settings_update_font_options (self);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_settings_get_property (GObject *gobject,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
ClutterSettings *self = CLUTTER_SETTINGS (gobject);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_DOUBLE_CLICK_TIME:
|
||||||
|
g_value_set_int (value, self->double_click_time);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_DOUBLE_CLICK_DISTANCE:
|
||||||
|
g_value_set_int (value, self->double_click_distance);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_NAME:
|
||||||
|
g_value_set_string (value, self->font_name);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_ANTIALIAS:
|
||||||
|
g_value_set_int (value, self->xft_antialias);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_DPI:
|
||||||
|
g_value_set_int (value, self->resolution * 1024);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_HINTING:
|
||||||
|
g_value_set_int (value, self->xft_hinting);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_HINT_STYLE:
|
||||||
|
g_value_set_string (value, self->xft_hint_style);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROP_FONT_RGBA:
|
||||||
|
g_value_set_string (value, self->xft_rgba);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_settings_notify (GObject *gobject,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
ClutterSettings *self = CLUTTER_SETTINGS (gobject);
|
||||||
|
|
||||||
|
g_signal_emit_by_name (self->backend, "settings-changed");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_settings_class_init (ClutterSettingsClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
|
GParamSpec *pspec;
|
||||||
|
|
||||||
|
gobject_class->set_property = clutter_settings_set_property;
|
||||||
|
gobject_class->get_property = clutter_settings_get_property;
|
||||||
|
gobject_class->notify = clutter_settings_notify;
|
||||||
|
gobject_class->finalize = clutter_settings_finalize;
|
||||||
|
|
||||||
|
pspec = g_param_spec_object ("backend",
|
||||||
|
"Backend",
|
||||||
|
"A pointer to the backend",
|
||||||
|
CLUTTER_TYPE_BACKEND,
|
||||||
|
CLUTTER_PARAM_WRITABLE |
|
||||||
|
G_PARAM_CONSTRUCT_ONLY);
|
||||||
|
g_object_class_install_property (gobject_class, PROP_BACKEND, pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_int ("double-click-time",
|
||||||
|
"Double Click Time",
|
||||||
|
"The time between clicks necessary to detect "
|
||||||
|
"a multiple click",
|
||||||
|
0, G_MAXINT,
|
||||||
|
250,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_DOUBLE_CLICK_TIME,
|
||||||
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_int ("double-click-distance",
|
||||||
|
"Double Click Distance",
|
||||||
|
"The distance between clicks necessary to detect "
|
||||||
|
"a multiple click",
|
||||||
|
0, G_MAXINT,
|
||||||
|
5,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_DOUBLE_CLICK_DISTANCE,
|
||||||
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_string ("font-name",
|
||||||
|
"Font Name",
|
||||||
|
"The description of the default font, as "
|
||||||
|
"one that could be parsed by Pango",
|
||||||
|
NULL,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_FONT_NAME,
|
||||||
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_int ("font-antialias",
|
||||||
|
"Font Antialias",
|
||||||
|
"Whether to use antialiasing (1 to enable, 0 to "
|
||||||
|
"disable, and -1 to use the default)",
|
||||||
|
-1, 1,
|
||||||
|
-1,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_FONT_ANTIALIAS,
|
||||||
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_int ("font-dpi",
|
||||||
|
"Font DPI",
|
||||||
|
"The resolution of the font, in 1024 * dots/inch, "
|
||||||
|
"or -1 to use the default",
|
||||||
|
-1, 1024 * 1024,
|
||||||
|
-1,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_FONT_DPI,
|
||||||
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_int ("font-hinting",
|
||||||
|
"Font Hinting",
|
||||||
|
"Whether to use hinting (1 to enable, 0 to disable "
|
||||||
|
"and -1 to use the default)",
|
||||||
|
-1, 1,
|
||||||
|
-1,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_FONT_HINTING,
|
||||||
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_string ("font-hint-style",
|
||||||
|
"Font Hint Style",
|
||||||
|
"The style of hinting (hintnone, hintslight, "
|
||||||
|
"hintmedium, hintfull)",
|
||||||
|
NULL,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_FONT_HINT_STYLE,
|
||||||
|
pspec);
|
||||||
|
|
||||||
|
pspec = g_param_spec_string ("font-subpixel-order",
|
||||||
|
"Font Subpixel Order",
|
||||||
|
"The type of subpixel antialiasing (none, rgb, "
|
||||||
|
"bgr, vrgb, vbgr)",
|
||||||
|
NULL,
|
||||||
|
CLUTTER_PARAM_READWRITE);
|
||||||
|
g_object_class_install_property (gobject_class,
|
||||||
|
PROP_FONT_RGBA,
|
||||||
|
pspec);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_settings_init (ClutterSettings *self)
|
||||||
|
{
|
||||||
|
self->resolution = -1.0;
|
||||||
|
|
||||||
|
self->double_click_time = 250;
|
||||||
|
self->double_click_distance = 5;
|
||||||
|
|
||||||
|
self->font_name = g_strdup (DEFAULT_FONT_NAME);
|
||||||
|
|
||||||
|
self->xft_antialias = -1;
|
||||||
|
self->xft_hinting = -1;
|
||||||
|
self->xft_hint_style = NULL;
|
||||||
|
self->xft_rgba = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clutter_settings_get_default:
|
||||||
|
*
|
||||||
|
* Retrieves the singleton instance of #ClutterSettings
|
||||||
|
*
|
||||||
|
* Return value: (transfer none): the instance of #ClutterSettings. The
|
||||||
|
* returned object is owned by Clutter and it should not be unreferenced
|
||||||
|
* directly
|
||||||
|
*
|
||||||
|
* Since: 1.4
|
||||||
|
*/
|
||||||
|
ClutterSettings *
|
||||||
|
clutter_settings_get_default (void)
|
||||||
|
{
|
||||||
|
ClutterMainContext *context = _clutter_context_get_default ();
|
||||||
|
|
||||||
|
if (G_LIKELY (context->settings != NULL))
|
||||||
|
return context->settings;
|
||||||
|
|
||||||
|
context->settings = g_object_new (CLUTTER_TYPE_SETTINGS,
|
||||||
|
"backend", context->backend,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return context->settings;
|
||||||
|
}
|
24
clutter/clutter-settings.h
Normal file
24
clutter/clutter-settings.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||||
|
#error "Only <clutter/clutter.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __CLUTTER_SETTINGS_H__
|
||||||
|
#define __CLUTTER_SETTINGS_H__
|
||||||
|
|
||||||
|
#include <clutter/clutter-types.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define CLUTTER_TYPE_SETTINGS (clutter_settings_get_type ())
|
||||||
|
#define CLUTTER_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_SETTINGS, ClutterSettings))
|
||||||
|
#define CLUTTER_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_SETTINGS))
|
||||||
|
|
||||||
|
typedef struct _ClutterSettings ClutterSettings;
|
||||||
|
|
||||||
|
GType clutter_settings_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
ClutterSettings *clutter_settings_get_default (void);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __CLUTTER_SETTINGS_H__ */
|
@ -87,6 +87,7 @@
|
|||||||
#include "clutter-score.h"
|
#include "clutter-score.h"
|
||||||
#include "clutter-scriptable.h"
|
#include "clutter-scriptable.h"
|
||||||
#include "clutter-script.h"
|
#include "clutter-script.h"
|
||||||
|
#include "clutter-settings.h"
|
||||||
#include "clutter-shader.h"
|
#include "clutter-shader.h"
|
||||||
#include "clutter-shader-effect.h"
|
#include "clutter-shader-effect.h"
|
||||||
#include "clutter-shader-types.h"
|
#include "clutter-shader-types.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user