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>
50 static guint theme_serial = 0;
52 /* cursor_cache holds a cache of non-pixmap cursors to avoid expensive
53 * libXcursor searches, cursors are added to it but never removed. We make
54 * the assumption that since there are a small number of GdkDisplay's and
55 * a small number of cursor's that this list will stay small enough
56 * not to be a problem.
58 static GSList* cursor_cache = NULL;
60 struct cursor_cache_key
67 /* Caller should check if there is already a match first.
68 * Cursor MUST be either a typed cursor or a pixmap with
72 add_to_cache (GdkCursorPrivate* cursor)
74 cursor_cache = g_slist_prepend (cursor_cache, cursor);
76 /* Take a ref so that if the caller frees it we still have it */
77 gdk_cursor_ref ((GdkCursor*) cursor);
80 /* Returns 0 on a match
83 cache_compare_func (gconstpointer listelem,
86 GdkCursorPrivate* cursor = (GdkCursorPrivate*)listelem;
87 struct cursor_cache_key* key = (struct cursor_cache_key*)target;
89 if ((cursor->cursor.type != key->type) ||
90 (cursor->display != key->display))
91 return 1; /* No match */
93 /* Elements marked as pixmap must be named cursors
94 * (since we don't store normal pixmap cursors
96 if (key->type == GDK_CURSOR_IS_PIXMAP)
97 return strcmp (key->name, cursor->name);
102 /* Returns the cursor if there is a match, NULL if not
103 * For named cursors type shall be GDK_CURSOR_IS_PIXMAP
104 * For unnamed, typed cursors, name shall be NULL
106 static GdkCursorPrivate*
107 find_in_cache (GdkDisplay *display,
112 struct cursor_cache_key key;
114 key.display = display;
118 res = g_slist_find_custom (cursor_cache, &key, cache_compare_func);
121 return (GdkCursorPrivate *) res->data;
126 /* Called by gdk_display_x11_finalize to flush any cached cursors
127 * for a dead display.
130 _gdk_x11_cursor_display_finalize (GdkDisplay *display)
133 GSList** itemp; /* Pointer to the thing to fix when we delete an item */
135 itemp = &cursor_cache;
138 GdkCursorPrivate* cursor = (GdkCursorPrivate*)(item->data);
139 if (cursor->display == display)
142 gdk_cursor_unref ((GdkCursor*) cursor);
143 /* Remove this item from the list */
144 *(itemp) = item->next;
146 item = g_slist_next (item);
147 g_slist_free_1 (olditem);
151 itemp = &(item->next);
152 item = g_slist_next (item);
158 get_blank_cursor (GdkDisplay *display)
162 Pixmap source_pixmap;
166 screen = gdk_display_get_default_screen (display);
167 pixmap = gdk_bitmap_create_from_data (gdk_screen_get_root_window (screen),
168 "\0\0\0\0\0\0\0\0", 1, 1);
170 source_pixmap = GDK_PIXMAP_XID (pixmap);
173 color.red = color.blue = color.green = 0;
178 cursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
179 source_pixmap, source_pixmap,
180 &color, &color, 1, 1);
181 g_object_unref (pixmap);
187 * gdk_cursor_new_for_display:
188 * @display: the #GdkDisplay for which the cursor will be created
189 * @cursor_type: cursor to create
191 * Creates a new cursor from the set of builtin cursors.
192 * Some useful ones are:
195 * <inlinegraphic format="PNG" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
198 * <inlinegraphic format="PNG" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
201 * <inlinegraphic format="PNG" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
204 * <inlinegraphic format="PNG" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
207 * <inlinegraphic format="PNG" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
210 * <inlinegraphic format="PNG" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
213 * <inlinegraphic format="PNG" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
216 * <inlinegraphic format="PNG" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
219 * <inlinegraphic format="PNG" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
222 * <inlinegraphic format="PNG" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
225 * <inlinegraphic format="PNG" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
228 * <inlinegraphic format="PNG" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
231 * <inlinegraphic format="PNG" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
234 * <inlinegraphic format="PNG" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
237 * <inlinegraphic format="PNG" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
240 * <inlinegraphic format="PNG" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
243 * <inlinegraphic format="PNG" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
246 * #GDK_BLANK_CURSOR (Blank cursor). Since 2.16
250 * Return value: a new #GdkCursor
255 gdk_cursor_new_for_display (GdkDisplay *display,
256 GdkCursorType cursor_type)
258 GdkCursorPrivate *private;
262 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
270 private = find_in_cache (display, cursor_type, NULL);
274 /* Cache had it, add a ref for this user */
275 gdk_cursor_ref ((GdkCursor*) private);
277 return (GdkCursor*) private;
281 if (cursor_type != GDK_BLANK_CURSOR)
282 xcursor = XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display),
285 xcursor = get_blank_cursor (display);
289 private = g_new (GdkCursorPrivate, 1);
290 private->display = display;
291 private->xcursor = xcursor;
292 private->name = NULL;
293 private->serial = theme_serial;
295 cursor = (GdkCursor *) private;
296 cursor->type = cursor_type;
297 cursor->ref_count = 1;
300 add_to_cache (private);
306 * gdk_cursor_new_from_pixmap:
307 * @source: the pixmap specifying the cursor.
308 * @mask: the pixmap specifying the mask, which must be the same size as
310 * @fg: the foreground color, used for the bits in the source which are 1.
311 * The color does not have to be allocated first.
312 * @bg: the background color, used for the bits in the source which are 0.
313 * The color does not have to be allocated first.
314 * @x: the horizontal offset of the 'hotspot' of the cursor.
315 * @y: the vertical offset of the 'hotspot' of the cursor.
317 * Creates a new cursor from a given pixmap and mask. Both the pixmap and mask
318 * must have a depth of 1 (i.e. each pixel has only 2 values - on or off).
319 * The standard cursor size is 16 by 16 pixels. You can create a bitmap
320 * from inline data as in the below example.
322 * <example><title>Creating a custom cursor</title>
324 * /<!-- -->* This data is in X bitmap format, and can be created with the 'bitmap'
325 * utility. *<!-- -->/
326 * #define cursor1_width 16
327 * #define cursor1_height 16
328 * static unsigned char cursor1_bits[] = {
329 * 0x80, 0x01, 0x40, 0x02, 0x20, 0x04, 0x10, 0x08, 0x08, 0x10, 0x04, 0x20,
330 * 0x82, 0x41, 0x41, 0x82, 0x41, 0x82, 0x82, 0x41, 0x04, 0x20, 0x08, 0x10,
331 * 0x10, 0x08, 0x20, 0x04, 0x40, 0x02, 0x80, 0x01};
333 * static unsigned char cursor1mask_bits[] = {
334 * 0x80, 0x01, 0xc0, 0x03, 0x60, 0x06, 0x30, 0x0c, 0x18, 0x18, 0x8c, 0x31,
335 * 0xc6, 0x63, 0x63, 0xc6, 0x63, 0xc6, 0xc6, 0x63, 0x8c, 0x31, 0x18, 0x18,
336 * 0x30, 0x0c, 0x60, 0x06, 0xc0, 0x03, 0x80, 0x01};
340 * GdkPixmap *source, *mask;
341 * GdkColor fg = { 0, 65535, 0, 0 }; /<!-- -->* Red. *<!-- -->/
342 * GdkColor bg = { 0, 0, 0, 65535 }; /<!-- -->* Blue. *<!-- -->/
345 * source = gdk_bitmap_create_from_data (NULL, cursor1_bits,
346 * cursor1_width, cursor1_height);
347 * mask = gdk_bitmap_create_from_data (NULL, cursor1mask_bits,
348 * cursor1_width, cursor1_height);
349 * cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
350 * gdk_pixmap_unref (source);
351 * gdk_pixmap_unref (mask);
354 * gdk_window_set_cursor (widget->window, cursor);
358 * Return value: a new #GdkCursor.
361 gdk_cursor_new_from_pixmap (GdkPixmap *source,
368 GdkCursorPrivate *private;
370 Pixmap source_pixmap, mask_pixmap;
375 g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
376 g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
377 g_return_val_if_fail (fg != NULL, NULL);
378 g_return_val_if_fail (bg != NULL, NULL);
380 source_pixmap = GDK_PIXMAP_XID (source);
381 mask_pixmap = GDK_PIXMAP_XID (mask);
382 display = GDK_PIXMAP_DISPLAY (source);
384 xfg.pixel = fg->pixel;
387 xfg.green = fg->green;
388 xbg.pixel = bg->pixel;
391 xbg.green = bg->green;
396 xcursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
397 source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
398 private = g_new (GdkCursorPrivate, 1);
399 private->display = display;
400 private->xcursor = xcursor;
401 private->name = NULL;
402 private->serial = theme_serial;
404 cursor = (GdkCursor *) private;
405 cursor->type = GDK_CURSOR_IS_PIXMAP;
406 cursor->ref_count = 1;
412 _gdk_cursor_destroy (GdkCursor *cursor)
414 GdkCursorPrivate *private;
416 g_return_if_fail (cursor != NULL);
417 g_return_if_fail (cursor->ref_count == 0);
419 private = (GdkCursorPrivate *) cursor;
420 if (!private->display->closed && private->xcursor)
421 XFreeCursor (GDK_DISPLAY_XDISPLAY (private->display), private->xcursor);
423 g_free (private->name);
428 * gdk_x11_cursor_get_xdisplay:
429 * @cursor: a #GdkCursor.
431 * Returns the display of a #GdkCursor.
433 * Return value: an Xlib <type>Display*</type>.
436 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
438 g_return_val_if_fail (cursor != NULL, NULL);
440 return GDK_DISPLAY_XDISPLAY(((GdkCursorPrivate *)cursor)->display);
444 * gdk_x11_cursor_get_xcursor:
445 * @cursor: a #GdkCursor.
447 * Returns the X cursor belonging to a #GdkCursor.
449 * Return value: an Xlib <type>Cursor</type>.
452 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
454 g_return_val_if_fail (cursor != NULL, None);
456 return ((GdkCursorPrivate *)cursor)->xcursor;
460 * gdk_cursor_get_display:
461 * @cursor: a #GdkCursor.
463 * Returns the display on which the #GdkCursor is defined.
465 * Returns: the #GdkDisplay associated to @cursor
471 gdk_cursor_get_display (GdkCursor *cursor)
473 g_return_val_if_fail (cursor != NULL, NULL);
475 return ((GdkCursorPrivate *)cursor)->display;
478 #if defined(HAVE_XCURSOR) && defined(HAVE_XFIXES) && XFIXES_MAJOR >= 2
481 * gdk_cursor_get_image:
482 * @cursor: a #GdkCursor
484 * Returns a #GdkPixbuf with the image used to display the cursor.
486 * Note that depending on the capabilities of the windowing system and
487 * on the cursor, GDK may not be able to obtain the image data. In this
488 * case, %NULL is returned.
490 * Returns: a #GdkPixbuf representing @cursor, or %NULL
495 gdk_cursor_get_image (GdkCursor *cursor)
498 GdkCursorPrivate *private;
499 XcursorImages *images = NULL;
503 guchar *data, *p, tmp;
507 g_return_val_if_fail (cursor != NULL, NULL);
509 private = (GdkCursorPrivate *) cursor;
511 xdisplay = GDK_DISPLAY_XDISPLAY (private->display);
513 size = XcursorGetDefaultSize (xdisplay);
514 theme = XcursorGetTheme (xdisplay);
516 if (cursor->type == GDK_CURSOR_IS_PIXMAP)
519 images = XcursorLibraryLoadImages (private->name, theme, size);
522 images = XcursorShapeLoadImages (cursor->type, theme, size);
527 image = images->images[0];
529 data = g_malloc (4 * image->width * image->height);
530 memcpy (data, image->pixels, 4 * image->width * image->height);
532 for (p = data; p < data + (4 * image->width * image->height); p += 4)
539 pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, TRUE,
540 8, image->width, image->height,
542 (GdkPixbufDestroyNotify)g_free, NULL);
545 gdk_pixbuf_set_option (pixbuf, "name", private->name);
546 g_snprintf (buf, 32, "%d", image->xhot);
547 gdk_pixbuf_set_option (pixbuf, "x_hot", buf);
548 g_snprintf (buf, 32, "%d", image->yhot);
549 gdk_pixbuf_set_option (pixbuf, "y_hot", buf);
551 XcursorImagesDestroy (images);
557 _gdk_x11_cursor_update_theme (GdkCursor *cursor)
560 GdkCursorPrivate *private;
561 Cursor new_cursor = None;
562 GdkDisplayX11 *display_x11;
564 private = (GdkCursorPrivate *) cursor;
565 xdisplay = GDK_DISPLAY_XDISPLAY (private->display);
566 display_x11 = GDK_DISPLAY_X11 (private->display);
568 if (!display_x11->have_xfixes)
571 if (private->serial == theme_serial)
574 private->serial = theme_serial;
576 if (private->xcursor != None)
578 if (cursor->type == GDK_CURSOR_IS_PIXMAP)
581 new_cursor = XcursorLibraryLoadCursor (xdisplay, private->name);
584 new_cursor = XcursorShapeLoadCursor (xdisplay, cursor->type);
586 if (new_cursor != None)
588 XFixesChangeCursor (xdisplay, new_cursor, private->xcursor);
589 private->xcursor = new_cursor;
595 update_cursor (gpointer data,
600 cursor = (GdkCursor*)(data);
605 _gdk_x11_cursor_update_theme (cursor);
609 * gdk_x11_display_set_cursor_theme:
610 * @display: a #GdkDisplay
611 * @theme: the name of the cursor theme to use, or %NULL to unset
612 * a previously set value
613 * @size: the cursor size to use, or 0 to keep the previous size
615 * Sets the cursor theme from which the images for cursor
618 * If the windowing system supports it, existing cursors created
619 * with gdk_cursor_new(), gdk_cursor_new_for_display() and
620 * gdk_cursor_new_for_name() are updated to reflect the theme
621 * change. Custom cursors constructed with gdk_cursor_new_from_pixmap()
622 * or gdk_cursor_new_from_pixbuf() will have to be handled
623 * by the application (GTK+ applications can learn about
624 * cursor theme changes by listening for change notification
625 * for the corresponding #GtkSetting).
630 gdk_x11_display_set_cursor_theme (GdkDisplay *display,
634 GdkDisplayX11 *display_x11;
639 g_return_if_fail (GDK_IS_DISPLAY (display));
641 display_x11 = GDK_DISPLAY_X11 (display);
642 xdisplay = GDK_DISPLAY_XDISPLAY (display);
644 old_theme = XcursorGetTheme (xdisplay);
645 old_size = XcursorGetDefaultSize (xdisplay);
647 if (old_size == size &&
648 (old_theme == theme ||
649 (old_theme && theme && strcmp (old_theme, theme) == 0)))
654 XcursorSetTheme (xdisplay, theme);
656 XcursorSetDefaultSize (xdisplay, size);
658 g_slist_foreach (cursor_cache, update_cursor, NULL);
664 gdk_cursor_get_image (GdkCursor *cursor)
666 g_return_val_if_fail (cursor != NULL, NULL);
672 gdk_x11_display_set_cursor_theme (GdkDisplay *display,
676 g_return_if_fail (GDK_IS_DISPLAY (display));
680 _gdk_x11_cursor_update_theme (GdkCursor *cursor)
682 g_return_if_fail (cursor != NULL);
690 create_cursor_image (GdkPixbuf *pixbuf,
694 guint width, height, rowstride, n_channels;
695 guchar *pixels, *src;
696 XcursorImage *xcimage;
699 width = gdk_pixbuf_get_width (pixbuf);
700 height = gdk_pixbuf_get_height (pixbuf);
702 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
703 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
704 pixels = gdk_pixbuf_get_pixels (pixbuf);
706 xcimage = XcursorImageCreate (width, height);
711 dest = xcimage->pixels;
717 for (j = 0; j < height; j++)
719 src = pixels + j * rowstride;
720 for (i = 0; i < width; i++)
722 *dest = (0xff << 24) | (src[0] << 16) | (src[1] << 8) | src[2];
731 _gdk_x11_convert_to_format (pixels, rowstride,
732 (guchar *) dest, 4 * width,
734 (G_BYTE_ORDER == G_BIG_ENDIAN) ?
735 GDK_MSB_FIRST : GDK_LSB_FIRST,
744 * gdk_cursor_new_from_pixbuf:
745 * @display: the #GdkDisplay for which the cursor will be created
746 * @pixbuf: the #GdkPixbuf containing the cursor image
747 * @x: the horizontal offset of the 'hotspot' of the cursor.
748 * @y: the vertical offset of the 'hotspot' of the cursor.
750 * Creates a new cursor from a pixbuf.
752 * Not all GDK backends support RGBA cursors. If they are not
753 * supported, a monochrome approximation will be displayed.
754 * The functions gdk_display_supports_cursor_alpha() and
755 * gdk_display_supports_cursor_color() can be used to determine
756 * whether RGBA cursors are supported;
757 * gdk_display_get_default_cursor_size() and
758 * gdk_display_get_maximal_cursor_size() give information about
761 * On the X backend, support for RGBA cursors requires a
762 * sufficently new version of the X Render extension.
764 * Returns: a new #GdkCursor.
769 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
774 XcursorImage *xcimage;
776 GdkCursorPrivate *private;
779 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
780 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
781 g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
782 g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
788 xcimage = create_cursor_image (pixbuf, x, y);
789 xcursor = XcursorImageLoadCursor (GDK_DISPLAY_XDISPLAY (display), xcimage);
790 XcursorImageDestroy (xcimage);
793 private = g_new (GdkCursorPrivate, 1);
794 private->display = display;
795 private->xcursor = xcursor;
796 private->name = NULL;
797 private->serial = theme_serial;
799 cursor = (GdkCursor *) private;
800 cursor->type = GDK_CURSOR_IS_PIXMAP;
801 cursor->ref_count = 1;
807 * gdk_cursor_new_from_name:
808 * @display: the #GdkDisplay for which the cursor will be created
809 * @name: the name of the cursor
811 * Creates a new cursor by looking up @name in the current cursor
814 * Returns: a new #GdkCursor, or %NULL if there is no cursor with
820 gdk_cursor_new_from_name (GdkDisplay *display,
825 GdkCursorPrivate *private;
828 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
834 private = find_in_cache (display, GDK_CURSOR_IS_PIXMAP, name);
838 /* Cache had it, add a ref for this user */
839 gdk_cursor_ref ((GdkCursor*) private);
841 return (GdkCursor*) private;
844 xdisplay = GDK_DISPLAY_XDISPLAY (display);
845 xcursor = XcursorLibraryLoadCursor (xdisplay, name);
850 private = g_new (GdkCursorPrivate, 1);
851 private->display = display;
852 private->xcursor = xcursor;
853 private->name = g_strdup (name);
854 private->serial = theme_serial;
856 cursor = (GdkCursor *) private;
857 cursor->type = GDK_CURSOR_IS_PIXMAP;
858 cursor->ref_count = 1;
859 add_to_cache (private);
865 * gdk_display_supports_cursor_alpha:
866 * @display: a #GdkDisplay
868 * Returns %TRUE if cursors can use an 8bit alpha channel
869 * on @display. Otherwise, cursors are restricted to bilevel
870 * alpha (i.e. a mask).
872 * Returns: whether cursors can have alpha channels.
877 gdk_display_supports_cursor_alpha (GdkDisplay *display)
879 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
881 return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
885 * gdk_display_supports_cursor_color:
886 * @display: a #GdkDisplay
888 * Returns %TRUE if multicolored cursors are supported
889 * on @display. Otherwise, cursors have only a forground
890 * and a background color.
892 * Returns: whether cursors can have multiple colors.
897 gdk_display_supports_cursor_color (GdkDisplay *display)
899 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
901 return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
905 * gdk_display_get_default_cursor_size:
906 * @display: a #GdkDisplay
908 * Returns the default size to use for cursors on @display.
910 * Returns: the default cursor size.
915 gdk_display_get_default_cursor_size (GdkDisplay *display)
917 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
919 return XcursorGetDefaultSize (GDK_DISPLAY_XDISPLAY (display));
925 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
931 GdkPixmap *pixmap, *mask;
932 guint width, height, n_channels, rowstride, i, j;
933 guint8 *data, *mask_data, *pixels;
934 GdkColor fg = { 0, 0, 0, 0 };
935 GdkColor bg = { 0, 0xffff, 0xffff, 0xffff };
938 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
939 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
941 width = gdk_pixbuf_get_width (pixbuf);
942 height = gdk_pixbuf_get_height (pixbuf);
944 g_return_val_if_fail (0 <= x && x < width, NULL);
945 g_return_val_if_fail (0 <= y && y < height, NULL);
947 n_channels = gdk_pixbuf_get_n_channels (pixbuf);
948 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
949 pixels = gdk_pixbuf_get_pixels (pixbuf);
951 data = g_new0 (guint8, (width + 7) / 8 * height);
952 mask_data = g_new0 (guint8, (width + 7) / 8 * height);
954 for (j = 0; j < height; j++)
956 guint8 *src = pixels + j * rowstride;
957 guint8 *d = data + (width + 7) / 8 * j;
958 guint8 *md = mask_data + (width + 7) / 8 * j;
960 for (i = 0; i < width; i++)
965 if (n_channels == 3 || src[3] >= 0x80)
977 screen = gdk_display_get_default_screen (display);
978 pixmap = gdk_bitmap_create_from_data (gdk_screen_get_root_window (screen),
979 data, width, height);
981 mask = gdk_bitmap_create_from_data (gdk_screen_get_root_window (screen),
982 mask_data, width, height);
984 cursor = gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, x, y);
986 g_object_unref (pixmap);
987 g_object_unref (mask);
996 gdk_cursor_new_from_name (GdkDisplay *display,
999 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
1005 gdk_display_supports_cursor_alpha (GdkDisplay *display)
1007 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1013 gdk_display_supports_cursor_color (GdkDisplay *display)
1015 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
1021 gdk_display_get_default_cursor_size (GdkDisplay *display)
1023 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
1025 /* no idea, really */
1033 * gdk_display_get_maximal_cursor_size:
1034 * @display: a #GdkDisplay
1035 * @width: the return location for the maximal cursor width
1036 * @height: the return location for the maximal cursor height
1038 * Gets the maximal size to use for cursors on @display.
1043 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
1050 g_return_if_fail (GDK_IS_DISPLAY (display));
1052 screen = gdk_display_get_default_screen (display);
1053 window = gdk_screen_get_root_window (screen);
1054 XQueryBestCursor (GDK_DISPLAY_XDISPLAY (display),
1055 GDK_WINDOW_XWINDOW (window),
1056 128, 128, width, height);
1059 #define __GDK_CURSOR_X11_C__
1060 #include "gdkaliasdef.c"