1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

WindowServer: Show the username of the WindowServer owner in the menu.

This commit is contained in:
Andreas Kling 2019-03-10 03:16:27 +01:00
parent 8175d75432
commit 64237c5028
2 changed files with 28 additions and 5 deletions

View file

@ -212,6 +212,8 @@ WSWindowManager::WSWindowManager()
}); });
#endif #endif
m_username = getlogin();
m_menu_selection_color = Color::from_rgb(0x84351a); m_menu_selection_color = Color::from_rgb(0x84351a);
{ {
@ -939,6 +941,7 @@ void WSWindowManager::compose()
else else
m_back_painter->blit_with_opacity(dst, *backing_store, dirty_rect_in_window_coordinates, window.opacity()); m_back_painter->blit_with_opacity(dst, *backing_store, dirty_rect_in_window_coordinates, window.opacity());
} }
return IterationDecision::Continue;
}); });
draw_menubar(); draw_menubar();
@ -968,8 +971,10 @@ Rect WSWindowManager::menubar_rect() const
void WSWindowManager::draw_menubar() void WSWindowManager::draw_menubar()
{ {
m_back_painter->fill_rect(menubar_rect(), Color::LightGray); auto menubar_rect = this->menubar_rect();
m_back_painter->draw_line({ 0, menubar_rect().bottom() }, { menubar_rect().right(), menubar_rect().bottom() }, Color::White);
m_back_painter->fill_rect(menubar_rect, Color::LightGray);
m_back_painter->draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, Color::White);
int index = 0; int index = 0;
for_each_active_menubar_menu([&] (WSMenu& menu) { for_each_active_menubar_menu([&] (WSMenu& menu) {
Color text_color = Color::Black; Color text_color = Color::Black;
@ -984,10 +989,19 @@ void WSWindowManager::draw_menubar()
TextAlignment::CenterLeft, TextAlignment::CenterLeft,
text_color text_color
); );
++index; ++index;
return true; return true;
}); });
int username_width = Font::default_bold_font().width(m_username);
Rect username_rect {
menubar_rect.right() - menubar_menu_margin() / 2 - Font::default_bold_font().width(m_username),
menubar_rect.y(),
username_width,
menubar_rect.height()
};
m_back_painter->draw_text(username_rect, m_username, Font::default_bold_font(), TextAlignment::CenterRight, Color::Black);
time_t now = time(nullptr); time_t now = time(nullptr);
auto* tm = localtime(&now); auto* tm = localtime(&now);
auto time_text = String::format("%4u-%02u-%02u %02u:%02u:%02u", auto time_text = String::format("%4u-%02u-%02u %02u:%02u:%02u",
@ -997,8 +1011,15 @@ void WSWindowManager::draw_menubar()
tm->tm_hour, tm->tm_hour,
tm->tm_min, tm->tm_min,
tm->tm_sec); tm->tm_sec);
auto time_rect = menubar_rect().translated(-(menubar_menu_margin() / 2), 0); int time_width = font().width(time_text);
m_back_painter->draw_text(time_rect, time_text, TextAlignment::CenterRight, Color::Black); Rect time_rect {
username_rect.left() - menubar_menu_margin() / 2 - time_width,
menubar_rect.y(),
time_width,
menubar_rect.height()
};
m_back_painter->draw_text(time_rect, time_text, font(), TextAlignment::CenterRight, Color::Black);
Rect cpu_rect { time_rect.right() - font().width(time_text) - (int)m_cpu_history.capacity() - 10, time_rect.y() + 1, (int)m_cpu_history.capacity(), time_rect.height() - 2 }; Rect cpu_rect { time_rect.right() - font().width(time_text) - (int)m_cpu_history.capacity() - 10, time_rect.y() + 1, (int)m_cpu_history.capacity(), time_rect.height() - 2 };
m_back_painter->fill_rect(cpu_rect, Color::Black); m_back_painter->fill_rect(cpu_rect, Color::Black);

View file

@ -172,6 +172,8 @@ private:
WSWindowSwitcher m_switcher; WSWindowSwitcher m_switcher;
CircularQueue<float, 30> m_cpu_history; CircularQueue<float, 30> m_cpu_history;
String m_username;
}; };
template<typename Callback> template<typename Callback>