@ -108,6 +108,7 @@ struct ImGui_ImplGlfw_Data
GLFWcursor * MouseCursors [ ImGuiMouseCursor_COUNT ] ;
ImVec2 LastValidMousePos ;
bool InstalledCallbacks ;
bool CallbacksChainForAllWindows ;
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
GLFWwindowfocusfun PrevUserCallbackWindowFocus ;
@ -270,10 +271,16 @@ static void ImGui_ImplGlfw_UpdateKeyModifiers()
io . AddKeyEvent ( ImGuiMod_Super , ( glfwGetKey ( bd - > Window , GLFW_KEY_LEFT_SUPER ) = = GLFW_PRESS ) | | ( glfwGetKey ( bd - > Window , GLFW_KEY_RIGHT_SUPER ) = = GLFW_PRESS ) ) ;
}
static bool ImGui_ImplGlfw_ShouldChainCallback ( GLFWwindow * window )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
return bd - > CallbacksChainForAllWindows ? true : ( window = = bd - > Window ) ;
}
void ImGui_ImplGlfw_MouseButtonCallback ( GLFWwindow * window , int button , int action , int mods )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
if ( bd - > PrevUserCallbackMousebutton ! = nullptr & & window = = bd - > Window )
if ( bd - > PrevUserCallbackMousebutton ! = nullptr & & ImGui_ImplGlfw_ShouldChainCallback ( window ) )
bd - > PrevUserCallbackMousebutton ( window , button , action , mods ) ;
ImGui_ImplGlfw_UpdateKeyModifiers ( ) ;
@ -286,7 +293,7 @@ void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int acti
void ImGui_ImplGlfw_ScrollCallback ( GLFWwindow * window , double xoffset , double yoffset )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
if ( bd - > PrevUserCallbackScroll ! = nullptr & & window = = bd - > Window )
if ( bd - > PrevUserCallbackScroll ! = nullptr & & ImGui_ImplGlfw_ShouldChainCallback ( window ) )
bd - > PrevUserCallbackScroll ( window , xoffset , yoffset ) ;
# ifdef __EMSCRIPTEN__
@ -334,7 +341,7 @@ static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
void ImGui_ImplGlfw_KeyCallback ( GLFWwindow * window , int keycode , int scancode , int action , int mods )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
if ( bd - > PrevUserCallbackKey ! = nullptr & & window = = bd - > Window )
if ( bd - > PrevUserCallbackKey ! = nullptr & & ImGui_ImplGlfw_ShouldChainCallback ( window ) )
bd - > PrevUserCallbackKey ( window , keycode , scancode , action , mods ) ;
if ( action ! = GLFW_PRESS & & action ! = GLFW_RELEASE )
@ -353,7 +360,7 @@ void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, i
void ImGui_ImplGlfw_WindowFocusCallback ( GLFWwindow * window , int focused )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
if ( bd - > PrevUserCallbackWindowFocus ! = nullptr & & window = = bd - > Window )
if ( bd - > PrevUserCallbackWindowFocus ! = nullptr & & ImGui_ImplGlfw_ShouldChainCallback ( window ) )
bd - > PrevUserCallbackWindowFocus ( window , focused ) ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
@ -363,7 +370,7 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
void ImGui_ImplGlfw_CursorPosCallback ( GLFWwindow * window , double x , double y )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
if ( bd - > PrevUserCallbackCursorPos ! = nullptr & & window = = bd - > Window )
if ( bd - > PrevUserCallbackCursorPos ! = nullptr & & ImGui_ImplGlfw_ShouldChainCallback ( window ) )
bd - > PrevUserCallbackCursorPos ( window , x , y ) ;
if ( glfwGetInputMode ( window , GLFW_CURSOR ) = = GLFW_CURSOR_DISABLED )
return ;
@ -378,7 +385,7 @@ void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
void ImGui_ImplGlfw_CursorEnterCallback ( GLFWwindow * window , int entered )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
if ( bd - > PrevUserCallbackCursorEnter ! = nullptr & & window = = bd - > Window )
if ( bd - > PrevUserCallbackCursorEnter ! = nullptr & & ImGui_ImplGlfw_ShouldChainCallback ( window ) )
bd - > PrevUserCallbackCursorEnter ( window , entered ) ;
if ( glfwGetInputMode ( window , GLFW_CURSOR ) = = GLFW_CURSOR_DISABLED )
return ;
@ -400,7 +407,7 @@ void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
void ImGui_ImplGlfw_CharCallback ( GLFWwindow * window , unsigned int c )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
if ( bd - > PrevUserCallbackChar ! = nullptr & & window = = bd - > Window )
if ( bd - > PrevUserCallbackChar ! = nullptr & & ImGui_ImplGlfw_ShouldChainCallback ( window ) )
bd - > PrevUserCallbackChar ( window , c ) ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
@ -472,6 +479,16 @@ void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window)
bd - > PrevUserCallbackMonitor = nullptr ;
}
// Set to 'true' to enable chaining installed callbacks for all windows (including secondary viewports created by backends or by user.
// This is 'false' by default meaning we only chain callbacks for the main viewport.
// We cannot set this to 'true' by default because user callbacks code may be not testing the 'window' parameter of their callback.
// If you set this to 'true' your user callback code will need to make sure you are testing the 'window' parameter.
void ImGui_ImplGlfw_SetCallbacksChainForAllWindows ( bool chain_for_all_windows )
{
ImGui_ImplGlfw_Data * bd = ImGui_ImplGlfw_GetBackendData ( ) ;
bd - > CallbacksChainForAllWindows = chain_for_all_windows ;
}
static bool ImGui_ImplGlfw_Init ( GLFWwindow * window , bool install_callbacks , GlfwClientApi client_api )
{
ImGuiIO & io = ImGui : : GetIO ( ) ;