]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkcursor-x11.c
wayland: Synthesize fullscreen window state change
[~andy/gtk] / gdk / x11 / gdkcursor-x11.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /*
19  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
20  * file for a list of people on the GTK+ Team.  See the ChangeLog
21  * files for a list of changes.  These files are distributed with
22  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
23  */
24
25 #include "config.h"
26
27 /* needs to be first because any header might include gdk-pixbuf.h otherwise */
28 #define GDK_PIXBUF_ENABLE_BACKEND
29 #include <gdk-pixbuf/gdk-pixbuf.h>
30
31 #include "gdkcursor.h"
32 #include "gdkcursorprivate.h"
33 #include "gdkprivate-x11.h"
34 #include "gdkdisplay-x11.h"
35
36 #include <X11/Xlib.h>
37 #include <X11/cursorfont.h>
38 #ifdef HAVE_XCURSOR
39 #include <X11/Xcursor/Xcursor.h>
40 #endif
41 #ifdef HAVE_XFIXES
42 #include <X11/extensions/Xfixes.h>
43 #endif
44 #include <string.h>
45 #include <errno.h>
46
47 struct _GdkX11Cursor
48 {
49   GdkCursor cursor;
50
51   Cursor xcursor;
52   gchar *name;
53   guint serial;
54 };
55
56 struct _GdkX11CursorClass
57 {
58   GdkCursorClass cursor_class;
59 };
60
61 static guint theme_serial = 0;
62
63 /* cursor_cache holds a cache of non-pixmap cursors to avoid expensive 
64  * libXcursor searches, cursors are added to it but only removed when
65  * their display is closed. We make the assumption that since there are 
66  * a small number of display's and a small number of cursor's that this 
67  * list will stay small enough not to be a problem.
68  */
69 static GSList* cursor_cache = NULL;
70
71 struct cursor_cache_key
72 {
73   GdkDisplay* display;
74   GdkCursorType type;
75   const char* name;
76 };
77
78 /* Caller should check if there is already a match first.
79  * Cursor MUST be either a typed cursor or a pixmap with 
80  * a non-NULL name.
81  */
82 static void
83 add_to_cache (GdkX11Cursor* cursor)
84 {
85   cursor_cache = g_slist_prepend (cursor_cache, cursor);
86
87   /* Take a ref so that if the caller frees it we still have it */
88   g_object_ref (cursor);
89 }
90
91 /* Returns 0 on a match
92  */
93 static gint
94 cache_compare_func (gconstpointer listelem, 
95                     gconstpointer target)
96 {
97   GdkX11Cursor* cursor = (GdkX11Cursor*)listelem;
98   struct cursor_cache_key* key = (struct cursor_cache_key*)target;
99
100   if ((cursor->cursor.type != key->type) ||
101       (gdk_cursor_get_display (GDK_CURSOR (cursor)) != key->display))
102     return 1; /* No match */
103   
104   /* Elements marked as pixmap must be named cursors 
105    * (since we don't store normal pixmap cursors 
106    */
107   if (key->type == GDK_CURSOR_IS_PIXMAP)
108     return strcmp (key->name, cursor->name);
109
110   return 0; /* Match */
111 }
112
113 /* Returns the cursor if there is a match, NULL if not
114  * For named cursors type shall be GDK_CURSOR_IS_PIXMAP
115  * For unnamed, typed cursors, name shall be NULL
116  */
117 static GdkX11Cursor*
118 find_in_cache (GdkDisplay    *display, 
119                GdkCursorType  type,
120                const char    *name)
121 {
122   GSList* res;
123   struct cursor_cache_key key;
124
125   key.display = display;
126   key.type = type;
127   key.name = name;
128
129   res = g_slist_find_custom (cursor_cache, &key, cache_compare_func);
130
131   if (res)
132     return (GdkX11Cursor *) res->data;
133
134   return NULL;
135 }
136
137 /* Called by gdk_x11_display_finalize to flush any cached cursors
138  * for a dead display.
139  */
140 void
141 _gdk_x11_cursor_display_finalize (GdkDisplay *display)
142 {
143   GSList* item;
144   GSList** itemp; /* Pointer to the thing to fix when we delete an item */
145   item = cursor_cache;
146   itemp = &cursor_cache;
147   while (item)
148     {
149       GdkX11Cursor* cursor = (GdkX11Cursor*)(item->data);
150       if (gdk_cursor_get_display (GDK_CURSOR (cursor)) == display)
151         {
152           GSList* olditem;
153           g_object_unref ((GdkCursor*) cursor);
154           /* Remove this item from the list */
155           *(itemp) = item->next;
156           olditem = item;
157           item = g_slist_next (item);
158           g_slist_free_1 (olditem);
159         } 
160       else 
161         {
162           itemp = &(item->next);
163           item = g_slist_next (item);
164         }
165     }
166 }
167
168 /*** GdkX11Cursor ***/
169
170 G_DEFINE_TYPE (GdkX11Cursor, gdk_x11_cursor, GDK_TYPE_CURSOR)
171
172 static GdkPixbuf* gdk_x11_cursor_get_image (GdkCursor *cursor);
173
174 static void
175 gdk_x11_cursor_finalize (GObject *object)
176 {
177   GdkX11Cursor *private = GDK_X11_CURSOR (object);
178   GdkDisplay *display;
179
180   display = gdk_cursor_get_display (GDK_CURSOR (object));
181   if (private->xcursor && !gdk_display_is_closed (display))
182     XFreeCursor (GDK_DISPLAY_XDISPLAY (display), private->xcursor);
183
184   g_free (private->name);
185
186   G_OBJECT_CLASS (gdk_x11_cursor_parent_class)->finalize (object);
187 }
188
189 static void
190 gdk_x11_cursor_class_init (GdkX11CursorClass *xcursor_class)
191 {
192   GdkCursorClass *cursor_class = GDK_CURSOR_CLASS (xcursor_class);
193   GObjectClass *object_class = G_OBJECT_CLASS (xcursor_class);
194
195   object_class->finalize = gdk_x11_cursor_finalize;
196
197   cursor_class->get_image = gdk_x11_cursor_get_image;
198 }
199
200 static void
201 gdk_x11_cursor_init (GdkX11Cursor *cursor)
202 {
203 }
204
205 static Cursor
206 get_blank_cursor (GdkDisplay *display)
207 {
208   GdkScreen *screen;
209   Pixmap pixmap;
210   XColor color;
211   Cursor cursor;
212   cairo_surface_t *surface;
213   cairo_t *cr;
214
215   screen = gdk_display_get_default_screen (display);
216   surface = _gdk_x11_window_create_bitmap_surface (gdk_screen_get_root_window (screen), 1, 1);
217   /* Clear surface */
218   cr = cairo_create (surface);
219   cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
220   cairo_paint (cr);
221   cairo_destroy (cr);
222  
223   pixmap = cairo_xlib_surface_get_drawable (surface);
224
225   color.pixel = 0; 
226   color.red = color.blue = color.green = 0;
227
228   if (gdk_display_is_closed (display))
229     cursor = None;
230   else
231     cursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
232                                   pixmap, pixmap,
233                                   &color, &color, 1, 1);
234   cairo_surface_destroy (surface);
235
236   return cursor;
237 }
238
239 GdkCursor*
240 _gdk_x11_display_get_cursor_for_type (GdkDisplay    *display,
241                                       GdkCursorType  cursor_type)
242 {
243   GdkX11Cursor *private;
244   Cursor xcursor;
245
246   if (gdk_display_is_closed (display))
247     {
248       xcursor = None;
249     }
250   else
251     {
252       private = find_in_cache (display, cursor_type, NULL);
253
254       if (private)
255         {
256           /* Cache had it, add a ref for this user */
257           g_object_ref (private);
258
259           return (GdkCursor*) private;
260         }
261       else
262         {
263           if (cursor_type != GDK_BLANK_CURSOR)
264             xcursor = XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display),
265                                          cursor_type);
266           else
267             xcursor = get_blank_cursor (display);
268        }
269     }
270
271   private = g_object_new (GDK_TYPE_X11_CURSOR,
272                           "cursor-type", cursor_type,
273                           "display", display,
274                           NULL);
275   private->xcursor = xcursor;
276   private->name = NULL;
277   private->serial = theme_serial;
278
279   if (xcursor != None)
280     add_to_cache (private);
281
282   return GDK_CURSOR (private);
283 }
284
285 /**
286  * gdk_x11_cursor_get_xdisplay:
287  * @cursor: (type GdkX11Cursor): a #GdkCursor.
288  * 
289  * Returns the display of a #GdkCursor.
290  * 
291  * Return value: (transfer none): an Xlib <type>Display*</type>.
292  **/
293 Display *
294 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
295 {
296   g_return_val_if_fail (cursor != NULL, NULL);
297
298   return GDK_DISPLAY_XDISPLAY (gdk_cursor_get_display (cursor));
299 }
300
301 /**
302  * gdk_x11_cursor_get_xcursor:
303  * @cursor: (type GdkX11Cursor): a #GdkCursor.
304  * 
305  * Returns the X cursor belonging to a #GdkCursor.
306  * 
307  * Return value: an Xlib <type>Cursor</type>.
308  **/
309 Cursor
310 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
311 {
312   g_return_val_if_fail (cursor != NULL, None);
313
314   return ((GdkX11Cursor *)cursor)->xcursor;
315 }
316
317 #if defined(HAVE_XCURSOR) && defined(HAVE_XFIXES) && XFIXES_MAJOR >= 2
318
319 static GdkPixbuf*  
320 gdk_x11_cursor_get_image (GdkCursor *cursor)
321 {
322   Display *xdisplay;
323   GdkX11Cursor *private;
324   XcursorImages *images = NULL;
325   XcursorImage *image;
326   gint size;
327   gchar buf[32];
328   guchar *data, *p, tmp;
329   GdkPixbuf *pixbuf;
330   gchar *theme;
331   
332   private = GDK_X11_CURSOR (cursor);
333     
334   xdisplay = GDK_DISPLAY_XDISPLAY (gdk_cursor_get_display (cursor));
335
336   size = XcursorGetDefaultSize (xdisplay);
337   theme = XcursorGetTheme (xdisplay);
338
339   if (cursor->type == GDK_CURSOR_IS_PIXMAP)
340     {
341       if (private->name)
342         images = XcursorLibraryLoadImages (private->name, theme, size);
343     }
344   else
345     images = XcursorShapeLoadImages (cursor->type, theme, size);
346
347   if (!images)
348     return NULL;
349
350   image = images->images[0];
351
352   data = g_malloc (4 * image->width * image->height);
353   memcpy (data, image->pixels, 4 * image->width * image->height);
354
355   for (p = data; p < data + (4 * image->width * image->height); p += 4)
356     {
357       tmp = p[0];
358       p[0] = p[2];
359       p[2] = tmp;
360     }
361
362   pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, TRUE,
363                                      8, image->width, image->height,
364                                      4 * image->width,
365                                      (GdkPixbufDestroyNotify)g_free, NULL);
366
367   if (private->name)
368     gdk_pixbuf_set_option (pixbuf, "name", private->name);
369   g_snprintf (buf, 32, "%d", image->xhot);
370   gdk_pixbuf_set_option (pixbuf, "x_hot", buf);
371   g_snprintf (buf, 32, "%d", image->yhot);
372   gdk_pixbuf_set_option (pixbuf, "y_hot", buf);
373
374   XcursorImagesDestroy (images);
375
376   return pixbuf;
377 }
378
379 void
380 _gdk_x11_cursor_update_theme (GdkCursor *cursor)
381 {
382   Display *xdisplay;
383   GdkX11Cursor *private;
384   Cursor new_cursor = None;
385   GdkX11Display *display_x11;
386
387   private = (GdkX11Cursor *) cursor;
388   display_x11 = GDK_X11_DISPLAY (gdk_cursor_get_display (cursor));
389   xdisplay = GDK_DISPLAY_XDISPLAY (display_x11);
390
391   if (!display_x11->have_xfixes)
392     return;
393
394   if (private->serial == theme_serial)
395     return;
396
397   private->serial = theme_serial;
398
399   if (private->xcursor != None)
400     {
401       if (cursor->type == GDK_BLANK_CURSOR)
402         return;
403
404       if (cursor->type == GDK_CURSOR_IS_PIXMAP)
405         {
406           if (private->name)
407             new_cursor = XcursorLibraryLoadCursor (xdisplay, private->name);
408         }
409       else 
410         new_cursor = XcursorShapeLoadCursor (xdisplay, cursor->type);
411       
412       if (new_cursor != None)
413         {
414           XFixesChangeCursor (xdisplay, new_cursor, private->xcursor);
415           private->xcursor = new_cursor;
416         }
417     }
418 }
419
420 static void
421 update_cursor (gpointer data,
422                gpointer user_data)
423 {
424   GdkCursor *cursor;
425
426   cursor = (GdkCursor*)(data);
427
428   if (!cursor)
429     return;
430
431   _gdk_x11_cursor_update_theme (cursor);
432 }
433
434 /**
435  * gdk_x11_display_set_cursor_theme:
436  * @display: (type GdkX11Display): a #GdkDisplay
437  * @theme: the name of the cursor theme to use, or %NULL to unset
438  *         a previously set value
439  * @size: the cursor size to use, or 0 to keep the previous size
440  *
441  * Sets the cursor theme from which the images for cursor
442  * should be taken.
443  *
444  * If the windowing system supports it, existing cursors created
445  * with gdk_cursor_new(), gdk_cursor_new_for_display() and
446  * gdk_cursor_new_for_name() are updated to reflect the theme
447  * change. Custom cursors constructed with
448  * gdk_cursor_new_from_pixbuf() will have to be handled
449  * by the application (GTK+ applications can learn about
450  * cursor theme changes by listening for change notification
451  * for the corresponding #GtkSetting).
452  *
453  * Since: 2.8
454  */
455 void
456 gdk_x11_display_set_cursor_theme (GdkDisplay  *display,
457                                   const gchar *theme,
458                                   const gint   size)
459 {
460   Display *xdisplay;
461   gchar *old_theme;
462   gint old_size;
463
464   g_return_if_fail (GDK_IS_DISPLAY (display));
465
466   xdisplay = GDK_DISPLAY_XDISPLAY (display);
467
468   old_theme = XcursorGetTheme (xdisplay);
469   old_size = XcursorGetDefaultSize (xdisplay);
470
471   if (old_size == size &&
472       (old_theme == theme ||
473        (old_theme && theme && strcmp (old_theme, theme) == 0)))
474     return;
475
476   theme_serial++;
477
478   XcursorSetTheme (xdisplay, theme);
479   if (size > 0)
480     XcursorSetDefaultSize (xdisplay, size);
481
482   g_slist_foreach (cursor_cache, update_cursor, NULL);
483 }
484
485 #else
486
487 static GdkPixbuf*
488 gdk_x11_cursor_get_image (GdkCursor *cursor)
489 {
490   return NULL;
491 }
492
493 void
494 gdk_x11_display_set_cursor_theme (GdkDisplay  *display,
495                                   const gchar *theme,
496                                   const gint   size)
497 {
498   g_return_if_fail (GDK_IS_DISPLAY (display));
499 }
500
501 void
502 _gdk_x11_cursor_update_theme (GdkCursor *cursor)
503 {
504   g_return_if_fail (cursor != NULL);
505 }
506
507 #endif
508
509 #ifdef HAVE_XCURSOR
510
511 static XcursorImage*
512 create_cursor_image (GdkPixbuf *pixbuf,
513                      gint       x,
514                      gint       y)
515 {
516   guint width, height;
517   XcursorImage *xcimage;
518   cairo_surface_t *surface;
519   cairo_t *cr;
520
521   width = gdk_pixbuf_get_width (pixbuf);
522   height = gdk_pixbuf_get_height (pixbuf);
523
524   xcimage = XcursorImageCreate (width, height);
525
526   xcimage->xhot = x;
527   xcimage->yhot = y;
528
529   surface = cairo_image_surface_create_for_data ((guchar *) xcimage->pixels,
530                                                  CAIRO_FORMAT_ARGB32,
531                                                  width,
532                                                  height,
533                                                  width * 4);
534
535   cr = cairo_create (surface);
536   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
537   gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
538   cairo_paint (cr);
539   cairo_destroy (cr);
540
541   cairo_surface_destroy (surface);
542
543   return xcimage;
544 }
545
546 GdkCursor *
547 _gdk_x11_display_get_cursor_for_pixbuf (GdkDisplay *display,
548                                         GdkPixbuf  *pixbuf,
549                                         gint        x,
550                                         gint        y)
551 {
552   XcursorImage *xcimage;
553   Cursor xcursor;
554   GdkX11Cursor *private;
555   const char *option;
556   char *end;
557   gint64 value;
558
559   if (x == -1 && (option = gdk_pixbuf_get_option (pixbuf, "x_hot")))
560     {
561       errno = 0;
562       end = NULL;
563       value = g_ascii_strtoll (option, &end, 10);
564       if (errno == 0 &&
565           end != option &&
566           value >= 0 && value < G_MAXINT)
567         x = (gint) value;
568     }
569   if (y == -1 && (option = gdk_pixbuf_get_option (pixbuf, "y_hot")))
570     {
571       errno = 0;
572       end = NULL;
573       value = g_ascii_strtoll (option, &end, 10);
574       if (errno == 0 &&
575           end != option &&
576           value >= 0 && value < G_MAXINT)
577         y = (gint) value;
578     }
579
580   g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
581   g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
582
583   if (gdk_display_is_closed (display))
584     {
585       xcursor = None;
586     }
587   else
588     {
589       xcimage = create_cursor_image (pixbuf, x, y);
590       xcursor = XcursorImageLoadCursor (GDK_DISPLAY_XDISPLAY (display), xcimage);
591       XcursorImageDestroy (xcimage);
592     }
593
594   private = g_object_new (GDK_TYPE_X11_CURSOR, 
595                           "cursor-type", GDK_CURSOR_IS_PIXMAP,
596                           "display", display,
597                           NULL);
598   private->xcursor = xcursor;
599   private->name = NULL;
600   private->serial = theme_serial;
601
602   return GDK_CURSOR (private);
603 }
604
605 GdkCursor*
606 _gdk_x11_display_get_cursor_for_name (GdkDisplay  *display,
607                                       const gchar *name)
608 {
609   Cursor xcursor;
610   Display *xdisplay;
611   GdkX11Cursor *private;
612
613   if (gdk_display_is_closed (display))
614     {
615       xcursor = None;
616     }
617   else
618     {
619       private = find_in_cache (display, GDK_CURSOR_IS_PIXMAP, name);
620
621       if (private)
622         {
623           /* Cache had it, add a ref for this user */
624           g_object_ref (private);
625
626           return (GdkCursor*) private;
627         }
628
629       xdisplay = GDK_DISPLAY_XDISPLAY (display);
630       xcursor = XcursorLibraryLoadCursor (xdisplay, name);
631       if (xcursor == None)
632         return NULL;
633     }
634
635   private = g_object_new (GDK_TYPE_X11_CURSOR,
636                           "cursor-type", GDK_CURSOR_IS_PIXMAP,
637                           "display", display,
638                           NULL);
639   private->xcursor = xcursor;
640   private->name = g_strdup (name);
641   private->serial = theme_serial;
642
643   add_to_cache (private);
644
645   return GDK_CURSOR (private);
646 }
647
648 gboolean
649 _gdk_x11_display_supports_cursor_alpha (GdkDisplay *display)
650 {
651   return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
652 }
653
654 gboolean
655 _gdk_x11_display_supports_cursor_color (GdkDisplay *display)
656 {
657   return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
658 }
659
660 void
661 _gdk_x11_display_get_default_cursor_size (GdkDisplay *display,
662                                           guint      *width,
663                                           guint      *height)
664 {
665   *width = *height = XcursorGetDefaultSize (GDK_DISPLAY_XDISPLAY (display));
666 }
667
668 #else
669
670 static GdkCursor*
671 gdk_cursor_new_from_pixmap (GdkDisplay     *display,
672                             Pixmap          source_pixmap,
673                             Pixmap          mask_pixmap,
674                             const GdkRGBA  *fg,
675                             const GdkRGBA  *bg,
676                             gint            x,
677                             gint            y)
678 {
679   GdkX11Cursor *private;
680   Cursor xcursor;
681   XColor xfg, xbg;
682
683   g_return_val_if_fail (fg != NULL, NULL);
684   g_return_val_if_fail (bg != NULL, NULL);
685
686   xfg.red = fg->red * 65535;
687   xfg.blue = fg->blue * 65535;
688   xfg.green = fg->green * 65535;
689
690   xbg.red = bg->red * 65535;
691   xbg.blue = bg->blue * 65535;
692   xbg.green = bg->green * 65535;
693
694   if (gdk_display_is_closed (display))
695     xcursor = None;
696   else
697     xcursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
698                                    source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
699   private = g_object_new (GDK_TYPE_X11_CURSOR,
700                           "cursor-type", GDK_CURSOR_IS_PIXMAP,
701                           "display", display,
702                           NULL);
703   private->xcursor = xcursor;
704   private->name = NULL;
705   private->serial = theme_serial;
706
707   return GDK_CURSOR (private);
708 }
709
710 GdkCursor *
711 _gdk_x11_display_get_cursor_for_pixbuf (GdkDisplay *display,
712                                         GdkPixbuf  *pixbuf,
713                                         gint        x,
714                                         gint        y)
715 {
716   GdkCursor *cursor;
717   cairo_surface_t *pixmap, *mask;
718   guint width, height, n_channels, rowstride, data_stride, i, j;
719   guint8 *data, *mask_data, *pixels;
720   GdkRGBA fg = { 0, 0, 0, 1 };
721   GdkRGBA bg = { 1, 1, 1, 1 };
722   GdkScreen *screen;
723   cairo_surface_t *image;
724   cairo_t *cr;
725
726   width = gdk_pixbuf_get_width (pixbuf);
727   height = gdk_pixbuf_get_height (pixbuf);
728
729   g_return_val_if_fail (0 <= x && x < width, NULL);
730   g_return_val_if_fail (0 <= y && y < height, NULL);
731
732   n_channels = gdk_pixbuf_get_n_channels (pixbuf);
733   rowstride = gdk_pixbuf_get_rowstride (pixbuf);
734   pixels = gdk_pixbuf_get_pixels (pixbuf);
735
736   data_stride = 4 * ((width + 31) / 32);
737   data = g_new0 (guint8, data_stride * height);
738   mask_data = g_new0 (guint8, data_stride * height);
739
740   for (j = 0; j < height; j++)
741     {
742       guint8 *src = pixels + j * rowstride;
743       guint8 *d = data + data_stride * j;
744       guint8 *md = mask_data + data_stride * j;
745
746       for (i = 0; i < width; i++)
747         {
748           if (src[1] < 0x80)
749             *d |= 1 << (i % 8);
750
751           if (n_channels == 3 || src[3] >= 0x80)
752             *md |= 1 << (i % 8);
753
754           src += n_channels;
755           if (i % 8 == 7)
756             {
757               d++;
758               md++;
759             }
760         }
761     }
762
763   screen = gdk_display_get_default_screen (display);
764
765   pixmap = _gdk_x11_window_create_bitmap_surface (gdk_screen_get_root_window (screen),
766                                                   width, height);
767   cr = cairo_create (pixmap);
768   image = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_A1,
769                                                width, height, data_stride);
770   cairo_set_source_surface (cr, image, 0, 0);
771   cairo_surface_destroy (image);
772   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
773   cairo_paint (cr);
774   cairo_destroy (cr);
775
776   mask = _gdk_x11_window_create_bitmap_surface (gdk_screen_get_root_window (screen),
777                                                 width, height);
778   cr = cairo_create (mask);
779   image = cairo_image_surface_create_for_data (mask_data, CAIRO_FORMAT_A1,
780                                                width, height, data_stride);
781   cairo_set_source_surface (cr, image, 0, 0);
782   cairo_surface_destroy (image);
783   cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
784   cairo_paint (cr);
785   cairo_destroy (cr);
786
787   cursor = gdk_cursor_new_from_pixmap (display,
788                                        cairo_xlib_surface_get_drawable (pixmap),
789                                        cairo_xlib_surface_get_drawable (mask),
790                                        &fg, &bg,
791                                        x, y);
792
793   cairo_surface_destroy (pixmap);
794   cairo_surface_destroy (mask);
795
796   g_free (data);
797   g_free (mask_data);
798
799   return cursor;
800 }
801
802 GdkCursor*
803 _gdk_x11_display_get_cursor_for_name (GdkDisplay  *display,
804                                       const gchar *name)
805 {
806   return NULL;
807 }
808
809 gboolean
810 _gdk_x11_display_supports_cursor_alpha (GdkDisplay *display)
811 {
812   return FALSE;
813 }
814
815 gboolean
816 _gdk_x11_display_supports_cursor_color (GdkDisplay *display)
817 {
818   return FALSE;
819 }
820
821 void
822 _gdk_x11_display_get_default_cursor_size (GdkDisplay *display,
823                                           guint      *width,
824                                           guint      *height)
825 {
826   /* no idea, really */
827   *width = *height = 20;
828   return;
829 }
830
831 #endif
832
833 void
834 _gdk_x11_display_get_maximal_cursor_size (GdkDisplay *display,
835                                           guint       *width,
836                                           guint       *height)
837 {
838   GdkScreen *screen;
839   GdkWindow *window;
840
841   g_return_if_fail (GDK_IS_DISPLAY (display));
842
843   screen = gdk_display_get_default_screen (display);
844   window = gdk_screen_get_root_window (screen);
845   XQueryBestCursor (GDK_DISPLAY_XDISPLAY (display),
846                     GDK_WINDOW_XID (window),
847                     128, 128, width, height);
848 }