WindowServer: Detach WSMenuManager from WSWindowManager

You can now get to the WSMenuManager via WSMenuManager::the().
Also note that it's initialized after WSWindowManager.
This commit is contained in:
Andreas Kling 2020-01-08 13:19:31 +01:00
parent 2d75396c94
commit 8ddd053c2a
Notes: sideshowbarker 2024-07-19 10:16:09 +09:00
8 changed files with 41 additions and 39 deletions

View file

@ -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<WindowServer::DestroyMenubarResponse> 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<WindowServer::DestroyMenubarResponse>();
}
@ -405,7 +405,7 @@ OwnPtr<WindowServer::CreateWindowResponse> 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<WindowServer::CreateWindowResponse>(window_id);
}
@ -420,7 +420,7 @@ OwnPtr<WindowServer::DestroyWindowResponse> 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);

View file

@ -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

View file

@ -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);
}

View file

@ -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) {

View file

@ -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;

View file

@ -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

View file

@ -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<WSButton> m_cursor_tracking_button;
WeakPtr<WSButton> m_hovered_button;

View file

@ -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();