summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-08-16 06:55:43 -0400
committerAndreas Kling <kling@serenityos.org>2022-08-16 16:52:09 +0200
commite87eb97e6804c34e68a903d258aa5d46096d39b4 (patch)
tree806457afee7998db2c8b079d1fb15f1b6e5a1fa5 /Userland/Services
parent4489f9dbefa4aaff32825d0371e1bf062bd3d91c (diff)
downloadserenity-e87eb97e6804c34e68a903d258aa5d46096d39b4.zip
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.
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/WindowServer/Menu.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp
index 992d114555..390a86f64f 100644
--- a/Userland/Services/WindowServer/Menu.cpp
+++ b/Userland/Services/WindowServer/Menu.cpp
@@ -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.