mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +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:
parent
95ab61e3db
commit
611370e7dc
19 changed files with 150 additions and 255 deletions
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/IDAllocator.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
#include <LibGUI/MenuItem.h>
|
||||
#include <LibGUI/Menubar.h>
|
||||
#include <LibGUI/WindowServerConnection.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
static IDAllocator s_menubar_id_allocator;
|
||||
|
||||
Menubar::Menubar()
|
||||
{
|
||||
}
|
||||
|
||||
Menubar::~Menubar()
|
||||
{
|
||||
unrealize_menubar();
|
||||
}
|
||||
|
||||
Menu& Menubar::add_menu(String name)
|
||||
{
|
||||
auto& menu = add<Menu>(move(name));
|
||||
m_menus.append(menu);
|
||||
return menu;
|
||||
}
|
||||
|
||||
int Menubar::realize_menubar()
|
||||
{
|
||||
auto menubar_id = s_menubar_id_allocator.allocate();
|
||||
WindowServerConnection::the().async_create_menubar(menubar_id);
|
||||
return menubar_id;
|
||||
}
|
||||
|
||||
void Menubar::unrealize_menubar()
|
||||
{
|
||||
if (m_menubar_id == -1)
|
||||
return;
|
||||
WindowServerConnection::the().async_destroy_menubar(m_menubar_id);
|
||||
m_menubar_id = -1;
|
||||
}
|
||||
|
||||
void Menubar::notify_added_to_window(Badge<Window>)
|
||||
{
|
||||
VERIFY(m_menubar_id == -1);
|
||||
m_menubar_id = realize_menubar();
|
||||
VERIFY(m_menubar_id != -1);
|
||||
for (auto& menu : m_menus) {
|
||||
int menu_id = menu.realize_menu();
|
||||
VERIFY(menu_id != -1);
|
||||
WindowServerConnection::the().async_add_menu_to_menubar(m_menubar_id, menu_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Menubar::notify_removed_from_window(Badge<Window>)
|
||||
{
|
||||
unrealize_menubar();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue