diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-13 17:54:30 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-13 17:54:30 +0100 |
commit | 4f98a35bebdc7e39d71615aa57df33e7ebd77d20 (patch) | |
tree | 3129feadfdafbf297477d14023af921bad213c0e /LibGUI/GMenuBar.cpp | |
parent | 96352ab735dce3fa448fe7c414ed047f1f145f81 (diff) | |
download | serenity-4f98a35bebdc7e39d71615aa57df33e7ebd77d20.zip |
WindowServer: Begin refactoring towards a fully asynchronous protocol.
In order to move the WindowServer to userspace, I have to eliminate its
dependence on system call facilities. The communication channel with each
client needs to be message-based in both directions.
Diffstat (limited to 'LibGUI/GMenuBar.cpp')
-rw-r--r-- | LibGUI/GMenuBar.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/LibGUI/GMenuBar.cpp b/LibGUI/GMenuBar.cpp index 18c08f1a62..9a2467a8d2 100644 --- a/LibGUI/GMenuBar.cpp +++ b/LibGUI/GMenuBar.cpp @@ -1,4 +1,5 @@ #include <LibGUI/GMenuBar.h> +#include <LibGUI/GEventLoop.h> #include <LibC/gui.h> GMenuBar::GMenuBar() @@ -7,10 +8,7 @@ GMenuBar::GMenuBar() GMenuBar::~GMenuBar() { - if (m_menubar_id) { - gui_menubar_destroy(m_menubar_id); - m_menubar_id = 0; - } + unrealize_menubar(); } void GMenuBar::add_menu(OwnPtr<GMenu>&& menu) @@ -18,10 +16,29 @@ void GMenuBar::add_menu(OwnPtr<GMenu>&& menu) m_menus.append(move(menu)); } +int GMenuBar::realize_menubar() +{ + GUI_ClientMessage request; + request.type = GUI_ClientMessage::Type::CreateMenubar; + GUI_Event response = GEventLoop::main().sync_request(request, GUI_Event::Type::DidCreateMenubar); + return response.menu.menubar_id; +} + +void GMenuBar::unrealize_menubar() +{ + if (!m_menubar_id) + return; + GUI_ClientMessage request; + request.type = GUI_ClientMessage::Type::DestroyMenubar; + request.menu.menubar_id = m_menubar_id; + GEventLoop::main().sync_request(request, GUI_Event::Type::DidDestroyMenubar); + m_menubar_id = 0; +} + void GMenuBar::notify_added_to_application(Badge<GApplication>) { ASSERT(!m_menubar_id); - m_menubar_id = gui_menubar_create(); + m_menubar_id = realize_menubar(); ASSERT(m_menubar_id > 0); for (auto& menu : m_menus) { ASSERT(menu); @@ -35,7 +52,5 @@ void GMenuBar::notify_added_to_application(Badge<GApplication>) void GMenuBar::notify_removed_from_application(Badge<GApplication>) { - ASSERT(m_menubar_id); - gui_menubar_destroy(m_menubar_id); - m_menubar_id = 0; + unrealize_menubar(); } |