From 9b5e0b6247280a2c142d77a5e5cd598fd0d749a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=BCseyin=20ASLIT=C3=9CRK?= Date: Sun, 9 Feb 2020 11:54:54 +0300 Subject: [PATCH] WindowServer: Remove username from MenuManager. Now, we have UserName applet. --- Base/etc/SystemServer.ini | 5 +++ Servers/WindowServer/MenuManager.cpp | 64 ++++++++++------------------ Servers/WindowServer/MenuManager.h | 5 +-- 3 files changed, 28 insertions(+), 46 deletions(-) diff --git a/Base/etc/SystemServer.ini b/Base/etc/SystemServer.ini index 348f05b685..1dcfe862a8 100644 --- a/Base/etc/SystemServer.ini +++ b/Base/etc/SystemServer.ini @@ -38,6 +38,11 @@ User=anon KeepAlive=1 User=anon +[UserName.MenuApplet] +Priority=low +KeepAlive=1 +User=anon + [AudioServer] Socket=/tmp/portal/audio # TODO: we may want to start it lazily, but right now WindowServer connects to it immediately on startup diff --git a/Servers/WindowServer/MenuManager.cpp b/Servers/WindowServer/MenuManager.cpp index 1e171ee0b9..843b204856 100644 --- a/Servers/WindowServer/MenuManager.cpp +++ b/Servers/WindowServer/MenuManager.cpp @@ -49,7 +49,6 @@ MenuManager& MenuManager::the() MenuManager::MenuManager() { s_the = this; - m_username = getlogin(); m_needs_window_resize = true; HashTable seen_app_categories; @@ -104,7 +103,7 @@ MenuManager::MenuManager() for (const auto& app : m_apps) { RefPtr icon; if (!app.icon_path.is_empty()) - icon = Gfx::Bitmap::load_from_file(app.icon_path); + icon = Gfx::Bitmap::load_from_file(app.icon_path); auto parent_menu = m_app_category_menus.get(app.category).value_or(*m_system_menu); parent_menu->add_item(make(*m_system_menu, app_identifier++, app.name, String(), true, false, false, icon)); @@ -215,29 +214,8 @@ void MenuManager::draw() auto menubar_rect = this->menubar_rect(); if (m_needs_window_resize) { - int username_width = Gfx::Font::default_bold_font().width(m_username); - - m_username_rect = { - menubar_rect.right() - menubar_menu_margin() / 2 - Gfx::Font::default_bold_font().width(m_username), - menubar_rect.y(), - username_width, - menubar_rect.height() - }; - - int right_edge_x = m_username_rect.left() - 4; - for (auto& existing_applet : m_applets) { - if (!existing_applet) - continue; - - Gfx::Rect new_applet_rect(right_edge_x - existing_applet->size().width(), 0, existing_applet->size().width(), existing_applet->size().height()); - Gfx::Rect dummy_menubar_rect(0, 0, 0, 18); - new_applet_rect.center_vertically_within(dummy_menubar_rect); - - existing_applet->set_rect_in_menubar(new_applet_rect); - right_edge_x = existing_applet->rect_in_menubar().x() - 4; - } - m_window->set_rect(menubar_rect); + calculate_applet_rects(); m_needs_window_resize = false; } @@ -263,8 +241,6 @@ void MenuManager::draw() return IterationDecision::Continue; }); - painter.draw_text(m_username_rect, m_username, Gfx::Font::default_bold_font(), Gfx::TextAlignment::CenterRight, palette.window_text()); - for (auto& applet : m_applets) { if (!applet) continue; @@ -272,11 +248,6 @@ void MenuManager::draw() } } -void MenuManager::tick_clock() -{ - refresh(); -} - void MenuManager::refresh() { if (!m_window) @@ -285,6 +256,25 @@ void MenuManager::refresh() window().invalidate(); } +void MenuManager::calculate_applet_rects() +{ + dbg() << "Recalculate applet rects." << m_applets.size(); + + auto menubar_rect = m_window->rect(); + int right_edge_x = menubar_rect.width() - 4; + for (auto& existing_applet : m_applets) { + if (!existing_applet) + continue; + + Gfx::Rect new_applet_rect(right_edge_x - existing_applet->size().width(), 0, existing_applet->size().width(), existing_applet->size().height()); + Gfx::Rect dummy_menubar_rect(0, 0, 0, 18); + new_applet_rect.center_vertically_within(dummy_menubar_rect); + + existing_applet->set_rect_in_menubar(new_applet_rect); + right_edge_x = existing_applet->rect_in_menubar().x() - 4; + } +} + void MenuManager::event(Core::Event& event) { if (WindowManager::the().active_window_is_modal()) @@ -472,18 +462,8 @@ void MenuManager::close_bar() void MenuManager::add_applet(Window& applet) { - int right_edge_x = m_username_rect.left() - 4; - for (auto& existing_applet : m_applets) { - if (existing_applet) - right_edge_x = existing_applet->rect_in_menubar().x() - 4; - } - - Gfx::Rect new_applet_rect(right_edge_x - applet.size().width(), 0, applet.size().width(), applet.size().height()); - Gfx::Rect dummy_menubar_rect(0, 0, 0, 18); - new_applet_rect.center_vertically_within(dummy_menubar_rect); - - applet.set_rect_in_menubar(new_applet_rect); m_applets.append(applet.make_weak_ptr()); + calculate_applet_rects(); } void MenuManager::remove_applet(Window& applet) diff --git a/Servers/WindowServer/MenuManager.h b/Servers/WindowServer/MenuManager.h index a7253ba3c1..8019496352 100644 --- a/Servers/WindowServer/MenuManager.h +++ b/Servers/WindowServer/MenuManager.h @@ -43,6 +43,7 @@ public: virtual ~MenuManager() override; void refresh(); + void calculate_applet_rects(); virtual void event(Core::Event&) override; @@ -102,18 +103,14 @@ private: void draw(); void draw_applet(const Window&); - void tick_clock(); RefPtr m_window; - String m_username; WeakPtr m_current_menu; Vector> m_open_menu_stack; Vector> m_applets; - Gfx::Rect m_username_rect; - bool m_needs_window_resize { false }; bool m_bar_open { false };