22 #include "../../SDL_internal.h"
24 #if SDL_VIDEO_DRIVER_WAYLAND
26 #include <sys/types.h>
33 #include "../SDL_sysvideo.h"
36 #include "../../events/SDL_mouse_c.h"
41 #include "wayland-cursor.h"
59 wayland_create_tmp_file(off_t
size)
61 static const char template[] =
"/sdl-shared-XXXXXX";
63 char tmp_path[PATH_MAX];
74 fd = mkostemp(tmp_path, O_CLOEXEC);
78 if (ftruncate(
fd,
size) < 0) {
87 mouse_buffer_release(
void *
data,
struct wl_buffer *
buffer)
91 static const struct wl_buffer_listener mouse_buffer_listener = {
96 create_buffer_from_shm(Wayland_CursorData *
d,
103 struct wl_shm_pool *shm_pool;
110 shm_fd = wayland_create_tmp_file(
size);
113 return SDL_SetError(
"Creating mouse cursor buffer failed.");
116 d->shm_data = mmap(
NULL,
118 PROT_READ | PROT_WRITE,
122 if (
d->shm_data == MAP_FAILED) {
128 shm_pool = wl_shm_create_pool(
data->shm, shm_fd,
size);
129 d->buffer = wl_shm_pool_create_buffer(shm_pool,
135 wl_buffer_add_listener(
d->buffer,
136 &mouse_buffer_listener,
139 wl_shm_pool_destroy (shm_pool);
154 Wayland_CursorData *
data = calloc (1,
sizeof (Wayland_CursorData));
167 if (create_buffer_from_shm (
data,
170 WL_SHM_FORMAT_ARGB8888) < 0)
182 wl_surface_set_user_data(
data->surface,
NULL);
196 CreateCursorFromWlCursor(
SDL_VideoData *
d,
struct wl_cursor *wlcursor)
202 Wayland_CursorData *
data = calloc (1,
sizeof (Wayland_CursorData));
210 data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);
211 data->surface = wl_compositor_create_surface(
d->compositor);
212 wl_surface_set_user_data(
data->surface,
NULL);
213 data->hot_x = wlcursor->images[0]->hotspot_x;
214 data->hot_y = wlcursor->images[0]->hotspot_y;
215 data->w = wlcursor->images[0]->width;
216 data->h = wlcursor->images[0]->height;
217 data->cursor= wlcursor;
226 Wayland_CreateDefaultCursor()
231 return CreateCursorFromWlCursor (
data,
232 WAYLAND_wl_cursor_theme_get_cursor(
data->cursor_theme,
250 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"left_ptr");
253 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"xterm");
256 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"watch");
259 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"hand1");
262 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"watch");
265 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"hand1");
268 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"hand1");
271 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"hand1");
274 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"hand1");
277 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"hand1");
280 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"xterm");
283 cursor = WAYLAND_wl_cursor_theme_get_cursor(
d->cursor_theme,
"hand1");
287 return CreateCursorFromWlCursor(
d,
cursor);
293 Wayland_CursorData *
d;
304 if (
d->buffer && !
d->cursor)
305 wl_buffer_destroy(
d->buffer);
308 wl_surface_destroy(
d->surface);
321 struct wl_pointer *
pointer =
d->pointer;
330 wl_pointer_set_cursor (
pointer, 0,
334 wl_surface_attach(
data->surface,
data->buffer, 0, 0);
335 wl_surface_damage(
data->surface, 0, 0,
data->w,
data->h);
336 wl_surface_commit(
data->surface);
340 wl_pointer_set_cursor (
pointer, 0,
356 Wayland_WarpMouseGlobal(
int x,
int y)
374 Wayland_InitMouse(
void)
390 Wayland_FiniMouse(
void)