[vte/vte-next] Use the background pattern from the style



commit e6f1416c5189da3baee9646438f9e8afdfeb23ad
Author: Christian Persch <chpe gnome org>
Date:   Mon May 23 01:32:04 2011 +0200

    Use the background pattern from the style

 doc/reference/vte-sections.txt |    2 -
 src/vte.c                      |  130 ++++++++++++----------------------------
 src/vte.h                      |    5 --
 src/vteapp.c                   |   42 ++-----------
 4 files changed, 44 insertions(+), 135 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 98c8c5a..689a7e7 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -25,8 +25,6 @@ vte_terminal_set_visible_bell
 vte_terminal_get_visible_bell
 vte_terminal_set_scroll_on_output
 vte_terminal_set_scroll_on_keystroke
-vte_terminal_get_background_pattern
-vte_terminal_set_background_pattern
 vte_terminal_set_scrollback_lines
 vte_terminal_get_has_selection
 vte_terminal_set_word_chars
diff --git a/src/vte.c b/src/vte.c
index 6982c26..8c7f9f3 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -139,7 +139,6 @@ enum {
         PROP_HSCROLL_POLICY,
         PROP_VSCROLL_POLICY,
         PROP_AUDIBLE_BELL,
-        PROP_BACKGROUND_PATTERN,
         PROP_BACKSPACE_BINDING,
         PROP_DELETE_BINDING,
         PROP_EMULATION,
@@ -4240,6 +4239,43 @@ vte_terminal_update_cursor_style(VteTerminal *terminal)
 }
 
 static void
