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)
132 GdkDrawableImplX11 *draw_impl = GDK_DRAWABLE_IMPL_X11 (impl);
134 if (draw_impl->xft_draw)
135 XftDrawDestroy (draw_impl->xft_draw);
137 if (!impl->is_foreign)
138 XFreePixmap (GDK_DISPLAY_XDISPLAY (display), GDK_PIXMAP_XID (wrapper));
141 _gdk_xid_table_remove (display, 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 (GdkDrawable *drawable,
164 GdkDrawableImplX11 *draw_impl;
165 GdkPixmapImplX11 *pix_impl;
169 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
170 g_return_val_if_fail ((drawable != 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 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
180 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
183 window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (drawable));
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 (drawable);
193 draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
194 GDK_WINDOW_XID (drawable),
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 (drawable);
206 gdk_drawable_set_colormap (pixmap, cmap);
209 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
210 &GDK_PIXMAP_XID (pixmap), pixmap);
215 gdk_bitmap_create_from_data (GdkDrawable *drawable,
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 (drawable == NULL || GDK_IS_DRAWABLE (drawable), 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 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
235 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
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 (drawable);
249 draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (drawable),
250 GDK_WINDOW_XID (drawable),
251 (char *)data, width, height);
253 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
254 &GDK_PIXMAP_XID (pixmap), pixmap);
259 gdk_pixmap_create_from_data (GdkDrawable *drawable,
268 GdkDrawableImplX11 *draw_impl;
269 GdkPixmapImplX11 *pix_impl;
271 g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), 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 ((drawable != 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 drawable = gdk_screen_get_root_window (gdk_screen_get_default ());
285 if (GDK_IS_WINDOW (drawable) && GDK_WINDOW_DESTROYED (drawable))
289 depth = gdk_drawable_get_visual (drawable)->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 (drawable);
302 draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (drawable),
303 GDK_WINDOW_XID (drawable),
304 (char *)data, width, height,
305 fg->pixel, bg->pixel, depth);
307 _gdk_xid_table_insert (GDK_WINDOW_DISPLAY (drawable),
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 pixmap 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.
329 gdk_pixmap_foreign_new_for_display (GdkDisplay *display,
330 GdkNativeWindow anid)
333 GdkDrawableImplX11 *draw_impl;
334 GdkPixmapImplX11 *pix_impl;
338 unsigned int w_ret, h_ret, bw_ret, depth_ret;
340 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
342 /* check to make sure we were passed something at
343 * least a little sane */
344 g_return_val_if_fail ((anid != 0), NULL);
346 /* set the pixmap to the passed in value */
349 /* get information about the Pixmap to fill in the structure for
351 if (!XGetGeometry (GDK_DISPLAY_XDISPLAY (display),
352 xpixmap, &root_return,
353 &x_ret, &y_ret, &w_ret, &h_ret, &bw_ret, &depth_ret))
356 pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
357 draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
358 pix_impl = GDK_PIXMAP_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
359 draw_impl->wrapper = GDK_DRAWABLE (pixmap);
361 draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root_return);
362 draw_impl->xid = xpixmap;
364 pix_impl->is_foreign = TRUE;
365 pix_impl->width = w_ret;
366 pix_impl->height = h_ret;
367 GDK_PIXMAP_OBJECT (pixmap)->depth = depth_ret;
369 _gdk_xid_table_insert (display, &GDK_PIXMAP_XID (pixmap), pixmap);
375 * gdk_pixmap_foreign_new:
376 * @anid: a native pixmap handle.
378 * Wraps a native window for the default display in a #GdkPixmap.
379 * This may fail if the pixmap has been destroyed.
381 * For example in the X backend, a native pixmap handle is an Xlib
384 * Return value: the newly-created #GdkPixmap wrapper for the
385 * native pixmap or %NULL if the pixmap has been destroyed.
388 gdk_pixmap_foreign_new (GdkNativeWindow anid)
390 return gdk_pixmap_foreign_new_for_display (gdk_display_get_default (), anid);
395 * @anid: a native pixmap handle.
397 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
399 * For example in the X backend, a native pixmap handle is an Xlib
402 * Return value: the #GdkWindow wrapper for the native window,
403 * or %NULL if there is none.
406 gdk_pixmap_lookup (GdkNativeWindow anid)
408 return (GdkPixmap*) gdk_xid_table_lookup_for_display (gdk_display_get_default (), anid);
412 * gdk_pixmap_lookup_for_display:
413 * @display: the #GdkDisplay associated with @anid
414 * @anid: a native pixmap handle.
416 * Looks up the #GdkPixmap that wraps the given native pixmap handle.
418 * For example in the X backend, a native pixmap handle is an Xlib
421 * Return value: the #GdkPixmap wrapper for the native pixmap,
422 * 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);