From 756a3bcc1fffd0cc85d570e61b874bbd620e4d95 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Mon, 14 Jan 2008 00:21:28 -0800 Subject: [PATCH] [Window] Set up real transparency if possible This adds the RGBA colormap code so that it is possible to have true transparency if you have a compositor enabled. --- tilda-window.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ tilda-window.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/tilda-window.c b/tilda-window.c index b0adcfd..7cff702 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -107,6 +107,30 @@ tilda_window_remove_term (TildaWindow *tw, gint terminal_number) return TRUE; } +/** + * This sets up the given TildaWindow for the capability of real + * transparency, if the X server is capable of it. */ +static void +tilda_window_setup_real_transparency (TildaWindow *self) +{ + GdkScreen *screen; + GdkColormap *colormap; + + screen = gtk_widget_get_screen (GTK_WIDGET(self->window)); + colormap = gdk_screen_get_rgba_colormap (screen); + + /* If possible, set the RGBA colormap so VTE can use real alpha + * channels for transparency. */ + if (colormap != NULL && gdk_screen_is_composited (screen)) + { + gtk_widget_set_colormap (GTK_WIDGET(self->window), colormap); + self->have_real_transparency = TRUE; + return; + } + + self->have_real_transparency = FALSE; +} + static void tilda_window_dbus_register_object (TildaWindow *tw) { @@ -126,6 +150,8 @@ static GObjectClass *parent_class = NULL; enum tilda_window_properties { TILDA_WINDOW_NUMBER = 1, + + TILDA_WINDOW_HAVE_REAL_TRANSPARENCY, }; static void @@ -159,6 +185,11 @@ tilda_window_set_property (GObject *object, g_print ("window number: %d\n", self->number); break; + case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY: + self->have_real_transparency = g_value_get_boolean (value); + g_print ("window have real transp: %d\n", self->have_real_transparency); + break; + default: /* We don't have this property */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -180,6 +211,10 @@ tilda_window_get_property (GObject *object, g_value_set_int (value, self->number); break; + case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY: + g_value_set_boolean (value, self->have_real_transparency); + break; + default: /* We don't have this property */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -211,6 +246,9 @@ tilda_window_constructor (GType type, /* Register this object with DBus */ tilda_window_dbus_register_object (self); + /* Try to set up real transparency */ + tilda_window_setup_real_transparency (self); + gtk_container_add (GTK_CONTAINER(self->window), self->notebook); gtk_widget_show (self->notebook); @@ -299,6 +337,13 @@ tilda_window_class_init (gpointer g_class, TILDA_WINDOW_NUMBER, pspec); + pspec = g_param_spec_boolean ("have-real-transparency", + NULL, NULL, FALSE, G_PARAM_READABLE); + + g_object_class_install_property (gobject_class, + TILDA_WINDOW_HAVE_REAL_TRANSPARENCY, + pspec); + /* TODO: more properties */ /* Hook the TildaWindow type into DBus */ diff --git a/tilda-window.h b/tilda-window.h index e11e17c..b8b408f 100644 --- a/tilda-window.h +++ b/tilda-window.h @@ -42,6 +42,8 @@ struct _TildaWindow { GPtrArray *terms; gint number; + + gboolean have_real_transparency; }; struct _TildaWindowClass { -- 2.25.1