From cb2d3e779b7baeb4ef604ce7bdc5aac078c620e4 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Windows 11)" <rob@synchro.net>
Date: Wed, 27 Dec 2023 20:06:34 -0800
Subject: [PATCH] Add support to SDL and GDI modes for CONIO_OPT_DISABLE_CLOSE

... to disable the OS or Window Manager's "close" app icon/control/option
which attempts an ungraceful termination of UIFC apps (e.g. SCFG) and does
weird and wonderful things (e.g. infinite loops which are invisible on
Win32-GDI, so you end up with a ghost/zombie process).

Disabling the OS/WM close option is an alternative solution to checking
uifc.exit_flags & UIFC_XF_QUIT everywhere you need to to avoid a
looping/zombie process.

Next up X11, which appears I need to remove _NET_WM_ACTION_CLOSE
from the _NET_WM_ALLOWED_ACTIONS Atom... ?
---
 src/conio/ciolib.h   | 15 +--------------
 src/conio/sdlfuncs.c |  2 ++
 src/conio/win32gdi.c |  2 ++
 3 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/src/conio/ciolib.h b/src/conio/ciolib.h
index 7d0fbd208c..09aeb68bfb 100644
--- a/src/conio/ciolib.h
+++ b/src/conio/ciolib.h
@@ -1,5 +1,3 @@
-/* $Id: ciolib.h,v 1.125 2020/06/27 00:04:44 deuce Exp $ */
-
 /****************************************************************************
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
@@ -13,21 +11,9 @@
  * See the GNU Lesser General Public License for more details: lgpl.txt or	*
  * http://www.fsf.org/copyleft/lesser.html									*
  *																			*
- * Anonymous FTP access to the most recent released source is available at	*
- * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
- *																			*
- * Anonymous CVS access to the development source and modification history	*
- * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
- *     (just hit return, no password is necessary)							*
- * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
- *																			*
  * For Synchronet coding style and modification guidelines, see				*
  * http://www.synchro.net/source.html										*
  *																			*
- * You are encouraged to submit any modifications (preferably in Unix diff	*
- * format) via e-mail to mods@synchro.net									*
- *																			*
  * Note: If this box doesn't appear square, then you need to fix your tabs.	*
  ****************************************************************************/
 
@@ -324,6 +310,7 @@ typedef struct {
 #define CONIO_OPT_EXTENDED_PALETTE  (1 << 12)
 #define CONIO_OPT_BLOCKY_SCALING    (1 << 13)
 #define CONIO_OPT_EXTERNAL_SCALING  (1 << 14)
+#define CONIO_OPT_DISABLE_CLOSE     (1 << 15) // Disable OS/WM app close control/menu-option
 	void	(*clreol)		(void);
 	int		(*puttext)		(int,int,int,int,void *);
 	int		(*vmem_puttext)		(int,int,int,int,struct vmem_cell *);
diff --git a/src/conio/sdlfuncs.c b/src/conio/sdlfuncs.c
index 4fa049471d..fb921f715e 100644
--- a/src/conio/sdlfuncs.c
+++ b/src/conio/sdlfuncs.c
@@ -232,6 +232,8 @@ int init_sdl_video(void)
 	if (!sdl.gotfuncs)
 		return -1;
 
+	if (cio_api.options & CONIO_OPT_DISABLE_CLOSE)
+		sdl.SetHint(SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4, "1");
 	sdl.SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2" );
 	sdl.SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1" );
 #ifdef _WIN32
diff --git a/src/conio/win32gdi.c b/src/conio/win32gdi.c
index 79a6d104ba..6687e1137a 100644
--- a/src/conio/win32gdi.c
+++ b/src/conio/win32gdi.c
@@ -858,6 +858,8 @@ gdi_thread(void *arg)
 	win = CreateWindowW(wc.lpszClassName, L"SyncConsole", STYLE, wx, wy, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
 	if (win == NULL)
 		goto fail;
+	if (cio_api.options & CONIO_OPT_DISABLE_CLOSE)
+		EnableMenuItem(GetSystemMenu(win, /* revert; */FALSE), SC_CLOSE, MF_DISABLED); // Disable the Windows' app-system-menu close option
 	// No failing after this...
 	init_success = true;
 	if (fullscreen)
-- 
GitLab