1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Store display index of window to settings

I have this annoying issue where the game will open on the wrong monitor
in fullscreen mode, because that monitor is considered to be display 0,
whereas the primary monitor I want is display 1.

To mitigate this somewhat, the game now stores the display index that it
was closed on, and will save it to settings. Then the next time the game
opens, it will open on that display index. This should work pretty well
as long as you aren't changing your monitor setup constantly.

Of course, none of this applies if your window manager is busted. For
example, on GNOME Wayland, which is what I use, in windowed mode the
game will always open on the monitor the cursor is on, and it won't even
be centered in the monitor. But it works fine if I use XWayland via
SDL_VIDEODRIVER=x11.
This commit is contained in:
Misa 2023-03-21 00:23:42 -07:00
parent 54990638fd
commit e3612afbd3
4 changed files with 31 additions and 3 deletions

View file

@ -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);

View file

@ -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)
);
}
}
}

View file

@ -31,6 +31,7 @@ public:
bool isForcedFullscreen(void);
int windowDisplay;
int windowWidth;
int windowHeight;
bool isWindowed;

View file

@ -11,6 +11,7 @@ enum
struct ScreenSettings
{
int windowDisplay;
int windowWidth;
int windowHeight;
bool fullscreen;