diff options
Diffstat (limited to 'gtk2_ardour/editor_actions.cc')
-rw-r--r-- | gtk2_ardour/editor_actions.cc | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/gtk2_ardour/editor_actions.cc b/gtk2_ardour/editor_actions.cc index 008a4d75dc..280bc3f9cb 100644 --- a/gtk2_ardour/editor_actions.cc +++ b/gtk2_ardour/editor_actions.cc @@ -1739,9 +1739,40 @@ Editor::parameter_changed (std::string p) } void -Editor::reset_focus () +Editor::reset_focus (Gtk::Widget* w) { - _track_canvas->grab_focus(); + /* this resets focus to the first focusable parent of the given widget, + * or, if there is no focusable parent, cancels focus in the toplevel + * window that the given widget is packed into (if there is one). + */ + + if (!w) { + return; + } + + Gtk::Widget* top = w->get_toplevel(); + + if (!top || !top->is_toplevel()) { + return; + } + + w = w->get_parent (); + + while (w) { + if (w->get_can_focus ()) { + Window* win = dynamic_cast<Window*> (top); + win->set_focus (*w); + return; + } + w = w->get_parent (); + } + + /* no focusable parent found, cancel focus in top level window. + C++ API cannot be used for this. Thanks, references. + */ + + gtk_window_set_focus (GTK_WINDOW(top->gobj()), 0); + } void |