[vte] widget: Move some methods to VteTerminalPrivate



commit c2adf41d46740fad84f7a7b7e5e51e77de41ea24
Author: Christian Persch <chpe gnome org>
Date:   Sat Jan 30 18:19:25 2016 +0100

    widget: Move some methods to VteTerminalPrivate

 src/vte.cc         |  121 +++++++++++++--------------------------------------
 src/vtegtk.cc      |   22 +++++++++-
 src/vteinternal.hh |    7 ++-
 src/vtetypes.hh    |    1 +
 4 files changed, 56 insertions(+), 95 deletions(-)
---
diff --git a/src/vte.cc b/src/vte.cc
index fc560c3..734583e 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -2600,12 +2600,18 @@ VteTerminalPrivate::set_background_alpha(double alpha)
         return true;
 }
 
+void
+VteTerminalPrivate::set_colors_default()
+{
+        set_colors(nullptr, nullptr, nullptr, 0);
+}
+
 /*
- * _vte_terminal_set_colors:
+ * VteTerminalPrivate::set_colors:
  * @terminal: a #VteTerminal
  * @foreground: (allow-none): the new foreground color, or %NULL
  * @background: (allow-none): the new background color, or %NULL
- * @palette: (array length=palette_size zero-terminated=0) (element-type Gdk.Color): the color palette
+ * @palette: (array length=palette_size zero-terminated=0): the color palette
  * @palette_size: the number of entries in @palette
  *
  * @palette specifies the new values for the 256 palette colors: 8 standard colors,
@@ -2618,17 +2624,12 @@ VteTerminalPrivate::set_background_alpha(double alpha)
  * color is taken from @palette[7].  If @background is %NULL and @palette_size is
  * greater than 0, the new background color is taken from @palette[0].
  */
