some code to actuall deal with transparency (this commit does not even build)
[simple-launcher] / applet-wrapper.cc
1 // This file is a part of Simple Launcher
2 //
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
4 //
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 #include <cairo/cairo.h>
19
20 #include <libhildondesktop/libhildondesktop.h>
21 #include "applet-wrapper.h"
22
23 #include "simple-launcher.h"
24
25 struct _SLAWrapperPrivate {
26   void *applet;
27   GdkPixmap *background_pixmap;
28 };
29
30   static void sla_wrapper_init(SLAWrapper *self);
31   static void sla_wrapper_class_init(SLAWrapperClass *klass);
32   static void sla_wrapper_finalize(GObject *object);
33   static gboolean sla_wrapper_expose(GtkWidget *widget, GdkEventExpose *event);
34   static void sla_wrapper_size_allocate(GtkWidget *widget, GtkAllocation *alloc);
35   static void sla_wrapper_size_request(GtkWidget *widget, GtkRequisition *requisition);
36
37 HD_DEFINE_PLUGIN(SLAWrapper, sla_wrapper, HILDON_DESKTOP_TYPE_HOME_ITEM)
38
39 static void sla_wrapper_init(SLAWrapper *self) {
40   GdkColormap *colormap = NULL;
41
42   self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SLA_TYPE_WRAPPER);
43   self->priv->background_pixmap = NULL;
44
45   if ((colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default())) != NULL) {
46     gtk_widget_set_colormap(GTK_WIDGET(self), colormap);
47   }
48 }
49
50 static void sla_wrapper_class_init(SLAWrapperClass *klass) {
51   GtkWidgetClass *widget_class;
52   GObjectClass *object_class;
53
54   widget_class = GTK_WIDGET_CLASS(klass);
55   object_class = G_OBJECT_CLASS(klass);
56
57   object_class->finalize = sla_wrapper_finalize;
58
59   widget_class->expose_event = sla_wrapper_expose;
60   widget_class->size_allocate = sla_wrapper_size_allocate;
61   widget_class->size_request = sla_wrapper_size_request;
62
63   g_type_class_add_private(klass, sizeof(SLAWrapperPrivate));   // Do I need this?
64 }
65
66 static void sla_wrapper_finalize(GObject *self) {
67   SLAWrapperPrivate *priv = SLA_WRAPPER(self)->priv;
68
69   if (priv->background_pixmap != NULL) {
70     g_object_unref(priv->background_pixmap);
71     priv->background_pixmap = NULL;
72   }
73 #if 0
74   free(priv->applet);
75 #endif
76 }
77
78 static gboolean sla_wrapper_expose(GtkWidget *widget, GdkEventExpose *event) {
79   if (GTK_WIDGET_DRAWABLE(widget)) {
80     cairo_t *cr;
81
82     SLAWrapperPrivate *priv = SLA_WRAPPER(widget)->priv;
83
84     if (priv->background_pixmap == NULL) {
85       priv->background_pixmap = gdk_pixmap_new(widget->window, SOME_WIDTH, SOME_HEIGHT, 32);
86
87       cr = gdk_cairo_create(priv->background_pixmap);
88
89       cairo_set_source_rgba(cr, OUR_R, OUR_G, OUR_B, OUR_A);
90       cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
91       cairo_paint(cr);
92       cairo_destroy(cr);
93     }
94
95     cr = gdk_cairo_create(widget->window);
96     gdk_cairo_set_source_pixmap(cr, priv->background_pixmap, 0, 0);
97
98     cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
99     cairo_paint(cr);
100     cairo_destroy(cr);
101
102     return GTK_WIDGET_CLASS(sla_wrapper_parent_class)->expose_event(widget, event);
103   } else {
104     return FALSE;
105   }
106 }
107
108 static void sla_wrapper_size_allocate(GtkWidget *widget, GtkAllocation *alloc) {
109   GTK_WIDGET_CLASS(sla_wrapper_parent_class)->size_allocate(widget, alloc);
110 }
111
112 static void sla_wrapper_size_request(GtkWidget *widget, GtkRequisition *requisition) {
113 #if 0
114   requisition->width = our_desired_width;
115   requisition->height = our_desired_height;
116 #endif
117 }
118
119 // vim:ts=2:sw=2:et