From a277453acbdc68c954fe562c88f7cce3b706c292 Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Sun, 27 Apr 2025 21:33:08 +0200 Subject: [PATCH 1/4] Added saving of user ui scale in the global configuration. Moved userScale into s_config. Prevented "Get started" and "Loading trace..." windows from having their position saved between restarts, because if you change scale and then restart, they might get pushed to the edge of the window, which is confusing. --- profiler/src/main.cpp | 28 +++++++++++++++++---------- profiler/src/profiler/TracyConfig.hpp | 2 ++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 7cb4c09d..fbc59854 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -101,7 +101,6 @@ static std::atomic viewShutdown { ViewShutdown::False }; static double animTime = 0; static float dpiScale = -1.f; static bool dpiScaleOverriddenFromEnv = false; -static float userScale = 1.f; static float prevScale = 1.f; static int dpiChanged = 0; static bool dpiFirstSetup = true; @@ -162,7 +161,7 @@ static void ScaleWindow(ImGuiWindow* window, float scale) static void SetupDPIScale() { - auto scale = dpiScale * userScale; + auto scale = dpiScale * s_config.userScale; if( !dpiFirstSetup && prevScale == scale ) return; dpiFirstSetup = false; @@ -204,12 +203,6 @@ static void SetupDPIScale() for( auto& w : ctx->Windows ) ScaleWindow( w, ratio ); } -static void SetupScaleCallback( float scale ) -{ - userScale = scale; - RunOnMainThread( []{ SetupDPIScale(); }, true ); -} - static int IsBusy() { if( loadThread.joinable() ) return 2; @@ -237,6 +230,9 @@ static void LoadConfig() if( ini_sget( ini, "memory", "percent", "%d", &v ) && v >= 1 && v < 1000 ) s_config.memoryLimitPercent = v; if( ini_sget( ini, "achievements", "enabled", "%d", &v ) ) s_config.achievements = v; if( ini_sget( ini, "achievements", "asked", "%d", &v ) ) s_config.achievementsAsked = v; + if( ini_sget( ini, "ui", "saveUserScale", "%d", &v ) ) s_config.saveUserScale = v; + if( ini_sget( ini, "ui", "userScale", "%lf", &v1 ) && v1 > 0.0 && s_config.saveUserScale ) s_config.userScale = v1; + ini_free( ini ); } @@ -267,10 +263,21 @@ static bool SaveConfig() fprintf( f, "enabled = %i\n", (int)s_config.achievements ); fprintf( f, "asked = %i\n", (int)s_config.achievementsAsked ); + fprintf( f, "\n[ui]\n" ); + fprintf( f, "saveUserScale = %i\n", (int)s_config.saveUserScale ); + fprintf( f, "userScale = %lf\n", s_config.userScale ); + fclose( f ); return true; } +static void SetupScaleCallback( float scale ) +{ + s_config.userScale = scale; + if ( s_config.saveUserScale ) SaveConfig(); + RunOnMainThread( []{ SetupDPIScale(); }, true ); +} + static void ScaleChanged( float scale ) { if( dpiScaleOverriddenFromEnv ) return; @@ -697,7 +704,7 @@ static void DrawContents() auto& style = ImGui::GetStyle(); style.Colors[ImGuiCol_WindowBg] = ImVec4( 0.129f, 0.137f, 0.11f, 1.f ); - ImGui::Begin( "Get started", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse ); + ImGui::Begin( "Get started", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings ); char buf[128]; sprintf( buf, "Tracy Profiler %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch ); ImGui::PushFont( s_bigFont ); @@ -839,6 +846,7 @@ static void DrawContents() ImGui::Spacing(); if( ImGui::Checkbox( "Enable achievements", &s_config.achievements ) ) SaveConfig(); + if( ImGui::Checkbox( "save UI scale", &s_config.saveUserScale) ) SaveConfig(); ImGui::PopStyleVar(); ImGui::TreePop(); @@ -1267,7 +1275,7 @@ static void DrawContents() { ImGui::OpenPopup( "Loading trace..." ); } - if( ImGui::BeginPopupModal( "Loading trace...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) + if( ImGui::BeginPopupModal( "Loading trace...", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings) ) { ImGui::PushFont( s_bigFont ); tracy::TextCentered( ICON_FA_HOURGLASS_HALF ); diff --git a/profiler/src/profiler/TracyConfig.hpp b/profiler/src/profiler/TracyConfig.hpp index bd0c464e..dd7f1cb4 100644 --- a/profiler/src/profiler/TracyConfig.hpp +++ b/profiler/src/profiler/TracyConfig.hpp @@ -20,6 +20,8 @@ struct Config int dynamicColors = 1; bool forceColors = false; int shortenName = (int)ShortenName::NoSpaceAndNormalize; + bool saveUserScale = false; + float userScale = 1.0f; }; } From 7474127bbbd658e12d25f0c0cee80cee5ccf4d3a Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Sun, 27 Apr 2025 21:38:23 +0200 Subject: [PATCH 2/4] Fixed typo --- profiler/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index fbc59854..b10a6680 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -846,7 +846,7 @@ static void DrawContents() ImGui::Spacing(); if( ImGui::Checkbox( "Enable achievements", &s_config.achievements ) ) SaveConfig(); - if( ImGui::Checkbox( "save UI scale", &s_config.saveUserScale) ) SaveConfig(); + if( ImGui::Checkbox( "Save UI scale", &s_config.saveUserScale) ) SaveConfig(); ImGui::PopStyleVar(); ImGui::TreePop(); From 6b03d1dd9e80069fef12e9f5043b627bfea99f17 Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Mon, 28 Apr 2025 15:37:04 +0200 Subject: [PATCH 3/4] The config is now always saved on exit. --- profiler/src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index b10a6680..fccb611d 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -274,7 +274,6 @@ static bool SaveConfig() static void SetupScaleCallback( float scale ) { s_config.userScale = scale; - if ( s_config.saveUserScale ) SaveConfig(); RunOnMainThread( []{ SetupDPIScale(); }, true ); } @@ -430,6 +429,8 @@ int main( int argc, char** argv ) backend.Show(); backend.Run(); + SaveConfig(); + if( loadThread.joinable() ) loadThread.join(); if( updateThread.joinable() ) updateThread.join(); if( updateNotesThread.joinable() ) updateNotesThread.join(); From 132a4ba32089bfe332794b67d432b2d1888a906c Mon Sep 17 00:00:00 2001 From: Simon van Bernem Date: Mon, 28 Apr 2025 17:01:29 +0200 Subject: [PATCH 4/4] Revert "The config is now always saved on exit." This reverts commit 6b03d1dd9e80069fef12e9f5043b627bfea99f17. --- profiler/src/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index fccb611d..b10a6680 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -274,6 +274,7 @@ static bool SaveConfig() static void SetupScaleCallback( float scale ) { s_config.userScale = scale; + if ( s_config.saveUserScale ) SaveConfig(); RunOnMainThread( []{ SetupDPIScale(); }, true ); } @@ -429,8 +430,6 @@ int main( int argc, char** argv ) backend.Show(); backend.Run(); - SaveConfig(); - if( loadThread.joinable() ) loadThread.join(); if( updateThread.joinable() ) updateThread.join(); if( updateNotesThread.joinable() ) updateNotesThread.join();