summaryrefslogtreecommitdiff
path: root/Servers/WindowServer/WSMenu.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin+git@viroteck.net>2019-05-16 01:06:21 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-05-16 01:22:54 +0200
commitf55965b5e84ac61a58aaed6e055680ca317a8540 (patch)
tree1fb4f3bba1990bab449896b2c770f2dd719187bf /Servers/WindowServer/WSMenu.cpp
parenta4b0dfff431579b45fc4d4c6439e74d79fc0e859 (diff)
downloadserenity-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.cpp18
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);
}