32
32
static void wrapper_plug_finalize (GObject *object);
33
#if GTK_CHECK_VERSION (3, 0, 0)
34
static gboolean wrapper_plug_draw (GtkWidget *widget,
33
37
static gboolean wrapper_plug_expose_event (GtkWidget *widget,
34
38
GdkEventExpose *event);
35
40
static void wrapper_plug_background_reset (WrapperPlug *plug);
82
91
wrapper_plug_init (WrapperPlug *plug)
93
#if GTK_CHECK_VERSION (3, 0, 0)
94
GdkVisual *visual = NULL;
96
GtkStyleContext *context;
97
GtkCssProvider *provider = gtk_css_provider_new();
84
100
GdkColormap *colormap = NULL;
85
101
GdkScreen *screen;
87
104
plug->background_alpha = 1.00;
88
105
plug->background_color = NULL;
94
111
/* allow painting, else compositing won't work */
95
112
gtk_widget_set_app_paintable (GTK_WIDGET (plug), TRUE);
114
#if !GTK_CHECK_VERSION (3, 0, 0)
97
115
/* old versions of gtk don't support transparent tray icons, if we
98
116
* set an argb colormap on the tray, the icons won't be embedded because
99
117
* the socket-plugin implementation requires identical colormaps */
100
118
if (gtk_check_version (2, 16, 0) != NULL
101
119
&& strcmp (wrapper_name, "systray") == 0)
104
123
/* set the colormap */
105
124
screen = gtk_window_get_screen (GTK_WINDOW (plug));
125
#if GTK_CHECK_VERSION (3, 0, 0)
126
visual = gdk_screen_get_rgba_visual (screen);
128
gtk_widget_set_visual (GTK_WIDGET (plug), visual);
106
130
colormap = gdk_screen_get_rgba_colormap (screen);
107
131
if (colormap != NULL)
108
132
gtk_widget_set_colormap (GTK_WIDGET (plug), colormap);
135
#if GTK_CHECK_VERSION (3, 0, 0)
136
/* set the panel class */
137
context = gtk_widget_get_style_context (GTK_WIDGET (plug));
138
gtk_style_context_add_class (context, "panel");
139
gtk_style_context_add_class (context, "xfce4-panel");
141
/* We need to set the plugin button to transparent and let everything else
142
* be in the theme or panel's color */
143
css_string = g_strdup_printf (".xfce4-panel .button { background-color: transparent; }");
144
gtk_css_provider_load_from_data (provider, css_string, -1, NULL);
145
gtk_style_context_add_provider (context,
146
GTK_STYLE_PROVIDER (provider),
147
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
150
g_object_unref (provider);
166
#if GTK_CHECK_VERSION (3, 0, 0)
168
wrapper_plug_draw (GtkWidget *widget,
171
WrapperPlug *plug = WRAPPER_PLUG (widget);
172
GtkStyleContext *style;
173
const GdkColor *color;
177
GError *error = NULL;
181
/* The "draw" signal is in widget coordinates, transform back to window */
182
gtk_cairo_transform_to_window (cr,
184
gtk_widget_get_window (gtk_widget_get_toplevel (GTK_WIDGET (plug))));
186
if (G_UNLIKELY (plug->background_image != NULL))
188
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
190
if (G_LIKELY (plug->background_image_cache != NULL))
192
cairo_set_source (cr, plug->background_image_cache);
197
/* load the image in a pixbuf */
198
pixbuf = gdk_pixbuf_new_from_file (plug->background_image, &error);
200
if (G_LIKELY (pixbuf != NULL))
202
gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
203
g_object_unref (G_OBJECT (pixbuf));
205
plug->background_image_cache = cairo_get_source (cr);
206
cairo_pattern_reference (plug->background_image_cache);
207
cairo_pattern_set_extend (plug->background_image_cache, CAIRO_EXTEND_REPEAT);
212
/* print error message */
213
g_warning ("Background image disabled, \"%s\" could not be loaded: %s",
214
plug->background_image, error != NULL ? error->message : "No error");
215
g_error_free (error);
217
/* disable background image */
218
wrapper_plug_background_reset (plug);
224
alpha = gtk_widget_is_composited (GTK_WIDGET (plug)) ? plug->background_alpha : 1.00;
226
if (alpha < 1.00 || plug->background_color != NULL)
228
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
230
/* get the background gdk color */
231
if (plug->background_color != NULL)
233
color = plug->background_color;
234
cairo_set_source_rgba (cr, PANEL_GDKCOLOR_TO_DOUBLE (color), alpha);
238
style = gtk_widget_get_style_context (widget);
239
gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &rgba);
241
gdk_cairo_set_source_rgba (cr, &rgba);
244
/* draw the background color */
251
return GTK_WIDGET_CLASS (wrapper_plug_parent_class)->draw (widget, cr);
124
257
wrapper_plug_expose_event (GtkWidget *widget,
125
258
GdkEventExpose *event)