[vte] widget: Add API to not clear the background



commit bc532dc160406aaea35756e9a9e8f755c82fddb2
Author: Christian Persch <chpe src gnome org>
Date:   Mon Feb 5 20:11:08 2018 +0100

    widget: Add API to not clear the background
    
    Remove the background operator again and only support a simple
    boolean clear-or-not-clear.
    
    This is useful only to support a background image.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767575

 doc/reference/vte-sections.txt |    2 +-
 src/app/app.cc                 |   32 ++------------------------------
 src/vte.cc                     |   30 ++++++++++++++++--------------
 src/vte/vteterminal.h          |    4 ++--
 src/vtedraw.cc                 |    3 +--
 src/vtedraw.hh                 |    1 -
 src/vtegtk.cc                  |   17 ++++++++---------
 src/vteinternal.hh             |    4 ++--
 8 files changed, 32 insertions(+), 61 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index a63fa34..6e37f0b 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -107,7 +107,7 @@ vte_terminal_pty_new_sync
 vte_terminal_watch_child
 
 <SUBSECTION>
-vte_terminal_set_background_operator
+vte_terminal_set_clear_background
 
 <SUBSECTION Standard>
 VTE_TYPE_CURSOR_BLINK_MODE
diff --git a/src/app/app.cc b/src/app/app.cc
index d63adb6..008facc 100644
--- a/src/app/app.cc
+++ b/src/app/app.cc
@@ -64,9 +64,7 @@ public:
         bool cursor_fg_color_set{false};
         bool hl_bg_color_set{false};
         bool hl_fg_color_set{false};
-        bool background_operator_set{false};
         cairo_extend_t background_extend{CAIRO_EXTEND_NONE};
-        cairo_operator_t background_operator{CAIRO_OPERATOR_SOURCE};
         char* command{nullptr};
         char* encoding{nullptr};
         char* font_string{nullptr};
@@ -183,11 +181,6 @@ private:
                 Options* that = static_cast<Options*>(data);
                 g_clear_object(&that->background_pixbuf);
                 that->background_pixbuf = gdk_pixbuf_new_from_file(value, error);
-                if (that->background_pixbuf != nullptr) {
-                        /* Default to actually showing the image */
-                        that->background_operator = CAIRO_OPERATOR_OVER;
-                        that->background_operator_set = true;
-                }
                 return that->background_pixbuf != nullptr;
         }
 
@@ -203,19 +196,6 @@ private:
         }
 
         static gboolean
-        parse_background_operator(char const* option, char const* value, void* data, GError** error)
-        {
-                Options* that = static_cast<Options*>(data);
-                int v;
-                auto rv = that->parse_enum(CAIRO_GOBJECT_TYPE_OPERATOR, value, v, error);
-                if (rv) {
-                        that->background_operator = cairo_operator_t(v);
-                        that->background_operator_set = true;
-                }
-                return rv;
-        }
-
-        static gboolean
         parse_cjk_width(char const* option, char const* value, void* data, GError** error)
         {
                 Options* that = static_cast<Options*>(data);
@@ -351,8 +331,6 @@ public:
                           "Set background image from file", "FILE" },
                         { "background-extend", 0, 0, G_OPTION_ARG_CALLBACK, (void*)parse_background_extend,
                           "Set background image extend", "EXTEND" },
-                        { "background-operator", 0, 0, G_OPTION_ARG_CALLBACK, 
(void*)parse_background_operator,
-                          "Set background draw operator", "OPERATOR" },
                         { "blink", 0, 0, G_OPTION_ARG_CALLBACK, (void*)parse_text_blink,
                           "Text blink mode (never|focused|unfocused|always)", "MODE" },
                         { "cell-height-scale", 0, 0, G_OPTION_ARG_DOUBLE, &cell_height_scale,
@@ -489,11 +467,6 @@ public:
                 if (reverse)
                         std::swap(fg_color, bg_color);
 
-                /* Sanity checks */
-                if (background_pixbuf != nullptr &&
-                    (!background_operator_set || background_operator == CAIRO_OPERATOR_SOURCE))
-                        g_printerr("Background image set but operator is SOURCE; image will not appear.\n");
-
                 return rv;
         }
 };
