30
30
#include <background_window.h>
31
#include <background_window_callbacks.h>
31
32
#include <annotation_window.h>
34
35
/* The background data used internally and by the callbacks. */
35
36
static BackgroundData *background_data;
38
39
/* Load a file image in the window. */
42
if (background_data->back_cr)
43
if (background_data->background_cr)
44
45
cairo_surface_t *surface = cairo_image_surface_create_from_png (background_data->background_image);
45
46
cairo_t *cr = cairo_create (surface);
47
48
gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), 1.0);
49
50
gint new_height = 0;
50
51
gint new_width = 0;
51
gdk_drawable_get_size (gtk_widget_get_window (background_data->background_window), &new_width, &new_height);
52
new_height = gdk_window_get_height (gtk_widget_get_window (background_data->background_window));
53
new_width = gdk_window_get_width (gtk_widget_get_window (background_data->background_window));
53
55
cairo_surface_t *scaled_surface = scale_surface (surface, new_width, new_height );
55
57
cairo_surface_destroy (surface);
57
59
cairo_destroy (cr);
59
cairo_set_source_surface (background_data->back_cr, scaled_surface, 0.0, 0.0);
61
cairo_paint (background_data->back_cr);
62
cairo_stroke (background_data->back_cr);
61
cairo_set_source_surface (background_data->background_cr, scaled_surface, 0.0, 0.0);
63
cairo_paint (background_data->background_cr);
64
cairo_stroke (background_data->background_cr);
64
66
cairo_surface_destroy (scaled_surface);
67
gtk_widget_input_shape_combine_mask (background_data->background_window,
71
drill_window_in_bar_area (background_data->background_window);
69
gtk_widget_input_shape_combine_region (background_data->background_window, NULL);
77
75
/* The windows has been exposed after the show_all request to change the background color. */
86
if (background_data->back_cr)
84
if (background_data->background_cr)
88
86
sscanf (background_data->background_color, "%02X%02X%02X%02X", &r, &g, &b, &a);
90
cairo_set_operator (background_data->back_cr, CAIRO_OPERATOR_SOURCE);
88
cairo_set_operator (background_data->background_cr, CAIRO_OPERATOR_SOURCE);
94
92
gdouble opacity = BACKGROUND_OPACITY;
95
cairo_set_source_rgb (background_data->back_cr, (gdouble) r/256, (gdouble) g/256, (gdouble) b/256);
93
cairo_set_source_rgb (background_data->background_cr, (gdouble) r/256, (gdouble) g/256, (gdouble) b/256);
98
96
* @TODO Implement with a full opaque windows and use cairo_set_source_rgba
100
98
* I set the opacity with alpha and I use cairo_set_source_rgb to workaround
101
99
* the problem on windows with rgba.
103
if (((gdouble) a/256) > BACKGROUND_OPACITY)
105
opacity = (gdouble) a/256;
101
if (((gdouble) a/256) > BACKGROUND_OPACITY)
103
opacity = (gdouble) a/256;
107
105
gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), opacity);
109
107
gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), 1);
110
cairo_set_source_rgba (background_data->back_cr,
108
cairo_set_source_rgba (background_data->background_cr,
117
cairo_paint (background_data->back_cr);
118
cairo_stroke (background_data->back_cr);
115
cairo_paint (background_data->background_cr);
116
cairo_stroke (background_data->background_cr);
121
119
if (((gint) a ) < 1)
123
gtk_widget_input_shape_combine_mask (background_data->background_window,
121
gtk_widget_input_shape_combine_region (background_data->background_window, NULL);
134
129
/* Allocate internal structure. */
135
130
static BackgroundData *
136
allocate_background_data ()
131
allocate_background_data ()
138
133
BackgroundData *background_data = g_malloc ((gsize) sizeof (BackgroundData));
139
134
background_data->background_color = (gchar *) NULL;
140
135
background_data->background_image = (gchar *) NULL;
141
background_data->back_cr = (cairo_t *) NULL;
142
background_data->background_shape = (GdkPixmap *) NULL;
136
background_data->background_cr = (cairo_t *) NULL;
143
137
background_data->background_window = (GtkWidget *) NULL;
144
138
background_data->background_type = 0;
145
139
return background_data;
149
143
/* Destroy the background window. */
151
destroy_background_window ()
145
destroy_background_window ()
153
147
if (background_data)
155
if (background_data->background_shape)
157
g_object_unref (background_data->background_shape);
158
background_data->background_shape = (GdkPixmap *) NULL;
161
150
if (background_data->background_window)
163
/* Destroy brutally the background window. */
164
gtk_widget_destroy (background_data->background_window);
165
background_data->background_window = (GtkWidget *) NULL;
152
/* Destroy brutally the background window. */
153
gtk_widget_destroy (background_data->background_window);
154
background_data->background_window = (GtkWidget *) NULL;
168
if (background_data->back_cr)
170
cairo_destroy (background_data->back_cr);
171
background_data->back_cr = (cairo_t *) NULL;
157
if (background_data->background_cr)
159
cairo_destroy (background_data->background_cr);
160
background_data->background_cr = (cairo_t *) NULL;
174
163
if (background_data->background_color)
176
g_free (background_data->background_color);
177
background_data->background_color = (gchar *) NULL;
165
g_free (background_data->background_color);
166
background_data->background_color = (gchar *) NULL;
180
169
/* Delete reference to the gtk builder object. */
181
170
if (background_data->background_window_gtk_builder)
183
g_object_unref (background_data->background_window_gtk_builder);
184
background_data->background_window_gtk_builder = (GtkBuilder *) NULL;
172
g_object_unref (background_data->background_window_gtk_builder);
173
background_data->background_window_gtk_builder = (GtkBuilder *) NULL;
187
176
if (background_data)
189
g_free (background_data);
190
background_data = (BackgroundData *) NULL;
178
g_free (background_data);
179
background_data = (BackgroundData *) NULL;
194
/* Quit the gtk engine. */
199
186
/* Clear the background. */
200
void clear_background_window ()
187
void clear_background_window ()
204
cairo_t *shape_cr = (cairo_t *) NULL;
207
190
* @HACK Deny the mouse input to go below the window putting the opacity greater than 0
208
191
* I avoid a complete transparent window because in some operating system this would become
212
195
gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), BACKGROUND_OPACITY);
214
clear_cairo_context (background_data->back_cr);
216
gdk_drawable_get_size (gtk_widget_get_window (background_data->background_window), &width, &height);
218
/* Instantiate a transparent pixmap to be used as mask. */
219
background_data->background_shape = gdk_pixmap_new ((GdkDrawable *) NULL, width, height, 1);
220
shape_cr = gdk_cairo_create (background_data->background_shape);
221
clear_cairo_context (shape_cr);
222
cairo_destroy (shape_cr);
197
clear_cairo_context (background_data->background_cr);
224
199
/* This allows the mouse event to be passed to the window below. */
226
gtk_widget_input_shape_combine_mask (background_data->background_window,
227
background_data->background_shape,
201
cairo_region_t* r = gdk_cairo_region_create_from_surface(cairo_get_target (background_data->background_cr));
202
gtk_widget_input_shape_combine_region (background_data->background_window, r);
203
cairo_region_destroy(r);
234
208
/* Create the background window. */
236
create_background_window ()
210
create_background_window ()
238
212
GError *error = (GError *) NULL;
239
213
GObject *background_obj = (GObject *) NULL;
256
230
background_obj = gtk_builder_get_object (background_data->background_window_gtk_builder, "backgroundWindow");
257
231
background_data->background_window = GTK_WIDGET (background_obj);
232
gtk_window_set_keep_above (GTK_WINDOW (background_data->background_window), TRUE);
234
/* This trys to set an alpha channel. */
235
on_back_screen_changed (background_data->background_window, NULL, background_data);
259
237
/* In the gtk 2.16.6 used for windows the gtkbuilder the double buffered property
260
238
* is not parsed from glade and then I set this by hands.
262
240
gtk_widget_set_double_buffered (background_data->background_window, FALSE);
264
242
gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), BACKGROUND_OPACITY);
266
gtk_widget_set_usize (background_data->background_window, gdk_screen_width (), gdk_screen_height ());
244
gtk_widget_set_size_request (background_data->background_window, gdk_screen_width (), gdk_screen_height ());
268
246
/* Connect all the callback from gtkbuilder xml file. */
269
247
gtk_builder_connect_signals (background_data->background_window_gtk_builder, (gpointer) background_data);
271
gtk_widget_show_all (background_data->background_window);
249
//gtk_widget_show_all (background_data->background_window);
273
251
/* This put in full screen; this will generate an exposure. */
274
252
gtk_window_fullscreen (GTK_WINDOW (background_data->background_window));