diff options
author | Linus Groh <mail@linusgroh.de> | 2022-05-04 18:39:45 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-05 21:54:53 +0200 |
commit | e5196c8e3d13db7ad2fe8bade240e90aad140d8a (patch) | |
tree | 6de38bcf9c3509d2a8a923f406de4fab4815aa7a | |
parent | ac991b0a89233a234f3332bffff903f8667cf10a (diff) | |
download | serenity-e5196c8e3d13db7ad2fe8bade240e90aad140d8a.zip |
WindowServer: Take vertical menu offset into account when adjusting pos
Unconditionally adding the item height offset to the adjusted vertical
position of a menu leads to an incorrect position if we previously
clamped the translation offset so the menu doesn't go off-screen.
Also add some comments to this coordinate math. Always add comments to
coordinate math.
-rw-r--r-- | Userland/Services/WindowServer/Menu.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp index 24bcd4810f..798bb2c468 100644 --- a/Userland/Services/WindowServer/Menu.cpp +++ b/Userland/Services/WindowServer/Menu.cpp @@ -609,14 +609,23 @@ void Menu::do_popup(Gfx::IntPoint const& position, bool make_input, bool as_subm 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); } 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. adjusted_pos.set_x(adjusted_pos.x() + 1); } if (adjusted_pos.y() + window.height() > screen.rect().bottom() - margin) { - adjusted_pos = adjusted_pos.translated(0, -min(window.height(), adjusted_pos.y())); + // Vertically translate the window by its full height, i.e. flip it at its horizontal axis. + auto offset = window.height(); + // ...but if it's a submenu, go back by one menu item height to keep the menu aligned with + // its parent item, if possible. if (as_submenu) - adjusted_pos = adjusted_pos.translated(0, item_height()); + offset -= item_height(); + // Before translating, clamp the calculated offset to the current distance between the + // screen and menu top edges to avoid going off-screen. + adjusted_pos = adjusted_pos.translated(0, -min(offset, adjusted_pos.y())); } window.move_to(adjusted_pos); |