1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

WindowServer+LibGUI: Automatically close child windows with parent

If a window has child windows when it's destroyed, WindowServer will
now automatically tear down all of its children as well.

This is communicated to the client program through a vector of window
ID's included with the response to WindowServer::DestroyWindow.

This does feel a little bit awkward, but managing it on the client side
also seems a bit awkward.
This commit is contained in:
Andreas Kling 2020-05-01 23:53:05 +02:00
parent a726fda546
commit 745b0b27fd
5 changed files with 47 additions and 16 deletions

View file

@ -472,6 +472,10 @@ OwnPtr<Messages::WindowServer::CreateWindowResponse> ClientConnection::handle(co
did_misbehave("CreateWindow with bad parent_window_id");
return nullptr;
}
if (parent_window->window_id() == window_id) {
did_misbehave("CreateWindow trying to make a window with itself as parent");
return nullptr;
}
window->set_parent_window(*parent_window);
}
@ -497,6 +501,25 @@ OwnPtr<Messages::WindowServer::CreateWindowResponse> ClientConnection::handle(co
return make<Messages::WindowServer::CreateWindowResponse>(window_id);
}
void ClientConnection::destroy_window(Window& window, Vector<i32>& destroyed_window_ids)
{
for (auto& child_window : window.child_windows()) {
if (!child_window)
continue;
ASSERT(child_window->window_id() != window.window_id());
destroy_window(*child_window, destroyed_window_ids);
}
destroyed_window_ids.append(window.window_id());
if (window.type() == WindowType::MenuApplet)
AppletManager::the().remove_applet(window);
WindowManager::the().invalidate(window);
remove_child(window);
m_windows.remove(window.window_id());
}
OwnPtr<Messages::WindowServer::DestroyWindowResponse> ClientConnection::handle(const Messages::WindowServer::DestroyWindow& message)
{
auto it = m_windows.find(message.window_id());
@ -505,16 +528,9 @@ OwnPtr<Messages::WindowServer::DestroyWindowResponse> ClientConnection::handle(c
return nullptr;
}
auto& window = *(*it).value;
if (window.type() == WindowType::MenuApplet)
AppletManager::the().remove_applet(window);
WindowManager::the().invalidate(window);
remove_child(window);
ASSERT(it->value.ptr() == &window);
m_windows.remove(message.window_id());
return make<Messages::WindowServer::DestroyWindowResponse>();
Vector<i32> destroyed_window_ids;
destroy_window(window, destroyed_window_ids);
return make<Messages::WindowServer::DestroyWindowResponse>(destroyed_window_ids);
}
void ClientConnection::post_paint_message(Window& window, bool ignore_occlusion)