1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 /* Needed for SEEK_END in SunOS */
37 #include "gdkpixmap-x11.h"
38 #include "gdkprivate-x11.h"
39 #include "gdkscreen-x11.h"
40 #include "gdkdisplay-x11.h"
42 #include <gdk/gdkinternals.h>
54 GdkColormap *colormap;
58 static void gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
62 static void gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *pixmap);
63 static void gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass);
64 static void gdk_pixmap_impl_x11_finalize (GObject *object);
66 static gpointer parent_class = NULL;
69 gdk_pixmap_impl_x11_get_type (void)
71 static GType object_type = 0;
75 static const GTypeInfo object_info =
77 sizeof (GdkPixmapImplX11Class),
79 (GBaseFinalizeFunc) NULL,
80 (GClassInitFunc) gdk_pixmap_impl_x11_class_init,
81 NULL, /* class_finalize */
82 NULL, /* class_data */
83 sizeof (GdkPixmapImplX11),
85 (GInstanceInitFunc) gdk_pixmap_impl_x11_init,
88 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
98 _gdk_pixmap_impl_get_type (void)
100 return gdk_pixmap_impl_x11_get_type ();
104 gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *impl)
111 gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass)
113 GObjectClass *object_class = G_OBJECT_CLASS (klass);
114 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
116 parent_class = g_type_class_peek_parent (klass);
118 object_class->finalize = gdk_pixmap_impl_x11_finalize;
120 drawable_class->get_size = gdk_pixmap_impl_x11_get_size;
124 gdk_pixmap_impl_x11_finalize (GObject *object)
126 GdkPixmapImplX11 *impl = GDK_PIXMAP_IMPL_X11 (object);
127 GdkPixmap *wrapper = GDK_PIXMAP (GDK_DRAWABLE_IMPL_X11 (impl)->wrapper);
128 GdkDisplay *display = GDK_PIXMAP_DISPLAY (wrapper);
130 if (!display->closed)
134 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
137 if (draw_impl->xft_draw)
138 XftDrawDestroy (draw_impl->xft_draw);
139 #else /* !HAVE_XFT2 */
140 if (draw_impl->picture)
141 XRenderFreePicture (GDK_DISPLAY_XDISPLAY (display), draw_impl->picture);
142 #endif /* HAVE_XFT2 */
144 #endif /* HAVE_XFT */
146 if (!impl->is_foreign)
147 XFreePixmap (GDK_DISPLAY_XDISPLAY (display), GDK_PIXMAP_XID (wrapper));
150 _gdk_xid_table_remove (display, GDK_PIXMAP_XID (wrapper));
152 G_OBJECT_CLASS (parent_class)->finalize (object);
156 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
161 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
163 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
167 gdk_pixmap_new (GdkDrawable *drawable,
173 GdkDrawableImplX11 *draw_impl;
174 GdkPixmapImplX11 *pix_impl;
178 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
179 g_return_val_if_fail ((drawable != NULL) || (depth != -1), NULL);
180 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
184 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
185 "for gdk_pixmap_new() to be multihead safe"));
186 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
189 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
192 window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (drawable));
194 depth = window_depth;
196 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
197 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
198 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
199 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
201 draw_impl->screen = GDK_WINDOW_SCREEN (drawable);
202 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
203 GDK_WINDOW_XID (drawable),
204 width, height, depth);
206 pix_impl->is_foreign = FALSE;
207 pix_impl->width = width;
208 pix_impl->height = height;
209 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
211 if (depth == window_depth)
213 cmap = gdk_drawable_get_colormap (drawable);
215 gdk_drawable_set_colormap (pixmap, cmap);
218 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
219 &GDK_PIXMAP_XID (pixmap), pixmap);
224 gdk_bitmap_create_from_data (GdkDrawable *drawable,
230 GdkDrawableImplX11 *draw_impl;
231 GdkPixmapImplX11 *pix_impl;
233 g_return_val_if_fail (data != NULL, NULL);
234 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
235 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
239 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
240 "for gdk_bitmap_create_from_data() to be multihead safe"));
241 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
244 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
247 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
248 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
249 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
250 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
252 pix_impl->is_foreign = FALSE;
253 pix_impl->width = width;
254 pix_impl->height = height;
255 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
257 draw_impl->screen = GDK_WINDOW_SCREEN (drawable);
258 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (drawable),
259 GDK_WINDOW_XID (drawable),
260 (char *)data, width, height);
262 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
263 &GDK_PIXMAP_XID (pixmap), pixmap);
268 gdk_pixmap_create_from_data (GdkDrawable *drawable,
277 GdkDrawableImplX11 *draw_impl;
278 GdkPixmapImplX11 *pix_impl;
280 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
281 g_return_val_if_fail (data != NULL, NULL);
282 g_return_val_if_fail (fg != NULL, NULL);
283 g_return_val_if_fail (bg != NULL, NULL);
284 g_return_val_if_fail ((drawable != NULL) || (depth != -1), NULL);
285 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
289 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window"
290 "for gdk_pixmap_create_from_data() to be multihead safe"));
291 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
294 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
298 depth = gdk_drawable_get_visual (drawable)->depth;
300 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
301 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
302 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
303 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
305 pix_impl->is_foreign = FALSE;
306 pix_impl->width = width;
307 pix_impl->height = height;
308 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
310 draw_impl->screen = GDK_DRAWABLE_SCREEN (drawable);
311 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (drawable),
312 GDK_WINDOW_XID (drawable),
313 (char *)data, width, height,
314 fg->pixel, bg->pixel, depth);
316 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
317 &GDK_PIXMAP_XID (pixmap), pixmap);
322 * gdk_pixmap_foreign_new_for_display:
323 * @display: The #GdkDisplay where @anid is located.
324 * @anid: a native pixmap handle.
326 * Wraps a native pixmap in a #GdkPixmap.
327 * This may fail if the pixmap has been destroyed.
329 * For example in the X backend, a native pixmap handle is an Xlib
332 * Return value: the newly-created #GdkPixmap wrapper for the
333 * native pixmap or %NULL if the pixmap has been destroyed.
338 gdk_pixmap_foreign_new_for_display (GdkDisplay *display,
339 GdkNativeWindow anid)
342 GdkDrawableImplX11 *draw_impl;
343 GdkPixmapImplX11 *pix_impl;
347 unsigned int w_ret, h_ret, bw_ret, depth_ret;
349 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
351 /* check to make sure we were passed something at
352 * least a little sane */
353 g_return_val_if_fail ((anid != 0), NULL);
355 /* set the pixmap to the passed in value */
358 /* get information about the Pixmap to fill in the structure for
360 if (!XGetGeometry (GDK_DISPLAY_XDISPLAY (display),
361 xpixmap, &root_return,
362 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
365 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
366 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
367 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
368 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
370 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root_return);
371 draw_impl->xid = xpixmap;
373 pix_impl->is_foreign = TRUE;
374 pix_impl->width = w_ret;
375 pix_impl->height = h_ret;
376 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
378 _gdk_xid_table_insert (display, &GDK_PIXMAP_XID (pixmap), pixmap);
384 * gdk_pixmap_foreign_new:
385 * @anid: a native pixmap handle.
387 * Wraps a native window for the default display in a #GdkPixmap.
388 * This may fail if the pixmap has been destroyed.
390 * For example in the X backend, a native pixmap handle is an Xlib
393 * Return value: the newly-created #GdkPixmap wrapper for the
394 * native pixmap or %NULL if the pixmap has been destroyed.
397 gdk_pixmap_foreign_new (GdkNativeWindow anid)
399 return gdk_pixmap_foreign_new_for_display (gdk_display_get_default (), anid);
404 * @anid: a native pixmap handle.
406 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
408 * For example in the X backend, a native pixmap handle is an Xlib
411 * Return value: the #GdkWindow wrapper for the native window,
412 * or %NULL if there is none.
415 gdk_pixmap_lookup (GdkNativeWindow anid)
417 return (GdkPixmap*) gdk_xid_table_lookup_for_display (gdk_display_get_default (), anid);
421 * gdk_pixmap_lookup_for_display:
422 * @display: the #GdkDisplay associated with @anid
423 * @anid: a native pixmap handle.
425 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
427 * For example in the X backend, a native pixmap handle is an Xlib
430 * Return value: the #GdkPixmap wrapper for the native pixmap,
431 * or %NULL if there is none.
436 gdk_pixmap_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
438 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
439 return (GdkPixmap*) gdk_xid_table_lookup_for_display (display, anid);