From 4e7f3bcabef0fb9e143b6c87a9e424cb350cbdf2 Mon Sep 17 00:00:00 2001
From: Miguel Borges de Freitas <92enen@gmail.com>
Date: Sat, 11 Feb 2023 12:06:36 +0000
Subject: [macos][nativewindowing] Always start the application on the last
 known screen

---
 xbmc/windowing/osx/WinSystemOSX.mm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/xbmc/windowing/osx/WinSystemOSX.mm b/xbmc/windowing/osx/WinSystemOSX.mm
index 90f6e969ce..4f4143d5a1 100644
--- a/xbmc/windowing/osx/WinSystemOSX.mm
+++ b/xbmc/windowing/osx/WinSystemOSX.mm
@@ -641,6 +641,12 @@ bool CWinSystemOSX::DestroyWindowSystem()
 
 bool CWinSystemOSX::CreateNewWindow(const std::string& name, bool fullScreen, RESOLUTION_INFO& res)
 {
+  // find the screen where the application started the last time. It'd be the default screen if the
+  // screen index is not found/available.
+  const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings();
+  m_lastDisplayNr = GetDisplayIndex(settings->GetString(CSettings::SETTING_VIDEOSCREEN_MONITOR));
+  NSScreen* screen = [NSScreen.screens objectAtIndex:m_lastDisplayNr];
+
   // force initial window creation to be windowed, if fullscreen, it will switch to it below
   // fixes the white screen of death if starting fullscreen and switching to windowed.
   RESOLUTION_INFO resInfo = CDisplaySettings::GetInstance().GetResolutionInfo(RES_WINDOW);
@@ -684,6 +690,9 @@ bool CWinSystemOSX::CreateNewWindow(const std::string& name, bool fullScreen, RE
 
       // associate with current window
       [appWindow setContentView:view];
+
+      // set the window to the appropriate screen
+      [appWindow setFrameOrigin:screen.frame.origin];
     });
 
     [view.getGLContext makeCurrentContext];
-- 
cgit v1.2.3