diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 82e81dae..221d7e99 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -4374,6 +4374,10 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, struct ScreenSett screen_settings->linearFilter = help.Int(pText); } + if (SDL_strcmp(pKey, "window_display") == 0) + { + screen_settings->windowDisplay = help.Int(pText); + } if (SDL_strcmp(pKey, "window_width") == 0) { screen_settings->windowWidth = help.Int(pText); @@ -4713,6 +4717,8 @@ void Game::serializesettings(tinyxml2::XMLElement* dataNode, const struct Screen xml::update_tag(dataNode, "useLinearFilter", (int) screen_settings->linearFilter); + xml::update_tag(dataNode, "window_display", screen_settings->windowDisplay); + xml::update_tag(dataNode, "window_width", screen_settings->windowWidth); xml::update_tag(dataNode, "window_height", screen_settings->windowHeight); diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index 6921c183..508bc3d4 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -16,6 +16,7 @@ void ScreenSettings_default(struct ScreenSettings* _this) { + _this->windowDisplay = 0; _this->windowWidth = SCREEN_WIDTH_PIXELS * 2; _this->windowHeight = SCREEN_HEIGHT_PIXELS * 2; _this->fullscreen = false; @@ -29,6 +30,7 @@ void Screen::init(const struct ScreenSettings* settings) { m_window = NULL; m_renderer = NULL; + windowDisplay = settings->windowDisplay; windowWidth = settings->windowWidth; windowHeight = settings->windowHeight; isWindowed = !settings->fullscreen; @@ -53,8 +55,8 @@ void Screen::init(const struct ScreenSettings* settings) m_window = SDL_CreateWindow( "VVVVVV", - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay), + SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay), SCREEN_WIDTH_PIXELS * 2, SCREEN_HEIGHT_PIXELS * 2, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI @@ -101,6 +103,13 @@ void Screen::destroy(void) void Screen::GetSettings(struct ScreenSettings* settings) { + windowDisplay = SDL_GetWindowDisplayIndex(m_window); + if (windowDisplay < 0) + { + vlog_error("Error: could not get display index: %s", SDL_GetError()); + windowDisplay = 0; + } + settings->windowDisplay = windowDisplay; settings->windowWidth = windowWidth; settings->windowHeight = windowHeight; @@ -134,6 +143,13 @@ void Screen::LoadIcon(void) void Screen::ResizeScreen(int x, int y) { + windowDisplay = SDL_GetWindowDisplayIndex(m_window); + if (windowDisplay < 0) + { + vlog_error("Error: could not get display index: %s", SDL_GetError()); + windowDisplay = 0; + } + if (x != -1 && y != -1) { // This is a user resize! @@ -163,7 +179,11 @@ void Screen::ResizeScreen(int x, int y) if (x != -1 && y != -1) { SDL_SetWindowSize(m_window, windowWidth, windowHeight); - SDL_SetWindowPosition(m_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + SDL_SetWindowPosition( + m_window, + SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay), + SDL_WINDOWPOS_CENTERED_DISPLAY(windowDisplay) + ); } } } diff --git a/desktop_version/src/Screen.h b/desktop_version/src/Screen.h index 7573ef8f..17fefddb 100644 --- a/desktop_version/src/Screen.h +++ b/desktop_version/src/Screen.h @@ -31,6 +31,7 @@ public: bool isForcedFullscreen(void); + int windowDisplay; int windowWidth; int windowHeight; bool isWindowed; diff --git a/desktop_version/src/ScreenSettings.h b/desktop_version/src/ScreenSettings.h index 5369844d..8c0bc04e 100644 --- a/desktop_version/src/ScreenSettings.h +++ b/desktop_version/src/ScreenSettings.h @@ -11,6 +11,7 @@ enum struct ScreenSettings { + int windowDisplay; int windowWidth; int windowHeight; bool fullscreen;