[Terminal] Add transparency support
[tilda-gobject.git] / tilda-terminal.c
index d1533db..ec76061 100644 (file)
@@ -175,6 +175,35 @@ tilda_terminal_window_title_changed_cb (GtkWidget *widget, gpointer data)
        g_free (new_title);
 }
 
+/**
+ * Set the given TildaTerminal to the appropriate transparency level
+ * based on the self->transparency_percent member. */
+static void
+tilda_terminal_set_transparent (TildaTerminal *self)
+{
+       TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
+       gdouble temp;
+
+       /* Convert the transparency to VTE's format */
+       temp = ((gdouble) self->transparency_percent) / 100.0;
+
+       if (self->transparency_percent > 0)
+       {
+               vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), temp);
+               vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), (1.0 - temp) * 0xffff);
+
+               /* Use fake transparency if necessary */
+               vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term),
+                                                                                                !parent_window->have_real_transparency);
+               return;
+       }
+
+       /* Turn off transparency */
+       vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), 0);
+       vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), 0xffff);
+       vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term), FALSE);
+}
+
 /*******************************************************************************
  * All GObject stuff is below. You probably don't need to change this...
  ******************************************************************************/
@@ -298,6 +327,7 @@ tilda_terminal_set_property (GObject      *object,
 
                case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
                        self->transparency_percent = g_value_get_int (value);
+                       tilda_terminal_set_transparent (self);
                        g_print ("terminal transp percent: %d\n", self->transparency_percent);
                        break;