WindowServer: Remove username from MenuManager.

Now, we have UserName applet.
This commit is contained in:
Hüseyin ASLITÜRK 2020-02-09 11:54:54 +03:00 committed by Andreas Kling
parent 57edcb54c2
commit 9b5e0b6247
Notes: sideshowbarker 2024-07-19 09:31:17 +09:00
3 changed files with 28 additions and 46 deletions

View file

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

View file

@ -49,7 +49,6 @@ MenuManager& MenuManager::the()
MenuManager::MenuManager()
{
s_the = this;
m_username = getlogin();
m_needs_window_resize = true;
HashTable<String> seen_app_categories;
@ -104,7 +103,7 @@ MenuManager::MenuManager()
for (const auto& app : m_apps) {
RefPtr<Gfx::Bitmap> 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<MenuItem>(*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)

View file

@ -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<Window> m_window;
String m_username;
WeakPtr<Menu> m_current_menu;
Vector<WeakPtr<Menu>> m_open_menu_stack;
Vector<WeakPtr<Window>> m_applets;
Gfx::Rect m_username_rect;
bool m_needs_window_resize { false };
bool m_bar_open { false };