diff options
author | Andreas Kling <kling@serenityos.org> | 2021-03-25 21:41:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-25 22:14:09 +0100 |
commit | 78b12e1521a5ab4e0a212c0e125b76a813be6f64 (patch) | |
tree | 63b47fca86bfba4ef53d62f301856e63f5bb2f28 /Userland/Libraries/LibGUI | |
parent | fcc8e3484f9c2312d80063fe8d6251830609385a (diff) | |
download | serenity-78b12e1521a5ab4e0a212c0e125b76a813be6f64.zip |
Userland: Turn all application menus into window menus :^)
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r-- | Userland/Libraries/LibGUI/Application.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Application.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/MenuBar.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/MenuBar.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.cpp | 16 |
5 files changed, 19 insertions, 19 deletions
diff --git a/Userland/Libraries/LibGUI/Application.cpp b/Userland/Libraries/LibGUI/Application.cpp index 73e4caa964..da40d8edfe 100644 --- a/Userland/Libraries/LibGUI/Application.cpp +++ b/Userland/Libraries/LibGUI/Application.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -125,15 +125,6 @@ void Application::quit(int exit_code) m_event_loop->quit(exit_code); } -void Application::set_menubar(RefPtr<MenuBar> menubar) -{ - if (m_menubar) - m_menubar->notify_removed_from_application({}); - m_menubar = move(menubar); - if (m_menubar) - m_menubar->notify_added_to_application({}); -} - void Application::register_global_shortcut_action(Badge<Action>, Action& action) { m_global_shortcut_actions.set(action.shortcut(), &action); diff --git a/Userland/Libraries/LibGUI/Application.h b/Userland/Libraries/LibGUI/Application.h index 32731c8853..b1710ce8dd 100644 --- a/Userland/Libraries/LibGUI/Application.h +++ b/Userland/Libraries/LibGUI/Application.h @@ -49,7 +49,6 @@ public: int exec(); void quit(int = 0); - void set_menubar(RefPtr<MenuBar>); Action* action_for_key_event(const KeyEvent&); void register_global_shortcut_action(Badge<Action>, Action&); @@ -106,7 +105,6 @@ private: void set_pending_drop_widget(Widget*); OwnPtr<Core::EventLoop> m_event_loop; - RefPtr<MenuBar> m_menubar; RefPtr<Gfx::PaletteImpl> m_palette; RefPtr<Gfx::PaletteImpl> m_system_palette; HashMap<Shortcut, Action*> m_global_shortcut_actions; diff --git a/Userland/Libraries/LibGUI/MenuBar.cpp b/Userland/Libraries/LibGUI/MenuBar.cpp index 1900aa046c..3fc5f65617 100644 --- a/Userland/Libraries/LibGUI/MenuBar.cpp +++ b/Userland/Libraries/LibGUI/MenuBar.cpp @@ -61,7 +61,7 @@ void MenuBar::unrealize_menubar() m_menubar_id = -1; } -void MenuBar::notify_added_to_application(Badge<Application>) +void MenuBar::notify_added_to_window(Badge<Window>) { VERIFY(m_menubar_id == -1); m_menubar_id = realize_menubar(); @@ -71,10 +71,9 @@ void MenuBar::notify_added_to_application(Badge<Application>) VERIFY(menu_id != -1); WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuToMenubar>(m_menubar_id, menu_id); } - WindowServerConnection::the().send_sync<Messages::WindowServer::SetApplicationMenubar>(m_menubar_id); } -void MenuBar::notify_removed_from_application(Badge<Application>) +void MenuBar::notify_removed_from_window(Badge<Window>) { unrealize_menubar(); } diff --git a/Userland/Libraries/LibGUI/MenuBar.h b/Userland/Libraries/LibGUI/MenuBar.h index 5e223cff9e..971bc5559e 100644 --- a/Userland/Libraries/LibGUI/MenuBar.h +++ b/Userland/Libraries/LibGUI/MenuBar.h @@ -41,8 +41,8 @@ public: Menu& add_menu(String name); - void notify_added_to_application(Badge<Application>); - void notify_removed_from_application(Badge<Application>); + void notify_added_to_window(Badge<Window>); + void notify_removed_from_window(Badge<Window>); int menubar_id() const { return m_menubar_id; } diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index a7f3c79911..23332112b1 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -110,6 +110,8 @@ Window::Window(Core::Object* parent) Window::~Window() { + if (m_menubar) + m_menubar->notify_removed_from_window({}); all_windows->remove(this); hide(); } @@ -161,6 +163,12 @@ 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); + } + reified_windows->set(m_window_id, this); Application::the()->did_create_window({}); update(); @@ -1057,9 +1065,13 @@ 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) + if (m_window_id && m_menubar) { + m_menubar->notify_added_to_window({}); WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowMenubar>(m_window_id, m_menubar->menubar_id()); + } } } |