From 8d4f1434f91388c53c1383ad615c029f8d984570 Mon Sep 17 00:00:00 2001
From: Xenhat Hex <me@xenh.at>
Date: Wed, 25 May 2022 17:18:49 -0400
Subject: [PATCH] Port "Keep graphics settings on GPU change" as-is From
 Polarity Viewer

---
 .../newview/app_settings/settings_alchemy.xml | 11 ++++++++
 indra/newview/llstartup.cpp                   | 25 +++++++++++++++++--
 indra/newview/llviewerwindow.cpp              |  5 +++-
 .../skins/default/xui/en/notifications.xml    | 17 +++++++++++++
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/indra/newview/app_settings/settings_alchemy.xml b/indra/newview/app_settings/settings_alchemy.xml
index bd0ad7244be..64159e580bc 100644
--- a/indra/newview/app_settings/settings_alchemy.xml
+++ b/indra/newview/app_settings/settings_alchemy.xml
@@ -354,6 +354,17 @@
       <key>Value</key>
       <integer>0</integer>
     </map>
+    <key>AlchemyKeepSettingsOnGPUChange</key>
+    <map>
+      <key>Comment</key>
+      <string>Keep graphical preferences when GPU changes</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>S32</string>
+      <key>Value</key>
+      <integer>-1</integer>
+    </map>
     <key>AlchemyLookAtShow</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index 352b47bbe82..a7695495c8b 100644
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -296,6 +296,7 @@ void transition_back_to_login_panel(const std::string& emsg);
 // [SL:KB] - Patch: Chat-Alerts | Checked: 2012-09-22 (Catznip-3.3)
 void handleLoadChatAlertSounds();
 // [/SL:KB]
+bool callbackConfirmDisplayPreferencesReset(const LLSD& notification, const LLSD& response);
 
 void callback_cache_name(const LLUUID& id, const std::string& full_name, bool is_group)
 {
@@ -425,12 +426,12 @@ bool idle_startup()
 		{
 			LLNotificationsUtil::add("DisplaySetToRecommendedFeatureChange");
 		}
-		else if ( ! lastGPU.empty() && (lastGPU != thisGPU))
+		else if ( ! lastGPU.empty() && (gSavedSettings.getS32("AlchemyKeepSettingsOnGPUChange") == -1) && (lastGPU != thisGPU))
 		{
 			LLSD subs;
 			subs["LAST_GPU"] = lastGPU;
 			subs["THIS_GPU"] = thisGPU;
-			LLNotificationsUtil::add("DisplaySetToRecommendedGPUChange", subs);
+			LLNotificationsUtil::add("AskForDisplayPreferencesReset", subs, callbackConfirmDisplayPreferencesReset);
 		}
 		else if (!gViewerWindow->getInitAlert().empty())
 		{
@@ -3859,3 +3860,23 @@ void handleLoadChatAlertSounds()
 	}
 }
 // [/SL:KB]
+
+bool callbackConfirmDisplayPreferencesReset(const LLSD& notification, const LLSD& response)
+{
+	S32 option = LLNotification::getSelectedOption(notification, response);
+	switch (option)
+	{
+	case 0: // Yes
+		LLFeatureManager::getInstance()->applyRecommendedSettings();
+		break;
+	case 1: // No
+		break;
+	case -1: // Cancel/window closed
+		break;
+	default:
+		// Don't ask again
+		gSavedSettings.setS32("AlchemyKeepSettingsOnGPUChange", 1);
+		break;
+	}
+	return false;
+}
\ No newline at end of file
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index dbfe0522ec6..e1512f7cb69 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -2034,7 +2034,10 @@ LLViewerWindow::LLViewerWindow(const Params& p)
 		|| (gSavedSettings.getString("LastGPUString") != LLFeatureManager::getInstance()->getGPUString())
 		|| (gSavedSettings.getBOOL("ProbeHardwareOnStartup")))
 	{
-		LLFeatureManager::getInstance()->applyRecommendedSettings();
+		if (gSavedSettings.getS32("AlchemyKeepSettingsOnGPUChange") < 1)
+		{
+			LLFeatureManager::getInstance()->applyRecommendedSettings();
+		}
 		gSavedSettings.setBOOL("ProbeHardwareOnStartup", FALSE);
 	}
 
diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml
index e02f2df7f7b..c74532d8c7c 100644
--- a/indra/newview/skins/default/xui/en/notifications.xml
+++ b/indra/newview/skins/default/xui/en/notifications.xml
@@ -12576,4 +12576,21 @@ Always Run disabled.
 	 Irrevocably destroying object. Hope you didn't need that.
  </notification>
 
+ <notification
+  icon="notify"
+  name="AskForDisplayPreferencesReset"
+  type="alertmodal">
+Your Graphic card seems to have changed
+
+from &apos;[LAST_GPU]&apos;
+to &apos;[THIS_GPU]&apos;
+
+Would you like to reset the graphic preferences?
+  <usetemplate
+  name="yesnocancelbuttons"
+  yestext="Reset now"
+  notext="Leave as-is"
+  canceltext="Never reset"/>
+ </notification>
+
 </notifications>
-- 
GitLab