~ubuntu-branches/debian/sid/ardesia/sid

« back to all changes in this revision

Viewing changes to src/background_window.c

  • Committer: Package Import Robot
  • Author(s): TANIGUCHI Takaki
  • Date: 2012-11-05 19:55:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20121105195518-ird6x2us0tui2q92
Tags: 1.1-1
* debian/watch: no longer use googlecode.d.n
* Imported Upstream version 1.1 (Closes: #620319, #692256)
* debian/control: add GTK+3 to B-D instead of GTK+2

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include <utils.h>
30
30
#include <background_window.h>
 
31
#include <background_window_callbacks.h>
31
32
#include <annotation_window.h>
32
33
 
33
34
 
34
35
/* The background data used internally and by the callbacks. */
35
36
static BackgroundData *background_data;
36
37
 
37
 
 
 
38
 
38
39
/* Load a file image in the window. */
39
40
static void
40
 
load_file ()
 
41
load_file               ()
41
42
{
42
 
  if (background_data->back_cr)
 
43
  if (background_data->background_cr)
43
44
    {
44
45
      cairo_surface_t *surface = cairo_image_surface_create_from_png (background_data->background_image);
45
46
      cairo_t *cr = cairo_create (surface);
46
47
 
47
48
      gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), 1.0);
48
 
          
 
49
        
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));
52
54
 
53
55
      cairo_surface_t *scaled_surface = scale_surface (surface, new_width, new_height );
54
 
          
 
56
        
55
57
      cairo_surface_destroy (surface);
56
 
          
 
58
        
57
59
      cairo_destroy (cr);
58
 
           
59
 
      cairo_set_source_surface (background_data->back_cr, scaled_surface, 0.0, 0.0);
60
 
        
61
 
      cairo_paint (background_data->back_cr);
62
 
      cairo_stroke (background_data->back_cr);
 
60
        
 
61
      cairo_set_source_surface (background_data->background_cr, scaled_surface, 0.0, 0.0);
 
62
        
 
63
      cairo_paint (background_data->background_cr);
 
64
      cairo_stroke (background_data->background_cr);
63
65
        
64
66
      cairo_surface_destroy (scaled_surface);
65
 
          
 
67
        
66
68
#ifndef _WIN32
67
 
      gtk_widget_input_shape_combine_mask (background_data->background_window,
68
 
                                           NULL,
69
 
                                           0,
70
 
                                           0);
71
 
      drill_window_in_bar_area (background_data->background_window);
 
69
      gtk_widget_input_shape_combine_region (background_data->background_window, NULL);
72
70
#endif
73
71
    }
74
72
}
76
74
 
77
75
/* The windows has been exposed after the show_all request to change the background color. */
78
76
static void
79
 
load_color ()
 
77
load_color              ()
80
78
{
81
79
  gint r = 0;
82
80
  gint g = 0;
83
81
  gint b = 0;
84
82
  gint a = 0;
85
83
 
86
 
  if (background_data->back_cr)
 
84
  if (background_data->background_cr)
87
85
    {
88
86
      sscanf (background_data->background_color, "%02X%02X%02X%02X", &r, &g, &b, &a);
89
87
 
90
 
      cairo_set_operator (background_data->back_cr, CAIRO_OPERATOR_SOURCE);
 
88
      cairo_set_operator (background_data->background_cr, CAIRO_OPERATOR_SOURCE);
91
89
 
92
90
 
93
91
#ifdef WIN32
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);
96
94
 
97
95
      /*
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. 
102
100
       */
103
 
          if (((gdouble) a/256) >  BACKGROUND_OPACITY)
104
 
             { 
105
 
                    opacity = (gdouble) a/256;
106
 
             }
 
101
       if (((gdouble) a/256) >  BACKGROUND_OPACITY)
 
102
         {
 
103
           opacity = (gdouble) a/256;
 
104
         }
107
105
      gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), opacity);
108
106
#else
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,
111
109
                             (gdouble) r/256,
112
 
                             (gdouble) g/256,
113
 
                             (gdouble) b/256,
