[mutter] clutter: Move font settings reading to ClutterSettings



commit 3958a019bb48d1d4062e5c1f011a6d79bf006d65
Author: Jonas Ådahl <jadahl gmail com>
Date:   Thu Jul 9 21:18:46 2020 +0200

    clutter: Move font settings reading to ClutterSettings
    
    There is no reason to use Xsettings for the X11 backend, as it comes
    from the GSetting store anyway, so move the font setting reading to
    ClutterSettings and read directly from GSettings.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1364

 clutter/clutter/clutter-settings.c              | 170 +++++++++++++++++++++++
 clutter/clutter/egl/clutter-backend-eglnative.c | 175 ------------------------
 clutter/clutter/egl/clutter-backend-eglnative.h |   3 -
 clutter/clutter/x11/clutter-settings-x11.h      |   6 -
 4 files changed, 170 insertions(+), 184 deletions(-)
---
diff --git a/clutter/clutter/clutter-settings.c b/clutter/clutter/clutter-settings.c
index b1af1bed07..acb607bd3f 100644
--- a/clutter/clutter/clutter-settings.c
+++ b/clutter/clutter/clutter-settings.c
@@ -40,6 +40,18 @@
 #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
+{
+  cairo_antialias_t cairo_antialias;
+  gint clutter_font_antialias;
+
+  cairo_hint_style_t cairo_hint_style;
+  const char *clutter_font_hint_style;
+
+  cairo_subpixel_order_t cairo_subpixel_order;
+  const char *clutter_font_subpixel_order;
+} FontSettings;
+
 /**
  * ClutterSettings:
  *
@@ -53,6 +65,7 @@ struct _ClutterSettings
   GObject parent_instance;
 
   ClutterBackend *backend;
+  GSettings *xsettings;
 
   gint double_click_time;
   gint double_click_distance;
@@ -267,6 +280,159 @@ settings_update_fontmap (ClutterSettings *self,
 #endif /* HAVE_PANGO_FT2 */
 }
 
