diff options
-rw-r--r-- | Libraries/LibGUI/Widget.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/Window.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibGUI/Window.h | 3 |
3 files changed, 11 insertions, 2 deletions
diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp index 06fd723fda..661f77f638 100644 --- a/Libraries/LibGUI/Widget.cpp +++ b/Libraries/LibGUI/Widget.cpp @@ -115,6 +115,8 @@ void Widget::child_event(Core::ChildEvent& event) else layout()->add_widget(Core::to<Widget>(*event.child())); } + if (window() && event.child() && Core::is<Widget>(*event.child())) + window()->did_add_widget({}, Core::to<Widget>(*event.child())); } if (event.type() == Event::ChildRemoved) { if (layout()) { diff --git a/Libraries/LibGUI/Window.cpp b/Libraries/LibGUI/Window.cpp index c0607948e4..805c8353f0 100644 --- a/Libraries/LibGUI/Window.cpp +++ b/Libraries/LibGUI/Window.cpp @@ -761,7 +761,13 @@ void Window::set_size_increment(const Gfx::Size& size_increment) WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement>(m_window_id, m_base_size, m_size_increment); } -void Window::did_remove_widget(Badge<Widget>, const Widget& widget) +void Window::did_add_widget(Badge<Widget>, Widget& widget) +{ + if (!m_focused_widget && widget.accepts_focus()) + set_focused_widget(&widget); +} + +void Window::did_remove_widget(Badge<Widget>, Widget& widget) { if (m_focused_widget == &widget) m_focused_widget = nullptr; diff --git a/Libraries/LibGUI/Window.h b/Libraries/LibGUI/Window.h index 0f3750253d..c2ca561f60 100644 --- a/Libraries/LibGUI/Window.h +++ b/Libraries/LibGUI/Window.h @@ -183,7 +183,8 @@ public: Action* action_for_key_event(const KeyEvent&); - void did_remove_widget(Badge<Widget>, const Widget&); + void did_add_widget(Badge<Widget>, Widget&); + void did_remove_widget(Badge<Widget>, Widget&); Window* find_parent_window(); |