From 16434f116c2a556a93530c995975deec0593fb16 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Wed, 24 Jan 2024 12:34:23 +0400 Subject: [PATCH] Add a way for Backend to signal scale changes On Wayland the scale now changes to the correct value as the Tracy window is moved across monitors. If the scale is overridden from environment, it does not change, just like before. --- profiler/src/Backend.hpp | 2 +- profiler/src/BackendGlfw.cpp | 2 +- profiler/src/BackendWayland.cpp | 5 ++++- profiler/src/main.cpp | 18 ++++++++++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/profiler/src/Backend.hpp b/profiler/src/Backend.hpp index 2f4262a3..f4a031bb 100644 --- a/profiler/src/Backend.hpp +++ b/profiler/src/Backend.hpp @@ -11,7 +11,7 @@ class RunQueue; class Backend { public: - Backend( const char* title, const std::function& redraw, RunQueue* mainThreadTasks ); + Backend( const char* title, const std::function& redraw, const std::function& scaleChanged, RunQueue* mainThreadTasks ); ~Backend(); void Show(); diff --git a/profiler/src/BackendGlfw.cpp b/profiler/src/BackendGlfw.cpp index f3525ee9..51897111 100644 --- a/profiler/src/BackendGlfw.cpp +++ b/profiler/src/BackendGlfw.cpp @@ -60,7 +60,7 @@ static void glfw_window_iconify_callback( GLFWwindow*, int iconified ) } -Backend::Backend( const char* title, const std::function& redraw, RunQueue* mainThreadTasks ) +Backend::Backend( const char* title, const std::function& redraw, const std::function& scaleChanged, RunQueue* mainThreadTasks ) { glfwSetErrorCallback( glfw_error_callback ); if( !glfwInit() ) exit( 1 ); diff --git a/profiler/src/BackendWayland.cpp b/profiler/src/BackendWayland.cpp index c33382e4..04d3d7e5 100644 --- a/profiler/src/BackendWayland.cpp +++ b/profiler/src/BackendWayland.cpp @@ -160,6 +160,7 @@ constexpr ImGuiKey s_keyTable[] = { }; static std::function s_redraw; +static std::function s_scaleChanged; static RunQueue* s_mainThreadTasks; static struct wl_display* s_dpy; @@ -662,9 +663,10 @@ static void SetupCursor() s_cursorY = cursor->images[0]->hotspot_y / s_maxScale; } -Backend::Backend( const char* title, const std::function& redraw, RunQueue* mainThreadTasks ) +Backend::Backend( const char* title, const std::function& redraw, const std::function& scaleChanged, RunQueue* mainThreadTasks ) { s_redraw = redraw; + s_scaleChanged = scaleChanged; s_mainThreadTasks = mainThreadTasks; s_w = m_winPos.w; s_h = m_winPos.h; @@ -820,6 +822,7 @@ void Backend::NewFrame( int& w, int& h ) { if( s_prevScale != s_maxScale ) { + s_scaleChanged( s_maxScale ); SetupCursor(); wl_surface_set_buffer_scale( s_surf, s_maxScale ); s_prevScale = s_maxScale; diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 34f7f087..97f798bf 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -95,6 +95,7 @@ static ConnectionHistory* connHist; static std::atomic viewShutdown { ViewShutdown::False }; static double animTime = 0; static float dpiScale = 1.f; +static bool dpiScaleOverriddenFromEnv = false; static Filters* filt; static RunQueue mainThreadTasks; static uint32_t updateVersion = 0; @@ -197,6 +198,15 @@ static bool SaveConfig() return true; } +static void ScaleChanged( float scale ) +{ + if ( dpiScaleOverriddenFromEnv ) return; + if ( dpiScale == scale ) return; + + dpiScale = scale; + SetupDPIScale( dpiScale, s_fixedWidth, s_bigFont, s_smallFont ); +} + int main( int argc, char** argv ) { sprintf( title, "Tracy Profiler %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch ); @@ -279,7 +289,7 @@ int main( int argc, char** argv ) LoadConfig(); ImGuiTracyContext imguiContext; - Backend backend( title, DrawContents, &mainThreadTasks ); + Backend backend( title, DrawContents, ScaleChanged, &mainThreadTasks ); tracy::InitTexture(); iconTex = tracy::MakeTexture(); zigzagTex = tracy::MakeTexture( true ); @@ -292,7 +302,11 @@ int main( int argc, char** argv ) if( envDpiScale ) { const auto cnv = atof( envDpiScale ); - if( cnv != 0 ) dpiScale = cnv; + if( cnv != 0 ) + { + dpiScale = cnv; + dpiScaleOverriddenFromEnv = true; + } } SetupDPIScale( dpiScale, s_fixedWidth, s_bigFont, s_smallFont );