+static void
+get_font_gsettings (GSettings    *xsettings,
+                    FontSettings *output)
+{
+  /* org.gnome.settings-daemon.GsdFontAntialiasingMode */
+  static const struct
+  {
+    cairo_antialias_t cairo_antialias;
+    gint clutter_font_antialias;
+  }
+  antialiasings[] =
+  {
+    /* none=0      */ {CAIRO_ANTIALIAS_NONE,     0},
+    /* grayscale=1 */ {CAIRO_ANTIALIAS_GRAY,     1},
+    /* rgba=2      */ {CAIRO_ANTIALIAS_SUBPIXEL, 1},
+  };
+
+  /* org.gnome.settings-daemon.GsdFontHinting */
+  static const struct
+  {
+    cairo_hint_style_t cairo_hint_style;
+    const char *clutter_font_hint_style;
+  }
+  hintings[] =
+  {
+    /* none=0   */ {CAIRO_HINT_STYLE_NONE,   "hintnone"},
+    /* slight=1 */ {CAIRO_HINT_STYLE_SLIGHT, "hintslight"},
+    /* medium=2 */ {CAIRO_HINT_STYLE_MEDIUM, "hintmedium"},
+    /* full=3   */ {CAIRO_HINT_STYLE_FULL,   "hintfull"},
+  };
+
+  /* org.gnome.settings-daemon.GsdFontRgbaOrder */
+  static const struct
+  {
+    cairo_subpixel_order_t cairo_subpixel_order;
+    const char *clutter_font_subpixel_order;
+  }
+  rgba_orders[] =
+  {
+    /* rgba=0 */ {CAIRO_SUBPIXEL_ORDER_RGB,  "rgb"}, /* XXX what is 'rgba'? */
+    /* rgb=1  */ {CAIRO_SUBPIXEL_ORDER_RGB,  "rgb"},
+    /* bgr=2  */ {CAIRO_SUBPIXEL_ORDER_BGR,  "bgr"},
+    /* vrgb=3 */ {CAIRO_SUBPIXEL_ORDER_VRGB, "vrgb"},
+    /* vbgr=4 */ {CAIRO_SUBPIXEL_ORDER_VBGR, "vbgr"},
+  };
+  guint i;
+
+  i = g_settings_get_enum (xsettings, "hinting");
+  if (i < G_N_ELEMENTS (hintings))
+    {
+      output->cairo_hint_style = hintings[i].cairo_hint_style;
+      output->clutter_font_hint_style = hintings[i].clutter_font_hint_style;
+    }
+  else
+    {
+      output->cairo_hint_style = CAIRO_HINT_STYLE_DEFAULT;
+      output->clutter_font_hint_style = NULL;
+    }
+
+  i = g_settings_get_enum (xsettings, "antialiasing");
+  if (i < G_N_ELEMENTS (antialiasings))
+    {
+      output->cairo_antialias = antialiasings[i].cairo_antialias;
+      output->clutter_font_antialias = antialiasings[i].clutter_font_antialias;
+    }
+  else
+    {
+      output->cairo_antialias = CAIRO_ANTIALIAS_DEFAULT;
+      output->clutter_font_antialias = -1;
+    }
+
+  i = g_settings_get_enum (xsettings, "rgba-order");
+  if (i < G_N_ELEMENTS (rgba_orders))
+    {
+      output->cairo_subpixel_order = rgba_orders[i].cairo_subpixel_order;
+      output->clutter_font_subpixel_order = rgba_orders[i].clutter_font_subpixel_order;
+    }
+  else
+    {
+      output->cairo_subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
+      output->clutter_font_subpixel_order = NULL;
+    }
+
+  if (output->cairo_antialias == CAIRO_ANTIALIAS_GRAY)
+    output->clutter_font_subpixel_order = "none";
+}
+
+static void
+init_font_options (ClutterSettings *self)
+{
+  GSettings *xsettings = self->xsettings;
+  cairo_font_options_t *options = cairo_font_options_create ();
+  FontSettings fs;
+
+  get_font_gsettings (xsettings, &fs);
+
+  cairo_font_options_set_hint_style (options, fs.cairo_hint_style);
+  cairo_font_options_set_antialias (options, fs.cairo_antialias);
+  cairo_font_options_set_subpixel_order (options, fs.cairo_subpixel_order);
+
+  clutter_backend_set_font_options (self->backend, options);
+
+  cairo_font_options_destroy (options);
+}
+
+static gboolean
+on_xsettings_change_event (GSettings *xsettings,
+                           gpointer   keys,
+                           gint       n_keys,
+                           gpointer   user_data)
+{
+  ClutterSettings *self = CLUTTER_SETTINGS (user_data);
+  FontSettings fs;
+  gint hinting;
+
+  get_font_gsettings (xsettings, &fs);
+  hinting = fs.cairo_hint_style == CAIRO_HINT_STYLE_NONE ? 0 : 1;
+  g_object_set (self,
+                "font-hinting",        hinting,
+                "font-hint-style",     fs.clutter_font_hint_style,
+                "font-antialias",      fs.clutter_font_antialias,
+                "font-subpixel-order", fs.clutter_font_subpixel_order,
+                NULL);
+
+  return FALSE;
+}
+
+static void
+load_initial_settings (ClutterSettings *self)
+{
+  static const gchar xsettings_path[] =
+    "org.gnome.settings-daemon.plugins.xsettings";
+  GSettingsSchemaSource *source = g_settings_schema_source_get_default ();
+  GSettingsSchema *schema;
+
+  schema = g_settings_schema_source_lookup (source, xsettings_path, TRUE);
+  if (!schema)
+    {
+      g_warning ("Failed to find schema: %s", xsettings_path);
+    }
+  else
+    {
+      self->xsettings = g_settings_new_full (schema, NULL, NULL);
+      if (self->xsettings)
+        {
+          init_font_options (self);
+          g_signal_connect (self->xsettings, "change-event",
+                            G_CALLBACK (on_xsettings_change_event),
+                            self);
+        }
+    }
+}
+
 static void
 clutter_settings_finalize (GObject *gobject)
 {
@@ -276,6 +442,8 @@ clutter_settings_finalize (GObject *gobject)
   g_free (self->xft_hint_style);
   g_free (self->xft_rgba);
 
+  g_clear_object (&self->xsettings);
+
   G_OBJECT_CLASS (clutter_settings_parent_class)->finalize (gobject);
 }
 
@@ -740,6 +908,8 @@ _clutter_settings_set_backend (ClutterSettings *settings,
   g_assert (CLUTTER_IS_BACKEND (backend));
 
   settings->backend = backend;
+
+  load_initial_settings (settings);
 }
 
 #define SETTINGS_GROUP  "Settings"
diff --git a/clutter/clutter/egl/clutter-backend-eglnative.c b/clutter/clutter/egl/clutter-backend-eglnative.c
index 8aa959caea..0b6597f1c2 100644
--- a/clutter/clutter/egl/clutter-backend-eglnative.c
+++ b/clutter/clutter/egl/clutter-backend-eglnative.c
@@ -44,7 +44,6 @@
 #include "clutter-private.h"
 #include "clutter-main.h"
 #include "clutter-stage-private.h"
-#include "clutter-settings-private.h"
 
 #ifdef COGL_HAS_EGL_SUPPORT
 #include "clutter-egl.h"
