-
-
Notifications
You must be signed in to change notification settings - Fork 400
feat: remember position of game window #9853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
15d83e0
to
7af36b3
Compare
016dcfd
to
8f8b6cf
Compare
0e4e728
to
fbf8742
Compare
fbf8742
to
0e0448b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @usidedown , I left few comments in this pull request. Would you mind to take a look at them when you have time?
if ( pos == fheroes2::Point{ -1, -1 } ) { | ||
_prevWindowPos = { SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED }; | ||
} | ||
else { | ||
_prevWindowPos = pos; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must have a check whether the position is within the screen area. Moreover, the position plus the size of the windows must be within the screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on the fence regarding these checks. They seem to be mostly useful if the user messes with fheroes2.cfg.
My main issue is that when setWindowPos is called _currentScreenResolution isn't set yet. Even if I postpone the check to engine::allocate, _currentScreenResolution is still not set.
Moreover, it's legal to be in a position where pos + size exceeds the screen size. Probably not useful even if you have multiple displays, but still valid.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the following situation:
- make the resolution 1920x1080
- move the window to the left part of the display
- change resolution to 640x480
As a result, the whole window is going to be invisible and outside the display. At very least we need to have a mechanism if a user messes up and they would always blame us :)
Or I might be wrong as SDL handles such cases so we don't need to do anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right!
I've implemented the check.
I believe it is better to check when the window is created rather then when the position is set to avoid race conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clang-Tidy
found issue(s) with the introduced code (1/1)
ecf3cb6
to
d2fa303
Compare
We will merge this pull request after the upcoming release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @usidedown , I put just few more minor comment. Could you please check them and see if they make sense?
src/engine/screen.cpp
Outdated
@@ -825,6 +825,9 @@ namespace | |||
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; | |||
#endif | |||
|
|||
// update the window position, in case we get queried for it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Very minor] Since every other comment starts from a capital letter I suggest to do the same here.
if ( pos == fheroes2::Point{ -1, -1 } ) { | ||
_prevWindowPos = { SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED }; | ||
} | ||
else { | ||
_prevWindowPos = pos; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming the following situation:
- make the resolution 1920x1080
- move the window to the left part of the display
- change resolution to 640x480
As a result, the whole window is going to be invisible and outside the display. At very least we need to have a mechanism if a user messes up and they would always blame us :)
Or I might be wrong as SDL handles such cases so we don't need to do anything.
src/fheroes2/system/settings.cpp
Outdated
@@ -398,6 +403,9 @@ std::string Settings::String() const | |||
os << std::endl << "# video mode: in-game width x in-game height : on-screen width x on-screen height" << std::endl; | |||
os << "videomode = " << display.width() << "x" << display.height() << ":" << display.screenSize().width << "x" << display.screenSize().height << std::endl; | |||
|
|||
os << std::endl << "# position of the game's window" << std::endl; | |||
os << "main window position = [ " << _windowPos.x << ", " << _windowPos.y << " ]" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name the parameter as game window position
as well?
Solves #1228
Saves the position of the window in fheroes2.conf.
The position is captured every time the window is moved, and saved to settings when the game exits.
It's possible to capture only when the game exits, but then we might not save the correct position if the user swaps to Fullscreen mode before quitting.