114
 
                             (gdouble) a/256);
 
110
                             (gdouble) g/256,
 
111
                             (gdouble) b/256,
 
112
                             (gdouble) a/256);
115
113
#endif
116
114
 
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);
119
117
 
120
118
#ifndef _WIN32
121
119
      if (((gint) a ) < 1)
122
 
        {
123
 
          gtk_widget_input_shape_combine_mask (background_data->background_window,
124
 
                                               NULL,
125
 
                                               0,
126
 
                                               0);
127
 
        }
 
120
        {
 
121
          gtk_widget_input_shape_combine_region (background_data->background_window, NULL);
 
122
        }
128
123
#endif
129
124
 
130
125
    }
133
128
 
134
129
/* Allocate internal structure. */
135
130
static BackgroundData *
136
 
allocate_background_data ()
 
131
allocate_background_data          ()
137
132
{
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;
148
142
 
149
143
/* Destroy the background window. */
150
144
void
151
 
destroy_background_window ()
 
145
destroy_background_window         ()
152
146
{
153
147
  if (background_data)
154
148
    {
155
 
      if (background_data->background_shape)
156
 
        {
157
 
          g_object_unref (background_data->background_shape);
158
 
          background_data->background_shape = (GdkPixmap *) NULL;
159
 
        }
160
 
 
 
149
   
161
150
      if (background_data->background_window)
162
 
        { 
163
 
          /* Destroy brutally the background window. */
164
 
          gtk_widget_destroy (background_data->background_window);
165
 
          background_data->background_window = (GtkWidget *) NULL;
166
 
        }
 
151
        {
 
152
          /* Destroy brutally the background window. */
 
153
          gtk_widget_destroy (background_data->background_window);
 
154
          background_data->background_window = (GtkWidget *) NULL;
 
155
        }
167
156
 
168
 
      if (background_data->back_cr)
169
 
        {
170
 
          cairo_destroy (background_data->back_cr);
171
 
          background_data->back_cr = (cairo_t *) NULL;
172
 
        }
 
157
      if (background_data->background_cr)
 
158
        {
 
159
          cairo_destroy (background_data->background_cr);
 
160
          background_data->background_cr = (cairo_t *) NULL;
 
161
        }
173
162
 
174
163
      if (background_data->background_color)
175
 
        {
176
 
          g_free (background_data->background_color);
177
 
          background_data->background_color = (gchar *) NULL;
178
 
        }
 
164
        {
 
165
          g_free (background_data->background_color);
 
166
          background_data->background_color = (gchar *) NULL;
 
167
        }
179
168
 
180
169
      /* Delete reference to the gtk builder object. */
181
170
      if (background_data->background_window_gtk_builder)
182
 
        {
183
 
          g_object_unref (background_data->background_window_gtk_builder);
184
 
          background_data->background_window_gtk_builder = (GtkBuilder *) NULL;
185
 
        }
 
171
        {
 
172
          g_object_unref (background_data->background_window_gtk_builder);
 
173
          background_data->background_window_gtk_builder = (GtkBuilder *) NULL;
 
174
        }
186
175
 
187
176
      if (background_data)
188
 
        {
189
 
          g_free (background_data);
190
 
          background_data = (BackgroundData *) NULL;
191
 
        }
 
177
        {
 
178
          g_free (background_data);
 
179
          background_data = (BackgroundData *) NULL;
 
180
        }
192
181
 
193
182
    }
194
 
  /* Quit the gtk engine. */
195
 
  gtk_main_quit ();
196
183
}
197
184
 
198
185
 
199
186
/* Clear the background. */
200
 
void clear_background_window ()
 
187
void clear_background_window      ()
201
188
{
202
 
  gint height       = -1;
203
 
  gint width        = -1;
204
 
  cairo_t *shape_cr = (cairo_t *) NULL;
205
 
 
206
189
  /*
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
211
194
   */
212
195
  gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), BACKGROUND_OPACITY);
213
196
 
214
 
  clear_cairo_context (background_data->back_cr);
