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/.
29 #define GDK_PIXBUF_ENABLE_BACKEND
32 #include <X11/cursorfont.h>
34 #include <X11/Xcursor/Xcursor.h>
37 #include <X11/extensions/Xfixes.h>
41 #include "gdkprivate-x11.h"
42 #include "gdkcursor.h"
43 #include "gdkdisplay-x11.h"
44 #include "gdkpixmap-x11.h"
46 #include <gdk/gdkpixmap.h>
47 #include <gdk-pixbuf/gdk-pixbuf.h>
49 static guint theme_serial = 0;
51 /* cursor_cache holds a cache of non-pixmap cursors to avoid expensive
52 * libXcursor searches, cursors are added to it but only removed when
53 * their display is closed. We make the assumption that since there are
54 * a small number of display's and a small number of cursor's that this
55 * list will stay small enough not to be a problem.
57 static GSList* cursor_cache = NULL;
59 struct cursor_cache_key
66 /* Caller should check if there is already a match first.
67 * Cursor MUST be either a typed cursor or a pixmap with
71 add_to_cache (GdkCursorPrivate* cursor)
73 cursor_cache = g_slist_prepend (cursor_cache, cursor);
75 /* Take a ref so that if the caller frees it we still have it */
76 gdk_cursor_ref ((GdkCursor*) cursor);
79 /* Returns 0 on a match
82 cache_compare_func (gconstpointer listelem,
85 GdkCursorPrivate* cursor = (GdkCursorPrivate*)listelem;
86 struct cursor_cache_key* key = (struct cursor_cache_key*)target;
88 if ((cursor->cursor.type != key->type) ||
89 (cursor->display != key->display))
90 return 1; /* No match */
92 /* Elements marked as pixmap must be named cursors
93 * (since we don't store normal pixmap cursors
95 if (key->type == GDK_CURSOR_IS_PIXMAP)
96 return strcmp (key->name, cursor->name);
101 /* Returns the cursor if there is a match, NULL if not
102 * For named cursors type shall be GDK_CURSOR_IS_PIXMAP
103 * For unnamed, typed cursors, name shall be NULL
105 static GdkCursorPrivate*
106 find_in_cache (GdkDisplay *display,
111 struct cursor_cache_key key;
113 key.display = display;
117 res = g_slist_find_custom (cursor_cache, &key, cache_compare_func);
120 return (GdkCursorPrivate *) res->data;
125 /* Called by gdk_display_x11_finalize to flush any cached cursors
126 * for a dead display.
129 _gdk_x11_cursor_display_finalize (GdkDisplay *display)
132 GSList** itemp; /* Pointer to the thing to fix when we delete an item */
134 itemp = &cursor_cache;
137 GdkCursorPrivate* cursor = (GdkCursorPrivate*)(item->data);
138 if (cursor->display == display)
141 gdk_cursor_unref ((GdkCursor*) cursor);
142 /* Remove this item from the list */
143 *(itemp) = item->next;
145 item = g_slist_next (item);
146 g_slist_free_1 (olditem);
150 itemp = &(item->next);
151 item = g_slist_next (item);
157 get_blank_cursor (GdkDisplay *display)
161 Pixmap source_pixmap;
166 screen = gdk_display_get_default_screen (display);
167 pixmap = gdk_pixmap_new (gdk_screen_get_root_window (screen), 1, 1, 1);
169 cr = gdk_cairo_create (pixmap);
170 cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
174 source_pixmap = GDK_PIXMAP_XID (pixmap);
177 color.red = color.blue = color.green = 0;
182 cursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
183 source_pixmap, source_pixmap,
184 &color, &color, 1, 1);
185 g_object_unref (pixmap);
191 * gdk_cursor_new_for_display:
192 * @display: the #GdkDisplay for which the cursor will be created
193 * @cursor_type: cursor to create
195 * Creates a new cursor from the set of builtin cursors.
196 * Some useful ones are:
199 * <inlinegraphic format="PNG" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
202 * <inlinegraphic format="PNG" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
205 * <inlinegraphic format="PNG" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
208 * <inlinegraphic format="PNG" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
211 * <inlinegraphic format="PNG" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
214 * <inlinegraphic format="PNG" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
217 * <inlinegraphic format="PNG" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
220 * <inlinegraphic format="PNG" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
223 * <inlinegraphic format="PNG" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
226 * <inlinegraphic format="PNG" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
229 * <inlinegraphic format="PNG" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
232 * <inlinegraphic format="PNG" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
235 * <inlinegraphic format="PNG" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
238 * <inlinegraphic format="PNG" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
241 * <inlinegraphic format="PNG" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
244 * <inlinegraphic format="PNG" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
247 * <inlinegraphic format="PNG" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
250 * #GDK_BLANK_CURSOR (Blank cursor). Since 2.16
254 * Return value: a new #GdkCursor
259 gdk_cursor_new_for_display (GdkDisplay *display,
260 GdkCursorType cursor_type)
262 GdkCursorPrivate *private;
266 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
274 private = find_in_cache (display, cursor_type, NULL);
278 /* Cache had it, add a ref for this user */
279 gdk_cursor_ref ((GdkCursor*) private);
281 return (GdkCursor*) private;
285 if (cursor_type != GDK_BLANK_CURSOR)
286 xcursor = XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display),
289 xcursor = get_blank_cursor (display);
293 private = g_new (GdkCursorPrivate, 1);
294 private->display = display;
295 private->xcursor = xcursor;
296 private->name = NULL;
297 private->serial = theme_serial;
299 cursor = (GdkCursor *) private;
300 cursor->type = cursor_type;
301 cursor->ref_count = 1;
304 add_to_cache (private);
310 * gdk_cursor_new_from_pixmap:
311 * @source: the pixmap specifying the cursor.
312 * @mask: the pixmap specifying the mask, which must be the same size as
314 * @fg: the foreground color, used for the bits in the source which are 1.
315 * The color does not have to be allocated first.
316 * @bg: the background color, used for the bits in the source which are 0.
317 * The color does not have to be allocated first.
318 * @x: the horizontal offset of the 'hotspot' of the cursor.
319 * @y: the vertical offset of the 'hotspot' of the cursor.
321 * Creates a new cursor from a given pixmap and mask. Both the pixmap and mask
322 * must have a depth of 1 (i.e. each pixel has only 2 values - on or off).
323 * The standard cursor size is 16 by 16 pixels. You can create a bitmap
324 * from inline data as in the below example.
326 * <example><title>Creating a custom cursor</title>
328 * /<!-- -->* This data is in X bitmap format, and can be created with the 'bitmap'
329 * utility. *<!-- -->/
330 * #define cursor1_width 16
331 * #define cursor1_height 16
332 * static unsigned char cursor1_bits[] = {
333 * 0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x20,
334 * 0x82, 0x41, 0x41, 0x82, 0x41, 0x82, 0x82, 0x41, 0x04, 0x20, 0x08, 0x10,
335 * 0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0x80, 0x01};
337 * static unsigned char cursor1mask_bits[] = {
338 * 0x80, 0x01, 0xc0, 0x03, 0x60, 0x06, 0x30, 0x0c, 0x18, 0x18, 0x8c, 0x31,
339 * 0xc6, 0x63, 0x63, 0xc6, 0x63, 0xc6, 0xc6, 0x63, 0x8c, 0x31, 0x18, 0x18,
340 * 0x30, 0x0c, 0x60, 0x06, 0xc0, 0x03, 0x80, 0x01};
344 * GdkPixmap *source, *mask;
345 * GdkColor fg = { 0, 65535, 0, 0 }; /<!-- -->* Red. *<!-- -->/
346 * GdkColor bg = { 0, 0, 0, 65535 }; /<!-- -->* Blue. *<!-- -->/
349 * source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
350 * cursor1_width, cursor1_height);
351 * mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
352 * cursor1_width, cursor1_height);
353 * cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
354 * g_object_unref (source);
355 * g_object_unref (mask);
358 * gdk_window_set_cursor (widget->window, cursor);
362 * Return value: a new #GdkCursor.
365 gdk_cursor_new_from_pixmap (GdkPixmap *source,
372 GdkCursorPrivate *private;
374 Pixmap source_pixmap, mask_pixmap;
379 g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
380 g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
381 g_return_val_if_fail (fg != NULL, NULL);
382 g_return_val_if_fail (bg != NULL, NULL);
384 source_pixmap = GDK_PIXMAP_XID (source);
385 mask_pixmap = GDK_PIXMAP_XID (mask);
386 display = GDK_PIXMAP_DISPLAY (source);
388 xfg.pixel = fg->pixel;
391 xfg.green = fg->green;
392 xbg.pixel = bg->pixel;
395 xbg.green = bg->green;
400 xcursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
401 source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
402 private = g_new (GdkCursorPrivate, 1);
403 private->display = display;
404 private->xcursor = xcursor;
405 private->name = NULL;
406 private->serial = theme_serial;
408 cursor = (GdkCursor *) private;
409 cursor->type = GDK_CURSOR_IS_PIXMAP;
410 cursor->ref_count = 1;
416 _gdk_cursor_destroy (GdkCursor *cursor)
418 GdkCursorPrivate *private;
420 g_return_if_fail (cursor != NULL);
421 g_return_if_fail (cursor->ref_count == 0);
423 private = (GdkCursorPrivate *) cursor;
424 if (!private->display->closed && private->xcursor)
425 XFreeCursor (GDK_DISPLAY_XDISPLAY (private->display), private->xcursor);
427 g_free (private->name);
432 * gdk_x11_cursor_get_xdisplay:
433 * @cursor: a #GdkCursor.
435 * Returns the display of a #GdkCursor.
437 * Return value: an Xlib <type>Display*</type>.
440 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
442 g_return_val_if_fail (cursor != NULL, NULL);
444 return GDK_DISPLAY_XDISPLAY(((GdkCursorPrivate *)cursor)->display);
448 * gdk_x11_cursor_get_xcursor:
449 * @cursor: a #GdkCursor.
451 * Returns the X cursor belonging to a #GdkCursor.
453 * Return value: an Xlib <type>Cursor</type>.
456 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
458 g_return_val_if_fail (cursor != NULL, None);
460 return ((GdkCursorPrivate *)cursor)->xcursor;
464 * gdk_cursor_get_display:
465 * @cursor: a #GdkCursor.
467 * Returns the display on which the #GdkCursor is defined.
469 * Returns: the #GdkDisplay associated to @cursor
475 gdk_cursor_get_display (GdkCursor *cursor)
477 g_return_val_if_fail (cursor != NULL, NULL);
479 return ((GdkCursorPrivate *)cursor)->display;
482 #if defined(HAVE_XCURSOR) && defined(HAVE_XFIXES) && XFIXES_MAJOR >= 2
485 * gdk_cursor_get_image:
486 * @cursor: a #GdkCursor
488 * Returns a #GdkPixbuf with the image used to display the cursor.
490 * Note that depending on the capabilities of the windowing system and
491 * on the cursor, GDK may not be able to obtain the image data. In this
492 * case, %NULL is returned.
494 * Returns: a #GdkPixbuf representing @cursor, or %NULL
499 gdk_cursor_get_image (GdkCursor *cursor)
502 GdkCursorPrivate *private;
503 XcursorImages *images = NULL;
507 guchar *data, *p, tmp;
511 g_return_val_if_fail (cursor != NULL, NULL);
513 private = (GdkCursorPrivate *) cursor;
515 xdisplay = GDK_DISPLAY_XDISPLAY (private->display);
517 size = XcursorGetDefaultSize (xdisplay);
518 theme = XcursorGetTheme (xdisplay);
520 if (cursor->type == GDK_CURSOR_IS_PIXMAP)
523 images = XcursorLibraryLoadImages (private->name, theme, size);
526 images = XcursorShapeLoadImages (cursor->type, theme, size);
531 image = images->images[0];
533 data = g_malloc (4 * image->width * image->height);
534 memcpy (data, image->pixels, 4 * image->width * image->height);
536 for (p = data; p < data + (4 * image->width * image->height); p += 4)
543 pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, TRUE,
544 8, image->width, image->height,
546 (GdkPixbufDestroyNotify)g_free, NULL);
549 gdk_pixbuf_set_option (pixbuf, "name", private->name);
550 g_snprintf (buf, 32, "%d", image->xhot);
551 gdk_pixbuf_set_option (pixbuf, "x_hot", buf);
552 g_snprintf (buf, 32, "%d", image->yhot);
553 gdk_pixbuf_set_option (pixbuf, "y_hot", buf);
555 XcursorImagesDestroy (images);
561 _gdk_x11_cursor_update_theme (GdkCursor *cursor)
564 GdkCursorPrivate *private;
565 Cursor new_cursor = None;
566 GdkDisplayX11 *display_x11;
568 private = (GdkCursorPrivate *) cursor;
569 xdisplay = GDK_DISPLAY_XDISPLAY (private->display);
570 display_x11 = GDK_DISPLAY_X11 (private->display);
572 if (!display_x11->have_xfixes)
575 if (private->serial == theme_serial)
578 private->serial = theme_serial;
580 if (private->xcursor != None)
582 if (cursor->type == GDK_BLANK_CURSOR)
585 if (cursor->type == GDK_CURSOR_IS_PIXMAP)
588 new_cursor = XcursorLibraryLoadCursor (xdisplay, private->name);
591 new_cursor = XcursorShapeLoadCursor (xdisplay, cursor->type);
593 if (new_cursor != None)
595 XFixesChangeCursor (xdisplay, new_cursor, private->xcursor);
596 private->xcursor = new_cursor;
602 update_cursor (gpointer data,
607 cursor = (GdkCursor*)(data);
612 _gdk_x11_cursor_update_theme (cursor);
616 * gdk_x11_display_set_cursor_theme:
617 * @display: a #GdkDisplay
618 * @theme: the name of the cursor theme to use, or %NULL to unset
619 * a previously set value
620 * @size: the cursor size to use, or 0 to keep the previous size
622 * Sets the cursor theme from which the images for cursor
625 * If the windowing system supports it, existing cursors created
626 * with gdk_cursor_new(), gdk_cursor_new_for_display() and
627 * gdk_cursor_new_for_name() are updated to reflect the theme
628 * change. Custom cursors constructed with gdk_cursor_new_from_pixmap()
629 * or gdk_cursor_new_from_pixbuf() will have to be handled
630 * by the application (GTK+ applications can learn about
631 * cursor theme changes by listening for change notification
632 * for the corresponding #GtkSetting).
637 gdk_x11_display_set_cursor_theme (GdkDisplay *display,
641 GdkDisplayX11 *display_x11;
646 g_return_if_fail (GDK_IS_DISPLAY (display));
648 display_x11 = GDK_DISPLAY_X11 (display);
649 xdisplay = GDK_DISPLAY_XDISPLAY (display);
651 old_theme = XcursorGetTheme (xdisplay);
652 old_size = XcursorGetDefaultSize (xdisplay);
654 if (old_size == size &&
655 (old_theme == theme ||
656 (old_theme && theme && strcmp (old_theme, theme) == 0)))
661 XcursorSetTheme (xdisplay, theme);
663 XcursorSetDefaultSize (xdisplay, size);
665 g_slist_foreach (cursor_cache, update_cursor, NULL);
671 gdk_cursor_get_image (GdkCursor *cursor)
673 g_return_val_if_fail (cursor != NULL, NULL);
679 gdk_x11_display_set_cursor_theme (GdkDisplay *display,
683 g_return_if_fail (GDK_IS_DISPLAY (display));
687 _gdk_x11_cursor_update_theme (GdkCursor *cursor)
689 g_return_if_fail (cursor != NULL);
697 create_cursor_image (GdkPixbuf *pixbuf,
701 guint width, height, rowstride, n_channels;
702 guchar *pixels, *src;
703 XcursorImage *xcimage;
706 width = gdk_pixbuf_get_width (pixbuf);
707 height = gdk_pixbuf_get_height (pixbuf);
709 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
710 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
711 pixels = gdk_pixbuf_get_pixels (pixbuf);
713 xcimage = XcursorImageCreate (width, height);
718 dest = xcimage->pixels;
724 for (j = 0; j < height; j++)
726 src = pixels + j * rowstride;
727 for (i = 0; i < width; i++)
729 *dest = (0xff << 24) | (src[0] << 16) | (src[1] << 8) | src[2];
738 _gdk_x11_convert_to_format (pixels, rowstride,
739 (guchar *) dest, 4 * width,
741 (G_BYTE_ORDER == G_BIG_ENDIAN) ?
742 GDK_MSB_FIRST : GDK_LSB_FIRST,
751 * gdk_cursor_new_from_pixbuf:
752 * @display: the #GdkDisplay for which the cursor will be created
753 * @pixbuf: the #GdkPixbuf containing the cursor image
754 * @x: the horizontal offset of the 'hotspot' of the cursor.
755 * @y: the vertical offset of the 'hotspot' of the cursor.
757 * Creates a new cursor from a pixbuf.
759 * Not all GDK backends support RGBA cursors. If they are not
760 * supported, a monochrome approximation will be displayed.
761 * The functions gdk_display_supports_cursor_alpha() and
762 * gdk_display_supports_cursor_color() can be used to determine
763 * whether RGBA cursors are supported;
764 * gdk_display_get_default_cursor_size() and
765 * gdk_display_get_maximal_cursor_size() give information about
768 * On the X backend, support for RGBA cursors requires a
769 * sufficently new version of the X Render extension.
771 * Returns: a new #GdkCursor.
776 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
781 XcursorImage *xcimage;
783 GdkCursorPrivate *private;
786 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
787 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
788 g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
789 g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
795 xcimage = create_cursor_image (pixbuf, x, y);
796 xcursor = XcursorImageLoadCursor (GDK_DISPLAY_XDISPLAY (display), xcimage);
797 XcursorImageDestroy (xcimage);
800 private = g_new (GdkCursorPrivate, 1);
801 private->display = display;
802 private->xcursor = xcursor;
803 private->name = NULL;
804 private->serial = theme_serial;
806 cursor = (GdkCursor *) private;
807 cursor->type = GDK_CURSOR_IS_PIXMAP;
808 cursor->ref_count = 1;
814 * gdk_cursor_new_from_name:
815 * @display: the #GdkDisplay for which the cursor will be created
816 * @name: the name of the cursor
818 * Creates a new cursor by looking up @name in the current cursor
821 * Returns: a new #GdkCursor, or %NULL if there is no cursor with
827 gdk_cursor_new_from_name (GdkDisplay *display,
832 GdkCursorPrivate *private;
835 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
841 private = find_in_cache (display, GDK_CURSOR_IS_PIXMAP, name);
845 /* Cache had it, add a ref for this user */
846 gdk_cursor_ref ((GdkCursor*) private);
848 return (GdkCursor*) private;
851 xdisplay = GDK_DISPLAY_XDISPLAY (display);
852 xcursor = XcursorLibraryLoadCursor (xdisplay, name);
857 private = g_new (GdkCursorPrivate, 1);
858 private->display = display;
859 private->xcursor = xcursor;
860 private->name = g_strdup (name);
861 private->serial = theme_serial;
863 cursor = (GdkCursor *) private;
864 cursor->type = GDK_CURSOR_IS_PIXMAP;
865 cursor->ref_count = 1;
866 add_to_cache (private);
872 * gdk_display_supports_cursor_alpha:
873 * @display: a #GdkDisplay
875 * Returns %TRUE if cursors can use an 8bit alpha channel
876 * on @display. Otherwise, cursors are restricted to bilevel
877 * alpha (i.e. a mask).
879 * Returns: whether cursors can have alpha channels.
884 gdk_display_supports_cursor_alpha (GdkDisplay *display)
886 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
888 return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
892 * gdk_display_supports_cursor_color:
893 * @display: a #GdkDisplay
895 * Returns %TRUE if multicolored cursors are supported
896 * on @display. Otherwise, cursors have only a forground
897 * and a background color.
899 * Returns: whether cursors can have multiple colors.
904 gdk_display_supports_cursor_color (GdkDisplay *display)
906 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
908 return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
912 * gdk_display_get_default_cursor_size:
913 * @display: a #GdkDisplay
915 * Returns the default size to use for cursors on @display.
917 * Returns: the default cursor size.
922 gdk_display_get_default_cursor_size (GdkDisplay *display)
924 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
926 return XcursorGetDefaultSize (GDK_DISPLAY_XDISPLAY (display));
932 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
938 GdkPixmap *pixmap, *mask;
939 guint width, height, n_channels, rowstride, data_stride, i, j;
940 guint8 *data, *mask_data, *pixels;
941 GdkColor fg = { 0, 0, 0, 0 };
942 GdkColor bg = { 0, 0xffff, 0xffff, 0xffff };
944 cairo_surface_t *image;
947 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
948 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
950 width = gdk_pixbuf_get_width (pixbuf);
951 height = gdk_pixbuf_get_height (pixbuf);
953 g_return_val_if_fail (0 <= x && x < width, NULL);
954 g_return_val_if_fail (0 <= y && y < height, NULL);
956 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
957 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
958 pixels = gdk_pixbuf_get_pixels (pixbuf);
960 data_stride = 4 * ((width + 31) / 32);
961 data = g_new0 (guint8, data_stride * height);
962 mask_data = g_new0 (guint8, data_stride * height);
964 for (j = 0; j < height; j++)
966 guint8 *src = pixels + j * rowstride;
967 guint8 *d = data + data_stride * j;
968 guint8 *md = mask_data + data_stride * j;
970 for (i = 0; i < width; i++)
975 if (n_channels == 3 || src[3] >= 0x80)
987 screen = gdk_display_get_default_screen (display);
989 pixmap = gdk_pixmap_new (gdk_screen_get_root_window (screen),
991 cr = gdk_cairo_create (pixmap);
992 image = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_A1,
993 width, height, data_stride);
994 cairo_set_source_surface (cr, image, 0, 0);
995 cairo_surface_destroy (image);
996 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1000 mask = gdk_pixmap_new (gdk_screen_get_root_window (screen),
1002 cr = gdk_cairo_create (mask);
1003 image = cairo_image_surface_create_for_data (mask_data, CAIRO_FORMAT_A1,
1004 width, height, data_stride);
1005 cairo_set_source_surface (cr, image, 0, 0);
1006 cairo_surface_destroy (image);
1007 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1011 cursor = gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, x, y);
1013 g_object_unref (pixmap);
1014 g_object_unref (mask);
1023 gdk_cursor_new_from_name (GdkDisplay *display,
1026 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1032 gdk_display_supports_cursor_alpha (GdkDisplay *display)
1034 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1040 gdk_display_supports_cursor_color (GdkDisplay *display)
1042 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1048 gdk_display_get_default_cursor_size (GdkDisplay *display)
1050 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
1052 /* no idea, really */
1060 * gdk_display_get_maximal_cursor_size:
1061 * @display: a #GdkDisplay
1062 * @width: (out): the return location for the maximal cursor width
1063 * @height: (out): the return location for the maximal cursor height
1065 * Gets the maximal size to use for cursors on @display.
1070 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
1077 g_return_if_fail (GDK_IS_DISPLAY (display));
1079 screen = gdk_display_get_default_screen (display);
1080 window = gdk_screen_get_root_window (screen);
1081 XQueryBestCursor (GDK_DISPLAY_XDISPLAY (display),
1082 GDK_WINDOW_XWINDOW (window),
1083 128, 128, width, height);