/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include namespace GUI { Menubar::Menubar() { } Menubar::~Menubar() { unrealize_menubar(); } Menu& Menubar::add_menu(String name) { auto& menu = add(move(name)); m_menus.append(menu); return menu; } int Menubar::realize_menubar() { return WindowServerConnection::the().send_sync()->menubar_id(); } void Menubar::unrealize_menubar() { if (m_menubar_id == -1) return; WindowServerConnection::the().send_sync(m_menubar_id); m_menubar_id = -1; } void Menubar::notify_added_to_window(Badge) { 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().send_sync(m_menubar_id, menu_id); } } void Menubar::notify_removed_from_window(Badge) { unrealize_menubar(); } }