@@ -917,9 +890,8 @@ vteapp_terminal_init(VteappTerminal *terminal)
 {
         terminal->background_pattern = nullptr;
 
-        if (options.background_operator_set)
-                vte_terminal_set_background_operator(VTE_TERMINAL(terminal),
-                                                     options.background_operator);
+        if (options.background_pixbuf != nullptr)
+                vte_terminal_set_clear_background(VTE_TERMINAL(terminal), false);
 }
 
 static GtkWidget *
diff --git a/src/vte.cc b/src/vte.cc
index 7e077c1..02c670a 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -10006,13 +10006,14 @@ VteTerminalPrivate::paint_im_preedit_string()
                        columns += items[i].columns;
                        preedit = g_utf8_next_char(preedit);
                }
-               _vte_draw_clear(m_draw,
-                               col * width,
-                               row_to_pixel(m_screen->cursor.row),
-                               width * columns,
-                               height,
-                                m_background_operator,
-                                get_color(VTE_DEFAULT_BG), m_background_alpha);
+                if (G_LIKELY(m_clear_background)) {
+                        _vte_draw_clear(m_draw,
+                                        col * width,
+                                        row_to_pixel(m_screen->cursor.row),
+                                        width * columns,
+                                        height,
+                                        get_color(VTE_DEFAULT_BG), m_background_alpha);
+                }
                draw_cells_with_attributes(
                                                        items, len,
                                                        m_im_preedit_attrs,
@@ -10068,10 +10069,11 @@ VteTerminalPrivate::widget_draw(cairo_t *cr)
        /* Designate the start of the drawing operation and clear the area. */
        _vte_draw_set_cairo(m_draw, cr);
 
-       _vte_draw_clear (m_draw, 0, 0,
-                        allocated_width, allocated_height,
-                         m_background_operator,
-                         get_color(VTE_DEFAULT_BG), m_background_alpha);
+        if (G_LIKELY(m_clear_background)) {
+                _vte_draw_clear (m_draw, 0, 0,
+                                 allocated_width, allocated_height,
+                                 get_color(VTE_DEFAULT_BG), m_background_alpha);
+        }
 
         /* Clip vertically, for the sake of smooth scrolling. We want the top and bottom paddings to be 
unused.
          * Don't clip horizontally so that antialiasing can legally overflow to the right padding. */
@@ -11754,11 +11756,11 @@ VteTerminalPrivate::set_word_char_exceptions(char const* exceptions)
 }
 
 void
-VteTerminalPrivate::set_background_operator(cairo_operator_t op)
+VteTerminalPrivate::set_clear_background(bool setting)
 {
-        if (m_background_operator == op)
+        if (m_clear_background == setting)
                 return;
 
-        m_background_operator = op;
+        m_clear_background = setting;
         invalidate_all();
 }
diff --git a/src/vte/vteterminal.h b/src/vte/vteterminal.h
index b96999f..4e2896c 100644
--- a/src/vte/vteterminal.h
+++ b/src/vte/vteterminal.h
@@ -483,8 +483,8 @@ gboolean vte_terminal_get_input_enabled (VteTerminal *terminal) _VTE_GNUC_NONNUL
 
 /* rarely useful functions */
 _VTE_PUBLIC
-void vte_terminal_set_background_operator(VteTerminal* terminal,
-                                          cairo_operator_t op) _VTE_GNUC_NONNULL(1);
+void vte_terminal_set_clear_background(VteTerminal* terminal,
+                                       gboolean setting) _VTE_GNUC_NONNULL(1);
 
 /* Writing contents out */
 _VTE_PUBLIC
