diff options
Diffstat (limited to 'gtk2_ardour/ardour_ui.cc')
-rw-r--r-- | gtk2_ardour/ardour_ui.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index e9ed833c7d..a53bcf167f 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -5660,3 +5660,55 @@ ARDOUR_UI::cancel_solo () _session->cancel_all_solo (); } } + +void +ARDOUR_UI::reset_focus (Gtk::Widget* w) +{ + /* 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->is_toplevel()) { + /* Setting the focus widget to a Gtk::Window causes all + * subsequent calls to ::has_focus() on the nominal + * focus widget in that window to return + * false. Workaround: never set focus to the toplevel + * itself. + */ + break; + } + + if (w->get_can_focus ()) { + Gtk::Window* win = dynamic_cast<Gtk::Window*> (top); + win->set_focus (*w); + return; + } + w = w->get_parent (); + } + + if (top == &_main_window) { + + } + + /* 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); + +} |