From ecaeea94e5b26d05f8b935455bef11fc27c3f543 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 2 Dec 2024 23:43:47 +0100 Subject: [PATCH] Replace gettimeofday with monotonic time let's be independent of NTP updates, daylight savings time and syscalls. --- gtk2_ardour/editor.cc | 12 ++++-------- gtk2_ardour/editor.h | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index c246e97b21..8932f52ac3 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -323,7 +323,7 @@ Editor::Editor () , pending_keyboard_selection_start (0) , ignore_gui_changes (false) , lock_dialog (0) - , last_event_time { 0, 0 } + , _last_event_time (g_get_monotonic_time ()) , _dragging_playhead (false) , ignore_map_change (false) , _stationary_playhead (false) @@ -1047,7 +1047,7 @@ Editor::generic_event_handler (GdkEvent* ev) case GDK_KEY_PRESS: case GDK_KEY_RELEASE: if (contents().get_mapped()) { - gettimeofday (&last_event_time, 0); + _last_event_time = g_get_monotonic_time (); } break; @@ -1078,13 +1078,9 @@ Editor::generic_event_handler (GdkEvent* ev) bool Editor::lock_timeout_callback () { - struct timeval now, delta; + int64_t dt = g_get_monotonic_time () - _last_event_time; - gettimeofday (&now, 0); - - timersub (&now, &last_event_time, &delta); - - if (delta.tv_sec > (time_t) UIConfiguration::instance().get_lock_gui_after_seconds()) { + if (dt * 1e-6 > UIConfiguration::instance().get_lock_gui_after_seconds()) { lock (); /* don't call again. Returning false will effectively disconnect us from the timer callback. diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 77f0785238..156317aafb 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1453,7 +1453,8 @@ private: void unlock (); Gtk::Dialog* lock_dialog; - struct timeval last_event_time; + int64_t _last_event_time; + bool generic_event_handler (GdkEvent*); bool lock_timeout_callback (); void start_lock_event_timing ();