Skip to content
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

Limit all resolutions on MacOS to currently selected resolution in the system #9323

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/engine/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,12 @@ namespace
static const std::vector<fheroes2::ResolutionInfo> filteredResolutions = []() {
std::set<fheroes2::ResolutionInfo> resolutionSet;

// At the moment we retrieve resolutions only from the first display.
const int displayId = 0;

const int displayCount = SDL_GetNumVideoDisplays();
if ( displayCount >= 1 ) {
const int displayModeCount = SDL_GetNumDisplayModes( 0 );
const int displayModeCount = SDL_GetNumDisplayModes( displayId );
if ( displayModeCount >= 1 ) {
for ( int i = 0; i < displayModeCount; ++i ) {
SDL_DisplayMode videoMode;
Expand Down Expand Up @@ -900,6 +903,35 @@ namespace
#endif
resolutionSet = FilterResolutions( resolutionSet );

#if defined( __APPLE__ )
if ( displayCount >= 1 ) {
// We should limit all available resolutions to the one which is currently chosen
// on the system to avoid ending up having application window which is bigger than screen resolution.
SDL_DisplayMode displayMode;

const int returnValue = SDL_GetCurrentDisplayMode( displayId, &displayMode );
if ( returnValue < 0 ) {
ERROR_LOG( "Failed to retrieve the current display mode. The error value: " << returnValue << ", description: " << SDL_GetError() )
return std::vector<fheroes2::ResolutionInfo>{ resolutionSet.rbegin(), resolutionSet.rend() };
}

// If the current display resolution is somehow very small, then ignore it.
// It could appear in cases when the device has smaller than the required by the game resolution.
if ( displayMode.w < fheroes2::Display::DEFAULT_WIDTH || displayMode.h < fheroes2::Display::DEFAULT_HEIGHT ) {
return std::vector<fheroes2::ResolutionInfo>{ resolutionSet.rbegin(), resolutionSet.rend() };
}

std::vector<fheroes2::ResolutionInfo> temp;
for ( auto iter = resolutionSet.rbegin(); iter != resolutionSet.rend(); ++iter ) {
if ( iter->screenWidth <= displayMode.w && iter->screenHeight <= displayMode.h ) {
temp.emplace_back( std::move( *iter ) );
}
}

return temp;
}
#endif

return std::vector<fheroes2::ResolutionInfo>{ resolutionSet.rbegin(), resolutionSet.rend() };
}();

Expand Down
Loading