~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to applets/notification_area/na-tray-child.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-30 11:04:49 UTC
  • mfrom: (1.3.4 upstream)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: james.westby@ubuntu.com-20110530110449-ut1tc5t61rpvf9e3
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "na-tray-child.h"
26
26
 
27
 
#include <glib/gi18n.h>
28
27
#include <gdk/gdk.h>
29
28
#include <gdk/gdkx.h>
30
29
#include <X11/Xatom.h>
54
53
       * extension. */
55
54
 
56
55
      /* Set a transparent background */
57
 
      GdkColor transparent = { 0, 0, 0, 0 }; /* only pixel=0 matters */
58
 
      gdk_window_set_background (window, &transparent);
 
56
      cairo_pattern_t *transparent = cairo_pattern_create_rgba (0, 0, 0, 0);
 
57
      gdk_window_set_background_pattern (window, transparent);
59
58
      gdk_window_set_composited (window, TRUE);
 
59
      cairo_pattern_destroy (transparent);
60
60
 
61
61
      child->parent_relative_bg = FALSE;
62
62
    }
63
 
  else if (visual == gdk_drawable_get_visual (GDK_DRAWABLE (gdk_window_get_parent (window))))
 
63
  else if (visual == gdk_window_get_visual (gdk_window_get_parent (window)))
64
64
    {
65
65
      /* Otherwise, if the visual matches the visual of the parent window, we
66
66
       * can use a parent-relative background and fake transparency. */
67
 
      gdk_window_set_back_pixmap (window, NULL, TRUE);
 
67
      gdk_window_set_background_pattern (window, NULL);
68
68
 
69
69
      child->parent_relative_bg = TRUE;
70
70
    }
172
172
}
173
173
 
174
174
/* The plug window should completely occupy the area of the child, so we won't
175
 
 * get an expose event. But in case we do (the plug unmaps itself, say), this
176
 
 * expose handler draws with real or fake transparency.
 
175
 * get a draw event. But in case we do (the plug unmaps itself, say), this
 
176
 * draw handler draws with real or fake transparency.
177
177
 */
178
178
static gboolean
179
 
na_tray_child_expose_event (GtkWidget      *widget,
180
 
                            GdkEventExpose *event)
 
179
na_tray_child_draw (GtkWidget *widget,
 
180
                    cairo_t   *cr)
181
181
{
182
182
  NaTrayChild *child = NA_TRAY_CHILD (widget);
183
 
  GdkWindow *window = gtk_widget_get_window (widget);
184
183
 
185
184
  if (na_tray_child_has_alpha (child))
186
185
    {
187
186
      /* Clear to transparent */
188
 
      cairo_t *cr = gdk_cairo_create (window);
189
187
      cairo_set_source_rgba (cr, 0, 0, 0, 0);
190
188
      cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
191
 
      gdk_cairo_region (cr, event->region);
192
 
      cairo_fill (cr);
193
 
      cairo_destroy (cr);
 
189
      cairo_paint (cr);
194
190
    }
195
191
  else if (child->parent_relative_bg)
196
192
    {
197
 
      /* Clear to parent-relative pixmap */
198
 
      gdk_window_clear_area (window,
199
 
                             event->area.x, event->area.y,
200
 
                             event->area.width, event->area.height);
 
193
      GdkWindow *window;
 
194
      cairo_surface_t *target;
 
195
      GdkRectangle clip_rect;
 
196
 
 
197
      window = gtk_widget_get_window (widget);
 
198
      target = cairo_get_group_target (cr);
 
199
 
 
200
      gdk_cairo_get_clip_rectangle (cr, &clip_rect);
 
201
 
 
202
      /* Clear to parent-relative pixmap
 
203
       * We need to use direct X access here because GDK doesn't know about
 
204
       * the parent relative pixmap. */
 
205
      cairo_surface_flush (target);
 
206
 
 
207
      XClearArea (GDK_WINDOW_XDISPLAY (window),
 
208
                  GDK_WINDOW_XID (window),
 
209
                  clip_rect.x, clip_rect.y,
 
210
                  clip_rect.width, clip_rect.height,
 
211
                  False);
 
212
      cairo_surface_mark_dirty_rectangle (target,
 
213
                                          clip_rect.x, clip_rect.y,
 
214
                                          clip_rect.width, clip_rect.height);
201
215
    }
202
216
 
203
217
  return FALSE;
221
235
  widget_class->style_set = na_tray_child_style_set;
222
236
  widget_class->realize = na_tray_child_realize;
223
237
  widget_class->size_allocate = na_tray_child_size_allocate;
224
 
  widget_class->expose_event = na_tray_child_expose_event;
 
238
  widget_class->draw = na_tray_child_draw;
225
239
}
226
240
 
