Make _vte_draw_new always create a pangocairo implementation
authorKristian Høgsberg <krh@bitplanet.net>
Wed, 23 Dec 2009 14:50:10 +0000 (09:50 -0500)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 23 Dec 2009 14:50:10 +0000 (09:50 -0500)
src/vtedraw.c
src/vtepangocairo.c

index 3ff3ec5..f3f73ee 100644 (file)
 #include "vtepangocairo.h"
 #include "vteskel.h"
 
-static const struct _vte_draw_impl
-*_vte_draw_impls[] = {
-       &_vte_draw_pangocairo,
-};
-
-static gboolean
-_vte_draw_init_user (struct _vte_draw *draw)
-{
-       const gchar *env;
-       gchar **strv, **s;
-       guint i;
-       gboolean success = TRUE;
-
-       env = g_getenv ("VTE_BACKEND");
-       if (!env) {
-               return FALSE;
-       }
-
-       strv = g_strsplit (env, ":;, \t", -1);
-       for (s = strv; *s; s++) {
-               char *p;
-
-               /* lower it */
-               for (p = *s; *p; p++)
-                       *p = g_ascii_tolower (*p);
-
-               /* match null draw */
-               if (strcmp (*s, _vte_draw_skel.name) == 0) {
-                       draw->impl = &_vte_draw_skel;
-                       goto out;
-               }
-
-               /* list available draws */
-               if (strcmp (*s, "list") == 0) {
-                       for (i = 0; i < G_N_ELEMENTS (_vte_draw_impls); i++) {
-                               g_printerr ("vte backend: %s\n", _vte_draw_impls[i]->name);
-                       }
-                       continue;
-               }
-
-               /* find among available draws */
-               for (i = 0; i < G_N_ELEMENTS (_vte_draw_impls); i++) {
-                       if (strcmp (*s, _vte_draw_impls[i]->name) == 0) {
-                               if (_vte_draw_impls[i]->check == NULL ||
-                                   _vte_draw_impls[i]->check (draw, draw->widget)) {
-                                       draw->impl = _vte_draw_impls[i];
-                                       goto out;
-                               }
-                       }
-               }
-       }
-
-       success = FALSE;
-out:
-       g_strfreev (strv);
-       return success;
-}
-
-
-static gboolean
-_vte_draw_init_default (struct _vte_draw *draw)
-{
-       guint i;
-
-       for (i = 0; i < G_N_ELEMENTS (_vte_draw_impls); i++) {
-               if (_vte_draw_impls[i]->check == NULL ||
-                   _vte_draw_impls[i]->check (draw, draw->widget)) {
-                       draw->impl = _vte_draw_impls[i];
-                       return TRUE;
-               }
-       }
-
-       return FALSE;
-}
-
-
-struct _vte_draw *
-_vte_draw_new (GtkWidget *widget)
-{
-       struct _vte_draw *draw;
-
-       /* Create the structure. */
-       draw = g_slice_new0 (struct _vte_draw);
-       draw->widget = g_object_ref (widget);
-
-       /* Allow the user to specify her preferred backends */
-       if (!_vte_draw_init_user (draw) &&
-                       /* Otherwise use the first thing that works */
-                       !_vte_draw_init_default (draw)) {
-               /* Something has to work. */
-               g_assert_not_reached ();
-               draw->impl = &_vte_draw_skel;
-       }
-
-       draw->requires_clear = draw->impl->always_requires_clear;
-
-       _vte_debug_print (VTE_DEBUG_DRAW,
-                       "draw_new (%s)\n", draw->impl->name);
-       _vte_debug_print (VTE_DEBUG_MISC, "Using %s.\n", draw->impl->name);
-
-       if (draw->impl->create)
-               draw->impl->create (draw, draw->widget);
-
-       return draw;
-}
-
-void
-_vte_draw_free (struct _vte_draw *draw)
-{
-       _vte_debug_print (VTE_DEBUG_DRAW, "draw_free\n");
-
-       if (draw->impl->destroy)
-               draw->impl->destroy (draw);
-
-       if (draw->widget != NULL) {
-               g_object_unref (draw->widget);
-       }
-
-       g_slice_free (struct _vte_draw, draw);
-}
-
 GdkVisual *
 _vte_draw_get_visual (struct _vte_draw *draw)
 {
index 7532c51..6527a25 100644 (file)
@@ -791,20 +791,38 @@ struct _vte_pangocairo_data {
        cairo_t *cr;
 };
 
-static void
-_vte_pangocairo_create (struct _vte_draw *draw, GtkWidget *widget)
+struct _vte_draw *
+_vte_draw_new (GtkWidget *widget)
 {
+       struct _vte_draw *draw;
        struct _vte_pangocairo_data *data;
 
+       /* Create the structure. */
+       draw = g_slice_new0 (struct _vte_draw);
+       draw->widget = g_object_ref (widget);
+       draw->impl = &_vte_draw_pangocairo;
+       draw->requires_clear = draw->impl->always_requires_clear;
+
+       _vte_debug_print (VTE_DEBUG_DRAW,
+                       "draw_new (%s)\n", draw->impl->name);
+       _vte_debug_print (VTE_DEBUG_MISC, "Using %s.\n", draw->impl->name);
+
+       if (draw->impl->create)
+               draw->impl->create (draw, draw->widget);
+
        data = g_slice_new0 (struct _vte_pangocairo_data);
        draw->impl_data = data;
+
+       return draw;
 }
 
-static void
-_vte_pangocairo_destroy (struct _vte_draw *draw)
+void
+_vte_draw_free (struct _vte_draw *draw)
 {
        struct _vte_pangocairo_data *data = draw->impl_data;
 
+       _vte_debug_print (VTE_DEBUG_DRAW, "draw_free\n");
+
        if (data->bg_pattern != NULL) {
                cairo_pattern_destroy (data->bg_pattern);
                data->bg_pattern = NULL;
@@ -817,6 +835,12 @@ _vte_pangocairo_destroy (struct _vte_draw *draw)
 
        g_slice_free (struct _vte_pangocairo_data, draw->impl_data);
        draw->impl_data = NULL;
+
+       if (draw->widget != NULL) {
+               g_object_unref (draw->widget);
+       }
+
+       g_slice_free (struct _vte_draw, draw);
 }
 
 static void
@@ -1120,8 +1144,8 @@ _vte_pangocairo_fill_rectangle (struct _vte_draw *draw,
 const struct _vte_draw_impl _vte_draw_pangocairo = {
        "pangocairo",
        NULL, /* check */
-       _vte_pangocairo_create,
-       _vte_pangocairo_destroy,
+       NULL, /* create */
+       NULL, /* destroy */
        NULL, /* get_visual */
        NULL, /* get_colormap */
        _vte_pangocairo_start,