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);
136 if (draw_impl->xft_draw)
137 XftDrawDestroy (draw_impl->xft_draw);
139 #endif /* HAVE_XFT */
141 if (!impl->is_foreign)
142 XFreePixmap (GDK_DISPLAY_XDISPLAY (display), GDK_PIXMAP_XID (wrapper));
145 _gdk_xid_table_remove (display, GDK_PIXMAP_XID (wrapper));
147 G_OBJECT_CLASS (parent_class)->finalize (object);
151 gdk_pixmap_impl_x11_get_size (GdkDrawable *drawable,
156 *width = GDK_PIXMAP_IMPL_X11 (drawable)->width;
158 *height = GDK_PIXMAP_IMPL_X11 (drawable)->height;
162 gdk_pixmap_new (GdkWindow *window,
168 GdkDrawableImplX11 *draw_impl;
169 GdkPixmapImplX11 *pix_impl;
173 g_return_val_if_fail (window == NULL || GDK_IS_DRAWABLE (window), NULL);
174 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
175 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
179 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
180 "for gdk_pixmap_new() to be multihead safe"));
181 window = gdk_screen_get_root_window (gdk_screen_get_default ());
184 if (GDK_IS_WINDOW (window) && GDK_WINDOW_DESTROYED (window))
187 window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
189 depth = window_depth;
191 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
192 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
193 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
194 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
196 draw_impl->screen = GDK_WINDOW_SCREEN (window);
197 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
198 GDK_WINDOW_XID (window),
199 width, height, depth);
201 pix_impl->is_foreign = FALSE;
202 pix_impl->width = width;
203 pix_impl->height = height;
204 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
206 if (depth == window_depth)
208 cmap = gdk_drawable_get_colormap (window);
210 gdk_drawable_set_colormap (pixmap, cmap);
213 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (window),
214 &GDK_PIXMAP_XID (pixmap), pixmap);
219 gdk_bitmap_create_from_data (GdkWindow *window,
225 GdkDrawableImplX11 *draw_impl;
226 GdkPixmapImplX11 *pix_impl;
228 g_return_val_if_fail (data != NULL, NULL);
229 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
230 g_return_val_if_fail (window == NULL || GDK_IS_DRAWABLE (window), NULL);
234 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window "
235 "for gdk_bitmap_create_from_data() to be multihead safe"));
236 window = gdk_screen_get_root_window (gdk_screen_get_default ());
239 if (GDK_IS_WINDOW (window) && GDK_WINDOW_DESTROYED (window))
242 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
243 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
244 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
245 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
247 pix_impl->is_foreign = FALSE;
248 pix_impl->width = width;
249 pix_impl->height = height;
250 GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
252 draw_impl->screen = GDK_WINDOW_SCREEN (window);
253 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (window),
254 GDK_WINDOW_XID (window),
255 (char *)data, width, height);
257 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (window),
258 &GDK_PIXMAP_XID (pixmap), pixmap);
263 gdk_pixmap_create_from_data (GdkWindow *window,
272 GdkDrawableImplX11 *draw_impl;
273 GdkPixmapImplX11 *pix_impl;
275 g_return_val_if_fail (window == NULL || GDK_IS_DRAWABLE (window), NULL);
276 g_return_val_if_fail (data != NULL, NULL);
277 g_return_val_if_fail (fg != NULL, NULL);
278 g_return_val_if_fail (bg != NULL, NULL);
279 g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
280 g_return_val_if_fail ((width != 0) && (height != 0), NULL);
284 GDK_NOTE (MULTIHEAD, g_message ("need to specify the screen parent window"
285 "for gdk_pixmap_create_from_data() to be multihead safe"));
286 window = gdk_screen_get_root_window (gdk_screen_get_default ());
289 if (GDK_IS_WINDOW (window) && GDK_WINDOW_DESTROYED (window))
293 depth = gdk_drawable_get_visual (window)->depth;
295 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
296 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
297 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
298 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
300 pix_impl->is_foreign = FALSE;
301 pix_impl->width = width;
302 pix_impl->height = height;
303 GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
305 draw_impl->screen = GDK_DRAWABLE_SCREEN (window);
306 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (window),
307 GDK_WINDOW_XID (window),
308 (char *)data, width, height,
309 fg->pixel, bg->pixel, depth);
311 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (window),
312 &GDK_PIXMAP_XID (pixmap), pixmap);
317 * gdk_pixmap_foreign_new_for_display:
318 * @display: The #GdkDisplay where @anid is located.
319 * @anid: a native pixmap handle.
321 * Wraps a native window in a #GdkPixmap.
322 * This may fail if the pixmap has been destroyed.
324 * For example in the X backend, a native pixmap handle is an Xlib
327 * Return value: the newly-created #GdkPixmap wrapper for the
328 * native pixmap or %NULL if the pixmap has been destroyed.
331 gdk_pixmap_foreign_new_for_display (GdkDisplay *display,
332 GdkNativeWindow anid)
335 GdkDrawableImplX11 *draw_impl;
336 GdkPixmapImplX11 *pix_impl;
340 unsigned int w_ret, h_ret, bw_ret, depth_ret;
342 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
344 /* check to make sure we were passed something at
345 * least a little sane */
346 g_return_val_if_fail ((anid != 0), NULL);
348 /* set the pixmap to the passed in value */
351 /* get information about the Pixmap to fill in the structure for
353 if (!XGetGeometry (GDK_DISPLAY_XDISPLAY (display),
354 xpixmap, &root_return,
355 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
358 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
359 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
360 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
361 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
363 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root_return);
364 draw_impl->xid = xpixmap;
366 pix_impl->is_foreign = TRUE;
367 pix_impl->width = w_ret;
368 pix_impl->height = h_ret;
369 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
371 _gdk_xid_table_insert (display, &GDK_PIXMAP_XID (pixmap), pixmap);
377 * gdk_pixmap_foreign_new:
378 * @anid: a native pixmap handle.
380 * Wraps a native window for the default display in a #GdkPixmap.
381 * This may fail if the pixmap has been destroyed.
383 * For example in the X backend, a native pixmap handle is an Xlib
386 * Return value: the newly-created #GdkPixmap wrapper for the
387 * native pixmap or %NULL if the pixmap has been destroyed.
390 gdk_pixmap_foreign_new (GdkNativeWindow anid)
392 return gdk_pixmap_foreign_new_for_display (gdk_display_get_default (), anid);
397 * @anid: a native pixmap handle.
399 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
401 * For example in the X backend, a native pixmap handle is an Xlib
404 * Return value: the #GdkWindow wrapper for the native window,
405 * or %NULL if there is none.
408 gdk_pixmap_lookup (GdkNativeWindow anid)
410 return (GdkPixmap*) gdk_xid_table_lookup_for_display (gdk_display_get_default (), anid);
414 * gdk_pixmap_lookup_for_display:
415 * @display : the #GdkDisplay associated with @anid
416 * @anid: a native pixmap handle.
418 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
420 * For example in the X backend, a native pixmap handle is an Xlib
423 * Return value: the #GdkWindow wrapper for the native window,
424 * or %NULL if there is none.
427 gdk_pixmap_lookup_for_display (GdkDisplay *display, GdkNativeWindow anid)
429 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
430 return (GdkPixmap*) gdk_xid_table_lookup_for_display (display, anid);