Skip to content

Commit

Permalink
Fixed bug changing cursors on Raspberry Pi
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Nov 27, 2018
1 parent 3f0d520 commit aea4835
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/video/raspberry/SDL_rpimouse.c
Expand Up @@ -51,6 +51,8 @@ static void RPI_FreeCursor(SDL_Cursor * cursor);
static void RPI_WarpMouse(SDL_Window * window, int x, int y);
static int RPI_WarpMouseGlobal(int x, int y);

static SDL_Cursor *global_cursor;

static SDL_Cursor *
RPI_CreateDefaultCursor(void)
{
Expand Down Expand Up @@ -126,21 +128,25 @@ RPI_ShowCursor(SDL_Cursor * cursor)
return -1;
}

if (cursor == NULL) {
/* FIXME: We hide the current mouse's cursor, what we actually need is *_HideCursor */
if (cursor == global_cursor) {
return 0;
}

if (mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element > DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start(10);
SDL_assert(update);
ret = vc_dispmanx_element_remove(update, curdata->element);
SDL_assert(ret == DISPMANX_SUCCESS);
ret = vc_dispmanx_update_submit_sync(update);
SDL_assert(ret == DISPMANX_SUCCESS);
curdata->element = DISPMANX_NO_HANDLE;
}
if (global_cursor != NULL) {
curdata = (RPI_CursorData *) global_cursor->driverdata;
if (curdata && curdata->element > DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start(0);
SDL_assert(update);
ret = vc_dispmanx_element_remove(update, curdata->element);
SDL_assert(ret == DISPMANX_SUCCESS);
ret = vc_dispmanx_update_submit_sync(update);
SDL_assert(ret == DISPMANX_SUCCESS);
curdata->element = DISPMANX_NO_HANDLE;
}
}
global_cursor = cursor;

if (cursor == NULL) {
return 0;
}

Expand All @@ -152,7 +158,7 @@ RPI_ShowCursor(SDL_Cursor * cursor)
if (mouse->focus == NULL) {
return -1;
}

display = SDL_GetDisplayForWindow(mouse->focus);
if (display == NULL) {
return -1;
Expand All @@ -167,7 +173,7 @@ RPI_ShowCursor(SDL_Cursor * cursor)
vc_dispmanx_rect_set(&src_rect, 0, 0, curdata->w << 16, curdata->h << 16);
vc_dispmanx_rect_set(&dst_rect, mouse->x, mouse->y, curdata->w, curdata->h);

update = vc_dispmanx_update_start(10);
update = vc_dispmanx_update_start(0);
SDL_assert(update);

env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER);
Expand Down Expand Up @@ -206,7 +212,7 @@ RPI_FreeCursor(SDL_Cursor * cursor)

if (curdata != NULL) {
if (curdata->element != DISPMANX_NO_HANDLE) {
update = vc_dispmanx_update_start(10);
update = vc_dispmanx_update_start(0);
SDL_assert(update);
ret = vc_dispmanx_element_remove(update, curdata->element);
SDL_assert(ret == DISPMANX_SUCCESS);
Expand Down Expand Up @@ -255,7 +261,7 @@ RPI_WarpMouseGlobal(int x, int y)
return 0;
}

update = vc_dispmanx_update_start(10);
update = vc_dispmanx_update_start(0);
if (!update) {
return 0;
}
Expand Down Expand Up @@ -311,7 +317,7 @@ RPI_WarpMouseGlobalGraphicOnly(int x, int y)
return 0;
}

update = vc_dispmanx_update_start(10);
update = vc_dispmanx_update_start(0);
if (!update) {
return 0;
}
Expand Down Expand Up @@ -368,7 +374,6 @@ RPI_InitMouse(_THIS)
void
RPI_QuitMouse(_THIS)
{

}

/* This is called when a mouse motion event occurs */
Expand Down

0 comments on commit aea4835

Please sign in to comment.