Handle iconification by waiting for events.

This commit is contained in:
Bartosz Taudul 2022-09-27 17:32:01 +02:00
parent ff8a85ea2d
commit 1e7c6e3f49
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -16,6 +16,7 @@ static GLFWwindow* s_window;
static std::function<void()> s_redraw;
static RunQueue* s_mainThreadTasks;
static WindowPosition* s_winPos;
static bool s_iconified;
static void glfw_error_callback( int error, const char* description )
{
@ -45,6 +46,11 @@ static void glfw_window_maximize_callback( GLFWwindow*, int maximized )
s_winPos->maximize = maximized;
}
static void glfw_window_iconify_callback( GLFWwindow*, int iconified )
{
s_iconified = iconified != 0;
}
Backend::Backend( const char* title, std::function<void()> redraw, RunQueue* mainThreadTasks )
{
@ -79,10 +85,12 @@ Backend::Backend( const char* title, std::function<void()> redraw, RunQueue* mai
s_redraw = redraw;
s_mainThreadTasks = mainThreadTasks;
s_winPos = &m_winPos;
s_iconified = false;
glfwSetWindowPosCallback( s_window, glfw_window_pos_callback );
glfwSetWindowSizeCallback( s_window, glfw_window_size_callback );
glfwSetWindowMaximizeCallback( s_window, glfw_window_maximize_callback );
glfwSetWindowIconifyCallback( s_window, glfw_window_iconify_callback );
}
Backend::~Backend()
@ -104,12 +112,13 @@ void Backend::Run()
{
while( !glfwWindowShouldClose( s_window ) )
{
glfwPollEvents();
if( glfwGetWindowAttrib( s_window, GLFW_ICONIFIED ) )
if( s_iconified )
{
std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
continue;
glfwWaitEvents();
}
else
{
glfwPollEvents();
s_redraw();
if( !glfwGetWindowAttrib( s_window, GLFW_FOCUSED ) )
{
@ -118,6 +127,7 @@ void Backend::Run()
s_mainThreadTasks->Run();
}
}
}
void Backend::NewFrame( int& w, int& h )
{