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>
55 GdkColormap *colormap;
59 static void gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
63 static void gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *pixmap);
64 static void gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass);
65 static void gdk_pixmap_impl_x11_finalize (GObject *object);
67 static gpointer parent_class = NULL;
70 gdk_pixmap_impl_x11_get_type (void)
72 static GType object_type = 0;
76 static const GTypeInfo object_info =
78 sizeof (GdkPixmapImplX11Class),
80 (GBaseFinalizeFunc) NULL,
81 (GClassInitFunc) gdk_pixmap_impl_x11_class_init,
82 NULL, /* class_finalize */
83 NULL, /* class_data */
84 sizeof (GdkPixmapImplX11),
86 (GInstanceInitFunc) gdk_pixmap_impl_x11_init,
89 object_type = g_type_register_static (GDK_TYPE_DRAWABLE_IMPL_X11,
99 _gdk_pixmap_impl_get_type (void)
101 return gdk_pixmap_impl_x11_get_type ();
105 gdk_pixmap_impl_x11_init (GdkPixmapImplX11 *impl)
112 gdk_pixmap_impl_x11_class_init (GdkPixmapImplX11Class *klass)
114 GObjectClass *object_class = G_OBJECT_CLASS (klass);
115 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
117 parent_class = g_type_class_peek_parent (klass);
119 object_class->finalize = gdk_pixmap_impl_x11_finalize;
121 drawable_class->get_size = gdk_pixmap_impl_x11_get_size;
125 gdk_pixmap_impl_x11_finalize (GObject *object)
127 GdkPixmapImplX11 *impl = GDK_PIXMAP_IMPL_X11 (object);
128 GdkPixmap *wrapper = GDK_PIXMAP (GDK_DRAWABLE_IMPL_X11 (impl)->wrapper);
129 GdkDisplay *display = GDK_PIXMAP_DISPLAY (wrapper);
131 if (!display->closed)
133 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
135 if (draw_impl->xft_draw)
136 XftDrawDestroy (draw_impl->xft_draw);
138 if (draw_impl->cairo_surface)
140 cairo_surface_destroy (draw_impl->cairo_surface);
141 draw_impl->cairo_surface = NULL;
144 if (!impl->is_foreign)
145 XFreePixmap (GDK_DISPLAY_XDISPLAY (display), GDK_PIXMAP_XID (wrapper));
148 _gdk_xid_table_remove (display, GDK_PIXMAP_XID (wrapper));
150 G_OBJECT_CLASS (parent_class)->finalize (object);
154 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
159 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
161 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
165 gdk_pixmap_new (GdkDrawable *drawable,
171 GdkDrawableImplX11 *draw_impl;
172 GdkPixmapImplX11 *pix_impl;
176 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
177 g_return_val_if_fail ((drawable != NULL) || (depth != -1), NULL);
178 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
182 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
183 "for gdk_pixmap_new() to be multihead safe"));
184 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
187 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
190 window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (drawable));
192 depth = window_depth;
194 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
195 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
196 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
197 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
199 draw_impl->screen = GDK_WINDOW_SCREEN (drawable);
200 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
201 GDK_WINDOW_XID (drawable),
202 width, height, depth);
204 pix_impl->is_foreign = FALSE;
205 pix_impl->width = width;
206 pix_impl->height = height;
207 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
209 if (depth == window_depth)
211 cmap = gdk_drawable_get_colormap (drawable);
213 gdk_drawable_set_colormap (pixmap, cmap);
216 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
217 &GDK_PIXMAP_XID (pixmap), pixmap);
222 gdk_bitmap_create_from_data (GdkDrawable *drawable,
228 GdkDrawableImplX11 *draw_impl;
229 GdkPixmapImplX11 *pix_impl;
231 g_return_val_if_fail (data != NULL, NULL);
232 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
233 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
237 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
238 "for gdk_bitmap_create_from_data() to be multihead safe"));
239 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
242 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
245 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
246 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
247 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
248 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
250 pix_impl->is_foreign = FALSE;
251 pix_impl->width = width;
252 pix_impl->height = height;
253 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
255 draw_impl->screen = GDK_WINDOW_SCREEN (drawable);
256 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (drawable),
257 GDK_WINDOW_XID (drawable),
258 (char *)data, width, height);
260 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
261 &GDK_PIXMAP_XID (pixmap), pixmap);
266 gdk_pixmap_create_from_data (GdkDrawable *drawable,
275 GdkDrawableImplX11 *draw_impl;
276 GdkPixmapImplX11 *pix_impl;
278 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
279 g_return_val_if_fail (data != NULL, NULL);
280 g_return_val_if_fail (fg != NULL, NULL);
281 g_return_val_if_fail (bg != NULL, NULL);
282 g_return_val_if_fail ((drawable != NULL) || (depth != -1), NULL);
283 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
287 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window"
288 "for gdk_pixmap_create_from_data() to be multihead safe"));
289 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
292 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
296 depth = gdk_drawable_get_visual (drawable)->depth;
298 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
299 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
300 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
301 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
303 pix_impl->is_foreign = FALSE;
304 pix_impl->width = width;
305 pix_impl->height = height;
306 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
308 draw_impl->screen = GDK_DRAWABLE_SCREEN (drawable);
309 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (drawable),
310 GDK_WINDOW_XID (drawable),
311 (char *)data, width, height,
312 fg->pixel, bg->pixel, depth);
314 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
315 &GDK_PIXMAP_XID (pixmap), pixmap);
320 * gdk_pixmap_foreign_new_for_display:
321 * @display: The #GdkDisplay where @anid is located.
322 * @anid: a native pixmap handle.
324 * Wraps a native pixmap in a #GdkPixmap.
325 * This may fail if the pixmap has been destroyed.
327 * For example in the X backend, a native pixmap handle is an Xlib
330 * Return value: the newly-created #GdkPixmap wrapper for the
331 * native pixmap or %NULL if the pixmap has been destroyed.
336 gdk_pixmap_foreign_new_for_display (GdkDisplay *display,
337 GdkNativeWindow anid)
340 GdkDrawableImplX11 *draw_impl;
341 GdkPixmapImplX11 *pix_impl;
345 unsigned int w_ret, h_ret, bw_ret, depth_ret;
347 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
349 /* check to make sure we were passed something at
350 * least a little sane */
351 g_return_val_if_fail ((anid != 0), NULL);
353 /* set the pixmap to the passed in value */
356 /* get information about the Pixmap to fill in the structure for
358 if (!XGetGeometry (GDK_DISPLAY_XDISPLAY (display),
359 xpixmap, &root_return,
360 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
363 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
364 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
365 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
366 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
368 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root_return);
369 draw_impl->xid = xpixmap;
371 pix_impl->is_foreign = TRUE;
372 pix_impl->width = w_ret;
373 pix_impl->height = h_ret;
374 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
376 _gdk_xid_table_insert (display, &GDK_PIXMAP_XID (pixmap), pixmap);
382 * gdk_pixmap_foreign_new:
383 * @anid: a native pixmap handle.
385 * Wraps a native window for the default display in a #GdkPixmap.
386 * This may fail if the pixmap has been destroyed.
388 * For example in the X backend, a native pixmap handle is an Xlib
391 * Return value: the newly-created #GdkPixmap wrapper for the
392 * native pixmap or %NULL if the pixmap has been destroyed.
395 gdk_pixmap_foreign_new (GdkNativeWindow anid)
397 return gdk_pixmap_foreign_new_for_display (gdk_display_get_default (), anid);
402 * @anid: a native pixmap handle.
404 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
406 * For example in the X backend, a native pixmap handle is an Xlib
409 * Return value: the #GdkWindow wrapper for the native window,
410 * or %NULL if there is none.
413 gdk_pixmap_lookup (GdkNativeWindow anid)
415 return (GdkPixmap*) gdk_xid_table_lookup_for_display (gdk_display_get_default (), anid);
419 * gdk_pixmap_lookup_for_display:
420 * @display: the #GdkDisplay associated with @anid
421 * @anid: a native pixmap handle.
423 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
425 * For example in the X backend, a native pixmap handle is an Xlib
428 * Return value: the #GdkPixmap wrapper for the native pixmap,
429 * or %NULL if there is none.
434 gdk_pixmap_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
436 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
437 return (GdkPixmap*) gdk_xid_table_lookup_for_display (display, anid);
440 #define __GDK_PIXMAP_X11_C__
441 #include "gdkaliasdef.c"