remove commented debug output
[ardour.git] / libs / gtkmm2ext / gtk_ui.cc
index 944019d4c350321d78af30c026eb9039678d1ef8..cfcc0df91a96d6d0acc932e05eb9658b5917431e 100644 (file)
@@ -38,6 +38,7 @@
 #include <gtkmm2ext/popup.h>
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/window_title.h>
+#include <gtkmm2ext/actions.h>
 
 #include "i18n.h"
 
@@ -47,22 +48,19 @@ using namespace Glib;
 using namespace PBD;
 using std::map;
 
-pthread_t UI::gui_thread;
 UI       *UI::theGtkUI = 0;
 
 BaseUI::RequestType Gtkmm2ext::ErrorMessage = BaseUI::new_request_type();
-BaseUI::RequestType Gtkmm2ext::Quit = BaseUI::new_request_type();
 BaseUI::RequestType Gtkmm2ext::TouchDisplay = BaseUI::new_request_type();
 BaseUI::RequestType Gtkmm2ext::StateChange = BaseUI::new_request_type();
 BaseUI::RequestType Gtkmm2ext::SetTip = BaseUI::new_request_type();
 BaseUI::RequestType Gtkmm2ext::AddIdle = BaseUI::new_request_type();
 BaseUI::RequestType Gtkmm2ext::AddTimeout = BaseUI::new_request_type();
 
-#include <pbd/abstract_ui.cc>  /* instantiate the template */
-
+#include "pbd/abstract_ui.cc"  /* instantiate the template */
 
 UI::UI (string namestr, int *argc, char ***argv)
-       : AbstractUI<UIRequest> (namestr, true)
+       : AbstractUI<UIRequest> (namestr)
 {
        theMain = new Main (argc, argv);
 #ifndef GTK_NEW_TOOLTIP_API
@@ -73,18 +71,26 @@ UI::UI (string namestr, int *argc, char ***argv)
 
        if (!theGtkUI) {
                theGtkUI = this;
-               gui_thread = pthread_self ();
        } else {
                fatal << "duplicate UI requested" << endmsg;
                /* NOTREACHED */
        }
 
-       /* add the pipe to the select/poll loop that GDK does */
+       /* the GUI event loop runs in the main thread of the app,
+          which is assumed to have called this.
+       */
+
+       run_loop_thread = Thread::self();
+       
+       /* store "this" as the UI-for-thread of this thread, same argument
+          as for previous line.
+       */
+
+       set_event_loop_for_thread (this);
+
+       /* attach our request source to the default main context */
 
-       gdk_input_add (signal_pipe[0],
-                      GDK_INPUT_READ,
-                      UI::signal_pipe_callback,
-                      this);
+       request_channel.ios()->attach (MainContext::get_default());
 
        errors = new TextViewer (800,600);
        errors->text().set_editable (false);
@@ -100,8 +106,6 @@ UI::UI (string namestr, int *argc, char ***argv)
        errors->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), (Window *) errors));
        errors->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
 
-       register_thread (pthread_self(), X_("GUI"));
-
        //load_rcfile (rcfile);
 }
 
@@ -113,7 +117,7 @@ UI::~UI ()
 bool
 UI::caller_is_ui_thread ()
 {
-       return pthread_equal (gui_thread, pthread_self());
+       return Thread::self() == run_loop_thread;
 }
 
 int
@@ -122,7 +126,9 @@ UI::load_rcfile (string path, bool themechange)
        /* Yes, pointers to Glib::RefPtr.  If these are not kept around,
         * a segfault somewhere deep in the wonderfully robust glib will result.
         * This does not occur if wiget.get_style is used instead of rc.get_style below,
-        * except that doesn't actually work... */
+        * except that doesn't actually work... 
+        */
+
        static Glib::RefPtr<Style>* fatal_style   = 0;
        static Glib::RefPtr<Style>* error_style   = 0;
        static Glib::RefPtr<Style>* warning_style = 0;
@@ -250,14 +256,6 @@ UI::running ()
        return _active;
 }
 
-void
-UI::kill ()
-{
-       if (_active) {
-               pthread_kill (gui_thread, SIGKILL);
-       }
-}
-
 void
 UI::quit ()
 {
@@ -300,17 +298,40 @@ UI::touch_display (Touchable *display)
        send_request (req);
 }
 
+void
+UI::set_tip (Widget &w, const gchar *tip)
+{
+       set_tip(&w, tip, "");
+}
+
+void
+UI::set_tip (Widget &w, const std::string& tip)
+{
+       set_tip(&w, tip.c_str(), "");
+}
+
 void
 UI::set_tip (Widget *w, const gchar *tip, const gchar *hlp)
 {
        UIRequest *req = get_request (SetTip);
 
+       std::string msg(tip);
+
+       Glib::RefPtr<Gtk::Action> action = w->get_action();
+       if (action) {
+               Gtk::AccelKey key;
+               bool has_key = ActionManager::lookup_entry(action->get_accel_path(), key);
+               if (has_key && key.get_abbrev() != "") {
+                       msg.append("\n\n Key: ").append(key.get_abbrev());
+               }
+       }
+
        if (req == 0) {
                return;
        }
 
        req->widget = w;
-       req->msg = tip;
+       req->msg = msg.c_str();
        req->msg2 = hlp;
 
        send_request (req);
@@ -348,16 +369,21 @@ UI::idle_add (int (*func)(void *), void *arg)
 
 /* END abstract_ui interfaces */
 
-void
-UI::signal_pipe_callback (void *arg, int fd, GdkInputCondition /*cond*/)
+/** Create a PBD::EventLoop::InvalidationRecord and attach a callback
+ *  to a given sigc::trackable so that PBD::EventLoop::invalidate_request
+ *  is called when that trackable is destroyed.
+ */
+PBD::EventLoop::InvalidationRecord*
+__invalidator (sigc::trackable& trackable, const char* file, int line)
 {
-       char buf[256];
+        PBD::EventLoop::InvalidationRecord* ir = new PBD::EventLoop::InvalidationRecord;
 
-       /* flush (nonblocking) pipe */
+        ir->file = file;
+        ir->line = line;
 
-       while (read (fd, buf, 256) > 0) {}
+        trackable.add_destroy_notify_callback (ir, PBD::EventLoop::invalidate_request);
 
-       ((UI *) arg)->handle_ui_requests ();
+        return ir;
 }
 
 void
@@ -374,8 +400,12 @@ UI::do_request (UIRequest* req)
                do_quit ();
 
        } else if (req->type == CallSlot) {
-
-               req->slot ();
+#ifndef NDEBUG
+               if (getenv ("DEBUG_THREADED_SIGNALS")) {
+                       cerr << "call slot for " << name() << endl;
+               }
+#endif
+               req->the_slot ();
 
        } else if (req->type == TouchDisplay) {
 
@@ -550,10 +580,9 @@ UI::handle_fatal (const char *message)
 
        win.set_default_size (400, 100);
 
-       string title;
-       title = name();
+       WindowTitle title(Glib::get_application_name());
        title += ": Fatal Error";
-       win.set_title (title);
+       win.set_title (title.get_string());
 
        win.set_position (WIN_POS_MOUSE);
        win.set_border_width (12);
@@ -573,7 +602,7 @@ UI::handle_fatal (const char *message)
 }
 
 void
-UI::popup_error (const char *text)
+UI::popup_error (const string& text)
 {
        PopUp *pup;