1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:47:34 +00:00

WindowServer: Prevent menubar menus from appearing off screen

Adds some logic to reposition menus that would appear off the right or
bottom edge of the screen so they appear completely on screen.

Co-authored-by: Sam Atkins <atkinssj@gmail.com>
This commit is contained in:
Mike Akers 2022-06-20 10:34:18 -04:00 committed by Sam Atkins
parent c6eaa39b99
commit 9a908748e0

View file

@ -884,7 +884,23 @@ void WindowFrame::open_menubar_menu(Menu& menu)
{
auto menubar_rect = this->menubar_rect();
MenuManager::the().close_everyone();
menu.ensure_menu_window(menu.rect_in_window_menubar().bottom_left().translated(rect().location()).translated(menubar_rect.location()));
auto position = menu.rect_in_window_menubar().bottom_left().translated(rect().location()).translated(menubar_rect.location());
auto& window = menu.ensure_menu_window(position);
auto window_rect = window.rect();
auto& screen = Screen::closest_to_rect(window_rect);
auto window_border_thickness = 1;
// If the menu is off the right edge of the screen align its right edge with the edge of the screen.
if (window_rect.right() > screen.width()) {
position = position.translated(((window_rect.right() - screen.width()) * -1) - window_border_thickness, 0);
}
// If the menu is below the bottom of the screen move it to appear above the menubar.
if (window_rect.bottom() > screen.height()) {
position = position.translated(0, (window_rect.height() * -1) - menubar_rect.height());
}
window.set_rect(position.x(), position.y(), window_rect.width(), window_rect.height());
MenuManager::the().open_menu(menu);
WindowManager::the().set_window_with_active_menu(&m_window);
invalidate(menubar_rect);