diff options
author | Robin Burchell <robin+git@viroteck.net> | 2019-05-16 01:06:21 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-16 01:22:54 +0200 |
commit | f55965b5e84ac61a58aaed6e055680ca317a8540 (patch) | |
tree | 1fb4f3bba1990bab449896b2c770f2dd719187bf /Servers/WindowServer/WSMenu.cpp | |
parent | a4b0dfff431579b45fc4d4c6439e74d79fc0e859 (diff) | |
download | serenity-f55965b5e84ac61a58aaed6e055680ca317a8540.zip |
WindowServer/GMenu: Adjust the popup position to fit the window inside the screen
Rather than passing a "top_anchored" bool. Fixes #22.
Diffstat (limited to 'Servers/WindowServer/WSMenu.cpp')
-rw-r--r-- | Servers/WindowServer/WSMenu.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Servers/WindowServer/WSMenu.cpp b/Servers/WindowServer/WSMenu.cpp index d900a49b6b..3d36316f30 100644 --- a/Servers/WindowServer/WSMenu.cpp +++ b/Servers/WindowServer/WSMenu.cpp @@ -4,6 +4,7 @@ #include "WSEvent.h" #include "WSEventLoop.h" #include "WSWindowManager.h" +#include "WSScreen.h" #include <WindowServer/WSAPITypes.h> #include <WindowServer/WSClientConnection.h> #include <SharedGraphics/CharacterBitmap.h> @@ -227,14 +228,21 @@ void WSMenu::close() menu_window()->set_visible(false); } -void WSMenu::popup(const Point& position, bool top_anchored) +void WSMenu::popup(const Point& position) { ASSERT(!is_empty()); + auto& window = ensure_menu_window(); - if (top_anchored) - window.move_to(position); - else - window.move_to(position.translated(0, -window.height())); + const int margin = 30; + Point adjusted_pos = position; + if (adjusted_pos.x() + window.width() >= WSScreen::the().width() - margin) { + adjusted_pos = adjusted_pos.translated(-window.width(), 0); + } + if (adjusted_pos.y() + window.height() >= WSScreen::the().height() - margin) { + adjusted_pos = adjusted_pos.translated(0, -window.height()); + } + + window.move_to(adjusted_pos); window.set_visible(true); WSWindowManager::the().set_current_menu(this); } |