-static void
-_vte_terminal_set_colors(VteTerminal *terminal,
-                         vte::color::rgb const* foreground,
-                         vte::color::rgb const* background,
-                         vte::color::rgb const* palette,
-                         gsize palette_size)
+void
+VteTerminalPrivate::set_colors(vte::color::rgb const* foreground,
+                               vte::color::rgb const* background,
+                               vte::color::rgb const* new_palette,
+                               gsize palette_size)
 {
-       gsize i;
-       vte::color::rgb color;
-       gboolean unset = FALSE;
-
        _vte_debug_print(VTE_DEBUG_MISC,
                        "Set color palette [%" G_GSIZE_FORMAT " elements].\n",
                        palette_size);
@@ -2636,18 +2637,18 @@ _vte_terminal_set_colors(VteTerminal *terminal,
        /* Accept NULL as the default foreground and background colors if we
         * got a palette. */
        if ((foreground == NULL) && (palette_size >= 8)) {
-               foreground = &palette[7];
+               foreground = &new_palette[7];
        }
        if ((background == NULL) && (palette_size >= 8)) {
-               background = &palette[0];
+               background = &new_palette[0];
        }
 
-       memset(&color, 0, sizeof(color));
-
        /* Initialize each item in the palette if we got any entries to work
         * with. */
-       for (i=0; i < G_N_ELEMENTS(terminal->pvt->palette); i++) {
-               unset = FALSE;
+       for (gsize i = 0; i < G_N_ELEMENTS(m_palette); i++) {
+                vte::color::rgb color;
+               bool unset = false;
+
                if (i < 16) {
                        color.blue = (i & 4) ? 0xc000 : 0;
                        color.green = (i & 2) ? 0xc000 : 0;
@@ -2673,7 +2674,7 @@ _vte_terminal_set_colors(VteTerminal *terminal,
                }
                else switch (i) {
                        case VTE_DEFAULT_BG:
-                               if (background != NULL) {
+                               if (background) {
                                        color = *background;
                                } else {
                                        color.red = 0;
@@ -2682,7 +2683,7 @@ _vte_terminal_set_colors(VteTerminal *terminal,
                                }
                                break;
                        case VTE_DEFAULT_FG:
-                               if (foreground != NULL) {
+                               if (foreground) {
                                        color = *foreground;
                                } else {
                                        color.red = 0xc000;
@@ -2691,51 +2692,37 @@ _vte_terminal_set_colors(VteTerminal *terminal,
                                }
                                break;
                        case VTE_BOLD_FG:
-                                color = vte::color::rgb(terminal->pvt->get_color(VTE_DEFAULT_FG),
-                                                        terminal->pvt->get_color(VTE_DEFAULT_BG),
+                                color = vte::color::rgb(get_color(VTE_DEFAULT_FG),
+                                                        get_color(VTE_DEFAULT_BG),
                                                         1.8);
                                break;
                        case VTE_HIGHLIGHT_BG:
-                               unset = TRUE;
+                               unset = true;
                                break;
                        case VTE_HIGHLIGHT_FG:
-                               unset = TRUE;
+                               unset = true;
                                break;
                        case VTE_CURSOR_BG:
-                               unset = TRUE;
+                               unset = true;
                                break;
                        case VTE_CURSOR_FG:
-                               unset = TRUE;
+                               unset = true;
                                break;
                        }
 
                /* Override from the supplied palette if there is one. */
                if (i < palette_size) {
-                       color = palette[i];
+                       color = new_palette[i];
                }
 
                /* Set up the color entry. */
                 if (unset)
-                        terminal->pvt->reset_color(i, VTE_COLOR_SOURCE_API);
+                        reset_color(i, VTE_COLOR_SOURCE_API);
                 else
-                        terminal->pvt->set_color(i, VTE_COLOR_SOURCE_API, color);
+                        set_color(i, VTE_COLOR_SOURCE_API, color);
        }
 }
 
-static vte::color::rgb *
-_pango_color_from_rgba(vte::color::rgb *color,
-                       const GdkRGBA *rgba)
-{
-        if (rgba == NULL)
-                return NULL;
-
-        color->red = rgba->red * 65535.;
-        color->green = rgba->green * 65535.;
-        color->blue = rgba->blue * 65535.;
-
-       return color;
-}
-
 /*
  * VteTerminalPrivate::set_color_bold:
  * @bold: (allow-none): the new bold color or %NULL
@@ -2898,52 +2885,6 @@ VteTerminalPrivate::reset_color_highlight_foreground()
 }
 
 /*
- * VteTerminalPrivate::set_colors:
- * @foreground: (allow-none): the new foreground color, or %NULL
- * @background: (allow-none): the new background color, or %NULL
- * @palette: (array length=palette_size zero-terminated=0) (element-type Gdk.RGBA) (allow-none): the color 
palette
- * @palette_size: the number of entries in @palette
- *
- * @palette specifies the new values for the 256 palette colors: 8 standard colors,
- * their 8 bright counterparts, 6x6x6 color cube, and 24 grayscale colors.
- * Omitted entries will default to a hardcoded value.
- *
- * @palette_size must be 0, 8, 16, 232 or 256.
- *
- * If @foreground is %NULL and @palette_size is greater than 0, the new foreground
- * color is taken from @palette[7].  If @background is %NULL and @palette_size is
- * greater than 0, the new background color is taken from @palette[0].
- */
-void
-VteTerminalPrivate::set_colors(GdkRGBA const *foreground,
-                               GdkRGBA const *background,
-                               GdkRGBA const *palette_,
-                               gsize palette_size)
-{
-       vte::color::rgb fg, bg, *pal;
-       gsize i;
-
-       g_assert((palette_size == 0) ||
-                 (palette_size == 8) ||
-                 (palette_size == 16) ||
-                 (palette_size == 232) ||
-                 (palette_size == 256));
-
-       pal = g_new(vte::color::rgb, palette_size);
-       for (i = 0; i < palette_size; ++i)
-                _pango_color_from_rgba(&pal[i], &palette_[i]);
-
-       _vte_terminal_set_colors(m_terminal,
-                                 _pango_color_from_rgba(&fg, foreground),
-                                 _pango_color_from_rgba(&bg, background),
-                                 pal, palette_size);
-
-        set_background_alpha(background ? background->alpha : 1.0);
-
-       g_free (pal);
-}
-
-/*
  * VteTerminalPrivate::cleanup_fragments:
  * @start: the starting column, inclusive
  * @end: the end column, exclusive
@@ -8079,7 +8020,7 @@ VteTerminalPrivate::VteTerminalPrivate(VteTerminal *t) :
         m_character_replacement = &m_character_replacements[0];
 
        /* Set up the desired palette. */
-       vte_terminal_set_default_colors(m_terminal);
+       set_colors_default();
        for (i = 0; i < VTE_PALETTE_SIZE; i++)
                m_palette[i].sources[VTE_COLOR_SOURCE_ESCAPE].is_set = FALSE;
 
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 0c1a7b5..f961188 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2847,7 +2847,25 @@ vte_terminal_set_colors(VteTerminal *terminal,
                         (palette_size == 232) ||
                         (palette_size == 256));
 
-        IMPL(terminal)->set_colors(foreground, background, palette, palette_size);
+        vte::color::rgb fg;
+        if (foreground)
+                fg = vte::color::rgb(foreground);
+        vte::color::rgb bg;
+        if (background)
+                bg = vte::color::rgb(background);
+
+        vte::color::rgb* pal = nullptr;
+        if (palette_size) {
+                pal = g_new0(vte::color::rgb, palette_size);
+                for (gsize i = 0; i < palette_size; ++i)
+                        pal[i] = vte::color::rgb(palette[i]);
+        }
+
+        auto impl = IMPL(terminal);
+        impl->set_colors(foreground ? &fg : nullptr,
+                         background ? &bg : nullptr,
+                         pal, palette_size);
+        impl->set_background_alpha(background ? background->alpha : 1.0);
 }
 
 /**
@@ -2860,7 +2878,7 @@ void
 vte_terminal_set_default_colors(VteTerminal *terminal)
 {
        g_return_if_fail(VTE_IS_TERMINAL(terminal));
-        IMPL(terminal)->set_colors(nullptr, nullptr, nullptr, 0);
+        IMPL(terminal)->set_colors_default();
 }
 
 /**
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index c69715a..07c4408 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -1076,10 +1076,11 @@ public:
         void reset_color_highlight_background();
         void set_color_highlight_foreground(vte::color::rgb const& color);
         void reset_color_highlight_foreground();
-        void set_colors(GdkRGBA const *foreground,
-                        GdkRGBA const *background,
-                        GdkRGBA const *palette,
+        void set_colors(vte::color::rgb const *foreground,
+                        vte::color::rgb const *background,
+                        vte::color::rgb const *palette,
                         gsize palette_size);
+        void set_colors_default();
         bool set_cursor_blink_mode(VteCursorBlinkMode mode);
         bool set_cursor_shape(VteCursorShape shape);
         bool set_cursor_style(VteCursorStyle style);
diff --git a/src/vtetypes.hh b/src/vtetypes.hh
index 7d610f6..fe8faf7 100644
--- a/src/vtetypes.hh
+++ b/src/vtetypes.hh
@@ -152,6 +152,7 @@ namespace color {
                 rgb() = default;
                 rgb(PangoColor const& c) { *static_cast<PangoColor*>(this) = c; }
                 rgb(GdkRGBA const* c);
+                rgb(GdkRGBA const& c) : rgb(&c) { }
 
                 rgb(rgb const& a, rgb const& b, double f);
                 rgb(rgb const* a, rgb const* b, double f) : rgb(*a, *b, f) { }


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