diff --git a/src/vtedraw.cc b/src/vtedraw.cc
index 2825146..37d324c 100644
--- a/src/vtedraw.cc
+++ b/src/vtedraw.cc
@@ -829,7 +829,6 @@ _vte_draw_set_source_color_alpha (struct _vte_draw *draw,
 
 void
 _vte_draw_clear (struct _vte_draw *draw, gint x, gint y, gint width, gint height,
-                 cairo_operator_t op,
                  vte::color::rgb const* color, double alpha)
 {
        _vte_debug_print (VTE_DEBUG_DRAW, "draw_clear (%d, %d, %d, %d)\n",
@@ -837,7 +836,7 @@ _vte_draw_clear (struct _vte_draw *draw, gint x, gint y, gint width, gint height
 
         g_assert(draw->cr);
        cairo_rectangle (draw->cr, x, y, width, height);
-       cairo_set_operator (draw->cr, op);
+       cairo_set_operator (draw->cr, CAIRO_OPERATOR_SOURCE);
        _vte_draw_set_source_color_alpha(draw, color, alpha);
        cairo_fill (draw->cr);
 }
diff --git a/src/vtedraw.hh b/src/vtedraw.hh
index b5c3d36..5248aef 100644
--- a/src/vtedraw.hh
+++ b/src/vtedraw.hh
@@ -58,7 +58,6 @@ void _vte_draw_set_cairo(struct _vte_draw *draw,
 
 void _vte_draw_clear(struct _vte_draw *draw,
                     gint x, gint y, gint width, gint height,
-                     cairo_operator_t op,
                      vte::color::rgb const* color, double alpha);
 
 void _vte_draw_set_text_font(struct _vte_draw *draw,
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 8dd3d69..bacfa01 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -4253,24 +4253,23 @@ vte_terminal_write_contents_sync (VteTerminal *terminal,
 }
 
 /**
- * vte_terminal_set_background_operator:
+ * vte_terminal_set_clear_background:
  * @terminal: a #VteTerminal
- * @operator: a #cairo_operator_t
+ * @setting:
  *
- * Sets the operator to use to paint the background with the background colour.
- * The default is %CAIRO_OPERATOR_SOURCE.
+ * Sets whether to paint the background with the background colour.
+ * The default is %TRUE.
  *
  * This function is rarely useful. One use for it is to add a background
- * image to the terminal, in which case %CAIRO_OPERATOR_OVER is most likely
- * the correct operator to use.
+ * image to the terminal.
  *
  * Since: 0.52
  */
 void
-vte_terminal_set_background_operator(VteTerminal* terminal,
-                                     cairo_operator_t op)
+vte_terminal_set_clear_background(VteTerminal* terminal,
+                                  gboolean setting)
 {
         g_return_if_fail(VTE_IS_TERMINAL(terminal));
 
-        IMPL(terminal)->set_background_operator(op);
+        IMPL(terminal)->set_clear_background(setting != FALSE);
 }
diff --git a/src/vteinternal.hh b/src/vteinternal.hh
index f25c87e..fe63e76 100644
--- a/src/vteinternal.hh
+++ b/src/vteinternal.hh
@@ -607,7 +607,7 @@ public:
         * and data, which should be dropped when unrealizing and (re)created
         * when realizing. */
         struct _vte_draw *m_draw;
-        cairo_operator_t m_background_operator{CAIRO_OPERATOR_SOURCE};
+        bool m_clear_background{true};
 
         VtePaletteColor m_palette[VTE_PALETTE_SIZE];
 
@@ -1268,7 +1268,7 @@ public:
         bool set_scroll_on_keystroke(bool scroll);
         bool set_scroll_on_output(bool scroll);
         bool set_word_char_exceptions(char const* exceptions);
-        void set_background_operator(cairo_operator_t op);
+        void set_clear_background(bool setting);
 
         bool write_contents_sync (GOutputStream *stream,
                                   VteWriteFlags flags,


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