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)
96 create_buffer_from_shm(Wayland_CursorData *
d,
103 struct wl_shm_pool *shm_pool;
106 int size =
stride * height;
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) {
136 &mouse_buffer_listener,
150 cursor = calloc(1,
sizeof (*cursor));
154 Wayland_CursorData *data = calloc (1,
sizeof (Wayland_CursorData));
167 if (create_buffer_from_shm (data,
179 surface->
h * surface->
pitch);
186 data->
w = surface->
w;
187 data->
h = surface->
h;
196 CreateCursorFromWlCursor(
SDL_VideoData *d,
struct wl_cursor *wlcursor)
200 cursor = calloc(1,
sizeof (*cursor));
202 Wayland_CursorData *data = calloc (1,
sizeof (Wayland_CursorData));
210 data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);
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,
242 struct wl_cursor *cursor =
NULL;
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)
328 Wayland_CursorData *data = cursor->
driverdata;
356 Wayland_WarpMouseGlobal(
int x,
int y)
374 Wayland_InitMouse(
void)
390 Wayland_FiniMouse(
void)
int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input)
SDL_Mouse * SDL_GetMouse(void)
static void wl_surface_set_user_data(struct wl_surface *wl_surface, void *user_data)
int(* ShowCursor)(SDL_Cursor *cursor)
static void wl_surface_commit(struct wl_surface *wl_surface)
GLint GLint GLint GLint GLint x
int(* SetRelativeMouseMode)(SDL_bool enabled)
static void wl_surface_attach(struct wl_surface *wl_surface, struct wl_buffer *buffer, int32_t x, int32_t y)
GLfloat GLfloat GLfloat GLfloat h
A collection of pixels used in software blitting.
static int wl_buffer_add_listener(struct wl_buffer *wl_buffer, const struct wl_buffer_listener *listener, void *data)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
struct wl_cursor_theme * cursor_theme
int Wayland_input_lock_pointer(struct SDL_WaylandInput *input)
static void wl_surface_destroy(struct wl_surface *wl_surface)
static void wl_surface_damage(struct wl_surface *wl_surface, int32_t x, int32_t y, int32_t width, int32_t height)
struct SDL_WaylandInput * input
GLint GLint GLsizei width
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
static SDL_AudioDeviceID device
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
static void wl_shm_pool_destroy(struct wl_shm_pool *wl_shm_pool)
GLubyte GLubyte GLubyte GLubyte w
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
GLint GLint GLint GLint GLint GLint y
GLsizei const void * pointer
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
int(* WarpMouseGlobal)(int x, int y)
static struct wl_buffer * wl_shm_pool_create_buffer(struct wl_shm_pool *wl_shm_pool, int32_t offset, int32_t width, int32_t height, int32_t stride, uint32_t format)
GLenum GLenum GLsizei const GLuint GLboolean enabled
void(* FreeCursor)(SDL_Cursor *cursor)
struct wl_pointer * pointer
#define SDL_assert(condition)
#define SDL_OutOfMemory()
static void wl_buffer_destroy(struct wl_buffer *wl_buffer)
struct wl_compositor * compositor
GLint GLint GLsizei GLsizei height
static struct wl_surface * wl_compositor_create_surface(struct wl_compositor *wl_compositor)
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
static void wl_pointer_set_cursor(struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, int32_t hotspot_x, int32_t hotspot_y)
void(* WarpMouse)(SDL_Window *window, int x, int y)
SDL_VideoDevice * SDL_GetVideoDevice(void)
static struct wl_shm_pool * wl_shm_create_pool(struct wl_shm *wl_shm, int32_t fd, int32_t size)
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
#define SDL_Unsupported()
int uint32_t uint32_t uint32_t uint32_t uint32_t int drmModeModeInfoPtr mode int uint32_t uint32_t uint32_t uint32_t int32_t hot_x