From bcdf55468a1b1d4a05ebc71aefbd2a2ed0427012 Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Mon, 13 Apr 2020 07:20:00 +0000
Subject: [PATCH] Only save window state if SyncTERM exits while in the startup
 mode... If you change the current mode before exiting, your window size will
 not be saves.

Also, fix crash in search when there's a blank option at the end.
---
 src/syncterm/syncterm.c | 58 ++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 27 deletions(-)

diff --git a/src/syncterm/syncterm.c b/src/syncterm/syncterm.c
index 21843f5a22..a0ba00823d 100644
--- a/src/syncterm/syncterm.c
+++ b/src/syncterm/syncterm.c
@@ -1731,33 +1731,37 @@ int main(int argc, char **argv)
 	if (last_bbs)
 		free(last_bbs);
 	// Save changed settings
-	ww = wh = sf = -1;
-	get_window_info(&ww, &wh, NULL, NULL);
-	sf = getscaling();
-	if((sf > 0 && sf != settings.scaling_factor) ||
-	    (ww > 0 && ww != settings.window_width) ||
-	    (wh > 0 && wh != settings.window_height)) {
-		char	inipath[MAX_PATH+1];
-		FILE	*inifile;
-		str_list_t	inicontents;
-
-		get_syncterm_filename(inipath, sizeof(inipath), SYNCTERM_PATH_INI, FALSE);
-		if((inifile=fopen(inipath,"r"))!=NULL) {
-			inicontents=iniReadFile(inifile);
-			fclose(inifile);
-		}
-		else {
-			inicontents=strListInit();
-		}
-		if (sf > 0 && sf != settings.scaling_factor)
-			iniSetInteger(&inicontents,"SyncTERM","ScalingFactor",sf,&ini_style);
-		if (ww > 0 && ww != settings.window_width)
-			iniSetInteger(&inicontents,"SyncTERM","WindowWidth",ww,&ini_style);
-		if (wh > 0 && wh != settings.window_height)
-			iniSetInteger(&inicontents,"SyncTERM","WindowHeight",wh,&ini_style);
-		if((inifile=fopen(inipath,"w"))!=NULL) {
-			iniWriteFile(inifile,inicontents);
-			fclose(inifile);
+	gettextinfo(&txtinfo);
+	// Only save window info if we're in the startup mode...
+	if (txtinfo.currmode == settings.startup_mode || (settings.startup_mode == SCREEN_MODE_CURRENT && txtinfo.currmode == C80)) {
+		ww = wh = sf = -1;
+		get_window_info(&ww, &wh, NULL, NULL);
+		sf = getscaling();
+		if((sf > 0 && sf != settings.scaling_factor) ||
+		    (ww > 0 && ww != settings.window_width) ||
+		    (wh > 0 && wh != settings.window_height)) {
+			char	inipath[MAX_PATH+1];
+			FILE	*inifile;
+			str_list_t	inicontents;
+
+			get_syncterm_filename(inipath, sizeof(inipath), SYNCTERM_PATH_INI, FALSE);
+			if((inifile=fopen(inipath,"r"))!=NULL) {
+				inicontents=iniReadFile(inifile);
+				fclose(inifile);
+			}
+			else {
+				inicontents=strListInit();
+			}
+			if (sf > 0 && sf != settings.scaling_factor)
+				iniSetInteger(&inicontents,"SyncTERM","ScalingFactor",sf,&ini_style);
+			if (ww > 0 && ww != settings.window_width)
+				iniSetInteger(&inicontents,"SyncTERM","WindowWidth",ww,&ini_style);
+			if (wh > 0 && wh != settings.window_height)
+				iniSetInteger(&inicontents,"SyncTERM","WindowHeight",wh,&ini_style);
+			if((inifile=fopen(inipath,"w"))!=NULL) {
+				iniWriteFile(inifile,inicontents);
+				fclose(inifile);
+			}
 		}
 	}
 
-- 
GitLab