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

LibGUI, WindowServer: Greatly simplify menubar logic

Currently, any number of menubars can be plugged in and out of a window.
This is unnecessary complexity, since we only need one menubar on a
window. This commit removes most of the logic for dynamically attaching
and detaching menubars and makes one menubar always available. The
menubar is only considered existent if it has at least a single menu in
it (in other words, an empty menubar will not be shown).

This commit additionally fixes a bug wherein menus added after a menubar
has been attached would not have their rects properly setup, and would
therefore appear glitched out on the top left corner of the menubar.
This commit is contained in:
sin-ack 2021-07-29 10:14:12 +00:00 committed by Andreas Kling
parent 95ab61e3db
commit 611370e7dc
19 changed files with 150 additions and 255 deletions

View file

@ -66,6 +66,7 @@ Window* Window::from_window_id(int window_id)
Window::Window(Core::Object* parent)
: Core::Object(parent)
, m_menubar(Menubar::construct())
{
all_windows->set(this);
m_rect_when_windowless = { -5000, -5000, 140, 140 };
@ -92,8 +93,6 @@ Window::Window(Core::Object* parent)
Window::~Window()
{
if (m_menubar)
m_menubar->notify_removed_from_window({});
all_windows->remove(this);
hide();
}
@ -162,11 +161,11 @@ void Window::show()
apply_icon();
if (m_menubar) {
// This little dance makes us create a server-side menubar.
auto menubar = move(m_menubar);
set_menubar(menubar);
}
m_menubar->for_each_menu([&](Menu& menu) {
menu.realize_menu_if_needed();
WindowServerConnection::the().async_add_menu(m_window_id, menu.menu_id());
return IterationDecision::Continue;
});
reified_windows->set(m_window_id, this);
Application::the()->did_create_window({});
@ -1172,22 +1171,12 @@ Gfx::Bitmap* Window::back_bitmap()
Menu& Window::add_menu(String name)
{
if (!m_menubar)
set_menubar(GUI::Menubar::construct());
return m_menubar->add_menu(move(name));
}
void Window::set_menubar(RefPtr<Menubar> menubar)
{
if (m_menubar == menubar)
return;
if (m_menubar)
m_menubar->notify_removed_from_window({});
m_menubar = move(menubar);
if (m_window_id && m_menubar) {
m_menubar->notify_added_to_window({});
WindowServerConnection::the().async_set_window_menubar(m_window_id, m_menubar->menubar_id());
Menu& menu = m_menubar->add_menu({}, move(name));
if (m_window_id) {
menu.realize_menu_if_needed();
WindowServerConnection::the().async_add_menu(m_window_id, menu.menu_id());
}
return menu;
}
bool Window::is_modified() const