fix embedded plugin UI keyboard handling
[ardour.git] / gtk2_ardour / plugin_ui.cc
index 28ef9b12972a870e4ddca1a7febbbbfc401076ac..b4e8e0001efdc62b4690e4afb4680bd519ceafc9 100644 (file)
@@ -73,6 +73,7 @@
 
 using namespace std;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using namespace PBD;
 using namespace Gtkmm2ext;
 using namespace Gtk;
@@ -159,6 +160,9 @@ PluginUIWindow::PluginUIWindow (
 
 PluginUIWindow::~PluginUIWindow ()
 {
+#ifndef NDEBUG
+       cerr << "PluginWindow deleted for " << this << endl;
+#endif
        delete _pluginui;
 }
 
@@ -224,7 +228,7 @@ PluginUIWindow::create_windows_vst_editor(boost::shared_ptr<PluginInsert>)
                      << endmsg;
                throw failed_constructor ();
        } else {
-               WindowsVSTPluginUI* vpu = new WindowsVSTPluginUI (insert, vp);
+               WindowsVSTPluginUI* vpu = new WindowsVSTPluginUI (insert, vp, GTK_WIDGET(this->gobj()));
 
                _pluginui = vpu;
                _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
@@ -329,6 +333,7 @@ PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
                _pluginui = lpu;
                add (*lpu);
                lpu->package (*this);
+               _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
        }
 
        return true;
@@ -348,6 +353,7 @@ PluginUIWindow::on_key_press_event (GdkEventKey* event)
 {
        if (_keyboard_focused) {
                if (_pluginui) {
+                       _pluginui->grab_focus();
                        if (_pluginui->non_gtk_gui()) {
                                _pluginui->forward_key_event (event);
                        } else {
@@ -361,6 +367,7 @@ PluginUIWindow::on_key_press_event (GdkEventKey* event)
                */
 
                if (_pluginui) {
+                       _pluginui->grab_focus();
                        if (_pluginui->non_gtk_gui()) {
                                /* pass editor window as the window for the event
                                   to be handled in, not this one, because there are
@@ -403,8 +410,6 @@ PluginUIWindow::plugin_going_away ()
        }
 
        death_connection.disconnect ();
-
-       delete_when_idle (this);
 }
 
 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
@@ -446,7 +451,7 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
        bypass_button.set_name ("plugin bypass button");
        bypass_button.set_text (_("Bypass"));
        bypass_button.set_active (!pi->active());
-       bypass_button.signal_button_release_event().connect (sigc::mem_fun(*this, &PlugUIBase::bypass_button_release));
+       bypass_button.signal_button_release_event().connect (sigc::mem_fun(*this, &PlugUIBase::bypass_button_release), false);
        focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
 
        focus_button.signal_button_release_event().connect (sigc::mem_fun(*this, &PlugUIBase::focus_toggled));