Use a blank cursor instead of PointerIcon.TYPE_NULL since that shows the default cursor on Samsung DeX
authorSam Lantinga <slouken@libsdl.org>
Mon, 18 Jun 2018 13:14:04 -0700
changeset 1202539a92b19f99e
parent 12024 3688283680b1
child 12027 83df3afcf475
Use a blank cursor instead of PointerIcon.TYPE_NULL since that shows the default cursor on Samsung DeX
src/video/android/SDL_androidmouse.c
src/video/android/SDL_androidmouse.h
src/video/android/SDL_androidvideo.c
     1.1 --- a/src/video/android/SDL_androidmouse.c	Mon Jun 18 13:14:02 2018 -0700
     1.2 +++ b/src/video/android/SDL_androidmouse.c	Mon Jun 18 13:14:04 2018 -0700
     1.3 @@ -52,6 +52,8 @@
     1.4  /* Last known Android mouse button state (includes all buttons) */
     1.5  static int last_state;
     1.6  
     1.7 +/* Blank cursor */
     1.8 +static SDL_Cursor *empty_cursor;
     1.9  
    1.10  static SDL_Cursor *
    1.11  Android_WrapCursor(int custom_cursor, int system_cursor)
    1.12 @@ -115,9 +117,35 @@
    1.13      SDL_free(cursor);
    1.14  }
    1.15  
    1.16 +static SDL_Cursor *
    1.17 +Android_CreateEmptyCursor()
    1.18 +{
    1.19 +    if (!empty_cursor) {
    1.20 +        SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(0, 1, 1, 32, SDL_PIXELFORMAT_ARGB8888);
    1.21 +        if (empty_surface) {
    1.22 +            SDL_memset(empty_surface->pixels, 0, empty_surface->h * empty_surface->pitch);
    1.23 +            empty_cursor = Android_CreateCursor(empty_surface, 0, 0);
    1.24 +            SDL_FreeSurface(empty_surface);
    1.25 +        }
    1.26 +    }
    1.27 +    return empty_cursor;
    1.28 +}
    1.29 +
    1.30 +static void
    1.31 +Android_DestroyEmptyCursor()
    1.32 +{
    1.33 +    if (empty_cursor) {
    1.34 +        Android_FreeCursor(empty_cursor);
    1.35 +        empty_cursor = NULL;
    1.36 +    }
    1.37 +}
    1.38 +
    1.39  static int
    1.40  Android_ShowCursor(SDL_Cursor * cursor)
    1.41  {
    1.42 +    if (!cursor) {
    1.43 +        cursor = Android_CreateEmptyCursor();
    1.44 +    }
    1.45      if (cursor) {
    1.46          SDL_AndroidCursorData *data = (SDL_AndroidCursorData*)cursor->driverdata;
    1.47          if (data->custom_cursor) {
    1.48 @@ -129,12 +157,11 @@
    1.49                  return SDL_Unsupported();
    1.50              }
    1.51          }
    1.52 +        return 0;
    1.53      } else {
    1.54 -        if (!Android_JNI_SetSystemCursor(-1)) {
    1.55 -            return SDL_Unsupported();
    1.56 -        }
    1.57 +        /* SDL error set inside Android_CreateEmptyCursor() */
    1.58 +        return -1;
    1.59      }
    1.60 -    return 0;
    1.61  }
    1.62  
    1.63  static int
    1.64 @@ -167,6 +194,12 @@
    1.65      last_state = 0;
    1.66  }
    1.67  
    1.68 +void
    1.69 +Android_QuitMouse(void)
    1.70 +{
    1.71 +    Android_DestroyEmptyCursor();
    1.72 +}
    1.73 +
    1.74  /* Translate Android mouse button state to SDL mouse button */
    1.75  static Uint8
    1.76  TranslateButton(int state)
     2.1 --- a/src/video/android/SDL_androidmouse.h	Mon Jun 18 13:14:02 2018 -0700
     2.2 +++ b/src/video/android/SDL_androidmouse.h	Mon Jun 18 13:14:04 2018 -0700
     2.3 @@ -26,6 +26,7 @@
     2.4  
     2.5  extern void Android_InitMouse(void);
     2.6  extern void Android_OnMouse(int button, int action, float x, float y, SDL_bool relative);
     2.7 +extern void Android_QuitMouse(void);
     2.8  
     2.9  #endif /* SDL_androidmouse_h_ */
    2.10  
     3.1 --- a/src/video/android/SDL_androidvideo.c	Mon Jun 18 13:14:02 2018 -0700
     3.2 +++ b/src/video/android/SDL_androidvideo.c	Mon Jun 18 13:14:04 2018 -0700
     3.3 @@ -201,6 +201,7 @@
     3.4  void
     3.5  Android_VideoQuit(_THIS)
     3.6  {
     3.7 +    Android_QuitMouse();
     3.8      Android_QuitTouch();
     3.9  }
    3.10