From 88dfa46644b2f2651b20fff182957faa6474c795 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 18 Jun 2018 13:14:04 -0700 Subject: [PATCH] Use a blank cursor instead of PointerIcon.TYPE_NULL since that shows the default cursor on Samsung DeX --- src/video/android/SDL_androidmouse.c | 41 +++++++++++++++++++++++++--- src/video/android/SDL_androidmouse.h | 1 + src/video/android/SDL_androidvideo.c | 1 + 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/video/android/SDL_androidmouse.c b/src/video/android/SDL_androidmouse.c index c79792d39..037b4538c 100644 --- a/src/video/android/SDL_androidmouse.c +++ b/src/video/android/SDL_androidmouse.c @@ -52,6 +52,8 @@ typedef struct /* Last known Android mouse button state (includes all buttons) */ static int last_state; +/* Blank cursor */ +static SDL_Cursor *empty_cursor; static SDL_Cursor * Android_WrapCursor(int custom_cursor, int system_cursor) @@ -115,9 +117,35 @@ Android_FreeCursor(SDL_Cursor * cursor) SDL_free(cursor); } +static SDL_Cursor * +Android_CreateEmptyCursor() +{ + if (!empty_cursor) { + SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888); + if (empty_surface) { + SDL_memset(empty_surface->pixels, 0, empty_surface->h * empty_surface->pitch); + empty_cursor = Android_CreateCursor(empty_surface, 0, 0); + SDL_FreeSurface(empty_surface); + } + } + return empty_cursor; +} + +static void +Android_DestroyEmptyCursor() +{ + if (empty_cursor) { + Android_FreeCursor(empty_cursor); + empty_cursor = NULL; + } +} + static int Android_ShowCursor(SDL_Cursor * cursor) { + if (!cursor) { + cursor = Android_CreateEmptyCursor(); + } if (cursor) { SDL_AndroidCursorData *data = (SDL_AndroidCursorData*)cursor->driverdata; if (data->custom_cursor) { @@ -129,12 +157,11 @@ Android_ShowCursor(SDL_Cursor * cursor) return SDL_Unsupported(); } } + return 0; } else { - if (!Android_JNI_SetSystemCursor(-1)) { - return SDL_Unsupported(); - } + /* SDL error set inside Android_CreateEmptyCursor() */ + return -1; } - return 0; } static int @@ -167,6 +194,12 @@ Android_InitMouse(void) last_state = 0; } +void +Android_QuitMouse(void) +{ + Android_DestroyEmptyCursor(); +} + /* Translate Android mouse button state to SDL mouse button */ static Uint8 TranslateButton(int state) diff --git a/src/video/android/SDL_androidmouse.h b/src/video/android/SDL_androidmouse.h index 9aa71f513..eca9e476a 100644 --- a/src/video/android/SDL_androidmouse.h +++ b/src/video/android/SDL_androidmouse.h @@ -26,6 +26,7 @@ extern void Android_InitMouse(void); extern void Android_OnMouse(int button, int action, float x, float y, SDL_bool relative); +extern void Android_QuitMouse(void); #endif /* SDL_androidmouse_h_ */ diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 79c20f62a..3cf5040b8 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -201,6 +201,7 @@ Android_VideoInit(_THIS) void Android_VideoQuit(_THIS) { + Android_QuitMouse(); Android_QuitTouch(); }