1997-11-24 22:37:52 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1997-11-24 22:37:52 +00:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
* Lesser General Public License for more details.
|
1997-11-24 22:37:52 +00:00
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-24 22:37:52 +00:00
|
|
|
*/
|
1999-02-24 07:37:18 +00:00
|
|
|
|
|
|
|
/*
|
2000-07-26 11:33:08 +00:00
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:37:18 +00:00
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2005-06-15 18:37:18 +00:00
|
|
|
|
2010-10-18 16:19:17 +00:00
|
|
|
/* needs to be first because any header might include gdk-pixbuf.h otherwise */
|
|
|
|
#define GDK_PIXBUF_ENABLE_BACKEND
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
|
2010-10-15 02:05:51 +00:00
|
|
|
#include "gdkcursor.h"
|
2010-12-20 01:20:48 +00:00
|
|
|
#include "gdkcursorprivate.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
#include "gdkprivate-x11.h"
|
|
|
|
#include "gdkdisplay-x11.h"
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/cursorfont.h>
|
2003-06-30 22:30:54 +00:00
|
|
|
#ifdef HAVE_XCURSOR
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
#endif
|
2005-06-14 15:10:13 +00:00
|
|
|
#ifdef HAVE_XFIXES
|
|
|
|
#include <X11/extensions/Xfixes.h>
|
|
|
|
#endif
|
|
|
|
#include <string.h>
|
1999-10-01 23:18:30 +00:00
|
|
|
|
2009-01-20 02:15:59 +00:00
|
|
|
static void
|
2017-11-03 05:01:56 +00:00
|
|
|
gdk_x11_cursor_remove_from_cache (gpointer data, GObject *cursor)
|
2009-01-20 02:15:59 +00:00
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
GdkDisplay *display = data;
|
|
|
|
Cursor xcursor;
|
2009-01-20 02:15:59 +00:00
|
|
|
|
2017-11-04 00:35:59 +00:00
|
|
|
xcursor = GDK_POINTER_TO_XID (g_hash_table_lookup (GDK_X11_DISPLAY (display)->cursors, cursor));
|
2017-11-03 05:01:56 +00:00
|
|
|
XFreeCursor (GDK_DISPLAY_XDISPLAY (display), xcursor);
|
2017-11-04 00:35:59 +00:00
|
|
|
g_hash_table_remove (GDK_X11_DISPLAY (display)->cursors, cursor);
|
2009-01-20 02:15:59 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 06:43:08 +00:00
|
|
|
void
|
2009-01-20 02:15:59 +00:00
|
|
|
_gdk_x11_cursor_display_finalize (GdkDisplay *display)
|
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer cursor;
|
|
|
|
|
|
|
|
if (GDK_X11_DISPLAY (display)->cursors)
|
2009-01-20 02:15:59 +00:00
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
g_hash_table_iter_init (&iter, GDK_X11_DISPLAY (display)->cursors);
|
|
|
|
while (g_hash_table_iter_next (&iter, &cursor, NULL))
|
|
|
|
g_object_weak_unref (G_OBJECT (cursor), gdk_x11_cursor_remove_from_cache, display);
|
|
|
|
g_hash_table_unref (GDK_X11_DISPLAY (display)->cursors);
|
2009-01-20 02:15:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Cursor
|
|
|
|
get_blank_cursor (GdkDisplay *display)
|
|
|
|
{
|
2010-08-27 14:00:09 +00:00
|
|
|
Pixmap pixmap;
|
2009-01-20 02:15:59 +00:00
|
|
|
XColor color;
|
|
|
|
Cursor cursor;
|
2010-08-27 14:00:09 +00:00
|
|
|
cairo_surface_t *surface;
|
2010-08-06 20:41:21 +00:00
|
|
|
cairo_t *cr;
|
2009-01-20 02:15:59 +00:00
|
|
|
|
2017-11-09 23:40:16 +00:00
|
|
|
surface = _gdk_x11_display_create_bitmap_surface (display, 1, 1);
|
2010-08-27 14:00:09 +00:00
|
|
|
/* Clear surface */
|
|
|
|
cr = cairo_create (surface);
|
2010-08-06 20:41:21 +00:00
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
|
|
|
|
cairo_paint (cr);
|
|
|
|
cairo_destroy (cr);
|
2009-01-20 02:15:59 +00:00
|
|
|
|
2010-08-27 14:00:09 +00:00
|
|
|
pixmap = cairo_xlib_surface_get_drawable (surface);
|
2009-01-20 02:15:59 +00:00
|
|
|
|
|
|
|
color.pixel = 0;
|
|
|
|
color.red = color.blue = color.green = 0;
|
2010-12-11 04:14:43 +00:00
|
|
|
|
|
|
|
if (gdk_display_is_closed (display))
|
2009-01-20 02:15:59 +00:00
|
|
|
cursor = None;
|
|
|
|
else
|
|
|
|
cursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
|
2010-08-27 14:00:09 +00:00
|
|
|
pixmap, pixmap,
|
2009-01-20 02:15:59 +00:00
|
|
|
&color, &color, 1, 1);
|
2010-08-27 14:00:09 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2009-01-20 02:15:59 +00:00
|
|
|
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
static const struct {
|
|
|
|
const char *css_name;
|
|
|
|
const char *traditional_name;
|
|
|
|
int cursor_glyph;
|
|
|
|
} name_map[] = {
|
|
|
|
{ "default", "left_ptr", XC_left_ptr, },
|
2017-11-04 22:12:46 +00:00
|
|
|
{ "help", "question_arrow", XC_question_arrow },
|
2017-11-03 05:01:56 +00:00
|
|
|
{ "context-menu", "left_ptr", XC_left_ptr },
|
|
|
|
{ "pointer", "hand", XC_hand1 },
|
|
|
|
{ "progress", "left_ptr_watch", XC_watch },
|
|
|
|
{ "wait", "watch", XC_watch },
|
|
|
|
{ "cell", "crosshair", XC_plus },
|
|
|
|
{ "crosshair", "cross", XC_crosshair },
|
|
|
|
{ "text", "xterm", XC_xterm },
|
|
|
|
{ "vertical-text","xterm", XC_xterm },
|
|
|
|
{ "alias", "dnd-link", XC_target },
|
|
|
|
{ "copy", "dnd-copy", XC_target },
|
|
|
|
{ "move", "dnd-move", XC_target },
|
|
|
|
{ "no-drop", "dnd-none", XC_pirate },
|
|
|
|
{ "dnd-ask", "dnd-copy", XC_target }, /* not CSS, but we want to guarantee it anyway */
|
|
|
|
{ "not-allowed", "crossed_circle", XC_pirate },
|
|
|
|
{ "grab", "hand2", XC_hand2 },
|
|
|
|
{ "grabbing", "hand2", XC_hand2 },
|
|
|
|
{ "all-scroll", "left_ptr", XC_left_ptr },
|
|
|
|
{ "col-resize", "h_double_arrow", XC_sb_h_double_arrow },
|
|
|
|
{ "row-resize", "v_double_arrow", XC_sb_v_double_arrow },
|
|
|
|
{ "n-resize", "top_side", XC_top_side },
|
|
|
|
{ "e-resize", "right_side", XC_right_side },
|
|
|
|
{ "s-resize", "bottom_side", XC_bottom_side },
|
|
|
|
{ "w-resize", "left_side", XC_left_side },
|
|
|
|
{ "ne-resize", "top_right_corner", XC_top_right_corner },
|
|
|
|
{ "nw-resize", "top_left_corner", XC_top_left_corner },
|
|
|
|
{ "se-resize", "bottom_right_corner", XC_bottom_right_corner },
|
|
|
|
{ "sw-resize", "bottom_left_corner", XC_bottom_left_corner },
|
|
|
|
{ "ew-resize", "h_double_arrow", XC_sb_h_double_arrow },
|
|
|
|
{ "ns-resize", "v_double_arrow", XC_sb_v_double_arrow },
|
|
|
|
{ "nesw-resize", "fd_double_arrow", XC_X_cursor },
|
|
|
|
{ "nwse-resize", "bd_double_arrow", XC_X_cursor },
|
|
|
|
{ "zoom-in", "left_ptr", XC_draped_box },
|
2017-11-04 22:58:17 +00:00
|
|
|
{ "zoom-out", "left_ptr", XC_draped_box }
|
2017-11-03 05:01:56 +00:00
|
|
|
};
|
2005-06-14 15:10:13 +00:00
|
|
|
|
2003-06-30 22:30:54 +00:00
|
|
|
#ifdef HAVE_XCURSOR
|
|
|
|
|
|
|
|
static XcursorImage*
|
2017-11-03 00:59:15 +00:00
|
|
|
create_cursor_image (GdkTexture *texture,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint scale)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
|
|
|
XcursorImage *xcimage;
|
|
|
|
|
2017-11-03 00:59:15 +00:00
|
|
|
xcimage = XcursorImageCreate (gdk_texture_get_width (texture), gdk_texture_get_height (texture));
|
2003-06-30 22:30:54 +00:00
|
|
|
|
2017-11-03 00:59:15 +00:00
|
|
|
xcimage->xhot = x;
|
|
|
|
xcimage->yhot = y;
|
2013-08-07 10:18:38 +00:00
|
|
|
|
2017-11-03 00:59:15 +00:00
|
|
|
gdk_texture_download (texture,
|
|
|
|
(guchar *) xcimage->pixels,
|
|
|
|
gdk_texture_get_width (texture) * 4);
|
2003-06-30 22:30:54 +00:00
|
|
|
|
|
|
|
return xcimage;
|
|
|
|
}
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
static Cursor
|
|
|
|
gdk_x11_cursor_create_for_texture (GdkDisplay *display,
|
|
|
|
GdkTexture *texture,
|
|
|
|
int x,
|
|
|
|
int y)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
|
|
|
XcursorImage *xcimage;
|
|
|
|
Cursor xcursor;
|
2013-08-07 10:18:38 +00:00
|
|
|
int target_scale;
|
2003-06-30 22:30:54 +00:00
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
target_scale =
|
|
|
|
gdk_monitor_get_scale_factor (gdk_display_get_primary_monitor (display));
|
|
|
|
xcimage = create_cursor_image (texture, x, y, target_scale);
|
|
|
|
xcursor = XcursorImageLoadCursor (GDK_DISPLAY_XDISPLAY (display), xcimage);
|
|
|
|
XcursorImageDestroy (xcimage);
|
2003-06-30 22:30:54 +00:00
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
return xcursor;
|
2005-06-14 15:10:13 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 13:37:39 +00:00
|
|
|
static const gchar *
|
|
|
|
name_fallback (const gchar *name)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (name_map); i++)
|
2015-05-08 13:37:39 +00:00
|
|
|
{
|
|
|
|
if (g_str_equal (name_map[i].css_name, name))
|
|
|
|
return name_map[i].traditional_name;
|
|
|
|
}
|
|
|
|
|
2016-01-06 19:54:33 +00:00
|
|
|
return NULL;
|
2015-05-08 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
static Cursor
|
|
|
|
gdk_x11_cursor_create_for_name (GdkDisplay *display,
|
|
|
|
const char *name)
|
2005-06-14 15:10:13 +00:00
|
|
|
{
|
|
|
|
Cursor xcursor;
|
|
|
|
Display *xdisplay;
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
if (strcmp (name, "none") == 0)
|
2017-11-02 01:47:35 +00:00
|
|
|
{
|
|
|
|
xcursor = get_blank_cursor (display);
|
|
|
|
}
|
2010-12-13 17:36:35 +00:00
|
|
|
else
|
2005-06-14 15:10:13 +00:00
|
|
|
{
|
|
|
|
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
|
|
|
xcursor = XcursorLibraryLoadCursor (xdisplay, name);
|
2015-05-08 13:37:39 +00:00
|
|
|
if (xcursor == None)
|
2016-01-06 19:54:33 +00:00
|
|
|
{
|
|
|
|
const char *fallback;
|
|
|
|
|
|
|
|
fallback = name_fallback (name);
|
|
|
|
if (fallback)
|
2017-11-03 05:01:56 +00:00
|
|
|
xcursor = XcursorLibraryLoadCursor (xdisplay, fallback);
|
2016-10-17 19:27:15 +00:00
|
|
|
}
|
2005-06-14 15:10:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
return xcursor;
|
2003-06-30 22:30:54 +00:00
|
|
|
}
|
|
|
|
|
2010-12-13 17:36:35 +00:00
|
|
|
gboolean
|
|
|
|
_gdk_x11_display_supports_cursor_alpha (GdkDisplay *display)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
|
|
|
return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
|
|
|
|
}
|
|
|
|
|
2010-12-13 17:36:35 +00:00
|
|
|
gboolean
|
|
|
|
_gdk_x11_display_supports_cursor_color (GdkDisplay *display)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
|
|
|
return XcursorSupportsARGB (GDK_DISPLAY_XDISPLAY (display));
|
|
|
|
}
|
|
|
|
|
2010-12-13 17:36:35 +00:00
|
|
|
void
|
|
|
|
_gdk_x11_display_get_default_cursor_size (GdkDisplay *display,
|
|
|
|
guint *width,
|
|
|
|
guint *height)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
2010-12-13 17:36:35 +00:00
|
|
|
*width = *height = XcursorGetDefaultSize (GDK_DISPLAY_XDISPLAY (display));
|
2003-06-30 22:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
static Cursor
|
|
|
|
gdk_x11_cursor_create_for_texture (GdkDisplay *display,
|
|
|
|
GdkTexture *texture,
|
|
|
|
int x,
|
|
|
|
int y)
|
2010-08-12 13:43:23 +00:00
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
return None;
|
2010-08-12 13:43:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
static Cursor
|
|
|
|
gdk_x11_cursor_create_for_name (GdkDisplay *display,
|
|
|
|
const gchar *name)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
gint i;
|
2003-06-30 22:30:54 +00:00
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
if (g_str_equal (name, "none"))
|
|
|
|
return get_blank_cursor (display);
|
2003-06-30 22:30:54 +00:00
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (name_map); i++)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
if (g_str_equal (name_map[i].css_name, name) ||
|
|
|
|
g_str_equal (name_map[i].traditional_name, name))
|
|
|
|
return XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display), name_map[i].cursor_glyph);
|
2003-06-30 22:30:54 +00:00
|
|
|
}
|
2010-12-13 17:36:35 +00:00
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
return None;
|
2005-06-14 20:43:20 +00:00
|
|
|
}
|
|
|
|
|
2010-12-13 17:36:35 +00:00
|
|
|
gboolean
|
|
|
|
_gdk_x11_display_supports_cursor_alpha (GdkDisplay *display)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-13 17:36:35 +00:00
|
|
|
gboolean
|
|
|
|
_gdk_x11_display_supports_cursor_color (GdkDisplay *display)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-13 17:36:35 +00:00
|
|
|
void
|
2010-12-28 03:19:52 +00:00
|
|
|
_gdk_x11_display_get_default_cursor_size (GdkDisplay *display,
|
|
|
|
guint *width,
|
|
|
|
guint *height)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
|
|
|
/* no idea, really */
|
2010-12-28 03:19:52 +00:00
|
|
|
*width = *height = 20;
|
|
|
|
return;
|
2003-06-30 22:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-12-13 17:36:35 +00:00
|
|
|
void
|
|
|
|
_gdk_x11_display_get_maximal_cursor_size (GdkDisplay *display,
|
|
|
|
guint *width,
|
|
|
|
guint *height)
|
2003-06-30 22:30:54 +00:00
|
|
|
{
|
2003-07-05 01:54:05 +00:00
|
|
|
g_return_if_fail (GDK_IS_DISPLAY (display));
|
2010-12-13 17:36:35 +00:00
|
|
|
|
|
|
|
XQueryBestCursor (GDK_DISPLAY_XDISPLAY (display),
|
2017-11-09 23:40:16 +00:00
|
|
|
GDK_SCREEN_XROOTWIN (GDK_X11_DISPLAY (display)->screen),
|
2010-12-13 17:36:35 +00:00
|
|
|
128, 128, width, height);
|
2003-06-30 22:30:54 +00:00
|
|
|
}
|
2017-11-03 05:01:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_x11_display_set_cursor_theme:
|
|
|
|
* @display: (type GdkX11Display): a #GdkDisplay
|
|
|
|
* @theme: the name of the cursor theme to use, or %NULL to unset
|
|
|
|
* a previously set value
|
|
|
|
* @size: the cursor size to use, or 0 to keep the previous size
|
|
|
|
*
|
|
|
|
* Sets the cursor theme from which the images for cursor
|
|
|
|
* should be taken.
|
|
|
|
*
|
|
|
|
* If the windowing system supports it, existing cursors created
|
|
|
|
* with gdk_cursor_new(), gdk_cursor_new_for_display() and
|
|
|
|
* gdk_cursor_new_from_name() are updated to reflect the theme
|
|
|
|
* change. Custom cursors constructed with
|
2017-11-30 01:14:53 +00:00
|
|
|
* gdk_cursor_new_from_texture() will have to be handled
|
2017-11-03 05:01:56 +00:00
|
|
|
* by the application (GTK+ applications can learn about
|
|
|
|
* cursor theme changes by listening for change notification
|
|
|
|
* for the corresponding #GtkSetting).
|
|
|
|
*
|
|
|
|
* Since: 2.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gdk_x11_display_set_cursor_theme (GdkDisplay *display,
|
|
|
|
const gchar *theme,
|
|
|
|
const gint size)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_XCURSOR) && defined(HAVE_XFIXES) && XFIXES_MAJOR >= 2
|
|
|
|
Display *xdisplay;
|
|
|
|
gchar *old_theme;
|
|
|
|
gint old_size;
|
|
|
|
gpointer cursor, xcursor;
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_DISPLAY (display));
|
|
|
|
|
|
|
|
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
|
|
|
|
|
|
|
old_theme = XcursorGetTheme (xdisplay);
|
|
|
|
old_size = XcursorGetDefaultSize (xdisplay);
|
|
|
|
|
|
|
|
if (old_size == size &&
|
|
|
|
(old_theme == theme ||
|
|
|
|
(old_theme && theme && strcmp (old_theme, theme) == 0)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
XcursorSetTheme (xdisplay, theme);
|
|
|
|
if (size > 0)
|
|
|
|
XcursorSetDefaultSize (xdisplay, size);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, GDK_X11_DISPLAY (display)->cursors);
|
|
|
|
while (g_hash_table_iter_next (&iter, &cursor, &xcursor))
|
|
|
|
{
|
|
|
|
const char *name = gdk_cursor_get_name (cursor);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
Cursor new_cursor = gdk_x11_cursor_create_for_name (display, name);
|
|
|
|
|
|
|
|
if (new_cursor != None)
|
|
|
|
{
|
|
|
|
XFixesChangeCursor (xdisplay, new_cursor, GDK_POINTER_TO_XID (xcursor));
|
|
|
|
g_hash_table_iter_replace (&iter, GDK_XID_TO_POINTER (new_cursor));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gdk_x11_display_get_xcursor:
|
2017-11-04 12:23:02 +00:00
|
|
|
* @display: (type GdkX11Display): a #GdkDisplay
|
2017-11-03 05:01:56 +00:00
|
|
|
* @cursor: a #GdkCursor.
|
|
|
|
*
|
|
|
|
* Returns the X cursor belonging to a #GdkCursor, potentially
|
|
|
|
* creating the cursor.
|
|
|
|
*
|
|
|
|
* Be aware that the returned cursor may not be unique to @cursor.
|
|
|
|
* It may for example be shared with its fallback cursor. On old
|
|
|
|
* X servers that don't support the XCursor extension, all cursors
|
|
|
|
* may even fall back to a few default cursors.
|
|
|
|
*
|
|
|
|
* Returns: an Xlib Cursor.
|
|
|
|
**/
|
|
|
|
Cursor
|
|
|
|
gdk_x11_display_get_xcursor (GdkDisplay *display,
|
|
|
|
GdkCursor *cursor)
|
|
|
|
{
|
|
|
|
GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
|
|
|
|
Cursor xcursor;
|
|
|
|
|
|
|
|
g_return_val_if_fail (cursor != NULL, None);
|
|
|
|
|
|
|
|
if (gdk_display_is_closed (display))
|
|
|
|
return None;
|
|
|
|
|
|
|
|
if (x11_display->cursors == NULL)
|
|
|
|
x11_display->cursors = g_hash_table_new (gdk_cursor_hash, gdk_cursor_equal);
|
|
|
|
|
|
|
|
xcursor = GDK_POINTER_TO_XID (g_hash_table_lookup (x11_display->cursors, cursor));
|
|
|
|
if (xcursor)
|
|
|
|
return xcursor;
|
|
|
|
|
|
|
|
if (gdk_cursor_get_name (cursor))
|
|
|
|
xcursor = gdk_x11_cursor_create_for_name (display, gdk_cursor_get_name (cursor));
|
|
|
|
else
|
|
|
|
xcursor = gdk_x11_cursor_create_for_texture (display,
|
|
|
|
gdk_cursor_get_texture (cursor),
|
|
|
|
gdk_cursor_get_hotspot_x (cursor),
|
|
|
|
gdk_cursor_get_hotspot_y (cursor));
|
|
|
|
|
|
|
|
if (xcursor != None)
|
|
|
|
{
|
|
|
|
g_object_weak_ref (G_OBJECT (cursor), gdk_x11_cursor_remove_from_cache, display);
|
|
|
|
g_hash_table_insert (x11_display->cursors, cursor, GDK_XID_TO_POINTER (xcursor));
|
|
|
|
return xcursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gdk_cursor_get_fallback (cursor))
|
|
|
|
return gdk_x11_display_get_xcursor (display, gdk_cursor_get_fallback (cursor));
|
|
|
|
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|