From 3e3b691a865daab159e7788fa97db763f46135ed Mon Sep 17 00:00:00 2001
From: Connor McLaughlin <stenzek@gmail.com>
Date: Tue, 18 May 2021 02:34:25 +1000
Subject: [PATCH] NoGUI: Hook up exclusive fullscreen

---
 src/duckstation-nogui/sdl_host_interface.cpp | 31 +++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/duckstation-nogui/sdl_host_interface.cpp b/src/duckstation-nogui/sdl_host_interface.cpp
index 76cf9422a..c74413950 100644
--- a/src/duckstation-nogui/sdl_host_interface.cpp
+++ b/src/duckstation-nogui/sdl_host_interface.cpp
@@ -95,7 +95,36 @@ bool SDLHostInterface::SetFullscreen(bool enabled)
   if (m_fullscreen == enabled)
     return true;
 
-  SDL_SetWindowFullscreen(m_window, enabled ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+  const std::string fullscreen_mode(GetStringSettingValue("GPU", "FullscreenMode", ""));
+  const bool is_exclusive_fullscreen = (enabled && !fullscreen_mode.empty() && m_display->SupportsFullscreen());
+  const bool was_exclusive_fullscreen = m_display->IsFullscreen();
+
+  if (was_exclusive_fullscreen)
+    m_display->SetFullscreen(false, 0, 0, 0.0f);
+
+  SDL_SetWindowFullscreen(m_window, (enabled && !is_exclusive_fullscreen) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
+
+  if (is_exclusive_fullscreen)
+  {
+    u32 width, height;
+    float refresh_rate;
+    bool result = false;
+
+    if (ParseFullscreenMode(fullscreen_mode, &width, &height, &refresh_rate))
+    {
+      result = m_display->SetFullscreen(true, width, height, refresh_rate);
+      if (result)
+      {
+        AddOSDMessage(TranslateStdString("OSDMessage", "Acquired exclusive fullscreen."), 10.0f);
+      }
+      else
+      {
+        AddOSDMessage(TranslateStdString("OSDMessage", "Failed to acquire exclusive fullscreen."), 10.0f);
+        enabled = false;
+      }
+    }
+  }
+
   m_fullscreen = enabled;
 
   const bool hide_cursor = (enabled && GetBoolSettingValue("Main", "HideCursorInFullscreen", true));