1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:18:12 +00:00

WindowServer: Do not pop-up submenus directly atop their ancestors

Previously submenus would pop-up on their immediate open ancestors in
cases of limited screen real estate. If the submenu was sufficiently
large, this could make it difficult to navigate back down the menu
stack. Now submenus display on either side of their ancestors, making
it easy to zig-zag up and down menu stacks. This is similar to how
menus operate in many other DEs.
This commit is contained in:
thankyouverycool 2022-08-16 06:55:43 -04:00 committed by Andreas Kling
parent 4489f9dbef
commit e87eb97e68

View file

@ -611,12 +611,17 @@ void Menu::do_popup(Gfx::IntPoint const& position, bool make_input, bool as_subm
auto& window = ensure_menu_window(position);
redraw_if_theme_changed();
int const margin = 30;
constexpr auto margin = 10;
Gfx::IntPoint adjusted_pos = position;
if (adjusted_pos.x() + window.width() > screen.rect().right() - margin) {
// Vertically translate the window by its full width, i.e. flip it at its vertical axis.
adjusted_pos = adjusted_pos.translated(-window.width(), 0);
// If the window is a submenu, translate to the opposite side of its immediate ancestor
if (auto* ancestor = MenuManager::the().closest_open_ancestor_of(*this); ancestor && as_submenu) {
constexpr auto offset = 1 + frame_thickness() * 2;
adjusted_pos = adjusted_pos.translated(-ancestor->menu_window()->width() + offset, 0);
}
} else {
// Even if no adjustment needs to be done, move the menu to the right by 1px so it's not
// underneath the cursor and can be closed by another click at the same position.