215
 
 
216
 
  gdk_drawable_get_size (gtk_widget_get_window (background_data->background_window), &width, &height);
217
 
 
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);
223
198
 
224
199
  /* This allows the mouse event to be passed to the window below. */
225
200
#ifndef _WIN32
226
 
  gtk_widget_input_shape_combine_mask (background_data->background_window,
227
 
                                       background_data->background_shape,
228
 
                                       0,
229
 
                                       0);
 
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);
230
204
#endif
231
205
}
232
206
 
233
207
 
234
208
/* Create the background window. */
235
209
GtkWidget *
236
 
create_background_window ()
 
210
create_background_window     ()
237
211
{
238
212
  GError *error = (GError *) NULL;
239
213
  GObject *background_obj = (GObject *) NULL;
255
229
 
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);
258
233
 
 
234
  /* This trys to set an alpha channel. */
 
235
  on_back_screen_changed (background_data->background_window, NULL, background_data);
 
236
  
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. 
261
239
   */
262
240
  gtk_widget_set_double_buffered (background_data->background_window, FALSE);
263
241
 
264
242
  gtk_window_set_opacity (GTK_WINDOW (background_data->background_window), BACKGROUND_OPACITY);
265
 
 
266
 
  gtk_widget_set_usize (background_data->background_window, gdk_screen_width (), gdk_screen_height ());
 
243
  
 
244
  gtk_widget_set_size_request (background_data->background_window, gdk_screen_width (), gdk_screen_height ());
267
245
 
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);
270
 
 
271
 
  gtk_widget_show_all (background_data->background_window);
 
248
    
 
249
  //gtk_widget_show_all (background_data->background_window);
272
250
 
273
251
  /* This put in full screen; this will generate an exposure. */
274
252
  gtk_window_fullscreen (GTK_WINDOW (background_data->background_window));
279
257
 
280
258
/* Get the background type */
281
259
gint
282
 
get_background_type()
 
260
get_background_type          ()
283
261
{
284
262
  return background_data->background_type;
285
263
}
287
265
 
288
266
/* Get the background image */
289
267
gchar * 
290
 
get_background_image()
 
268
get_background_image         ()
291
269
{
292
270
  return background_data->background_image;
293
271
}
295
273
 
296
274
/* Get the background colour */
297
275
gchar * 
298
 
get_background_color()
 
276
get_background_color         ()
299
277
{
300
278
  return background_data->background_color;
301
279
}
303
281
 
304
282
/* Set the background type. */
305
283
void
306
 
set_background_type (gint type)
 
284
set_background_type          (gint type)
307
285
{
308
286
  background_data->background_type = type;
309
287
}
311
289
 
312
290
/* Set the background image. */
313
291
void
314
 
set_background_image (gchar *name)
 
292
set_background_image         (gchar *name)
315
293
{
316
294
  background_data->background_image = name;
317
295
}
319
297
 
320
298
/* Update the background image. */
321
299
void
322
 
update_background_image (gchar *name)
 
300
update_background_image      (gchar *name)
323
301
{
324
302
  set_background_image (name);
325
303
  load_file ();
328
306
 
329
307
/* Set the background colour. */
330
308
void
331
 
set_background_color (gchar* rgba)
 
309
set_background_color         (gchar* rgba)
332
310
{
333
311
  background_data->background_color = g_strdup_printf ("%s", rgba);
334
312
}
336
314
 
337
315
/* Update the background colour. */
338
316
void
339
 
update_background_color (gchar* rgba)
 
317
update_background_color      (gchar* rgba)
340
318
{
341
319
  set_background_color (rgba);
342
320
  load_color ();
345
323
 
346
324
/* Get the background window. */
347
325
GtkWidget *
348
 
get_background_window ()
 
326
get_background_window        ()
349
327
{
350
328
  return background_data->background_window;
351
329
}
353
331
 
354
332
/* Set the background window. */
355
333
void
356
 
set_background_window (GtkWidget *widget)
 
334
set_background_window        (GtkWidget *widget)
357
335
{
358
336
  background_data->background_window = widget;
359
337
}