22 #include "../../SDL_internal.h" 24 #if SDL_VIDEO_DRIVER_WAYLAND 31 #include <sys/types.h> 38 #include "../SDL_sysvideo.h" 41 #include "../../events/SDL_mouse_c.h" 46 #include "wayland-cursor.h" 53 struct wl_surface *surface;
64 wayland_create_tmp_file(off_t
size)
66 static const char template[] =
"/sdl-shared-XXXXXX";
68 char tmp_path[PATH_MAX];
80 fd = mkostemp(tmp_path, O_CLOEXEC);
84 if (ftruncate(fd, size) < 0) {
93 mouse_buffer_release(
void *
data,
struct wl_buffer *
buffer)
97 static const struct wl_buffer_listener mouse_buffer_listener = {
102 create_buffer_from_shm(Wayland_CursorData *
d,
109 struct wl_shm_pool *shm_pool;
112 int size =
stride * height;
116 shm_fd = wayland_create_tmp_file(size);
119 fprintf(stderr,
"creating mouse cursor buffer failed!\n");
123 d->shm_data = mmap(
NULL,
125 PROT_READ | PROT_WRITE,
129 if (d->shm_data == MAP_FAILED) {
131 fprintf (stderr,
"mmap () failed\n");
135 shm_pool = wl_shm_create_pool(data->
shm, shm_fd, size);
136 d->buffer = wl_shm_pool_create_buffer(shm_pool,
142 wl_buffer_add_listener(d->buffer,
143 &mouse_buffer_listener,
146 wl_shm_pool_destroy (shm_pool);
153 Wayland_CreateCursor(
SDL_Surface *surface,
int hot_x,
int hot_y)
157 cursor =
calloc(1,
sizeof (*cursor));
161 Wayland_CursorData *data =
calloc (1,
sizeof (Wayland_CursorData));
169 if (create_buffer_from_shm (data,
172 WL_SHM_FORMAT_XRGB8888) < 0)
181 surface->
h * surface->
pitch);
183 data->surface = wl_compositor_create_surface(wd->
compositor);
184 wl_surface_set_user_data(data->surface,
NULL);
188 data->
w = surface->
w;
189 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));
205 data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);
206 data->surface = wl_compositor_create_surface(d->
compositor);
207 wl_surface_set_user_data(data->surface,
NULL);
208 data->hot_x = wlcursor->images[0]->hotspot_x;
209 data->hot_y = wlcursor->images[0]->hotspot_y;
210 data->w = wlcursor->images[0]->width;
211 data->h = wlcursor->images[0]->height;
212 data->cursor= wlcursor;
221 Wayland_CreateDefaultCursor()
226 return CreateCursorFromWlCursor (data,
237 struct wl_cursor *cursor =
NULL;
245 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"left_ptr");
248 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"xterm");
251 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"watch");
254 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
257 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"watch");
260 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
263 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
266 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
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,
"xterm");
278 cursor = WAYLAND_wl_cursor_theme_get_cursor(d->
cursor_theme,
"hand1");
282 return CreateCursorFromWlCursor(d, cursor);
288 Wayland_CursorData *
d;
299 if (d->buffer && !d->cursor)
300 wl_buffer_destroy(d->buffer);
303 wl_surface_destroy(d->surface);
323 Wayland_CursorData *data = cursor->
driverdata;
325 wl_surface_attach(data->surface, data->buffer, 0, 0);
326 wl_surface_damage(data->surface, 0, 0, data->w, data->h);
327 wl_surface_commit(data->surface);
328 wl_pointer_set_cursor (pointer, 0,
335 wl_pointer_set_cursor (pointer, 0,
351 Wayland_WarpMouseGlobal(
int x,
int y)
363 Wayland_InitMouse(
void)
379 Wayland_FiniMouse(
void)
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)
A collection of pixels used in software blitting.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
struct wl_cursor_theme * cursor_theme
GLint GLint GLsizei GLsizei height
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