new timer-based GUI locking code
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 25 Jun 2014 12:28:36 +0000 (08:28 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 25 Jun 2014 12:28:36 +0000 (08:28 -0400)
gtk2_ardour/editor.cc
gtk2_ardour/editor.h
gtk2_ardour/editor_ops.cc

index 7787b89ef598000adb4bdb59c08769736391deb7..addf2f3b38d6be05707a9456295292fb7b6caf59 100644 (file)
@@ -45,6 +45,7 @@
 #include "pbd/unknown_type.h"
 #include "pbd/unwind.h"
 #include "pbd/stacktrace.h"
+#include "pbd/timersub.h"
 
 #include <glibmm/miscutils.h>
 #include <glibmm/uriutils.h>
@@ -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
index 1356c16834d764928f0ae3edb24306d0174a5f63..45cfc5cbc89f7e73131cb885f55f89659e931e83 100644 (file)
@@ -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;
index 7f0aacb17d600a4b9f65dcd7bd5d9c873d774f62..29c119f15c9357ce589429e2c9b8f67e256a399d 100644 (file)
@@ -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 ();
+       
 }