22 #include "../../SDL_internal.h" 24 #if SDL_VIDEO_DRIVER_WAYLAND 30 #include <sys/types.h> 37 #include "../SDL_sysvideo.h" 40 #include "../../events/SDL_mouse_c.h" 45 #include "wayland-cursor.h" 52 struct wl_surface *surface;
63 wayland_create_tmp_file(off_t
size)
65 static const char template[] =
"/sdl-shared-XXXXXX";
67 char tmp_path[PATH_MAX];
78 fd = mkostemp(tmp_path, O_CLOEXEC);
82 if (ftruncate(fd, size) < 0) {
91 mouse_buffer_release(
void *
data,
struct wl_buffer *
buffer)
95 static const struct wl_buffer_listener mouse_buffer_listener = {
100 create_buffer_from_shm(Wayland_CursorData *
d,
107 struct wl_shm_pool *shm_pool;
110 int size =
stride * height;
114 shm_fd = wayland_create_tmp_file(size);
117 return SDL_SetError(
"Creating mouse cursor buffer failed.");
120 d->shm_data = mmap(
NULL,
122 PROT_READ | PROT_WRITE,
126 if (d->shm_data == MAP_FAILED) {
132 shm_pool = wl_shm_create_pool(data->
shm, shm_fd, size);
133 d->buffer = wl_shm_pool_create_buffer(shm_pool,
139 wl_buffer_add_listener(d->buffer,
140 &mouse_buffer_listener,
143 wl_shm_pool_destroy (shm_pool);
150 Wayland_CreateCursor(
SDL_Surface *surface,
int hot_x,
int hot_y)
154 cursor =
calloc(1,
sizeof (*cursor));
158 Wayland_CursorData *data =
calloc (1,
sizeof (Wayland_CursorData));
171 if (create_buffer_from_shm (data,
174 WL_SHM_FORMAT_ARGB8888) < 0)
183 surface->
h * surface->
pitch);
185 data->surface = wl_compositor_create_surface(wd->
compositor);
186 wl_surface_set_user_data(data->surface,
NULL);
190 data->
w = surface->
w;
191 data->
h = surface->
h;
200 CreateCursorFromWlCursor(
SDL_VideoData *d,
struct wl_cursor *wlcursor)
204 cursor =
calloc(1,
sizeof (*cursor));
206 Wayland_CursorData *data =
calloc (1,
sizeof (Wayland_CursorData));
214 data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);
215 data->surface = wl_compositor_create_surface(d->
compositor);
216 wl_surface_set_user_data(data->surface,
NULL);
217 data->hot_x = wlcursor->images[0]->hotspot_x;
218 data->hot_y = wlcursor->images[0]->hotspot_y;
219 data->w = wlcursor->images[0]->width;
220 data->h = wlcursor->images[0]->height;
221 data->cursor= wlcursor;
230 Wayland_CreateDefaultCursor()
235 return CreateCursorFromWlCursor (data,
246 struct wl_cursor *cursor =
NULL;
254 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"left_ptr");
257 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"xterm");
260 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"watch");
263 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
266 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"watch");
269 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
272 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
275 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
278 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
281 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
284 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"xterm");
287 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
291 return CreateCursorFromWlCursor(d, cursor);
297 Wayland_CursorData *
d;
308 if (d->buffer && !d->cursor)
309 wl_buffer_destroy(d->buffer);
312 wl_surface_destroy(d->surface);
332 Wayland_CursorData *data = cursor->
driverdata;
334 wl_pointer_set_cursor (pointer, 0,
338 wl_surface_attach(data->surface, data->buffer, 0, 0);
339 wl_surface_damage(data->surface, 0, 0, data->w, data->h);
340 wl_surface_commit(data->surface);
344 wl_pointer_set_cursor (pointer, 0,
360 Wayland_WarpMouseGlobal(
int x,
int y)
378 Wayland_InitMouse(
void)
394 Wayland_FiniMouse(
void)
int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
SDL_Mouse * SDL_GetMouse(void)
int(* ShowCursor)(SDL_Cursor *cursor)
GLint GLint GLsizei width
GLint GLint GLint GLint GLint x
int(* SetRelativeMouseMode)(SDL_bool enabled)
static SDL_Window * window
A collection of pixels used in software blitting.
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)
GLint GLint GLsizei GLsizei height
struct SDL_WaylandInput * input
GLsizei const void * pointer
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
GLint GLint GLint GLint GLint GLint 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
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
int(* WarpMouseGlobal)(int x, int y)
GLenum GLenum GLsizei const GLuint GLboolean enabled
void(* FreeCursor)(SDL_Cursor *cursor)
struct wl_pointer * pointer
#define SDL_assert(condition)
#define SDL_OutOfMemory()
struct wl_compositor * compositor
The type used to identify a window.
void(* WarpMouse)(SDL_Window *window, int x, int y)
SDL_VideoDevice * SDL_GetVideoDevice(void)
GLubyte GLubyte GLubyte GLubyte w
SDL_Cursor *(* CreateSystemCursor)(SDL_SystemCursor id)
#define SDL_Unsupported()
GLfloat GLfloat GLfloat GLfloat h