static void cinnamon_tray_manager_child_on_realize (GtkWidget *widget, CinnamonTrayManagerChild *child) { /* If the tray child is using an RGBA colormap (and so we have real * transparency), we don't need to worry about the background. If * not, we obey the bg-color property by creating a cairo pattern of * that color and setting it as our background. Then "parent-relative" * background on the socket and the plug within that will cause * the icons contents to appear on top of our background color. */ if (!na_tray_child_has_alpha (NA_TRAY_CHILD (child->socket))) { ClutterColor color = child->manager->priv->bg_color; cairo_pattern_t *bg_pattern; bg_pattern = cairo_pattern_create_rgb (color.red / 255., color.green / 255., color.blue / 255.); gdk_window_set_background_pattern (gtk_widget_get_window (widget), bg_pattern); cairo_pattern_destroy (bg_pattern); } }
/* The plug window should completely occupy the area of the child, so we won't * get an expose event. But in case we do (the plug unmaps itself, say), this * expose handler draws with real or fake transparency. */ static gboolean na_tray_child_expose_event (GtkWidget *widget, GdkEventExpose *event) { NaTrayChild *child = NA_TRAY_CHILD (widget); GdkWindow *window = gtk_widget_get_window (widget); if (na_tray_child_has_alpha (child)) { /* Clear to transparent */ cairo_t *cr = gdk_cairo_create (window); cairo_set_source_rgba (cr, 0, 0, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); gdk_cairo_region (cr, event->region); cairo_fill (cr); cairo_destroy (cr); } else if (child->parent_relative_bg) { /* Clear to parent-relative pixmap */ gdk_window_clear_area (window, event->area.x, event->area.y, event->area.width, event->area.height); } return FALSE; }
na_tray_child_expose_event (GtkWidget *widget, GdkEventExpose *event) #endif { NaTrayChild *child = NA_TRAY_CHILD (widget); GdkWindow *window = gtk_widget_get_window (widget); if (na_tray_child_has_alpha (child)) { /* Clear to transparent */ #if !GTK_CHECK_VERSION (3, 0, 0) cairo_t *cr = gdk_cairo_create (window); #endif cairo_set_source_rgba (cr, 0, 0, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); #if GTK_CHECK_VERSION (3, 0, 0) cairo_paint (cr); #else gdk_cairo_region (cr, event->region); cairo_fill (cr); cairo_destroy (cr); #endif } else if (child->parent_relative_bg) { /* Clear to parent-relative pixmap */ #if GTK_CHECK_VERSION (3, 0, 0) GdkWindow *window; cairo_surface_t *target; GdkRectangle clip_rect; window = gtk_widget_get_window (widget); target = cairo_get_group_target (cr); gdk_cairo_get_clip_rectangle (cr, &clip_rect); /* Clear to parent-relative pixmap * We need to use direct X access here because GDK doesn't know about * the parent relative pixmap. */ cairo_surface_flush (target); XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height, False); cairo_surface_mark_dirty_rectangle (target, clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height); #else gdk_window_clear_area (window, event->area.x, event->area.y, event->area.width, event->area.height); #endif } return FALSE; }
static void na_tray_child_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { NaTrayChild *child = NA_TRAY_CHILD (widget); GtkAllocation widget_allocation; gboolean moved, resized; gtk_widget_get_allocation (widget, &widget_allocation); moved = (allocation->x != widget_allocation.x || allocation->y != widget_allocation.y); resized = (allocation->width != widget_allocation.width || allocation->height != widget_allocation.height); /* When we are allocating the widget while mapped we need special handling * for both real and fake transparency. * * Real transparency: we need to invalidate and trigger a redraw of the old * and new areas. (GDK really should handle this for us, but doesn't as of * GTK+-2.14) * * Fake transparency: if the widget moved, we need to force the contents to * be redrawn with the new offset for the parent-relative background. */ if ((moved || resized) && gtk_widget_get_mapped (widget)) { if (na_tray_child_has_alpha (child)) gdk_window_invalidate_rect (gdk_window_get_parent (gtk_widget_get_window (widget)), &widget_allocation, FALSE); } GTK_WIDGET_CLASS (na_tray_child_parent_class)->size_allocate (widget, allocation); if ((moved || resized) && gtk_widget_get_mapped (widget)) { if (na_tray_child_has_alpha (NA_TRAY_CHILD (widget))) gdk_window_invalidate_rect (gdk_window_get_parent (gtk_widget_get_window (widget)), &widget_allocation, FALSE); else if (moved && child->parent_relative_bg) na_tray_child_force_redraw (child); } }
/* The plug window should completely occupy the area of the child, so we won't * get a draw event. But in case we do (the plug unmaps itself, say), this * draw handler draws with real or fake transparency. */ static gboolean na_tray_child_draw (GtkWidget *widget, cairo_t *cr) { NaTrayChild *child = NA_TRAY_CHILD (widget); if (na_tray_child_has_alpha (child)) { /* Clear to transparent */ cairo_set_source_rgba (cr, 0, 0, 0, 0); cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); } else if (child->parent_relative_bg) { GdkWindow *window; cairo_surface_t *target; GdkRectangle clip_rect; window = gtk_widget_get_window (widget); target = cairo_get_group_target (cr); gdk_cairo_get_clip_rectangle (cr, &clip_rect); /* Clear to parent-relative pixmap * We need to use direct X access here because GDK doesn't know about * the parent relative pixmap. */ cairo_surface_flush (target); XClearArea (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window), clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height, False); cairo_surface_mark_dirty_rectangle (target, clip_rect.x, clip_rect.y, clip_rect.width, clip_rect.height); } return FALSE; }