|
@@ -21,7 +21,7 @@
|
|
// CHANGELOG
|
|
// CHANGELOG
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
|
// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
|
-// 2023-02-02: Inputs: Scaling X value on Emscripten (bug?). (#4019, #6096)
|
|
|
|
|
|
+// 2023-02-03: Emscripten: Registering custom low-level mouse wheel handler to get more accurate scrolling impulses on Emscripten. (#4019, #6096)
|
|
// 2023-01-18: Handle unsupported glfwGetVideoMode() call on e.g. Emscripten.
|
|
// 2023-01-18: Handle unsupported glfwGetVideoMode() call on e.g. Emscripten.
|
|
// 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty.
|
|
// 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty.
|
|
// 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908)
|
|
// 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908)
|
|
@@ -87,6 +87,11 @@
|
|
#include <GLFW/glfw3native.h> // for glfwGetCocoaWindow()
|
|
#include <GLFW/glfw3native.h> // for glfwGetCocoaWindow()
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
|
+#include <emscripten.h>
|
|
|
|
+#include <emscripten/html5.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
// We gather version tests as define in order to easily see which features are version-dependent.
|
|
// We gather version tests as define in order to easily see which features are version-dependent.
|
|
#define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION)
|
|
#define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION)
|
|
#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_COMBINED >= 3200) // 3.2+ GLFW_FLOATING
|
|
#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_COMBINED >= 3200) // 3.2+ GLFW_FLOATING
|
|
@@ -129,6 +134,7 @@ struct ImGui_ImplGlfw_Data
|
|
ImVec2 LastValidMousePos;
|
|
ImVec2 LastValidMousePos;
|
|
GLFWwindow* KeyOwnerWindows[GLFW_KEY_LAST];
|
|
GLFWwindow* KeyOwnerWindows[GLFW_KEY_LAST];
|
|
bool InstalledCallbacks;
|
|
bool InstalledCallbacks;
|
|
|
|
+ bool CallbacksChainForAllWindows;
|
|
bool WantUpdateMonitors;
|
|
bool WantUpdateMonitors;
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
WNDPROC GlfwWndProc;
|
|
WNDPROC GlfwWndProc;
|
|
@@ -300,10 +306,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));
|
|
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)
|
|
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
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);
|
|
bd->PrevUserCallbackMousebutton(window, button, action, mods);
|
|
|
|
|
|
ImGui_ImplGlfw_UpdateKeyModifiers();
|
|
ImGui_ImplGlfw_UpdateKeyModifiers();
|
|
@@ -316,11 +328,12 @@ void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int acti
|
|
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
|
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
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);
|
|
bd->PrevUserCallbackScroll(window, xoffset, yoffset);
|
|
|
|
|
|
#ifdef __EMSCRIPTEN__
|
|
#ifdef __EMSCRIPTEN__
|
|
- xoffset /= 100.0;
|
|
|
|
|
|
+ // Ignore GLFW events: will be processed in ImGui_ImplEmscripten_WheelCallback().
|
|
|
|
+ return;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
@@ -363,7 +376,7 @@ static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
|
|
void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
|
|
void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
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);
|
|
bd->PrevUserCallbackKey(window, keycode, scancode, action, mods);
|
|
|
|
|
|
if (action != GLFW_PRESS && action != GLFW_RELEASE)
|
|
if (action != GLFW_PRESS && action != GLFW_RELEASE)
|
|
@@ -385,7 +398,7 @@ void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, i
|
|
void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
|
|
void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
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);
|
|
bd->PrevUserCallbackWindowFocus(window, focused);
|
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
@@ -395,7 +408,7 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
|
|
void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
|
void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
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);
|
|
bd->PrevUserCallbackCursorPos(window, x, y);
|
|
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
|
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
|
return;
|
|
return;
|
|
@@ -417,7 +430,7 @@ void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
|
void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
|
|
void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
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);
|
|
bd->PrevUserCallbackCursorEnter(window, entered);
|
|
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
|
if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
|
return;
|
|
return;
|
|
@@ -439,7 +452,7 @@ void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
|
|
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
|
|
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
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);
|
|
bd->PrevUserCallbackChar(window, c);
|
|
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
@@ -452,6 +465,24 @@ void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int)
|
|
bd->WantUpdateMonitors = true;
|
|
bd->WantUpdateMonitors = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
|
+static EM_BOOL ImGui_ImplEmscripten_WheelCallback(int, const EmscriptenWheelEvent* ev, void*)
|
|
|
|
+{
|
|
|
|
+ // Mimic Emscripten_HandleWheel() in SDL.
|
|
|
|
+ // Corresponding equivalent in GLFW JS emulation layer has incorrect quantizing preventing small values. See #6096
|
|
|
|
+ float multiplier = 0.0f;
|
|
|
|
+ if (ev->deltaMode == DOM_DELTA_PIXEL) { multiplier = 1.0f / 100.0f; } // 100 pixels make up a step.
|
|
|
|
+ else if (ev->deltaMode == DOM_DELTA_LINE) { multiplier = 1.0f / 3.0f; } // 3 lines make up a step.
|
|
|
|
+ else if (ev->deltaMode == DOM_DELTA_PAGE) { multiplier = 80.0f; } // A page makes up 80 steps.
|
|
|
|
+ float wheel_x = ev->deltaX * -multiplier;
|
|
|
|
+ float wheel_y = ev->deltaY * -multiplier;
|
|
|
|
+ ImGuiIO& io = ImGui::GetIO();
|
|
|
|
+ io.AddMouseWheelEvent(wheel_x, wheel_y);
|
|
|
|
+ //IMGUI_DEBUG_LOG("[Emsc] mode %d dx: %.2f, dy: %.2f, dz: %.2f --> feed %.2f %.2f\n", (int)ev->deltaMode, ev->deltaX, ev->deltaY, ev->deltaZ, wheel_x, wheel_y);
|
|
|
|
+ return EM_TRUE;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
|
|
void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
|
|
{
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
@@ -494,6 +525,16 @@ void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window)
|
|
bd->PrevUserCallbackMonitor = nullptr;
|
|
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)
|
|
static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
|
|
{
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
@@ -548,6 +589,12 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
|
|
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
|
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
|
|
if (install_callbacks)
|
|
if (install_callbacks)
|
|
ImGui_ImplGlfw_InstallCallbacks(window);
|
|
ImGui_ImplGlfw_InstallCallbacks(window);
|
|
|
|
+ // Register Emscripten Wheel callback to workaround issue in Emscripten GLFW Emulation (#6096)
|
|
|
|
+ // We intentionally do not check 'if (install_callbacks)' here, as some users may set it to false and call GLFW callback themselves.
|
|
|
|
+ // FIXME: May break chaining in case user registered their own Emscripten callback?
|
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
|
+ emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, NULL, false, ImGui_ImplEmscripten_WheelCallback);
|
|
|
|
+#endif
|
|
|
|
|
|
// Update monitors the first time (note: monitor callback are broken in GLFW 3.2 and earlier, see github.com/glfw/glfw/issues/784)
|
|
// Update monitors the first time (note: monitor callback are broken in GLFW 3.2 and earlier, see github.com/glfw/glfw/issues/784)
|
|
ImGui_ImplGlfw_UpdateMonitors();
|
|
ImGui_ImplGlfw_UpdateMonitors();
|