diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 7787b89ef5..addf2f3b38 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -45,6 +45,7 @@ #include "pbd/unknown_type.h" #include "pbd/unwind.h" #include "pbd/stacktrace.h" +#include "pbd/timersub.h" #include #include @@ -1108,6 +1109,58 @@ Editor::on_realize () { Window::on_realize (); Realized (); + + start_lock_event_timing (); + signal_event().connect (sigc::mem_fun (*this, &Editor::generic_event_handler)); +} + +void +Editor::start_lock_event_timing () +{ + /* check if we should lock the GUI every 30 seconds */ + + Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::lock_timeout_callback), 30 * 1000); +} + +bool +Editor::generic_event_handler (GdkEvent* ev) +{ + switch (ev->type) { + case GDK_BUTTON_PRESS: + case GDK_BUTTON_RELEASE: + case GDK_MOTION_NOTIFY: + case GDK_KEY_PRESS: + case GDK_KEY_RELEASE: + gettimeofday (&last_event_time, 0); + break; + default: + break; + } + return false; +} + +bool +Editor::lock_timeout_callback () +{ + struct timeval now, delta; + const uint32_t lock_timeout_secs = 5; /* 2 minutes */ + + gettimeofday (&now, 0); + + timersub (&now, &last_event_time, &delta); + + if (delta.tv_sec > lock_timeout_secs) { + lock (); + /* don't call again. Returning false will effectively + disconnect us from the timer callback. + + unlock() will call start_lock_event_timing() to get things + started again. + */ + return false; + } + + return true; } void diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 1356c16834..45cfc5cbc8 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1360,6 +1360,11 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void unlock (); ArdourDialog* lock_dialog; + struct timeval last_event_time; + bool generic_event_handler (GdkEvent*); + bool lock_timeout_callback (); + void start_lock_event_timing (); + Gtk::Menu fade_context_menu; Gtk::Menu xfade_in_context_menu; diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 7f0aacb17d..29c119f15c 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -7137,7 +7137,14 @@ Editor::lock () lock_dialog->set_size_request (200, 200); } +#ifdef __APPLE__ + /* The global menu bar continues to be accessible to applications + with modal dialogs, which means that we need to desensitize + all items in the menu bar. Since those items are really just + proxies for actions, that means disabling all actions. + */ ActionManager::disable_all_actions (); +#endif lock_dialog->present (); } @@ -7145,5 +7152,11 @@ void Editor::unlock () { lock_dialog->hide (); + +#ifdef __APPLE__ ActionManager::pop_action_state (); +#endif + + start_lock_event_timing (); + }