diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm index 1eb79d99cb81..d0089352a7db 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -16,6 +16,7 @@ #include "imgui.h" #include "imgui_impl_osx.h" #import +#include // CHANGELOG // (minor and older changes stripped away, please see git history for details) @@ -37,7 +38,8 @@ @class ImFocusObserver; // Data -static CFAbsoluteTime g_Time = 0.0; +static double g_HostClockPeriod; +static double g_Time = 0.0; static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static bool g_MouseCursorHidden = false; static bool g_MouseJustPressed[ImGuiMouseButton_COUNT] = {}; @@ -52,6 +54,19 @@ + (id)_windowResizeNorthSouthCursor; + (id)_windowResizeEastWestCursor; @end +static void InitHostClockPeriod() +{ + struct mach_timebase_info info; + mach_timebase_info(&info); + // Period is the reciprocal of frequency. + g_HostClockPeriod = 1e-9 * ((double)info.denom / (double)info.numer); +} + +static double GetMachAbsoluteTimeInSeconds() +{ + return (double)mach_absolute_time() * g_HostClockPeriod; +} + static void resetKeys() { ImGuiIO& io = ImGui::GetIO(); @@ -231,9 +246,11 @@ void ImGui_ImplOSX_NewFrame(NSView* view) } // Setup time step - if (g_Time == 0.0) - g_Time = CFAbsoluteTimeGetCurrent(); - CFAbsoluteTime current_time = CFAbsoluteTimeGetCurrent(); + if (g_Time == 0.0) { + InitHostClockPeriod(); + g_Time = GetMachAbsoluteTimeInSeconds(); + } + double current_time = GetMachAbsoluteTimeInSeconds(); io.DeltaTime = (float)(current_time - g_Time); g_Time = current_time;