227
241
GtkWidget *
233
247
  NaTrayChild *child;
234
248
  GdkVisual *visual;
235
249
  gboolean visual_has_alpha;
236
 
  GdkColormap *colormap;
237
 
  gboolean new_colormap;
238
250
  int red_prec, green_prec, blue_prec, depth;
239
251
  int result;
240
252
 
250
262
  gdk_error_trap_push ();
251
263
  result = XGetWindowAttributes (xdisplay, icon_window,
252
264
                                 &window_attributes);
253
 
  gdk_error_trap_pop ();
 
265
  gdk_error_trap_pop_ignored ();
254
266
 
255
267
  if (!result) /* Window already gone */
256
268
    return NULL;
260
272
  if (!visual) /* Icon window is on another screen? */
261
273
    return NULL;
262
274
 
263
 
  new_colormap = FALSE;
264
 
 
265
 
  if (visual == gdk_screen_get_rgb_visual (screen))
266
 
    colormap = gdk_screen_get_rgb_colormap (screen);
267
 
  else if (visual == gdk_screen_get_rgba_visual (screen))
268
 
    colormap = gdk_screen_get_rgba_colormap (screen);
269
 
  else if (visual == gdk_screen_get_system_visual (screen))
270
 
    colormap = gdk_screen_get_system_colormap (screen);
271
 
  else
272
 
    {
273
 
      colormap = gdk_colormap_new (visual, FALSE);
274
 
      new_colormap = TRUE;
275
 
    }
276
 
 
277
275
  child = g_object_new (NA_TYPE_TRAY_CHILD, NULL);
278
276
  child->icon_window = icon_window;
279
277
 
280
 
  gtk_widget_set_colormap (GTK_WIDGET (child), colormap);
 
278
  gtk_widget_set_visual (GTK_WIDGET (child), visual);
281
279
 
282
280
  /* We have alpha if the visual has something other than red, green,
283
281
   * and blue */
292
290
 
293
291
  child->composited = child->has_alpha;
294
292
 
295
 
  if (new_colormap)
296
 
    g_object_unref (colormap);
297
 
 
298
293
  return GTK_WIDGET (child);
299
294
}
300
295
 
422
417
      gtk_widget_get_allocation (widget, &allocation);
423
418
 
424
419
      xev.xexpose.type = Expose;
425
 
      xev.xexpose.window = GDK_WINDOW_XWINDOW (plug_window);
 
420
      xev.xexpose.window = GDK_WINDOW_XID (plug_window);
426
421
      xev.xexpose.x = 0;
427
422
      xev.xexpose.y = 0;
428
423
      xev.xexpose.width = allocation.width;
430
425
      xev.xexpose.count = 0;
431
426
 
432
427
      gdk_error_trap_push ();
433
 
      XSendEvent (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget)),
 
428
      XSendEvent (xdisplay,
434
429
                  xev.xexpose.window,
435
430
                  False, ExposureMask,
436
431
                  &xev);
437
 
      /* We have to sync to reliably catch errors from the XSendEvent(),
438
 
       * since that is asynchronous.
439
 
       */
440
 
      XSync (xdisplay, False);
441
 
      gdk_error_trap_pop ();
 
432
      gdk_error_trap_pop_ignored ();
442
433
#else
443
434
      /* Hiding and showing is the safe way to do it, but can result in more
444
435
       * flickering.
482
473
 
483
474
  gdk_error_trap_push ();
484
475
  XGetClassHint (xdisplay, xwindow, &ch);
485
 
  gdk_error_trap_pop ();
 
476
  gdk_error_trap_pop_ignored ();
486
477
 
487
478
  if (res_class)
488
479
    *res_class = NULL;