+vte_terminal_update_background_style(VteTerminal *terminal)
+{
+        VteTerminalPrivate *pvt = terminal->pvt;
+        GtkStyleContext *context;
+        cairo_pattern_t *pattern;
+
+        context = gtk_widget_get_style_context(&terminal->widget);
+        gtk_style_context_get(context,
+                              GTK_STATE_FLAG_NORMAL,
+                              GTK_STYLE_PROPERTY_BACKGROUND_IMAGE, &pattern,
+                              NULL);
+
+        if (pattern && cairo_pattern_get_extend(pattern) == CAIRO_EXTEND_NONE) {
+                g_warning ("Pattern extend is wrong\n");
+                cairo_pattern_destroy(pattern);
+                return;
+        }
+
+        _vte_debug_print(VTE_DEBUG_MISC | VTE_DEBUG_STYLE,
+                         "%s background pattern.\n",
+                         pattern ? "Setting" : "Clearing");
+
+        if (pattern == pvt->bg_pattern) {
+                if (pattern)
+                        cairo_pattern_destroy(pattern);
+                return;
+        }
+
+        if (pvt->bg_pattern) {
+                cairo_pattern_destroy (pvt->bg_pattern);
+        }
+        pvt->bg_pattern = pattern /* adopted */;
+
+        vte_terminal_queue_background_update(terminal);
+}
+
+static void
 vte_terminal_update_style(VteTerminal *terminal)
 {
         VteTerminalPrivate *pvt = terminal->pvt;
@@ -4250,6 +4286,7 @@ vte_terminal_update_style(VteTerminal *terminal)
         vte_terminal_set_padding(terminal);
         vte_terminal_update_style_colors(terminal, FALSE);
         vte_terminal_update_cursor_style(terminal);
+        vte_terminal_update_background_style(terminal);
 
         gtk_widget_style_get(widget,
                              "allow-bold", &allow_bold,
@@ -10501,9 +10538,6 @@ vte_terminal_get_property (GObject *object,
                 case PROP_AUDIBLE_BELL:
                         g_value_set_boolean (value, vte_terminal_get_audible_bell (terminal));
                         break;
-                case PROP_BACKGROUND_PATTERN:
-                        g_value_set_pointer (value, pvt->bg_pattern);
-                        break;
                 case PROP_BACKSPACE_BINDING:
                         g_value_set_enum (value, pvt->backspace_binding);
                         break;
@@ -10578,9 +10612,6 @@ vte_terminal_set_property (GObject *object,
                 case PROP_AUDIBLE_BELL:
                         vte_terminal_set_audible_bell (terminal, g_value_get_boolean (value));
                         break;
-                case PROP_BACKGROUND_PATTERN:
-                        vte_terminal_set_background_pattern (terminal, g_value_get_pointer (value));
-                        break;
                 case PROP_BACKSPACE_BINDING:
                         vte_terminal_set_backspace_binding (terminal, g_value_get_enum (value));
                         break;
@@ -11237,19 +11268,6 @@ vte_terminal_class_init(VteTerminalClass *klass)
                  g_param_spec_boolean ("audible-bell", NULL, NULL,
                                        TRUE,
                                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-     
-        /**
-         * VteTerminal:background-pattern: (type cairo_pattern_t):
-         *
-         * Sets a background pattern for the widget.
-         * 
-         * Since: 0.30
-         */
-        g_object_class_install_property
-                (gobject_class,
-                 PROP_BACKGROUND_PATTERN,
-                 g_param_spec_pointer ("background-pattern", NULL, NULL,
-                                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
         /**
          * VteTerminal:backspace-binding:
@@ -11840,78 +11858,6 @@ vte_terminal_queue_background_update(VteTerminal *terminal)
 }
 
 /**
- * vte_terminal_get_background_pattern:
- * @terminal: a #VteTerminal
- *
- * Returns the current background pattern for the widget.
- *
- * Returns: (transfer none): a #cairo_pattern_t, or %NULL
- *
- * Since: 0.30
- */
-cairo_pattern_t *
-vte_terminal_get_background_pattern(VteTerminal *terminal)
-{
-        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
-
-        return terminal->pvt->bg_pattern;
-}
-
-/**
- * vte_terminal_set_background_pattern:
- * @terminal: a #VteTerminal
- * @pattern: (allow-none): a #cairo_pattern_t, or %NULL to unset the background
- *
- * Sets a background pattern for the widget.  Text which would otherwise be
- * drawn using the default background color will instead be drawn over the
- * specified pattern.  If necessary, the pattern will be tiled to cover the
- * widget's entire visible area.
- *
- * If using a surface pattern, it is recommended to update the pattern
- * on #GtkWidget:realize to use a similar surface to the widget's window.
- *
- * Since: 0.30
- */
-void
-vte_terminal_set_background_pattern(VteTerminal *terminal,
-                                    cairo_pattern_t *pattern)
-{
-        VteTerminalPrivate *pvt;
-        GObject *object;
-
-	g_return_if_fail(VTE_IS_TERMINAL(terminal));
-        if (pattern) {
-                g_return_if_fail(cairo_pattern_get_extend(pattern) != CAIRO_EXTEND_NONE);
-        }
-
-        object = G_OBJECT(terminal);
-        pvt = terminal->pvt;
-
-        if (pattern == pvt->bg_pattern)
-                return;
-
-	_vte_debug_print(VTE_DEBUG_MISC,
-			"%s background pattern.\n",
-			pattern ? "Setting" : "Clearing");
-
-        g_object_freeze_notify(object);
-
-        if (pvt->bg_pattern) {
-                cairo_pattern_destroy (pvt->bg_pattern);
-        }
-        if (pattern) {
-                cairo_pattern_reference (pattern);
-        }
-        pvt->bg_pattern = pattern;
-
-        g_object_notify(object, "background-pattern");
-
-	vte_terminal_queue_background_update(terminal);
-
-        g_object_thaw_notify(object);
-}
-
-/**
  * vte_terminal_get_has_selection:
  * @terminal: a #VteTerminal
  *
diff --git a/src/vte.h b/src/vte.h
index 5f58d89..c4ed863 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -226,11 +226,6 @@ void vte_terminal_set_scroll_on_output(VteTerminal *terminal, gboolean scroll);
 void vte_terminal_set_scroll_on_keystroke(VteTerminal *terminal,
 					  gboolean scroll);
 
-/* Background effects. */
-cairo_pattern_t *vte_terminal_get_background_pattern(VteTerminal *terminal);
-void vte_terminal_set_background_pattern(VteTerminal *terminal,
-                                         cairo_pattern_t *pattern);
-
 /* Set the number of scrollback lines, above or at an internal minimum. */
 void vte_terminal_set_scrollback_lines(VteTerminal *terminal, glong lines);
 
diff --git a/src/vteapp.c b/src/vteapp.c
index 6cd7c98..4f7516d 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -542,7 +542,7 @@ main(int argc, char **argv)
 		(char *) "FOO=BAR", (char *) "BOO=BIZ",
 #endif
 		NULL};
-	const char *background = NULL;
+	char *background = NULL;
 	gboolean audible = TRUE,
 		 debug = FALSE, dingus = FALSE, dbuffer = TRUE,
 		 console = FALSE, scroll = FALSE, keep = FALSE,
@@ -558,7 +558,6 @@ main(int argc, char **argv)
 	const char *command = NULL;
 	const char *working_directory = NULL;
 	const char *output_file = NULL;
-        char *tint_color_string = NULL;
 	char *pty_flags_string = NULL;
         char *cursor_color_string = NULL;
 	char *cursor_blink_mode_string = NULL;
@@ -711,11 +710,6 @@ main(int argc, char **argv)
 			"PTY flags set from default|no-utmp|no-wtmp|no-lastlog|no-helper|no-fallback", NULL
 		},
                 {
-                        "tint-color", 0, 0,
-                        G_OPTION_ARG_STRING, &tint_color_string,
-                        "Background tint color", "RGBA"
-                },
-                {
                         "border-width", 0, 0,
                         G_OPTION_ARG_STRING, &border_width_string,
                         "Border with", "WIDTH"
@@ -791,6 +785,11 @@ main(int argc, char **argv)
         }
 
         g_string_append (css_string, "VteTerminal {\n");
+        if (background) {
+                g_string_append_printf (css_string, "background-image: url(\"%s\");\n",
+                                        background);
+                g_free(background);
+        }
         if (cursor_color_string) {
                 g_string_append_printf (css_string, "-VteTerminal-cursor-background-color: %s;\n",
                                         cursor_color_string);
@@ -955,35 +954,6 @@ main(int argc, char **argv)
 	vte_terminal_set_scrollback_lines(terminal, lines);
 	vte_terminal_set_mouse_autohide(terminal, TRUE);
 
-	if (background != NULL) {
-                cairo_surface_t *surface;
-
-                surface = cairo_image_surface_create_from_png (background);
-                if (cairo_surface_status (surface) == CAIRO_STATUS_SUCCESS) {
-                        cairo_pattern_t *pattern;
-
-                        pattern = cairo_pattern_create_for_surface(surface);
-                        cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
-                        vte_terminal_set_background_pattern(terminal, pattern);
-                        cairo_pattern_destroy(pattern);
-                } else {
-                        g_printerr("Failed to create background pattern\n");
-                }
-                cairo_surface_destroy (surface);
-        } else if (tint_color_string) {
-                GdkRGBA tint;
-                cairo_pattern_t *pattern;
-
-                tint.red = tint.green = tint.blue = 1.; tint.alpha = .875;
-                if (!gdk_rgba_parse (&tint, tint_color_string))
-                        g_printerr ("Failed to parse tint color string\n");
-                g_free (tint_color_string);
-
-                pattern = cairo_pattern_create_rgba (tint.red, tint.green, tint.blue, tint.alpha);
-                vte_terminal_set_background_pattern(terminal, pattern);
-                cairo_pattern_destroy(pattern);
-        }
-
 	if (termcap != NULL) {
 		vte_terminal_set_emulation(terminal, termcap);
 	}



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