2010-12-18 20:38:49 +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
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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/>.
|
2010-12-18 20:38:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
2015-02-28 03:28:28 +00:00
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
2010-12-18 20:38:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#define GDK_PIXBUF_ENABLE_BACKEND
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gdkprivate-wayland.h"
|
|
|
|
#include "gdkcursorprivate.h"
|
|
|
|
#include "gdkdisplay-wayland.h"
|
|
|
|
#include "gdkwayland.h"
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2020-01-24 18:33:13 +00:00
|
|
|
#include "cursor/wayland-cursor.h"
|
2011-02-09 19:48:29 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_cursor_remove_from_cache (gpointer data, GObject *cursor)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
GdkWaylandDisplay *display = data;
|
2014-09-06 00:41:06 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
g_hash_table_remove (display->cursor_surface_cache, cursor);
|
|
|
|
}
|
2010-12-18 20:38:49 +00:00
|
|
|
|
2014-08-10 16:15:40 +00:00
|
|
|
void
|
|
|
|
_gdk_wayland_display_init_cursors (GdkWaylandDisplay *display)
|
2013-03-21 02:34:03 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
display->cursor_surface_cache = g_hash_table_new_full (gdk_cursor_hash, gdk_cursor_equal, NULL, (GDestroyNotify) cairo_surface_destroy);
|
2013-03-21 02:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gdk_wayland_display_finalize_cursors (GdkWaylandDisplay *display)
|
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer cursor;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, display->cursor_surface_cache);
|
|
|
|
while (g_hash_table_iter_next (&iter, &cursor, NULL))
|
|
|
|
g_object_weak_unref (G_OBJECT (cursor), gdk_wayland_cursor_remove_from_cache, display);
|
|
|
|
g_hash_table_destroy (display->cursor_surface_cache);
|
2013-03-21 02:34:03 +00:00
|
|
|
}
|
|
|
|
|
2015-05-08 13:38:56 +00:00
|
|
|
static const struct {
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *css_name, *traditional_name;
|
2015-05-08 13:38:56 +00:00
|
|
|
} name_map[] = {
|
|
|
|
{ "default", "left_ptr" },
|
2017-11-04 22:12:46 +00:00
|
|
|
{ "help", "question_arrow" },
|
2016-01-06 19:56:06 +00:00
|
|
|
{ "context-menu", "left_ptr" },
|
2015-05-08 13:38:56 +00:00
|
|
|
{ "pointer", "hand" },
|
|
|
|
{ "progress", "left_ptr_watch" },
|
|
|
|
{ "wait", "watch" },
|
|
|
|
{ "cell", "crosshair" },
|
|
|
|
{ "crosshair", "cross" },
|
|
|
|
{ "text", "xterm" },
|
2016-01-06 19:56:06 +00:00
|
|
|
{ "vertical-text","xterm" },
|
2015-05-08 13:38:56 +00:00
|
|
|
{ "alias", "dnd-link" },
|
|
|
|
{ "copy", "dnd-copy" },
|
2016-01-06 19:56:06 +00:00
|
|
|
{ "move", "dnd-move" },
|
2015-05-08 13:38:56 +00:00
|
|
|
{ "no-drop", "dnd-none" },
|
2016-01-08 20:38:02 +00:00
|
|
|
{ "dnd-ask", "dnd-copy" }, /* not CSS, but we want to guarantee it anyway */
|
2015-05-08 13:38:56 +00:00
|
|
|
{ "not-allowed", "crossed_circle" },
|
|
|
|
{ "grab", "hand2" },
|
2016-01-06 19:56:06 +00:00
|
|
|
{ "grabbing", "hand2" },
|
|
|
|
{ "all-scroll", "left_ptr" },
|
2015-05-08 13:38:56 +00:00
|
|
|
{ "col-resize", "h_double_arrow" },
|
|
|
|
{ "row-resize", "v_double_arrow" },
|
|
|
|
{ "n-resize", "top_side" },
|
|
|
|
{ "e-resize", "right_side" },
|
|
|
|
{ "s-resize", "bottom_side" },
|
|
|
|
{ "w-resize", "left_side" },
|
|
|
|
{ "ne-resize", "top_right_corner" },
|
|
|
|
{ "nw-resize", "top_left_corner" },
|
|
|
|
{ "se-resize", "bottom_right_corner" },
|
|
|
|
{ "sw-resize", "bottom_left_corner" },
|
|
|
|
{ "ew-resize", "h_double_arrow" },
|
|
|
|
{ "ns-resize", "v_double_arrow" },
|
|
|
|
{ "nesw-resize", "fd_double_arrow" },
|
|
|
|
{ "nwse-resize", "bd_double_arrow" },
|
2016-01-06 19:56:06 +00:00
|
|
|
{ "zoom-in", "left_ptr" },
|
2017-11-04 22:58:17 +00:00
|
|
|
{ "zoom-out", "left_ptr" }
|
2015-05-08 13:38:56 +00:00
|
|
|
};
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static const char *
|
|
|
|
name_fallback (const char *name)
|
2015-05-08 13:38:56 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2015-05-08 13:38:56 +00:00
|
|
|
|
2017-11-04 22:58:17 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (name_map); i++)
|
2015-05-08 13:38:56 +00:00
|
|
|
{
|
|
|
|
if (g_str_equal (name_map[i].css_name, name))
|
|
|
|
return name_map[i].traditional_name;
|
|
|
|
}
|
|
|
|
|
2016-01-06 19:56:06 +00:00
|
|
|
return NULL;
|
2015-05-08 13:38:56 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
static struct wl_cursor *
|
|
|
|
gdk_wayland_cursor_load_for_name (GdkWaylandDisplay *display_wayland,
|
|
|
|
struct wl_cursor_theme *theme,
|
2020-01-24 18:33:13 +00:00
|
|
|
int scale,
|
2017-11-03 21:41:31 +00:00
|
|
|
const char *name)
|
2013-03-23 00:30:51 +00:00
|
|
|
{
|
|
|
|
struct wl_cursor *c;
|
2017-11-02 19:38:07 +00:00
|
|
|
|
2020-01-24 18:33:13 +00:00
|
|
|
c = wl_cursor_theme_get_cursor (theme, name, scale);
|
2015-05-08 13:38:56 +00:00
|
|
|
if (!c)
|
2016-01-06 19:56:06 +00:00
|
|
|
{
|
|
|
|
const char *fallback;
|
|
|
|
|
2017-11-02 19:38:07 +00:00
|
|
|
fallback = name_fallback (name);
|
2016-01-06 19:56:06 +00:00
|
|
|
if (fallback)
|
|
|
|
{
|
2020-01-24 18:33:13 +00:00
|
|
|
c = wl_cursor_theme_get_cursor (theme, fallback, scale);
|
2016-01-06 19:56:06 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-08 13:38:56 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
return c;
|
2013-03-23 00:30:51 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
static void
|
2017-11-03 21:41:31 +00:00
|
|
|
buffer_release_callback (void *_data,
|
|
|
|
struct wl_buffer *wl_buffer)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
cairo_surface_t *cairo_surface = _data;
|
2010-12-18 20:38:49 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
cairo_surface_destroy (cairo_surface);
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
static const struct wl_buffer_listener buffer_listener = {
|
|
|
|
buffer_release_callback
|
|
|
|
};
|
|
|
|
|
2011-02-09 19:48:29 +00:00
|
|
|
struct wl_buffer *
|
2017-11-03 21:41:31 +00:00
|
|
|
_gdk_wayland_cursor_get_buffer (GdkWaylandDisplay *display,
|
|
|
|
GdkCursor *cursor,
|
|
|
|
guint desired_scale,
|
|
|
|
guint image_index,
|
|
|
|
int *hotspot_x,
|
|
|
|
int *hotspot_y,
|
|
|
|
int *width,
|
|
|
|
int *height,
|
|
|
|
int *scale)
|
2011-02-09 19:48:29 +00:00
|
|
|
{
|
2020-04-26 18:42:45 +00:00
|
|
|
GdkTexture *texture;
|
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
if (gdk_cursor_get_name (cursor))
|
2013-03-26 14:19:37 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
struct wl_cursor *c;
|
2012-07-11 13:43:16 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
if (g_str_equal (gdk_cursor_get_name (cursor), "none"))
|
2019-04-18 14:22:48 +00:00
|
|
|
goto none;
|
2011-02-09 19:48:29 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
c = gdk_wayland_cursor_load_for_name (display,
|
2020-01-24 18:33:13 +00:00
|
|
|
_gdk_wayland_display_get_cursor_theme (display),
|
|
|
|
desired_scale,
|
2017-11-03 21:41:31 +00:00
|
|
|
gdk_cursor_get_name (cursor));
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
struct wl_cursor_image *image;
|
2013-03-28 12:08:43 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
if (image_index >= c->image_count)
|
|
|
|
{
|
|
|
|
g_warning (G_STRLOC " out of bounds cursor image [%d / %d]",
|
|
|
|
image_index,
|
|
|
|
c->image_count - 1);
|
|
|
|
image_index = 0;
|
|
|
|
}
|
2013-03-28 12:08:43 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
image = c->images[image_index];
|
2013-03-26 14:19:37 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
*hotspot_x = image->hotspot_x / desired_scale;
|
|
|
|
*hotspot_y = image->hotspot_y / desired_scale;
|
2013-03-26 14:19:37 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
*width = image->width / desired_scale;
|
|
|
|
*height = image->height / desired_scale;
|
|
|
|
*scale = desired_scale;
|
2014-09-01 16:44:48 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
return wl_cursor_image_get_buffer (image);
|
2013-03-28 12:08:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-03-13 07:40:18 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
struct wl_buffer *buffer;
|
2015-03-13 07:40:18 +00:00
|
|
|
|
2020-04-26 18:42:45 +00:00
|
|
|
texture = gdk_cursor_get_texture (cursor);
|
|
|
|
|
|
|
|
from_texture:
|
2017-11-03 21:41:31 +00:00
|
|
|
surface = g_hash_table_lookup (display->cursor_surface_cache, cursor);
|
|
|
|
if (surface == NULL)
|
|
|
|
{
|
2017-11-04 23:05:56 +00:00
|
|
|
surface = _gdk_wayland_display_create_shm_surface (display,
|
|
|
|
gdk_texture_get_width (texture),
|
|
|
|
gdk_texture_get_height (texture),
|
|
|
|
1);
|
2017-11-03 21:41:31 +00:00
|
|
|
|
|
|
|
gdk_texture_download (texture,
|
|
|
|
cairo_image_surface_get_data (surface),
|
|
|
|
cairo_image_surface_get_stride (surface));
|
|
|
|
cairo_surface_mark_dirty (surface);
|
|
|
|
|
|
|
|
g_object_weak_ref (G_OBJECT (cursor), gdk_wayland_cursor_remove_from_cache, display);
|
|
|
|
g_hash_table_insert (display->cursor_surface_cache, cursor, surface);
|
|
|
|
}
|
2015-03-13 07:40:18 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
*hotspot_x = gdk_cursor_get_hotspot_x (cursor);
|
|
|
|
*hotspot_y = gdk_cursor_get_hotspot_y (cursor);
|
|
|
|
*width = gdk_texture_get_width (texture);
|
|
|
|
*height = gdk_texture_get_height (texture);
|
|
|
|
*scale = 1;
|
2017-04-12 17:56:49 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
cairo_surface_reference (surface);
|
|
|
|
buffer = _gdk_wayland_shm_surface_get_wl_buffer (surface);
|
|
|
|
wl_buffer_add_listener (buffer, &buffer_listener, surface);
|
2015-03-13 07:40:18 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
2010-12-18 20:38:49 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
if (gdk_cursor_get_fallback (cursor))
|
|
|
|
return _gdk_wayland_cursor_get_buffer (display,
|
|
|
|
gdk_cursor_get_fallback (cursor),
|
|
|
|
desired_scale,
|
|
|
|
image_index,
|
|
|
|
hotspot_x, hotspot_y,
|
|
|
|
width, height,
|
|
|
|
scale);
|
2020-04-26 18:42:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
texture = gdk_texture_new_from_resource ("/org/gtk/libgdk/cursor/default");
|
|
|
|
goto from_texture;
|
|
|
|
}
|
2010-12-18 20:38:49 +00:00
|
|
|
|
2019-04-18 14:22:48 +00:00
|
|
|
none:
|
|
|
|
*hotspot_x = 0;
|
|
|
|
*hotspot_y = 0;
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
*scale = 1;
|
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
return NULL;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
guint
|
|
|
|
_gdk_wayland_cursor_get_next_image_index (GdkWaylandDisplay *display,
|
|
|
|
GdkCursor *cursor,
|
|
|
|
guint scale,
|
|
|
|
guint current_image_index,
|
|
|
|
guint *next_image_delay)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
struct wl_cursor *c;
|
2010-12-18 20:38:49 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
if (!gdk_cursor_get_name (cursor) ||
|
|
|
|
g_str_equal (gdk_cursor_get_name (cursor), "none"))
|
2017-04-12 17:56:49 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
*next_image_delay = 0;
|
|
|
|
return current_image_index;
|
2017-04-12 17:56:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
c = gdk_wayland_cursor_load_for_name (display,
|
2020-01-24 18:33:13 +00:00
|
|
|
_gdk_wayland_display_get_cursor_theme (display),
|
|
|
|
scale,
|
2017-11-03 21:41:31 +00:00
|
|
|
gdk_cursor_get_name (cursor));
|
2012-07-11 13:43:16 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
if (c)
|
2016-10-17 19:26:29 +00:00
|
|
|
{
|
2017-11-03 21:41:31 +00:00
|
|
|
if (current_image_index >= c->image_count)
|
|
|
|
{
|
|
|
|
g_warning (G_STRLOC " out of bounds cursor image [%d / %d]",
|
|
|
|
current_image_index, c->image_count - 1);
|
|
|
|
current_image_index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->image_count == 1)
|
|
|
|
{
|
|
|
|
*next_image_delay = 0;
|
|
|
|
return current_image_index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*next_image_delay = c->images[current_image_index]->delay;
|
|
|
|
return (current_image_index + 1) % c->image_count;
|
|
|
|
}
|
2016-10-17 19:26:29 +00:00
|
|
|
}
|
2012-07-11 13:43:16 +00:00
|
|
|
|
2017-11-03 21:41:31 +00:00
|
|
|
if (gdk_cursor_get_fallback (cursor))
|
|
|
|
return _gdk_wayland_cursor_get_next_image_index (display,
|
|
|
|
gdk_cursor_get_fallback (cursor),
|
|
|
|
scale,
|
|
|
|
current_image_index,
|
|
|
|
next_image_delay);
|
|
|
|
|
|
|
|
*next_image_delay = 0;
|
|
|
|
return current_image_index;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|