diff options
author | Miguel Borges de Freitas <92enen@gmail.com> | 2023-02-21 12:17:33 +0000 |
---|---|---|
committer | Miguel Borges de Freitas <92enen@gmail.com> | 2023-02-21 12:17:50 +0000 |
commit | f8b7b7e7747e62005b3d12b3287b95cffc2fcb6f (patch) | |
tree | a28868325e0e73cc7cf4ae81f109e3d84286b5ad | |
parent | e0cb6ad8bc5825f512a68cddf202250974372a05 (diff) |
[macos][windowing] Only move and center if screen exists
-rw-r--r-- | xbmc/windowing/osx/WinSystemOSX.mm | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/xbmc/windowing/osx/WinSystemOSX.mm b/xbmc/windowing/osx/WinSystemOSX.mm index ba2e327cd2..be6a8efdaf 100644 --- a/xbmc/windowing/osx/WinSystemOSX.mm +++ b/xbmc/windowing/osx/WinSystemOSX.mm @@ -667,7 +667,11 @@ bool CWinSystemOSX::CreateNewWindow(const std::string& name, bool fullScreen, RE // 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]; + NSScreen* screen = nil; + if (m_lastDisplayNr < NSScreen.screens.count) + { + 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. @@ -714,29 +718,32 @@ bool CWinSystemOSX::CreateNewWindow(const std::string& name, bool fullScreen, RE [appWindow setContentView:view]; // set the window to the appropriate screen and screen position - if (m_bFullScreen) + if (screen) { - [appWindow setFrameOrigin:screen.frame.origin]; - } - else - { - // if there are stored window positions use that as the origin point - const int top = settings->GetInt(SETTING_WINDOW_TOP); - const int left = settings->GetInt(SETTING_WINDOW_LEFT); - - NSPoint windowPos; - if (top != 0 || left != 0) + if (m_bFullScreen) { - windowPos = NSMakePoint(left, top); + [appWindow setFrameOrigin:screen.frame.origin]; } else { - // otherwise center the window on the screen - windowPos = - NSMakePoint(screen.frame.origin.x + screen.frame.size.width / 2 - m_nWidth / 2, - screen.frame.origin.y + screen.frame.size.height / 2 - m_nHeight / 2); + // if there are stored window positions use that as the origin point + const int top = settings->GetInt(SETTING_WINDOW_TOP); + const int left = settings->GetInt(SETTING_WINDOW_LEFT); + + NSPoint windowPos; + if (top != 0 || left != 0) + { + windowPos = NSMakePoint(left, top); + } + else + { + // otherwise center the window on the screen + windowPos = + NSMakePoint(screen.frame.origin.x + screen.frame.size.width / 2 - m_nWidth / 2, + screen.frame.origin.y + screen.frame.size.height / 2 - m_nHeight / 2); + } + [appWindow setFrameOrigin:windowPos]; } - [appWindow setFrameOrigin:windowPos]; } }); |