Support dynamic DPI scaling.

This commit is contained in:
Bartosz Taudul 2024-01-30 19:37:10 +01:00
parent a28c115c5c
commit 74cd6a711e
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -95,6 +95,8 @@ static ConnectionHistory* connHist;
static std::atomic<ViewShutdown> viewShutdown { ViewShutdown::False };
static double animTime = 0;
static float dpiScale = 1.f;
static float userScale = 1.f;
static bool dynamicDpi = true;
static Filters* filt;
static RunQueue mainThreadTasks;
static uint32_t updateVersion = 0;
@ -165,7 +167,10 @@ static void SetupDPIScale( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigF
static void SetupScaleCallback( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont )
{
RunOnMainThread( [scale, &cb_fixedWidth, &cb_bigFont, &cb_smallFont] { SetupDPIScale( scale * dpiScale, cb_fixedWidth, cb_bigFont, cb_smallFont ); }, true );
userScale = scale;
RunOnMainThread( [&cb_fixedWidth, &cb_bigFont, &cb_smallFont] {
SetupDPIScale( userScale * dpiScale, cb_fixedWidth, cb_bigFont, cb_smallFont );
}, true );
}
static void LoadConfig()
@ -292,7 +297,11 @@ int main( int argc, char** argv )
if( envDpiScale )
{
const auto cnv = atof( envDpiScale );
if( cnv != 0 ) dpiScale = cnv;
if( cnv != 0 )
{
dpiScale = cnv;
dynamicDpi = false;
}
}
SetupDPIScale( dpiScale, s_fixedWidth, s_bigFont, s_smallFont );
@ -487,6 +496,16 @@ static void DrawContents()
UpdateBroadcastClients();
#endif
if( dynamicDpi )
{
const auto newDpiScale = bptr->GetDpiScale();
if( newDpiScale != dpiScale )
{
dpiScale = newDpiScale;
SetupDPIScale( userScale * dpiScale, s_fixedWidth, s_bigFont, s_smallFont );
}
}
int display_w, display_h;
bptr->NewFrame( display_w, display_h );