fix embedded plugin UI keyboard handling

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.
This commit is contained in:
Robin Gareus 2015-02-21 03:16:04 +01:00
parent 642e4950b9
commit a0eeb80885
6 changed files with 24 additions and 1 deletions

View 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*/);

View 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)
{

View 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()
{

View File

@ -60,6 +60,7 @@ class LV2PluginUI : public PlugUIBase, public Gtk::VBox
bool stop_updating(GdkEventAny*);
int package (Gtk::Window&);
void grab_focus ();
private:

View 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

View 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;