From b7d22508fa7a6a4c31c2fca901566fe505193dfa Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 29 Nov 2020 12:46:01 -0700 Subject: [PATCH] Add blib event callback to BaseUI, with a virtual method to be overridden by derived classes. --- libs/pbd/base_ui.cc | 12 ++++++++++++ libs/pbd/pbd/base_ui.h | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/libs/pbd/base_ui.cc b/libs/pbd/base_ui.cc index 34b972b3a4..e2f368527f 100644 --- a/libs/pbd/base_ui.cc +++ b/libs/pbd/base_ui.cc @@ -60,6 +60,7 @@ BaseUI::BaseUI (const string& loop_name) , m_context(MainContext::get_default()) , run_loop_thread (0) , request_channel (true) + , glib_event_callback (boost::bind (&BaseUI::event_loop_precall, this)) { base_ui_instance = this; request_channel.set_receive_handler (sigc::mem_fun (*this, &BaseUI::request_handler)); @@ -120,6 +121,12 @@ BaseUI::run () _main_loop = MainLoop::create (m_context); attach_request_source (); + /* + * every time the main loop runs (i.e. before any actual event handling) + */ + + glib_event_callback.attach (m_context); + Glib::Threads::Mutex::Lock lm (_run_lock); run_loop_thread = Glib::Threads::Thread::create (mem_fun (*this, &BaseUI::main_thread)); _running.wait (_run_lock); @@ -175,3 +182,8 @@ BaseUI::attach_request_source () DEBUG_TRACE (DEBUG::EventLoop, string_compose ("%1: attach request source\n", event_loop_name())); request_channel.attach (m_context); } + +void +BaseUI::event_loop_precall () +{ +} diff --git a/libs/pbd/pbd/base_ui.h b/libs/pbd/pbd/base_ui.h index af501fc666..0d10308392 100644 --- a/libs/pbd/pbd/base_ui.h +++ b/libs/pbd/pbd/base_ui.h @@ -33,6 +33,7 @@ #include "pbd/libpbd_visibility.h" #include "pbd/crossthread.h" #include "pbd/event_loop.h" +#include "pbd/glib_event_source.h" #include "pbd/pthread_utils.h" /** A BaseUI is an abstraction designed to be used with any "user @@ -75,6 +76,12 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop */ void quit (); + /* derived classes can override this in order to call code once per + main loop iteration (i.e. before any event dispatching is done + within the main loop) + */ + virtual void event_loop_precall (); + protected: bool _ok; @@ -122,6 +129,8 @@ class LIBPBD_API BaseUI : public sigc::trackable, public PBD::EventLoop int setup_request_pipe (); void main_thread (); + + GlibEventLoopCallback glib_event_callback; }; #endif /* __pbd_base_ui_h__ */