static cairo_t * gdk_cairo_create (GdkDrawable *drawable) { int width, height; cairo_t *cr = NULL; cairo_surface_t *surface = NULL; GdkVisual *visual = gdk_drawable_get_visual (drawable); gdk_drawable_get_size (drawable, &width, &height); if (visual) surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable), GDK_VISUAL_XVISUAL (visual), width, height); else if (gdk_drawable_get_depth (drawable) == 1) surface = cairo_xlib_surface_create_for_bitmap (GDK_PIXMAP_XDISPLAY (drawable), GDK_PIXMAP_XID (drawable), GDK_SCREEN_XSCREEN (gdk_drawable_get_screen (drawable)), width, height); else { g_warning ("Using Cairo rendering requires the drawable argument to\n" "have a specified colormap. All windows have a colormap,\n" "however, pixmaps only have colormap by default if they\n" "were created with a non-NULL window argument. Otherwise\n" "a colormap must be set on them with " "gdk_drawable_set_colormap"); return NULL; } if (surface) { cr = cairo_create (surface); cairo_surface_destroy (surface); } return cr; }
GdkPixbuf* meta_gdk_pixbuf_get_from_pixmap (GdkPixbuf *dest, Pixmap xpixmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height) { cairo_surface_t *surface; Display *display; Window root_return; int x_ret, y_ret; unsigned int w_ret, h_ret, bw_ret, depth_ret; XWindowAttributes attrs; GdkPixbuf *retval; display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); if (!XGetGeometry (display, xpixmap, &root_return, &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret)) return NULL; if (depth_ret == 1) { surface = cairo_xlib_surface_create_for_bitmap (display, xpixmap, GDK_SCREEN_XSCREEN (gdk_screen_get_default ()), w_ret, h_ret); } else { if (!XGetWindowAttributes (display, root_return, &attrs)) return NULL; surface = cairo_xlib_surface_create (display, xpixmap, attrs.visual, w_ret, h_ret); } retval = gdk_pixbuf_get_from_surface (surface, src_x, src_y, width, height); cairo_surface_destroy (surface); return retval; }