Skip to content

Commit

Permalink
Use a blank cursor instead of PointerIcon.TYPE_NULL since that shows …
Browse files Browse the repository at this point in the history
…the default cursor on Samsung DeX
  • Loading branch information
slouken committed Jun 18, 2018
1 parent a515853 commit 88dfa46
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/video/android/SDL_androidmouse.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/video/android/SDL_androidmouse.h
Expand Up @@ -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_ */

Expand Down
1 change: 1 addition & 0 deletions src/video/android/SDL_androidvideo.c
Expand Up @@ -201,6 +201,7 @@ Android_VideoInit(_THIS)
void
Android_VideoQuit(_THIS)
{
Android_QuitMouse();
Android_QuitTouch();
}

Expand Down

0 comments on commit 88dfa46

Please sign in to comment.