1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 12:55:09 +00:00

WindowServer: Compute some layout rects in WSMenuManager up front

Currently menu applets are laid out relative to the "audio rect" which
is the rect of the little audio muted state icon thingy.

There was an issue where applets would be placed at a negative X coord
if they were added to the WindowServer before the first time drawing
the menubar.
This commit is contained in:
Andreas Kling 2019-12-05 19:59:11 +01:00
parent 20bbeba6d5
commit 6e6e0b9de8
3 changed files with 38 additions and 32 deletions

View file

@ -241,11 +241,6 @@ void WSWindowManager::set_resolution(int width, int height)
}
}
int WSWindowManager::menubar_menu_margin() const
{
return 16;
}
void WSWindowManager::set_current_menubar(WSMenuBar* menubar)
{
if (menubar)
@ -255,11 +250,11 @@ void WSWindowManager::set_current_menubar(WSMenuBar* menubar)
#ifdef DEBUG_MENUS
dbg() << "[WM] Current menubar is now " << menubar;
#endif
Point next_menu_location { menubar_menu_margin() / 2, 0 };
Point next_menu_location { WSMenuManager::menubar_menu_margin() / 2, 0 };
int index = 0;
for_each_active_menubar_menu([&](WSMenu& menu) {
int text_width = index == 1 ? Font::default_bold_font().width(menu.name()) : font().width(menu.name());
menu.set_rect_in_menubar({ next_menu_location.x() - menubar_menu_margin() / 2, 0, text_width + menubar_menu_margin(), menubar_rect().height() - 1 });
menu.set_rect_in_menubar({ next_menu_location.x() - WSMenuManager::menubar_menu_margin() / 2, 0, text_width + WSMenuManager::menubar_menu_margin(), menubar_rect().height() - 1 });
menu.set_text_rect_in_menubar({ next_menu_location, { text_width, menubar_rect().height() } });
next_menu_location.move_by(menu.rect_in_menubar().width(), 0);
++index;
@ -926,7 +921,7 @@ Rect WSWindowManager::menubar_rect() const
{
if (active_fullscreen_window())
return {};
return { 0, 0, WSScreen::the().rect().width(), 18 };
return m_menu_manager.menubar_rect();
}
void WSWindowManager::draw_window_switcher()