From 8ddd053c2a947bce2df4faa3de60bab9cab85420 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 8 Jan 2020 13:19:31 +0100 Subject: [PATCH] WindowServer: Detach WSMenuManager from WSWindowManager You can now get to the WSMenuManager via WSMenuManager::the(). Also note that it's initialized after WSWindowManager. --- Servers/WindowServer/WSClientConnection.cpp | 8 +++--- Servers/WindowServer/WSMenu.cpp | 14 +++++----- Servers/WindowServer/WSMenuItem.cpp | 2 +- Servers/WindowServer/WSMenuManager.cpp | 18 ++++++++----- Servers/WindowServer/WSMenuManager.h | 3 ++- Servers/WindowServer/WSWindowManager.cpp | 30 ++++++++++----------- Servers/WindowServer/WSWindowManager.h | 4 --- Servers/WindowServer/main.cpp | 1 + 8 files changed, 41 insertions(+), 39 deletions(-) diff --git a/Servers/WindowServer/WSClientConnection.cpp b/Servers/WindowServer/WSClientConnection.cpp index 01860856661..3094f29cf89 100644 --- a/Servers/WindowServer/WSClientConnection.cpp +++ b/Servers/WindowServer/WSClientConnection.cpp @@ -49,7 +49,7 @@ WSClientConnection::WSClientConnection(CLocalSocket& client_socket, int client_i WSClientConnection::~WSClientConnection() { - WSWindowManager::the().menu_manager().close_all_menus_from_client({}, *this); + WSMenuManager::the().close_all_menus_from_client({}, *this); auto windows = move(m_windows); } @@ -85,7 +85,7 @@ OwnPtr WSClientConnection::handle(const Wi return nullptr; } auto& menubar = *(*it).value; - WSWindowManager::the().menu_manager().close_menubar(menubar); + WSMenuManager::the().close_menubar(menubar); m_menubars.remove(it); return make(); } @@ -405,7 +405,7 @@ OwnPtr WSClientConnection::handle(const Wind window->set_base_size(message.base_size()); window->invalidate(); if (window->type() == WSWindowType::MenuApplet) - WSWindowManager::the().menu_manager().add_applet(*window); + WSMenuManager::the().add_applet(*window); m_windows.set(window_id, move(window)); return make(window_id); } @@ -420,7 +420,7 @@ OwnPtr WSClientConnection::handle(const Win auto& window = *(*it).value; if (window.type() == WSWindowType::MenuApplet) - WSWindowManager::the().menu_manager().remove_applet(window); + WSMenuManager::the().remove_applet(window); WSWindowManager::the().invalidate(window); remove_child(window); diff --git a/Servers/WindowServer/WSMenu.cpp b/Servers/WindowServer/WSMenu.cpp index 1533a58a5e5..9c0ea38bbb6 100644 --- a/Servers/WindowServer/WSMenu.cpp +++ b/Servers/WindowServer/WSMenu.cpp @@ -127,7 +127,7 @@ WSWindow& WSMenu::ensure_menu_window() void WSMenu::draw() { auto palette = WSWindowManager::the().palette(); - m_theme_index_at_last_paint = WSWindowManager::the().menu_manager().theme_index(); + m_theme_index_at_last_paint = WSMenuManager::the().theme_index(); ASSERT(menu_window()); ASSERT(menu_window()->backing_store()); @@ -205,10 +205,10 @@ void WSMenu::redraw_for_new_hovered_item() { if (m_hovered_item && m_hovered_item->is_submenu()) { ASSERT(m_hovered_item == &m_items.at(m_current_index)); - WSWindowManager::the().menu_manager().close_everyone_not_in_lineage(*m_hovered_item->submenu()); + WSMenuManager::the().close_everyone_not_in_lineage(*m_hovered_item->submenu()); m_hovered_item->submenu()->popup(m_hovered_item->rect().top_right().translated(menu_window()->rect().location()), true); } else { - WSWindowManager::the().menu_manager().close_everyone_not_in_lineage(*this); + WSMenuManager::the().close_everyone_not_in_lineage(*this); } redraw(); } @@ -359,7 +359,7 @@ void WSMenu::did_activate(WSMenuItem& item) if (on_item_activation) on_item_activation(item); - WSWindowManager::the().menu_manager().close_bar(); + WSMenuManager::the().close_bar(); if (m_client) m_client->post_message(WindowClient::MenuItemActivated(m_menu_id, item.identifier())); @@ -385,12 +385,12 @@ WSMenuItem* WSMenu::item_at(const Point& position) void WSMenu::close() { - WSWindowManager::the().menu_manager().close_menu_and_descendants(*this); + WSMenuManager::the().close_menu_and_descendants(*this); } void WSMenu::redraw_if_theme_changed() { - if (m_theme_index_at_last_paint != WSWindowManager::the().menu_manager().theme_index()) + if (m_theme_index_at_last_paint != WSMenuManager::the().theme_index()) redraw(); } @@ -412,7 +412,7 @@ void WSMenu::popup(const Point& position, bool is_submenu) window.move_to(adjusted_pos); window.set_visible(true); - WSWindowManager::the().menu_manager().set_current_menu(this, is_submenu); + WSMenuManager::the().set_current_menu(this, is_submenu); } bool WSMenu::is_menu_ancestor_of(const WSMenu& other) const diff --git a/Servers/WindowServer/WSMenuItem.cpp b/Servers/WindowServer/WSMenuItem.cpp index 108d543c2f5..1ccfc88f09d 100644 --- a/Servers/WindowServer/WSMenuItem.cpp +++ b/Servers/WindowServer/WSMenuItem.cpp @@ -48,5 +48,5 @@ WSMenu* WSMenuItem::submenu() ASSERT(is_submenu()); if (m_menu.client()) return m_menu.client()->find_menu_by_id(m_submenu_id); - return WSWindowManager::the().menu_manager().find_internal_menu_by_id(m_submenu_id); + return WSMenuManager::the().find_internal_menu_by_id(m_submenu_id); } diff --git a/Servers/WindowServer/WSMenuManager.cpp b/Servers/WindowServer/WSMenuManager.cpp index 0ff230c7006..d6c53635a35 100644 --- a/Servers/WindowServer/WSMenuManager.cpp +++ b/Servers/WindowServer/WSMenuManager.cpp @@ -11,8 +11,17 @@ //#define DEBUG_MENUS +static WSMenuManager* s_the; + +WSMenuManager& WSMenuManager::the() +{ + ASSERT(s_the); + return *s_the; +} + WSMenuManager::WSMenuManager() { + s_the = this; m_username = getlogin(); m_needs_window_resize = true; @@ -140,18 +149,15 @@ WSMenuManager::WSMenuManager() // NOTE: This ensures that the system menu has the correct dimensions. set_current_menubar(nullptr); + + m_window = WSWindow::construct(*this, WSWindowType::Menubar); + m_window->set_rect(menubar_rect()); } WSMenuManager::~WSMenuManager() { } -void WSMenuManager::setup() -{ - m_window = WSWindow::construct(*this, WSWindowType::Menubar); - m_window->set_rect(menubar_rect()); -} - bool WSMenuManager::is_open(const WSMenu& menu) const { for (int i = 0; i < m_open_menu_stack.size(); ++i) { diff --git a/Servers/WindowServer/WSMenuManager.h b/Servers/WindowServer/WSMenuManager.h index c497e740ff1..4fd9e1d544e 100644 --- a/Servers/WindowServer/WSMenuManager.h +++ b/Servers/WindowServer/WSMenuManager.h @@ -11,10 +11,11 @@ class AClientConnection; class WSMenuManager final : public CObject { C_OBJECT(WSMenuManager) public: + static WSMenuManager& the(); + WSMenuManager(); virtual ~WSMenuManager() override; - void setup(); void refresh(); virtual void event(CEvent&) override; diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp index b49e217865a..08632da5add 100644 --- a/Servers/WindowServer/WSWindowManager.cpp +++ b/Servers/WindowServer/WSWindowManager.cpp @@ -43,8 +43,6 @@ WSWindowManager::WSWindowManager(const PaletteImpl& palette) reload_config(false); - m_menu_manager.setup(); - invalidate(); WSCompositor::the().compose(); } @@ -117,7 +115,7 @@ const Font& WSWindowManager::app_menu_font() const void WSWindowManager::set_resolution(int width, int height) { WSCompositor::the().set_resolution(width, height); - m_menu_manager.set_needs_window_resize(); + WSMenuManager::the().set_needs_window_resize(); WSClientConnection::for_each_client([&](WSClientConnection& client) { client.notify_about_new_screen_rect(WSScreen::the().rect()); }); @@ -275,7 +273,7 @@ void WSWindowManager::notify_rect_changed(WSWindow& window, const Rect& old_rect tell_wm_listeners_window_rect_changed(window); - m_menu_manager.refresh(); + WSMenuManager::the().refresh(); } void WSWindowManager::recompute_occlusions() @@ -710,12 +708,12 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& hovere // FIXME: Now that the menubar has a dedicated window, is this special-casing really necessary? if (!active_window_is_modal() && menubar_rect().contains(event.position())) { - m_menu_manager.dispatch_event(event); + WSMenuManager::the().dispatch_event(event); return; } - if (!menu_manager().open_menu_stack().is_empty()) { - auto* topmost_menu = menu_manager().open_menu_stack().last().ptr(); + if (!WSMenuManager::the().open_menu_stack().is_empty()) { + auto* topmost_menu = WSMenuManager::the().open_menu_stack().last().ptr(); ASSERT(topmost_menu); auto* window = topmost_menu->menu_window(); ASSERT(window); @@ -741,13 +739,13 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& hovere } if (event.type() == WSEvent::MouseDown) { - m_menu_manager.close_bar(); + WSMenuManager::the().close_bar(); topmost_menu->set_window_menu_open(false); } } if (event.type() == WSEvent::MouseMove) { - for (auto& menu : m_menu_manager.open_menu_stack()) { + for (auto& menu : WSMenuManager::the().open_menu_stack()) { if (!menu) continue; if (!menu->menu_window()->rect().contains(event.position())) @@ -914,7 +912,7 @@ Rect WSWindowManager::menubar_rect() const { if (active_fullscreen_window()) return {}; - return m_menu_manager.menubar_rect(); + return WSMenuManager::the().menubar_rect(); } void WSWindowManager::draw_window_switcher() @@ -994,11 +992,11 @@ void WSWindowManager::event(CEvent& event) // FIXME: I would prefer to be WSEvent::KeyUp, and be at the top of this function // However, the modifier is Invalid of Mod_Logo for a keyup event. Move after a fix is made. if (key_event.type() == WSEvent::KeyDown && key_event.modifiers() == Mod_Logo) { - m_menu_manager.open_menu(m_menu_manager.system_menu()); + WSMenuManager::the().open_menu(WSMenuManager::the().system_menu()); return; } - m_menu_manager.dispatch_event(event); + WSMenuManager::the().dispatch_event(event); } CObject::event(event); @@ -1047,10 +1045,10 @@ void WSWindowManager::set_active_window(WSWindow* window) auto* client = window->client(); ASSERT(client); - menu_manager().set_current_menubar(client->app_menubar()); + WSMenuManager::the().set_current_menubar(client->app_menubar()); tell_wm_listeners_window_state_changed(*m_active_window); } else { - menu_manager().set_current_menubar(nullptr); + WSMenuManager::the().set_current_menubar(nullptr); } if (active_client != previously_active_client) { @@ -1093,7 +1091,7 @@ void WSWindowManager::invalidate(const WSWindow& window) void WSWindowManager::invalidate(const WSWindow& window, const Rect& rect) { if (window.type() == WSWindowType::MenuApplet) { - menu_manager().invalidate_applet(window, rect); + WSMenuManager::the().invalidate_applet(window, rect); return; } @@ -1119,7 +1117,7 @@ const WSClientConnection* WSWindowManager::active_client() const void WSWindowManager::notify_client_changed_app_menubar(WSClientConnection& client) { if (active_client() == &client) - menu_manager().set_current_menubar(client.app_menubar()); + WSMenuManager::the().set_current_menubar(client.app_menubar()); } const WSCursor& WSWindowManager::active_cursor() const diff --git a/Servers/WindowServer/WSWindowManager.h b/Servers/WindowServer/WSWindowManager.h index f02a497a6bf..b8271ebafd0 100644 --- a/Servers/WindowServer/WSWindowManager.h +++ b/Servers/WindowServer/WSWindowManager.h @@ -94,9 +94,6 @@ public: void draw_window_switcher(); - WSMenuManager& menu_manager() { return m_menu_manager; } - const WSMenuManager& menu_manager() const { return m_menu_manager; } - Rect menubar_rect() const; const WSCursor& active_cursor() const; @@ -259,7 +256,6 @@ private: u8 m_keyboard_modifiers { 0 }; WSWindowSwitcher m_switcher; - WSMenuManager m_menu_manager; WeakPtr m_cursor_tracking_button; WeakPtr m_hovered_button; diff --git a/Servers/WindowServer/main.cpp b/Servers/WindowServer/main.cpp index 1f6849f8b1c..5c786d655d1 100644 --- a/Servers/WindowServer/main.cpp +++ b/Servers/WindowServer/main.cpp @@ -34,6 +34,7 @@ int main(int, char**) wm_config->read_num_entry("Screen", "Height", 768)); WSCompositor::the(); auto wm = WSWindowManager::construct(*palette); + auto mm = WSMenuManager::construct(); dbgprintf("Entering WindowServer main loop.\n"); loop.exec();