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



commit d8435b2439ab49dff272b0da3078ac5cc675d4b6
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                      |  136 +++++++++++++---------------------------
 src/vte.h                      |    5 --
 src/vteapp.c                   |   42 ++-----------
 4 files changed, 50 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 0a735ab..2e9d6dc 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -69,6 +69,8 @@ typedef gunichar wint_t;
 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
 #endif
 
+#define CAIRO_GOBJECT_TYPE_PATTERN (g_type_from_name("CairoPattern"))
+
 static void vte_terminal_set_visibility (VteTerminal *terminal, GdkVisibilityState state);
 static void vte_terminal_set_termcap(VteTerminal *terminal, const char *path,
 				     gboolean reset);
@@ -139,7 +141,6 @@ enum {
         PROP_HSCROLL_POLICY,
         PROP_VSCROLL_POLICY,
         PROP_AUDIBLE_BELL,
-        PROP_BACKGROUND_PATTERN,
         PROP_BACKSPACE_BINDING,
         PROP_DELETE_BINDING,
         PROP_EMULATION,
@@ -4238,6 +4239,33 @@ vte_terminal_update_cursor_style(VteTerminal *terminal)
 }
 
 static void
+vte_terminal_update_background_style(VteTerminal *terminal)
+{
+        VteTerminalPrivate *pvt = terminal->pvt;
+        cairo_pattern_t *pattern;
+
+        gtk_widget_style_get(&terminal->widget, "background-pattern", &pattern, NULL);
+        g_return_if_fail (pattern == NULL || cairo_pattern_get_extend(pattern) != CAIRO_EXTEND_NONE);
+
+        _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;
@@ -4248,6 +4276,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,
@@ -10499,9 +10528,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;
@@ -10576,9 +10602,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;
@@ -11235,19 +11258,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:
@@ -11478,6 +11488,20 @@ vte_terminal_class_init(VteTerminalClass *klass)
                                        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
         /**
+         * VteTerminal:background-pattern:
+         *
+         * A #cairo_pattern_t to use as background.
+         * Must not have extends %CAIRO_EXTEND_NONE.
+         *
+         * Since: 0.30
+         */
+        gtk_widget_class_install_style_property
+                (widget_class,
+                 g_param_spec_boxed ("background-pattern", NULL, NULL,
+                                     CAIRO_GOBJECT_TYPE_PATTERN,
+                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+        /**
          * VteTerminal:cursor-blink-mode:
          *
          * Sets whether or not the cursor will blink. Using %VTE_CURSOR_BLINK_SYSTEM
@@ -11838,78 +11862,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 bb3c460..ad83c40 100644
--- a/src/vteapp.c
+++ b/src/vteapp.c
@@ -546,7 +546,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,
@@ -562,7 +562,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;
@@ -715,11 +714,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"
@@ -795,6 +789,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);
@@ -959,35 +958,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]