|
@@ -47,11 +47,110 @@ typedef struct {
|
|
int hot_x, hot_y;
|
|
int hot_x, hot_y;
|
|
int w, h;
|
|
int w, h;
|
|
|
|
|
|
- /* Either a preloaded cursor, or one we created ourselves */
|
|
|
|
- struct wl_cursor *cursor;
|
|
|
|
|
|
+ /* shm_data is non-NULL for custom cursors.
|
|
|
|
+ * When shm_data is NULL, system_cursor must be valid
|
|
|
|
+ */
|
|
|
|
+ SDL_SystemCursor system_cursor;
|
|
void *shm_data;
|
|
void *shm_data;
|
|
} Wayland_CursorData;
|
|
} Wayland_CursorData;
|
|
|
|
|
|
|
|
+static SDL_bool
|
|
|
|
+wayland_get_system_cursor(SDL_VideoData *vdata, Wayland_CursorData *cdata, float *scale)
|
|
|
|
+{
|
|
|
|
+ struct wl_cursor_theme *theme = NULL;
|
|
|
|
+ struct wl_cursor *cursor;
|
|
|
|
+
|
|
|
|
+ SDL_Window *focus;
|
|
|
|
+ SDL_WindowData *focusdata;
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ /* FIXME: We need to be able to query the cursor size from the desktop at
|
|
|
|
+ * some point! For a while this was 32, but when testing on real desktops it
|
|
|
|
+ * seems like most of them default to 24. We'll need a protocol to get this
|
|
|
|
+ * for real, but for now this is a pretty safe bet.
|
|
|
|
+ * -flibit
|
|
|
|
+ */
|
|
|
|
+ int size = 24;
|
|
|
|
+
|
|
|
|
+ /* First, find the appropriate theme based on the current scale... */
|
|
|
|
+ focus = SDL_GetMouse()->focus;
|
|
|
|
+ if (focus == NULL) {
|
|
|
|
+ /* Nothing to see here, bail. */
|
|
|
|
+ return SDL_FALSE;
|
|
|
|
+ }
|
|
|
|
+ focusdata = focus->driverdata;
|
|
|
|
+ *scale = focusdata->scale_factor;
|
|
|
|
+ size *= focusdata->scale_factor;
|
|
|
|
+ for (i = 0; i < vdata->num_cursor_themes; i += 1) {
|
|
|
|
+ if (vdata->cursor_themes[i].size == size) {
|
|
|
|
+ theme = vdata->cursor_themes[i].theme;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (theme == NULL) {
|
|
|
|
+ vdata->cursor_themes = SDL_realloc(vdata->cursor_themes,
|
|
|
|
+ sizeof(SDL_WaylandCursorTheme) * (vdata->num_cursor_themes + 1));
|
|
|
|
+ if (vdata->cursor_themes == NULL) {
|
|
|
|
+ SDL_OutOfMemory();
|
|
|
|
+ return SDL_FALSE;
|
|
|
|
+ }
|
|
|
|
+ theme = WAYLAND_wl_cursor_theme_load(NULL, size, vdata->shm);
|
|
|
|
+ vdata->cursor_themes[vdata->num_cursor_themes++].theme = theme;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Next, find the cursor from the theme... */
|
|
|
|
+ switch(cdata->system_cursor)
|
|
|
|
+ {
|
|
|
|
+ case SDL_SYSTEM_CURSOR_ARROW:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "left_ptr");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_IBEAM:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "xterm");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_WAIT:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "watch");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_CROSSHAIR:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "hand1");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_WAITARROW:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "watch");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_SIZENWSE:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "hand1");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_SIZENESW:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "hand1");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_SIZEWE:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "hand1");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_SIZENS:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "hand1");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_SIZEALL:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "hand1");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_NO:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "xterm");
|
|
|
|
+ break;
|
|
|
|
+ case SDL_SYSTEM_CURSOR_HAND:
|
|
|
|
+ cursor = WAYLAND_wl_cursor_theme_get_cursor(theme, "hand1");
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ SDL_assert(0);
|
|
|
|
+ return SDL_FALSE;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* ... Set the cursor data, finally. */
|
|
|
|
+ cdata->buffer = WAYLAND_wl_cursor_image_get_buffer(cursor->images[0]);
|
|
|
|
+ cdata->hot_x = cursor->images[0]->hotspot_x;
|
|
|
|
+ cdata->hot_y = cursor->images[0]->hotspot_y;
|
|
|
|
+ cdata->w = cursor->images[0]->width;
|
|
|
|
+ cdata->h = cursor->images[0]->height;
|
|
|
|
+ return SDL_TRUE;
|
|
|
|
+}
|
|
|
|
+
|
|
static int
|
|
static int
|
|
wayland_create_tmp_file(off_t size)
|
|
wayland_create_tmp_file(off_t size)
|
|
{
|
|
{
|
|
@@ -192,30 +291,30 @@ Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
|
}
|
|
}
|
|
|
|
|
|
static SDL_Cursor *
|
|
static SDL_Cursor *
|
|
-CreateCursorFromWlCursor(SDL_VideoData *d, struct wl_cursor *wlcursor)
|
|
|
|
|
|
+Wayland_CreateSystemCursor(SDL_SystemCursor id)
|
|
{
|
|
{
|
|
|
|
+ SDL_VideoData *data = SDL_GetVideoDevice()->driverdata;
|
|
SDL_Cursor *cursor;
|
|
SDL_Cursor *cursor;
|
|
|
|
|
|
cursor = SDL_calloc(1, sizeof (*cursor));
|
|
cursor = SDL_calloc(1, sizeof (*cursor));
|
|
if (cursor) {
|
|
if (cursor) {
|
|
- Wayland_CursorData *data = SDL_calloc (1, sizeof (Wayland_CursorData));
|
|
|
|
- if (!data) {
|
|
|
|
|
|
+ Wayland_CursorData *cdata = SDL_calloc (1, sizeof (Wayland_CursorData));
|
|
|
|
+ if (!cdata) {
|
|
SDL_OutOfMemory();
|
|
SDL_OutOfMemory();
|
|
SDL_free(cursor);
|
|
SDL_free(cursor);
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
- cursor->driverdata = (void *) data;
|
|
|
|
|
|
+ cursor->driverdata = (void *) cdata;
|
|
|
|
|
|
- data->buffer = WAYLAND_wl_cursor_image_get_buffer(wlcursor->images[0]);
|
|
|
|
- data->surface = wl_compositor_create_surface(d->compositor);
|
|
|
|
- wl_surface_set_user_data(data->surface, NULL);
|
|
|
|
- data->hot_x = wlcursor->images[0]->hotspot_x;
|
|
|
|
- data->hot_y = wlcursor->images[0]->hotspot_y;
|
|
|
|
- data->w = wlcursor->images[0]->width;
|
|
|
|
- data->h = wlcursor->images[0]->height;
|
|
|
|
- data->cursor= wlcursor;
|
|
|
|
|
|
+ cdata->surface = wl_compositor_create_surface(data->compositor);
|
|
|
|
+ wl_surface_set_user_data(cdata->surface, NULL);
|
|
|
|
+
|
|
|
|
+ /* Note that we can't actually set any other cursor properties, as this
|
|
|
|
+ * is output-specific. See wayland_get_system_cursor for the rest!
|
|
|
|
+ */
|
|
|
|
+ cdata->system_cursor = id;
|
|
} else {
|
|
} else {
|
|
- SDL_OutOfMemory ();
|
|
|
|
|
|
+ SDL_OutOfMemory();
|
|
}
|
|
}
|
|
|
|
|
|
return cursor;
|
|
return cursor;
|
|
@@ -224,66 +323,7 @@ CreateCursorFromWlCursor(SDL_VideoData *d, struct wl_cursor *wlcursor)
|
|
static SDL_Cursor *
|
|
static SDL_Cursor *
|
|
Wayland_CreateDefaultCursor()
|
|
Wayland_CreateDefaultCursor()
|
|
{
|
|
{
|
|
- SDL_VideoDevice *device = SDL_GetVideoDevice();
|
|
|
|
- SDL_VideoData *data = device->driverdata;
|
|
|
|
-
|
|
|
|
- return CreateCursorFromWlCursor (data,
|
|
|
|
- WAYLAND_wl_cursor_theme_get_cursor(data->cursor_theme,
|
|
|
|
- "left_ptr"));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static SDL_Cursor *
|
|
|
|
-Wayland_CreateSystemCursor(SDL_SystemCursor id)
|
|
|
|
-{
|
|
|
|
- SDL_VideoDevice *vd = SDL_GetVideoDevice();
|
|
|
|
- SDL_VideoData *d = vd->driverdata;
|
|
|
|
-
|
|
|
|
- struct wl_cursor *cursor = NULL;
|
|
|
|
-
|
|
|
|
- switch(id)
|
|
|
|
- {
|
|
|
|
- default:
|
|
|
|
- SDL_assert(0);
|
|
|
|
- return NULL;
|
|
|
|
- case SDL_SYSTEM_CURSOR_ARROW:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_IBEAM:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_WAIT:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "watch");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_CROSSHAIR:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_WAITARROW:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "watch");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_SIZENWSE:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_SIZENESW:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_SIZEWE:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_SIZENS:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_SIZEALL:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_NO:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
|
|
|
|
- break;
|
|
|
|
- case SDL_SYSTEM_CURSOR_HAND:
|
|
|
|
- cursor = WAYLAND_wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return CreateCursorFromWlCursor(d, cursor);
|
|
|
|
|
|
+ return Wayland_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
static void
|
|
@@ -300,14 +340,14 @@ Wayland_FreeCursor(SDL_Cursor *cursor)
|
|
if (!d)
|
|
if (!d)
|
|
return;
|
|
return;
|
|
|
|
|
|
- if (d->buffer && !d->cursor)
|
|
|
|
|
|
+ if (d->buffer && d->shm_data)
|
|
wl_buffer_destroy(d->buffer);
|
|
wl_buffer_destroy(d->buffer);
|
|
|
|
|
|
if (d->surface)
|
|
if (d->surface)
|
|
wl_surface_destroy(d->surface);
|
|
wl_surface_destroy(d->surface);
|
|
|
|
|
|
/* Not sure what's meant to happen to shm_data */
|
|
/* Not sure what's meant to happen to shm_data */
|
|
- SDL_free (cursor->driverdata);
|
|
|
|
|
|
+ SDL_free(cursor->driverdata);
|
|
SDL_free(cursor);
|
|
SDL_free(cursor);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -317,8 +357,8 @@ Wayland_ShowCursor(SDL_Cursor *cursor)
|
|
SDL_VideoDevice *vd = SDL_GetVideoDevice();
|
|
SDL_VideoDevice *vd = SDL_GetVideoDevice();
|
|
SDL_VideoData *d = vd->driverdata;
|
|
SDL_VideoData *d = vd->driverdata;
|
|
struct SDL_WaylandInput *input = d->input;
|
|
struct SDL_WaylandInput *input = d->input;
|
|
-
|
|
|
|
struct wl_pointer *pointer = d->pointer;
|
|
struct wl_pointer *pointer = d->pointer;
|
|
|
|
+ float scale = 1.0f;
|
|
|
|
|
|
if (!pointer)
|
|
if (!pointer)
|
|
return -1;
|
|
return -1;
|
|
@@ -327,22 +367,26 @@ Wayland_ShowCursor(SDL_Cursor *cursor)
|
|
{
|
|
{
|
|
Wayland_CursorData *data = cursor->driverdata;
|
|
Wayland_CursorData *data = cursor->driverdata;
|
|
|
|
|
|
- wl_pointer_set_cursor (pointer,
|
|
|
|
- input->pointer_enter_serial,
|
|
|
|
- data->surface,
|
|
|
|
- data->hot_x,
|
|
|
|
- data->hot_y);
|
|
|
|
|
|
+ /* TODO: High-DPI custom cursors? -flibit */
|
|
|
|
+ if (data->shm_data == NULL) {
|
|
|
|
+ if (!wayland_get_system_cursor(d, data, &scale)) {
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ wl_surface_set_buffer_scale(data->surface, scale);
|
|
|
|
+ wl_pointer_set_cursor(pointer,
|
|
|
|
+ input->pointer_enter_serial,
|
|
|
|
+ data->surface,
|
|
|
|
+ data->hot_x / scale,
|
|
|
|
+ data->hot_y / scale);
|
|
wl_surface_attach(data->surface, data->buffer, 0, 0);
|
|
wl_surface_attach(data->surface, data->buffer, 0, 0);
|
|
wl_surface_damage(data->surface, 0, 0, data->w, data->h);
|
|
wl_surface_damage(data->surface, 0, 0, data->w, data->h);
|
|
wl_surface_commit(data->surface);
|
|
wl_surface_commit(data->surface);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- wl_pointer_set_cursor (pointer,
|
|
|
|
- input->pointer_enter_serial,
|
|
|
|
- NULL,
|
|
|
|
- 0,
|
|
|
|
- 0);
|
|
|
|
|
|
+ wl_pointer_set_cursor(pointer, input->pointer_enter_serial, NULL, 0, 0);
|
|
}
|
|
}
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
@@ -389,10 +433,12 @@ Wayland_InitMouse(void)
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
void
|
|
-Wayland_FiniMouse(void)
|
|
|
|
|
|
+Wayland_FiniMouse(SDL_VideoData *data)
|
|
{
|
|
{
|
|
- /* This effectively assumes that nobody else
|
|
|
|
- * touches SDL_Mouse which is effectively
|
|
|
|
- * a singleton */
|
|
|
|
|
|
+ int i;
|
|
|
|
+ for (i = 0; i < data->num_cursor_themes; i += 1) {
|
|
|
|
+ WAYLAND_wl_cursor_theme_destroy(data->cursor_themes[i].theme);
|
|
|
|
+ }
|
|
|
|
+ SDL_free(data->cursor_themes);
|
|
}
|
|
}
|
|
#endif /* SDL_VIDEO_DRIVER_WAYLAND */
|
|
#endif /* SDL_VIDEO_DRIVER_WAYLAND */
|