2017-08-02 19:22:48 +02:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2020-01-17 05:49:25 +01:00
|
|
|
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
2017-08-02 19:22:48 +02:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
2017-08-22 02:20:50 +02:00
|
|
|
|
2017-08-02 19:22:48 +02:00
|
|
|
#include "../../SDL_internal.h"
|
|
|
|
|
|
|
|
#if SDL_VIDEO_DRIVER_KMSDRM
|
|
|
|
|
|
|
|
#include "SDL_kmsdrmvideo.h"
|
|
|
|
#include "SDL_kmsdrmmouse.h"
|
|
|
|
#include "SDL_kmsdrmdyn.h"
|
2020-07-19 17:55:01 +02:00
|
|
|
#include "SDL_assert.h"
|
2017-08-02 19:22:48 +02:00
|
|
|
|
|
|
|
#include "../../events/SDL_mouse_c.h"
|
|
|
|
#include "../../events/default_cursor.h"
|
|
|
|
|
|
|
|
static SDL_Cursor *KMSDRM_CreateDefaultCursor(void);
|
|
|
|
static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y);
|
|
|
|
static int KMSDRM_ShowCursor(SDL_Cursor * cursor);
|
|
|
|
static void KMSDRM_MoveCursor(SDL_Cursor * cursor);
|
|
|
|
static void KMSDRM_FreeCursor(SDL_Cursor * cursor);
|
|
|
|
static void KMSDRM_WarpMouse(SDL_Window * window, int x, int y);
|
|
|
|
static int KMSDRM_WarpMouseGlobal(int x, int y);
|
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Converts a pixel from straight-alpha [AA, RR, GG, BB], which the SDL cursor surface has,
|
|
|
|
to premultiplied-alpha [AA. AA*RR, AA*GG, AA*BB].
|
|
|
|
These multiplications have to be done with floats instead of uint32_t's, and the resulting values have
|
|
|
|
to be converted to be relative to the 0-255 interval, where 255 is 1.00 and anything between 0 and 255 is 0.xx. */
|
|
|
|
void alpha_premultiply_ARGB8888 (uint32_t *pixel) {
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
uint32_t A, R, G, B;
|
2017-11-24 21:03:28 +01:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Component bytes extraction. */
|
|
|
|
A = (*pixel >> (3 << 3)) & 0xFF;
|
|
|
|
R = (*pixel >> (2 << 3)) & 0xFF;
|
|
|
|
G = (*pixel >> (1 << 3)) & 0xFF;
|
|
|
|
B = (*pixel >> (0 << 3)) & 0xFF;
|
2020-02-09 20:44:22 +01:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Alpha pre-multiplication of each component. */
|
|
|
|
R = (float)A * ((float)R /255);
|
|
|
|
G = (float)A * ((float)G /255);
|
|
|
|
B = (float)A * ((float)B /255);
|
2017-11-24 21:03:28 +01:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* ARGB8888 pixel recomposition. */
|
|
|
|
(*pixel) = (((uint32_t)A << 24) | ((uint32_t)R << 16) | ((uint32_t)G << 8)) | ((uint32_t)B << 0);
|
|
|
|
}
|
2017-11-24 21:03:28 +01:00
|
|
|
|
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
static SDL_Cursor *
|
|
|
|
KMSDRM_CreateDefaultCursor(void)
|
|
|
|
{
|
|
|
|
return SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY);
|
2017-11-24 21:03:28 +01:00
|
|
|
}
|
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Create a GBM cursor from a surface, which means creating a hardware cursor.
|
|
|
|
Most programs use software cursors, but protracker-clone for example uses
|
|
|
|
an optional hardware cursor. */
|
2017-08-02 19:22:48 +02:00
|
|
|
static SDL_Cursor *
|
|
|
|
KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *dev = SDL_GetVideoDevice();
|
2020-02-09 20:44:22 +01:00
|
|
|
SDL_VideoData *viddata = ((SDL_VideoData *)dev->driverdata);
|
2017-08-02 19:22:48 +02:00
|
|
|
KMSDRM_CursorData *curdata;
|
|
|
|
SDL_Cursor *cursor;
|
2020-07-19 17:55:01 +02:00
|
|
|
uint64_t usable_cursor_w, usable_cursor_h;
|
|
|
|
uint32_t bo_stride, pixel;
|
|
|
|
uint32_t *buffer = NULL;
|
2017-08-02 19:22:48 +02:00
|
|
|
size_t bufsize;
|
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* All code below assumes ARGB8888 format for the cursor surface, like other backends do.
|
|
|
|
Also, the GBM BO pixels have to be alpha-premultiplied, but the SDL surface we receive has
|
|
|
|
straight-alpha pixels, so we always have to convert. */
|
|
|
|
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
|
|
|
|
SDL_assert(surface->pitch == surface->w * 4);
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
if (!KMSDRM_gbm_device_is_format_supported(viddata->gbm, GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE)) {
|
|
|
|
printf("Unsupported pixel format for cursor\n");
|
2017-08-02 19:22:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!cursor) {
|
2017-08-02 19:22:48 +02:00
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
curdata = (KMSDRM_CursorData *) SDL_calloc(1, sizeof(*curdata));
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!curdata) {
|
2017-08-02 19:22:48 +02:00
|
|
|
SDL_OutOfMemory();
|
|
|
|
SDL_free(cursor);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Find out what GBM cursor size is recommended by the driver. */
|
|
|
|
if (KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_WIDTH, &usable_cursor_w) ||
|
|
|
|
KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_HEIGHT, &usable_cursor_h)) {
|
|
|
|
SDL_SetError("Could not get the recommended GBM cursor size");
|
|
|
|
goto cleanup;
|
2017-11-24 21:03:28 +01:00
|
|
|
}
|
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
if (usable_cursor_w == 0 || usable_cursor_w == 0) {
|
|
|
|
SDL_SetError("Could not get an usable GBM cursor size");
|
|
|
|
goto cleanup;
|
2017-11-24 21:03:28 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:22:48 +02:00
|
|
|
curdata->hot_x = hot_x;
|
|
|
|
curdata->hot_y = hot_y;
|
2017-11-24 21:03:28 +01:00
|
|
|
curdata->w = usable_cursor_w;
|
|
|
|
curdata->h = usable_cursor_h;
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
curdata->bo = KMSDRM_gbm_bo_create(viddata->gbm, usable_cursor_w, usable_cursor_h, GBM_FORMAT_ARGB8888,
|
2017-08-02 19:22:48 +02:00
|
|
|
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
|
2017-11-24 21:03:28 +01:00
|
|
|
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!curdata->bo) {
|
2017-08-02 19:22:48 +02:00
|
|
|
SDL_SetError("Could not create GBM cursor BO");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
bo_stride = KMSDRM_gbm_bo_get_stride(curdata->bo);
|
2017-11-24 21:03:28 +01:00
|
|
|
bufsize = bo_stride * curdata->h;
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Always use a temp buffer: it serves the purpose of storing the alpha-premultiplied pixels (so
|
|
|
|
we can copy them to the gbm BO with a single gb_bo_write() call), and also copying from the
|
|
|
|
SDL surface, line by line, to a gbm BO with different pitch. */
|
|
|
|
buffer = (uint32_t*)SDL_malloc(bufsize);
|
|
|
|
if (!buffer) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
if (SDL_MUSTLOCK(surface)) {
|
|
|
|
if (SDL_LockSurface(surface) < 0) {
|
|
|
|
/* Could not lock surface */
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Clean the whole temporary buffer. */
|
|
|
|
SDL_memset(buffer, 0x00, bo_stride * curdata->h);
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Copy from SDL surface to buffer, pre-multiplying by alpha each pixel as we go. */
|
|
|
|
for (int i = 0; i < surface->h; i++) {
|
|
|
|
for (int j = 0; j < surface->w; j++) {
|
|
|
|
pixel = ((uint32_t*)surface->pixels)[i * surface->w + j];
|
|
|
|
alpha_premultiply_ARGB8888 (&pixel);
|
|
|
|
SDL_memcpy(buffer + (i * curdata->w) + j, &pixel, 4);
|
2017-08-02 19:22:48 +02:00
|
|
|
}
|
2020-07-19 17:55:01 +02:00
|
|
|
}
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
if (SDL_MUSTLOCK(surface)) {
|
|
|
|
SDL_UnlockSurface(surface);
|
|
|
|
}
|
2017-08-02 19:22:48 +02:00
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
if (KMSDRM_gbm_bo_write(curdata->bo, buffer, bufsize)) {
|
|
|
|
SDL_SetError("Could not write to GBM cursor BO");
|
|
|
|
goto cleanup;
|
2017-08-02 19:22:48 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 17:55:01 +02:00
|
|
|
/* Free temporary buffer */
|
|
|
|
SDL_free(buffer);
|
|
|
|
buffer = NULL;
|
|
|
|
|
2017-08-02 19:22:48 +02:00
|
|
|
cursor->driverdata = curdata;
|
|
|
|
|
|
|
|
return cursor;
|
|
|
|
|
|
|
|
cleanup:
|
2020-02-09 20:44:22 +01:00
|
|
|
if (buffer) {
|
2017-08-02 19:22:48 +02:00
|
|
|
SDL_free(buffer);
|
|
|
|
}
|
2020-02-09 20:44:22 +01:00
|
|
|
if (cursor) {
|
2017-08-02 19:22:48 +02:00
|
|
|
SDL_free(cursor);
|
|
|
|
}
|
2020-02-09 20:44:22 +01:00
|
|
|
if (curdata) {
|
|
|
|
if (curdata->bo) {
|
2017-08-02 19:22:48 +02:00
|
|
|
KMSDRM_gbm_bo_destroy(curdata->bo);
|
|
|
|
}
|
|
|
|
SDL_free(curdata);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the specified cursor, or hide if cursor is NULL */
|
|
|
|
static int
|
|
|
|
KMSDRM_ShowCursor(SDL_Cursor * cursor)
|
|
|
|
{
|
|
|
|
SDL_VideoDevice *dev = SDL_GetVideoDevice();
|
2020-02-09 20:44:22 +01:00
|
|
|
SDL_VideoData *viddata = ((SDL_VideoData *)dev->driverdata);
|
2017-08-02 19:22:48 +02:00
|
|
|
SDL_Mouse *mouse;
|
|
|
|
KMSDRM_CursorData *curdata;
|
|
|
|
SDL_VideoDisplay *display = NULL;
|
2020-02-09 20:44:22 +01:00
|
|
|
SDL_DisplayData *dispdata = NULL;
|
2017-08-02 19:22:48 +02:00
|
|
|
int ret;
|
|
|
|
uint32_t bo_handle;
|
|
|
|
|
|
|
|
mouse = SDL_GetMouse();
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!mouse) {
|
2017-08-02 19:22:48 +02:00
|
|
|
return SDL_SetError("No mouse.");
|
|
|
|
}
|
|
|
|
|
2020-02-09 20:44:22 +01:00
|
|
|
if (mouse->focus) {
|
2017-08-02 19:22:48 +02:00
|
|
|
display = SDL_GetDisplayForWindow(mouse->focus);
|
2020-02-09 20:44:22 +01:00
|
|
|
if (display) {
|
|
|
|
dispdata = (SDL_DisplayData*) display->driverdata;
|
2017-08-02 19:22:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!cursor) {
|
2017-08-02 19:22:48 +02:00
|
|
|
/* Hide current cursor */
|
2020-02-09 20:44:22 +01:00
|
|
|
if (mouse->cur_cursor && mouse->cur_cursor->driverdata) {
|
2017-08-02 19:22:48 +02:00
|
|
|
curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
|
|
|
|
|
|
|
|
if (curdata->crtc_id != 0) {
|
2020-02-09 20:44:22 +01:00
|
|
|
ret = KMSDRM_drmModeSetCursor(viddata->drm_fd, curdata->crtc_id, 0, 0, 0);
|
2017-08-02 19:22:48 +02:00
|
|
|
if (ret) {
|
|
|
|
SDL_SetError("Could not hide current cursor with drmModeSetCursor().");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* Mark previous cursor as not-displayed */
|
|
|
|
curdata->crtc_id = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* otherwise if possible, hide global cursor */
|
2020-02-09 20:44:22 +01:00
|
|
|
if (dispdata && dispdata->crtc_id != 0) {
|
|
|
|
ret = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc_id, 0, 0, 0);
|
2017-08-02 19:22:48 +02:00
|
|
|
if (ret) {
|
|
|
|
SDL_SetError("Could not hide display's cursor with drmModeSetCursor().");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SDL_SetError("Couldn't find cursor to hide.");
|
|
|
|
}
|
|
|
|
/* If cursor != NULL, show new cursor on display */
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!display) {
|
2017-08-02 19:22:48 +02:00
|
|
|
return SDL_SetError("Could not get display for mouse.");
|
|
|
|
}
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!dispdata) {
|
2017-08-02 19:22:48 +02:00
|
|
|
return SDL_SetError("Could not get display driverdata.");
|
|
|
|
}
|
|
|
|
|
|
|
|
curdata = (KMSDRM_CursorData *) cursor->driverdata;
|
2020-02-09 20:44:22 +01:00
|
|
|
if (!curdata || !curdata->bo) {
|
2017-08-02 19:22:48 +02:00
|
|
|
return SDL_SetError("Cursor not initialized properly.");
|
|
|
|
}
|
|
|
|
|
|
|
|
bo_handle = KMSDRM_gbm_bo_get_handle(curdata->bo).u32;
|
|
|
|
if (curdata->hot_x == 0 && curdata->hot_y == 0) {
|
2020-02-09 20:44:22 +01:00
|
|
|
ret = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc_id, bo_handle,
|
2017-08-02 19:22:48 +02:00
|
|
|
curdata->w, curdata->h);
|
|
|
|
} else {
|
2020-02-09 20:44:22 +01:00
|
|
|
ret = KMSDRM_drmModeSetCursor2(viddata->drm_fd, dispdata->crtc_id, bo_handle,
|
|
|
|
curdata->w, curdata->h, curdata->hot_x, curdata->hot_y);
|
2017-08-02 19:22:48 +02:00
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
SDL_SetError("drmModeSetCursor failed.");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-02-09 20:44:22 +01:00
|
|
|
curdata->crtc_id = dispdata->crtc_id;
|
2017-08-02 19:22:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free a window manager cursor */
|
|
|
|
static void
|
|
|
|
KMSDRM_FreeCursor(SDL_Cursor * cursor)
|
|
|
|
{
|
|
|
|
KMSDRM_CursorData *curdata;
|
|
|
|
int drm_fd;
|
|
|
|
|
2020-02-09 20:44:22 +01:00
|
|
|
if (cursor) {
|
2017-08-02 19:22:48 +02:00
|
|
|
curdata = (KMSDRM_CursorData *) cursor->driverdata;
|
|
|
|
|
2020-02-09 20:44:22 +01:00
|
|
|
if (curdata) {
|
|
|
|
if (curdata->bo) {
|
2017-08-02 19:22:48 +02:00
|
|
|
if (curdata->crtc_id != 0) {
|
|
|
|
drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
|
|
|
|
/* Hide the cursor if previously shown on a CRTC */
|
|
|
|
KMSDRM_drmModeSetCursor(drm_fd, curdata->crtc_id, 0, 0, 0);
|
|
|
|
curdata->crtc_id = 0;
|
|
|
|
}
|
|
|
|
KMSDRM_gbm_bo_destroy(curdata->bo);
|
|
|
|
curdata->bo = NULL;
|
|
|
|
}
|
|
|
|
SDL_free(cursor->driverdata);
|
|
|
|
}
|
|
|
|
SDL_free(cursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Warp the mouse to (x,y) */
|
|
|
|
static void
|
|
|
|
KMSDRM_WarpMouse(SDL_Window * window, int x, int y)
|
|
|
|
{
|
|
|
|
/* Only one global/fullscreen window is supported */
|
|
|
|
KMSDRM_WarpMouseGlobal(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Warp the mouse to (x,y) */
|
|
|
|
static int
|
|
|
|
KMSDRM_WarpMouseGlobal(int x, int y)
|
|
|
|
{
|
|
|
|
KMSDRM_CursorData *curdata;
|
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
|
|
|
|
2020-02-09 20:44:22 +01:00
|
|
|
if (mouse && mouse->cur_cursor && mouse->cur_cursor->driverdata) {
|
2017-12-05 05:37:01 +01:00
|
|
|
/* Update internal mouse position. */
|
|
|
|
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x, y);
|
|
|
|
|
|
|
|
/* And now update the cursor graphic position on screen. */
|
2017-08-02 19:22:48 +02:00
|
|
|
curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
|
2020-02-09 20:44:22 +01:00
|
|
|
if (curdata->bo) {
|
2017-12-05 05:37:01 +01:00
|
|
|
|
2017-08-02 19:22:48 +02:00
|
|
|
if (curdata->crtc_id != 0) {
|
|
|
|
int ret, drm_fd;
|
|
|
|
drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
|
|
|
|
ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, x, y);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
SDL_SetError("drmModeMoveCursor() failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
return SDL_SetError("Cursor is not currently shown.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return SDL_SetError("Cursor not initialized properly.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return SDL_SetError("No mouse or current cursor.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KMSDRM_InitMouse(_THIS)
|
|
|
|
{
|
|
|
|
/* FIXME: Using UDEV it should be possible to scan all mice
|
|
|
|
* but there's no point in doing so as there's no multimice support...yet!
|
|
|
|
*/
|
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
|
|
|
|
|
|
|
mouse->CreateCursor = KMSDRM_CreateCursor;
|
|
|
|
mouse->ShowCursor = KMSDRM_ShowCursor;
|
|
|
|
mouse->MoveCursor = KMSDRM_MoveCursor;
|
|
|
|
mouse->FreeCursor = KMSDRM_FreeCursor;
|
|
|
|
mouse->WarpMouse = KMSDRM_WarpMouse;
|
|
|
|
mouse->WarpMouseGlobal = KMSDRM_WarpMouseGlobal;
|
|
|
|
|
|
|
|
SDL_SetDefaultCursor(KMSDRM_CreateDefaultCursor());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KMSDRM_QuitMouse(_THIS)
|
|
|
|
{
|
|
|
|
/* TODO: ? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is called when a mouse motion event occurs */
|
|
|
|
static void
|
|
|
|
KMSDRM_MoveCursor(SDL_Cursor * cursor)
|
|
|
|
{
|
|
|
|
SDL_Mouse *mouse = SDL_GetMouse();
|
2017-12-05 05:37:01 +01:00
|
|
|
KMSDRM_CursorData *curdata;
|
|
|
|
int drm_fd, ret;
|
|
|
|
|
|
|
|
/* We must NOT call SDL_SendMouseMotion() here or we will enter recursivity!
|
|
|
|
That's why we move the cursor graphic ONLY. */
|
2020-02-09 20:44:22 +01:00
|
|
|
if (mouse && mouse->cur_cursor && mouse->cur_cursor->driverdata) {
|
2017-12-05 05:37:01 +01:00
|
|
|
curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
|
2018-09-24 20:49:25 +02:00
|
|
|
drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
|
|
|
|
ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->x, mouse->y);
|
2017-12-05 05:37:01 +01:00
|
|
|
|
2018-09-24 20:49:25 +02:00
|
|
|
if (ret) {
|
|
|
|
SDL_SetError("drmModeMoveCursor() failed.");
|
|
|
|
}
|
2017-12-05 05:37:01 +01:00
|
|
|
}
|
2017-08-02 19:22:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SDL_VIDEO_DRIVER_KMSDRM */
|
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|