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);
131 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
133 if (draw_impl->picture)
134 XRenderFreePicture (GDK_PIXMAP_XDISPLAY (wrapper), draw_impl->picture);
136 #endif /* HAVE_XFT */
138 if (!impl->is_foreign)
139 XFreePixmap (GDK_PIXMAP_XDISPLAY (wrapper), GDK_PIXMAP_XID (wrapper));
141 _gdk_xid_table_remove (GDK_PIXMAP_DISPLAY (wrapper), GDK_PIXMAP_XID (wrapper));
143 G_OBJECT_CLASS (parent_class)->finalize (object);
147 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
152 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
154 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
158 gdk_pixmap_new (GdkWindow *window,
164 GdkDrawableImplX11 *draw_impl;
165 GdkPixmapImplX11 *pix_impl;
169 g_return_val_if_fail (window == NULL || GDK_IS_DRAWABLE (window), NULL);
170 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
171 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
175 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
176 "for gdk_pixmap_new() to be multihead safe"));
177 window = gdk_screen_get_root_window (gdk_screen_get_default ());
180 if (GDK_IS_WINDOW (window) && GDK_WINDOW_DESTROYED (window))
183 window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
185 depth = window_depth;
187 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
188 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
189 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
190 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
192 draw_impl->screen = GDK_WINDOW_SCREEN (window);
193 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
194 GDK_WINDOW_XID (window),
195 width, height, depth);
197 pix_impl->is_foreign = FALSE;
198 pix_impl->width = width;
199 pix_impl->height = height;
200 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
202 if (depth == window_depth)
204 cmap = gdk_drawable_get_colormap (window);
206 gdk_drawable_set_colormap (pixmap, cmap);
209 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (window),
210 &GDK_PIXMAP_XID (pixmap), pixmap);
215 gdk_bitmap_create_from_data (GdkWindow *window,
221 GdkDrawableImplX11 *draw_impl;
222 GdkPixmapImplX11 *pix_impl;
224 g_return_val_if_fail (data != NULL, NULL);
225 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
226 g_return_val_if_fail (window == NULL || GDK_IS_DRAWABLE (window), NULL);
230 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
231 "for gdk_bitmap_create_from_data() to be multihead safe"));
232 window = gdk_screen_get_root_window (gdk_screen_get_default ());
235 if (GDK_IS_WINDOW (window) && GDK_WINDOW_DESTROYED (window))
238 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
239 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
240 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
241 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
243 pix_impl->is_foreign = FALSE;
244 pix_impl->width = width;
245 pix_impl->height = height;
246 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
248 draw_impl->screen = GDK_WINDOW_SCREEN (window);
249 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (window),
250 GDK_WINDOW_XID (window),
251 (char *)data, width, height);
253 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (window),
254 &GDK_PIXMAP_XID (pixmap), pixmap);
259 gdk_pixmap_create_from_data (GdkWindow *window,
268 GdkDrawableImplX11 *draw_impl;
269 GdkPixmapImplX11 *pix_impl;
271 g_return_val_if_fail (window == NULL || GDK_IS_DRAWABLE (window), NULL);
272 g_return_val_if_fail (data != NULL, NULL);
273 g_return_val_if_fail (fg != NULL, NULL);
274 g_return_val_if_fail (bg != NULL, NULL);
275 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
276 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
280 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window"
281 "for gdk_pixmap_create_from_data() to be multihead safe"));
282 window = gdk_screen_get_root_window (gdk_screen_get_default ());
285 if (GDK_IS_WINDOW (window) && GDK_WINDOW_DESTROYED (window))
289 depth = gdk_drawable_get_visual (window)->depth;
291 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
292 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
293 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
294 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
296 pix_impl->is_foreign = FALSE;
297 pix_impl->width = width;
298 pix_impl->height = height;
299 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
301 draw_impl->screen = GDK_DRAWABLE_SCREEN (window);
302 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (window),
303 GDK_WINDOW_XID (window),
304 (char *)data, width, height,
305 fg->pixel, bg->pixel, depth);
307 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (window),
308 &GDK_PIXMAP_XID (pixmap), pixmap);
313 * gdk_pixmap_foreign_new_for_display:
314 * @display: The #GdkDisplay where @anid is located.
315 * @anid: a native pixmap handle.
317 * Wraps a native window in a #GdkPixmap.
318 * This may fail if the pixmap has been destroyed.
320 * For example in the X backend, a native pixmap handle is an Xlib
323 * Return value: the newly-created #GdkPixmap wrapper for the
324 * native pixmap or %NULL if the pixmap has been destroyed.
327 gdk_pixmap_foreign_new_for_display (GdkDisplay *display,
328 GdkNativeWindow anid)
331 GdkDrawableImplX11 *draw_impl;
332 GdkPixmapImplX11 *pix_impl;
336 unsigned int w_ret, h_ret, bw_ret, depth_ret;
338 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
340 /* check to make sure we were passed something at
341 * least a little sane */
342 g_return_val_if_fail ((anid != 0), NULL);
344 /* set the pixmap to the passed in value */
347 /* get information about the Pixmap to fill in the structure for
349 if (!XGetGeometry (GDK_DISPLAY_XDISPLAY (display),
350 xpixmap, &root_return,
351 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
354 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
355 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
356 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
357 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
359 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root_return);
360 draw_impl->xid = xpixmap;
362 pix_impl->is_foreign = TRUE;
363 pix_impl->width = w_ret;
364 pix_impl->height = h_ret;
365 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
367 _gdk_xid_table_insert (display, &GDK_PIXMAP_XID (pixmap), pixmap);
373 * gdk_pixmap_foreign_new:
374 * @anid: a native pixmap handle.
376 * Wraps a native window for the default display in a #GdkPixmap.
377 * This may fail if the pixmap has been destroyed.
379 * For example in the X backend, a native pixmap handle is an Xlib
382 * Return value: the newly-created #GdkPixmap wrapper for the
383 * native pixmap or %NULL if the pixmap has been destroyed.
386 gdk_pixmap_foreign_new (GdkNativeWindow anid)
388 return gdk_pixmap_foreign_new_for_display (gdk_display_get_default (), anid);
393 * @anid: a native pixmap handle.
395 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
397 * For example in the X backend, a native pixmap handle is an Xlib
400 * Return value: the #GdkWindow wrapper for the native window,
401 * or %NULL if there is none.
404 gdk_pixmap_lookup (GdkNativeWindow anid)
406 return (GdkPixmap*) gdk_xid_table_lookup_for_display (gdk_display_get_default (), anid);
410 * gdk_pixmap_lookup_for_display:
411 * @display : the #GdkDisplay associated with @anid
412 * @anid: a native pixmap handle.
414 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
416 * For example in the X backend, a native pixmap handle is an Xlib
419 * Return value: the #GdkWindow wrapper for the native window,
420 * or %NULL if there is none.
423 gdk_pixmap_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
425 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
426 return (GdkPixmap*) gdk_xid_table_lookup_for_display (display, anid);