Enforce DPI scale setup on first render frame.

Not all backends know their DPI before window is available.
This commit is contained in:
Bartosz Taudul 2024-09-28 13:54:39 +02:00
parent 04b921e200
commit 44ae59f363
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 12 additions and 2 deletions

View File

@ -20,7 +20,7 @@ static EGLDisplay s_eglDpy;
static EGLContext s_eglCtx; static EGLContext s_eglCtx;
static EGLSurface s_eglSurf; static EGLSurface s_eglSurf;
static float s_prevScale; static float s_prevScale = -1;
static int s_width, s_height; static int s_width, s_height;
static uint64_t s_time; static uint64_t s_time;
static const char* s_prevCursor = nullptr; static const char* s_prevCursor = nullptr;

View File

@ -17,9 +17,11 @@
static GLFWwindow* s_window; static GLFWwindow* s_window;
static std::function<void()> s_redraw; static std::function<void()> s_redraw;
static std::function<void(float)> s_scaleChanged;
static RunQueue* s_mainThreadTasks; static RunQueue* s_mainThreadTasks;
static WindowPosition* s_winPos; static WindowPosition* s_winPos;
static bool s_iconified; static bool s_iconified;
static float s_prevScale = -1;
extern tracy::Config s_config; extern tracy::Config s_config;
@ -95,6 +97,7 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
ImGui_ImplOpenGL3_Init( "#version 150" ); ImGui_ImplOpenGL3_Init( "#version 150" );
s_redraw = redraw; s_redraw = redraw;
s_scaleChanged = scaleChanged;
s_mainThreadTasks = mainThreadTasks; s_mainThreadTasks = mainThreadTasks;
s_winPos = &m_winPos; s_winPos = &m_winPos;
s_iconified = false; s_iconified = false;
@ -152,6 +155,13 @@ void Backend::Attention()
void Backend::NewFrame( int& w, int& h ) void Backend::NewFrame( int& w, int& h )
{ {
const auto scale = GetDpiScale();
if( scale != s_prevScale )
{
s_prevScale = scale;
s_scaleChanged( scale );
}
glfwGetFramebufferSize( s_window, &w, &h ); glfwGetFramebufferSize( s_window, &w, &h );
m_w = w; m_w = w;
m_h = h; m_h = h;

View File

@ -222,7 +222,7 @@ struct Output
}; };
static std::unordered_map<uint32_t, std::unique_ptr<Output>> s_output; static std::unordered_map<uint32_t, std::unique_ptr<Output>> s_output;
static int s_maxScale = 120; static int s_maxScale = 120;
static int s_prevScale = 120; static int s_prevScale = -1;
static bool s_running = true; static bool s_running = true;
static int s_width, s_height; static int s_width, s_height;