fix embedded plugin UI keyboard handling
authorRobin Gareus <robin@gareus.org>
Sat, 21 Feb 2015 02:16:04 +0000 (03:16 +0100)
committerRobin Gareus <robin@gareus.org>
Sat, 21 Feb 2015 02:16:04 +0000 (03:16 +0100)
When the GUI is opened the first time all is fine, focus is on the
embedded widget. However once a user presses one of the preset buttons
(Add, Save,...) there is no possibility to return focus to the
embedded widget. Ardour always 'sees' it as focus=GtkButton and passes
the event to the editor.

gtk2_ardour/au_pluginui.h
gtk2_ardour/au_pluginui.mm
gtk2_ardour/lv2_plugin_ui.cc
gtk2_ardour/lv2_plugin_ui.h
gtk2_ardour/plugin_ui.cc
gtk2_ardour/plugin_ui.h

index 424d81e901ed18e833e6116e3854d80d31c801e5..71c81dfde360070112db9df8af6a0111a0e7fdca 100644 (file)
@@ -76,6 +76,7 @@ class AUPluginUI : public PlugUIBase, public Gtk::VBox
        void lower_box_realized ();
        void cocoa_view_resized ();
        void on_realize ();
+       void grab_focus();
        void forward_key_event (GdkEventKey*);
 
        bool on_window_show (const std::string& /*title*/);
index 9040d28a6fcee463dfd1cc97791a6a4d8573105e..76b94781d5021b97ab5d764a281f9432561a3ba0 100644 (file)
@@ -677,6 +677,13 @@ AUPluginUI::parent_cocoa_window ()
        return 0;
 }
 
+void
+AUPluginUI::grab_focus()
+{
+       if (au_view) {
+               [au_view becomeFirstResponder];
+       }
+}
 void
 AUPluginUI::forward_key_event (GdkEventKey* ev)
 {
index 3a64a830d16d43a4adad471789d2b36871bdadca..8e57eeed6094985379f7ae7dd7bd438fcd302632 100644 (file)
@@ -341,6 +341,8 @@ LV2PluginUI::lv2ui_instantiate(const std::string& title)
                                container->add(*Gtk::manage(Glib::wrap(c_widget)));
                        }
                        container->show_all();
+                       gtk_widget_set_can_focus(c_widget, true);
+                       gtk_widget_grab_focus(c_widget);
                } else {
                        _external_ui_ptr = (struct lv2_external_ui*)GET_WIDGET(_inst);
                }
@@ -368,6 +370,15 @@ LV2PluginUI::lv2ui_instantiate(const std::string& title)
        }
 }
 
+void
+LV2PluginUI::grab_focus()
+{
+       if (_inst && !_lv2->is_external_ui()) {
+               GtkWidget* c_widget = (GtkWidget*)GET_WIDGET(_inst);
+               gtk_widget_grab_focus(c_widget);
+       }
+}
+
 void
 LV2PluginUI::lv2ui_free()
 {
index a39386a7e041d455b5c9027b3857bbc2997b27b2..6a8acf9cf53e0454e38a3c08d1127ac201da43db 100644 (file)
@@ -60,6 +60,7 @@ class LV2PluginUI : public PlugUIBase, public Gtk::VBox
        bool stop_updating(GdkEventAny*);
 
        int package (Gtk::Window&);
+       void grab_focus ();
 
   private:
 
index 717fd6d44be71ee52d7cd38a621a90e5059612a4..b4e8e0001efdc62b4690e4afb4680bd519ceafc9 100644 (file)
@@ -353,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 {
@@ -366,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
index 14bfbe3ecadf99bc07e6be96cfb3ae604839a313..58dc6ce2a3ce61a92d4805f7966d4a0cc8089090 100644 (file)
@@ -103,7 +103,8 @@ class PlugUIBase : public virtual sigc::trackable, public PBD::ScopedConnectionL
        virtual void on_window_hide() {}
 
        virtual void forward_key_event (GdkEventKey*) {}
-        virtual bool non_gtk_gui() const { return false; }
+       virtual void grab_focus () {}
+  virtual bool non_gtk_gui() const { return false; }
 
        sigc::signal<void,bool> KeyboardFocused;