From b06ef3a18cee1595844161736fc644268ab40f11 Mon Sep 17 00:00:00 2001 From: Manuel Alfayate Corchete Date: Mon, 21 Dec 2020 01:53:11 +0100 Subject: [PATCH] [Video/KMSDRM] Manually re-show the cursor on window creation, if needed. --- src/video/kmsdrm/SDL_kmsdrmmouse.c | 25 +++++++++++++++++++++++++ src/video/kmsdrm/SDL_kmsdrmmouse.h | 2 ++ src/video/kmsdrm/SDL_kmsdrmvideo.c | 9 +++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c index e17c3c579..26a7dad90 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.c +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c @@ -179,6 +179,31 @@ cleanup: return ret; } +/* When we create a window, we have to test if we have to show the cursor, + and explicily do so if necessary. + This is because when we destroy a window, we take the cursor away from the + cursor plane, and destroy the cusror GBM BO. So we have to re-show it, + so to say. */ +void +KMSDRM_InitCursor() +{ + SDL_Mouse *mouse = NULL; + mouse = SDL_GetMouse(); + + if (!mouse) { + return; + } + if (!(mouse->cur_cursor)) { + return; + } + + if (!(mouse->cursor_shown)) { + return; + } + + KMSDRM_ShowCursor(mouse->cur_cursor); +} + /* Show the specified cursor, or hide if cursor is NULL. cur_cursor is the current cursor, and cursor is the new cursor. A cursor is displayed on a display, so we have to add a pointer to dispdata diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.h b/src/video/kmsdrm/SDL_kmsdrmmouse.h index f44104e31..8993a315d 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.h +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.h @@ -47,6 +47,8 @@ typedef struct _KMSDRM_CursorData extern void KMSDRM_InitMouse(_THIS); extern void KMSDRM_DeinitMouse(_THIS); +extern void KMSDRM_InitCursor(); + #endif /* SDL_KMSDRM_mouse_h_ */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 847f49d91..678aefdcd 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -1748,9 +1748,14 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window) SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA); } - /* Can't init mouse sooner because planes are not ready. - We do it along with the KMSDRM_GBMInit() call, so do this only when GBM is not init. */ + /* Can't init mouse stuff sooner cursor plane is not ready. */ KMSDRM_InitMouse(_this); + + /* Since we take cursor buffer way from the cursor plane and + destroy the cursor GBM BO when we destroy a window, we must + also manually re-show the cursor on screen, if necessary, + when we create a window. */ + KMSDRM_InitCursor(); } /* Allocate window internal data */