Skip to content
Open
Changes from 6 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
41 changes: 39 additions & 2 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3624,6 +3624,38 @@
return get_option<int>( "TERMINAL_Y" ) * fontheight;
}

// Measures scaling factor for high-dpi displays
static std::pair<float, float> get_display_scale( int display_index )
{
#if SDL_VERSION_ATLEAST(2,26,0)
int x = SDL_WINDOWPOS_CENTERED_DISPLAY( display_index );

Check failure on line 3631 in src/sdltiles.cpp

View workflow job for this annotation

GitHub Actions / run-clang-tidy (directly-changed)

Variables 'x' and 'y' could be combined into a single 'point' variable. [cata-combine-locals-into-point,-warnings-as-errors]
int y = SDL_WINDOWPOS_CENTERED_DISPLAY( display_index );

SDL_Window *w = SDL_CreateWindow(
"probe",
x, y,
16, 16,
SDL_WINDOW_HIDDEN | SDL_WINDOW_ALLOW_HIGHDPI
);
if( !w ) {
return std::make_pair( 1.0f, 1.0f );
}

int lw, lh;

Check failure on line 3644 in src/sdltiles.cpp

View workflow job for this annotation

GitHub Actions / run-clang-tidy (directly-changed)

multiple declarations in a single statement reduces readability [readability-isolate-declaration,-warnings-as-errors]
SDL_GetWindowSize( w, &lw, &lh );
int pw, ph;

Check failure on line 3646 in src/sdltiles.cpp

View workflow job for this annotation

GitHub Actions / run-clang-tidy (directly-changed)

multiple declarations in a single statement reduces readability [readability-isolate-declaration,-warnings-as-errors]
SDL_GetWindowSizeInPixels( w, &pw, &ph );
SDL_DestroyWindow( w );

float scale_w = lw ? static_cast<float>( pw ) / static_cast<float>( lw ) : 1.0f;
float scale_h = lh ? static_cast<float>( ph ) / static_cast<float>( lh ) : 1.0f;
return std::make_pair( scale_w, scale_h );
#else
( void )display_index; // avoid unused parameter lint
return std::make_pair( 1.0f, 1.0f );
#endif
}

static void init_term_size_and_scaling_factor()
{
scaling_factor = 1;
Expand Down Expand Up @@ -3658,7 +3690,11 @@
SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_MAXIMIZED
) );

#if SDL_VERSION_ATLEAST(2,26,0)
SDL_GetWindowSizeInPixels( test_window.get(), &max_width, &max_height );
#else
SDL_GetWindowSize( test_window.get(), &max_width, &max_height );
#endif

// If the video subsystem isn't reset the test window messes things up later
test_window.reset();
Expand All @@ -3667,8 +3703,9 @@

} else {
// For fullscreen or window borderless maximum size is the display size
max_width = current_display.w;
max_height = current_display.h;
auto [ dpi_scale_w, dpi_scale_h ] = get_display_scale( current_display_id );
max_width = dpi_scale_w * current_display.w;
max_height = dpi_scale_h * current_display.h;
}
} else {
dbg( D_WARNING ) << "Failed to get current Display Mode, assuming infinite display size.";
Expand Down
Loading