mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:57:44 +00:00
WindowServer: Remove username from MenuManager.
Now, we have UserName applet.
This commit is contained in:
parent
57edcb54c2
commit
9b5e0b6247
3 changed files with 28 additions and 46 deletions
|
@ -38,6 +38,11 @@ User=anon
|
||||||
KeepAlive=1
|
KeepAlive=1
|
||||||
User=anon
|
User=anon
|
||||||
|
|
||||||
|
[UserName.MenuApplet]
|
||||||
|
Priority=low
|
||||||
|
KeepAlive=1
|
||||||
|
User=anon
|
||||||
|
|
||||||
[AudioServer]
|
[AudioServer]
|
||||||
Socket=/tmp/portal/audio
|
Socket=/tmp/portal/audio
|
||||||
# TODO: we may want to start it lazily, but right now WindowServer connects to it immediately on startup
|
# TODO: we may want to start it lazily, but right now WindowServer connects to it immediately on startup
|
||||||
|
|
|
@ -49,7 +49,6 @@ MenuManager& MenuManager::the()
|
||||||
MenuManager::MenuManager()
|
MenuManager::MenuManager()
|
||||||
{
|
{
|
||||||
s_the = this;
|
s_the = this;
|
||||||
m_username = getlogin();
|
|
||||||
m_needs_window_resize = true;
|
m_needs_window_resize = true;
|
||||||
|
|
||||||
HashTable<String> seen_app_categories;
|
HashTable<String> seen_app_categories;
|
||||||
|
@ -104,7 +103,7 @@ MenuManager::MenuManager()
|
||||||
for (const auto& app : m_apps) {
|
for (const auto& app : m_apps) {
|
||||||
RefPtr<Gfx::Bitmap> icon;
|
RefPtr<Gfx::Bitmap> icon;
|
||||||
if (!app.icon_path.is_empty())
|
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);
|
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));
|
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();
|
auto menubar_rect = this->menubar_rect();
|
||||||
|
|
||||||
if (m_needs_window_resize) {
|
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);
|
m_window->set_rect(menubar_rect);
|
||||||
|
calculate_applet_rects();
|
||||||
m_needs_window_resize = false;
|
m_needs_window_resize = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,8 +241,6 @@ void MenuManager::draw()
|
||||||
return IterationDecision::Continue;
|
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) {
|
for (auto& applet : m_applets) {
|
||||||
if (!applet)
|
if (!applet)
|
||||||
continue;
|
continue;
|
||||||
|
@ -272,11 +248,6 @@ void MenuManager::draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuManager::tick_clock()
|
|
||||||
{
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuManager::refresh()
|
void MenuManager::refresh()
|
||||||
{
|
{
|
||||||
if (!m_window)
|
if (!m_window)
|
||||||
|
@ -285,6 +256,25 @@ void MenuManager::refresh()
|
||||||
window().invalidate();
|
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)
|
void MenuManager::event(Core::Event& event)
|
||||||
{
|
{
|
||||||
if (WindowManager::the().active_window_is_modal())
|
if (WindowManager::the().active_window_is_modal())
|
||||||
|
@ -472,18 +462,8 @@ void MenuManager::close_bar()
|
||||||
|
|
||||||
void MenuManager::add_applet(Window& applet)
|
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());
|
m_applets.append(applet.make_weak_ptr());
|
||||||
|
calculate_applet_rects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuManager::remove_applet(Window& applet)
|
void MenuManager::remove_applet(Window& applet)
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
virtual ~MenuManager() override;
|
virtual ~MenuManager() override;
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
void calculate_applet_rects();
|
||||||
|
|
||||||
virtual void event(Core::Event&) override;
|
virtual void event(Core::Event&) override;
|
||||||
|
|
||||||
|
@ -102,18 +103,14 @@ private:
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void draw_applet(const Window&);
|
void draw_applet(const Window&);
|
||||||
void tick_clock();
|
|
||||||
|
|
||||||
RefPtr<Window> m_window;
|
RefPtr<Window> m_window;
|
||||||
String m_username;
|
|
||||||
|
|
||||||
WeakPtr<Menu> m_current_menu;
|
WeakPtr<Menu> m_current_menu;
|
||||||
Vector<WeakPtr<Menu>> m_open_menu_stack;
|
Vector<WeakPtr<Menu>> m_open_menu_stack;
|
||||||
|
|
||||||
Vector<WeakPtr<Window>> m_applets;
|
Vector<WeakPtr<Window>> m_applets;
|
||||||
|
|
||||||
Gfx::Rect m_username_rect;
|
|
||||||
|
|
||||||
bool m_needs_window_resize { false };
|
bool m_needs_window_resize { false };
|
||||||
bool m_bar_open { false };
|
bool m_bar_open { false };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue