SDL-1.2: atari:video:xbios: refresh desktop when exiting CTPCI

From cbe3ea96648d6fb574e6e7d905224a02c6a1ba19 Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Thu, 21 Dec 2023 21:33:28 +0100
Subject: [PATCH] atari:video:xbios: refresh desktop when exiting CTPCI

As CTPCI's VsetScreen() and VsetMode() does reinitialise the AES
(contrary to what normal TOS does), we have to do some housekeeping.

This isn't perfect though -- the menubar is kept dirty. However it is
much better than having no cursor at all accompanied by black screen.

Ideally we should reuse gem's GEM_LockScreen() and GEM_UnlockScreen()
for this but currently it requires initialisation of the whole backend
so let's keep things simple for now.
---
 src/video/xbios/SDL_xbios_ctpci.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/video/xbios/SDL_xbios_ctpci.c b/src/video/xbios/SDL_xbios_ctpci.c
index ac8baab4..92a264f1 100644
--- a/src/video/xbios/SDL_xbios_ctpci.c
+++ b/src/video/xbios/SDL_xbios_ctpci.c
@@ -28,6 +28,7 @@
 	Patrice Mandin
 */
 
+#include <gem.h>
 #include <mint/cookie.h>
 #include <mint/falcon.h>
 
@@ -71,6 +72,8 @@ static const Uint8 mode_bpp[]={
 static int enum_actually_add;
 static SDL_VideoDevice *enum_this;
 #endif
+static SDL_bool aes_present = SDL_FALSE;
+static GRECT desktop;
 
 /*--- Functions ---*/
 
@@ -154,6 +157,17 @@ static void saveMode(_THIS, SDL_PixelFormat *vformat)
 {
 	SCREENINFO si = { 0 };
 
+	if (appl_init() >= 0) {
+		wind_update(BEG_UPDATE);
+		wind_update(BEG_MCTRL);
+
+		graf_mouse(M_OFF, NULL);
+
+		wind_get(0, WF_WORKXYWH, &desktop.g_x, &desktop.g_y, &desktop.g_w, &desktop.g_h);
+
+		aes_present = SDL_TRUE;
+	}
+
 	/* Read infos about current mode */
 	VsetScreen(-1, &XBIOS_oldvmode, VN_MAGIC, CMD_GETMODE);
 
@@ -200,6 +214,17 @@ static void restoreMode(_THIS)
 	if (XBIOS_oldnumcol) {
 		VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
 	}
+
+	if (aes_present) {
+		graf_mouse(M_ON, NULL);
+		graf_mouse(ARROW, NULL);
+
+		wind_update(END_MCTRL);
+		wind_update(END_UPDATE);
+
+		form_dial(FMD_FINISH, 0, 0, 0, 0, desktop.g_x, desktop.g_y, desktop.g_w, desktop.g_h);
+		appl_exit();
+	}
 }
 
 static void swapVbuffers(_THIS)