@@ -57,8 +56,6 @@ clutter_backend_egl_native_dispose (GObject *gobject)
 {
   ClutterBackendEglNative *backend_egl_native = CLUTTER_BACKEND_EGL_NATIVE (gobject);
 
-  g_clear_object (&backend_egl_native->xsettings);
-
   if (backend_egl_native->event_timer != NULL)
     {
       g_timer_destroy (backend_egl_native->event_timer);
@@ -76,181 +73,9 @@ clutter_backend_egl_native_class_init (ClutterBackendEglNativeClass *klass)
   gobject_class->dispose = clutter_backend_egl_native_dispose;
 }
 
-typedef struct
-{
-  cairo_antialias_t cairo_antialias;
-  gint clutter_font_antialias;
-
-  cairo_hint_style_t cairo_hint_style;
-  const char *clutter_font_hint_style;
-
-  cairo_subpixel_order_t cairo_subpixel_order;
-  const char *clutter_font_subpixel_order;
-} FontSettings;
-
-static void
-get_font_gsettings (GSettings    *xsettings,
-                    FontSettings *output)
-{
-  /* org.gnome.settings-daemon.GsdFontAntialiasingMode */
-  static const struct
-  {
-    cairo_antialias_t cairo_antialias;
-    gint clutter_font_antialias;
-  }
-  antialiasings[] =
-  {
-    /* none=0      */ {CAIRO_ANTIALIAS_NONE,     0},
-    /* grayscale=1 */ {CAIRO_ANTIALIAS_GRAY,     1},
-    /* rgba=2      */ {CAIRO_ANTIALIAS_SUBPIXEL, 1},
-  };
-
-  /* org.gnome.settings-daemon.GsdFontHinting */
-  static const struct
-  {
-    cairo_hint_style_t cairo_hint_style;
-    const char *clutter_font_hint_style;
-  }
-  hintings[] =
-  {
-    /* none=0   */ {CAIRO_HINT_STYLE_NONE,   "hintnone"},
-    /* slight=1 */ {CAIRO_HINT_STYLE_SLIGHT, "hintslight"},
-    /* medium=2 */ {CAIRO_HINT_STYLE_MEDIUM, "hintmedium"},
-    /* full=3   */ {CAIRO_HINT_STYLE_FULL,   "hintfull"},
-  };
-
-  /* org.gnome.settings-daemon.GsdFontRgbaOrder */
-  static const struct
-  {
-    cairo_subpixel_order_t cairo_subpixel_order;
-    const char *clutter_font_subpixel_order;
-  }
-  rgba_orders[] =
-  {
-    /* rgba=0 */ {CAIRO_SUBPIXEL_ORDER_RGB,  "rgb"}, /* XXX what is 'rgba'? */
-    /* rgb=1  */ {CAIRO_SUBPIXEL_ORDER_RGB,  "rgb"},
-    /* bgr=2  */ {CAIRO_SUBPIXEL_ORDER_BGR,  "bgr"},
-    /* vrgb=3 */ {CAIRO_SUBPIXEL_ORDER_VRGB, "vrgb"},
-    /* vbgr=4 */ {CAIRO_SUBPIXEL_ORDER_VBGR, "vbgr"},
-  };
-  guint i;
-
-  i = g_settings_get_enum (xsettings, "hinting");
-  if (i < G_N_ELEMENTS (hintings))
-    {
-      output->cairo_hint_style = hintings[i].cairo_hint_style;
-      output->clutter_font_hint_style = hintings[i].clutter_font_hint_style;
-    }
-  else
-    {
-      output->cairo_hint_style = CAIRO_HINT_STYLE_DEFAULT;
-      output->clutter_font_hint_style = NULL;
-    }
-
-  i = g_settings_get_enum (xsettings, "antialiasing");
-  if (i < G_N_ELEMENTS (antialiasings))
-    {
-      output->cairo_antialias = antialiasings[i].cairo_antialias;
-      output->clutter_font_antialias = antialiasings[i].clutter_font_antialias;
-    }
-  else
-    {
-      output->cairo_antialias = CAIRO_ANTIALIAS_DEFAULT;
-      output->clutter_font_antialias = -1;
-    }
-
-  i = g_settings_get_enum (xsettings, "rgba-order");
-  if (i < G_N_ELEMENTS (rgba_orders))
-    {
-      output->cairo_subpixel_order = rgba_orders[i].cairo_subpixel_order;
-      output->clutter_font_subpixel_order = rgba_orders[i].clutter_font_subpixel_order;
-    }
-  else
-    {
-      output->cairo_subpixel_order = CAIRO_SUBPIXEL_ORDER_DEFAULT;
-      output->clutter_font_subpixel_order = NULL;
-    }
-
-  if (output->cairo_antialias == CAIRO_ANTIALIAS_GRAY)
-    output->clutter_font_subpixel_order = "none";
-}
-
-static void
-init_font_options (ClutterBackendEglNative *backend_egl_native)
-{
-  GSettings *xsettings = backend_egl_native->xsettings;
-  cairo_font_options_t *options = cairo_font_options_create ();
-  FontSettings fs;
-
-  get_font_gsettings (xsettings, &fs);
-
-  cairo_font_options_set_hint_style (options, fs.cairo_hint_style);
-  cairo_font_options_set_antialias (options, fs.cairo_antialias);
-  cairo_font_options_set_subpixel_order (options, fs.cairo_subpixel_order);
-
-  clutter_backend_set_font_options (CLUTTER_BACKEND (backend_egl_native),
-                                    options);
-
-  cairo_font_options_destroy (options);
-}
-
-static gboolean
-on_xsettings_change_event (GSettings *xsettings,
-                           gpointer   keys,
-                           gint       n_keys,
-                           gpointer   user_data)
-{
-  /*
-   * A simpler alternative to this function that does not update the screen
-   * immediately (like macOS :P):
-   *
-   *   init_font_options (CLUTTER_BACKEND_EGL_NATIVE (user_data));
-   *
-   * which has the added benefit of eliminating the need for all the
-   * FontSettings.clutter_ fields. However the below approach is better for
-   * testing settings and more consistent with the existing x11 backend...
-   */
-  ClutterSettings *csettings = clutter_settings_get_default ();
-  FontSettings fs;
-  gint hinting;
-
-  get_font_gsettings (xsettings, &fs);
-  hinting = fs.cairo_hint_style == CAIRO_HINT_STYLE_NONE ? 0 : 1;
-  g_object_set (csettings,
-                "font-hinting",        hinting,
-                "font-hint-style",     fs.clutter_font_hint_style,
-                "font-antialias",      fs.clutter_font_antialias,
-                "font-subpixel-order", fs.clutter_font_subpixel_order,
-                NULL);
-
-  return FALSE;
-}
-
 static void
 clutter_backend_egl_native_init (ClutterBackendEglNative *backend_egl_native)
 {
-  static const gchar xsettings_path[] = "org.gnome.settings-daemon.plugins.xsettings";
-  GSettingsSchemaSource *source = g_settings_schema_source_get_default ();
-  GSettingsSchema *schema = g_settings_schema_source_lookup (source,
-                                                             xsettings_path,
-                                                             TRUE);
-
-  if (!schema)
-    {
-      g_warning ("Failed to find schema: %s", xsettings_path);
-    }
-  else
-    {
-      backend_egl_native->xsettings = g_settings_new_full (schema, NULL, NULL);
-      if (backend_egl_native->xsettings)
-        {
-          init_font_options (backend_egl_native);
-          g_signal_connect (backend_egl_native->xsettings, "change-event",
-                            G_CALLBACK (on_xsettings_change_event),
-                            backend_egl_native);
-        }
-    }
-
   backend_egl_native->event_timer = g_timer_new ();
 }
 
diff --git a/clutter/clutter/egl/clutter-backend-eglnative.h b/clutter/clutter/egl/clutter-backend-eglnative.h
index cc63f89b32..6c0412e812 100644
--- a/clutter/clutter/egl/clutter-backend-eglnative.h
+++ b/clutter/clutter/egl/clutter-backend-eglnative.h
@@ -58,9 +58,6 @@ struct _ClutterBackendEglNative
 
   /* event timer */
   GTimer *event_timer;
-
-  /* "xsettings" is still the defacto place for Xft settings, even in Wayland */
-  GSettings *xsettings;
 };
 
 struct _ClutterBackendEglNativeClass
diff --git a/clutter/clutter/x11/clutter-settings-x11.h b/clutter/clutter/x11/clutter-settings-x11.h
index b7d1b0e3f9..b678416a04 100644
--- a/clutter/clutter/x11/clutter-settings-x11.h
+++ b/clutter/clutter/x11/clutter-settings-x11.h
@@ -8,12 +8,6 @@ static const struct {
 } _clutter_settings_map[] = {
   { "Net/DoubleClickDistance", "double-click-distance" },
   { "Net/DndDragThreshold",    "dnd-drag-threshold" },
-  { "Gtk/FontName",            "font-name" },
-  { "Xft/Antialias",           "font-antialias" },
-  { "Xft/Hinting",             "font-hinting" },
-  { "Xft/HintStyle",           "font-hint-style" },
-  { "Xft/RGBA",                "font-subpixel-order" },
-  { "Fontconfig/Timestamp",    "fontconfig-timestamp" },
 };
 
 static const gint _n_clutter_settings_map = G_N_ELEMENTS (_clutter_settings_map);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]