summaryrefslogtreecommitdiff
path: root/Servers/WindowServer
diff options
context:
space:
mode:
Diffstat (limited to 'Servers/WindowServer')
-rw-r--r--Servers/WindowServer/WSAPITypes.h1
-rw-r--r--Servers/WindowServer/WSClientConnection.cpp2
-rw-r--r--Servers/WindowServer/WSEvent.h5
-rw-r--r--Servers/WindowServer/WSEventLoop.cpp2
-rw-r--r--Servers/WindowServer/WSMenu.cpp18
-rw-r--r--Servers/WindowServer/WSMenu.h2
6 files changed, 17 insertions, 13 deletions
diff --git a/Servers/WindowServer/WSAPITypes.h b/Servers/WindowServer/WSAPITypes.h
index 7ba9095516..2f54a0beaa 100644
--- a/Servers/WindowServer/WSAPITypes.h
+++ b/Servers/WindowServer/WSAPITypes.h
@@ -258,7 +258,6 @@ struct WSAPI_ClientMessage {
bool checkable;
bool checked;
WSAPI_Point position;
- bool top_anchored;
} menu;
struct {
WSAPI_Rect rect;
diff --git a/Servers/WindowServer/WSClientConnection.cpp b/Servers/WindowServer/WSClientConnection.cpp
index 57bd34adc9..81ba62134d 100644
--- a/Servers/WindowServer/WSClientConnection.cpp
+++ b/Servers/WindowServer/WSClientConnection.cpp
@@ -260,7 +260,7 @@ void WSClientConnection::handle_request(const WSAPIPopupMenuRequest& request)
return;
}
auto& menu = *(*it).value;
- menu.popup(position, request.top_anchored());
+ menu.popup(position);
}
void WSClientConnection::handle_request(const WSAPIDismissMenuRequest& request)
diff --git a/Servers/WindowServer/WSEvent.h b/Servers/WindowServer/WSEvent.h
index d894044e21..72cd89c2f0 100644
--- a/Servers/WindowServer/WSEvent.h
+++ b/Servers/WindowServer/WSEvent.h
@@ -235,22 +235,19 @@ private:
class WSAPIPopupMenuRequest : public WSAPIClientRequest {
public:
- WSAPIPopupMenuRequest(int client_id, int menu_id, const Point& position, bool top_anchored)
+ WSAPIPopupMenuRequest(int client_id, int menu_id, const Point& position)
: WSAPIClientRequest(WSEvent::APIPopupMenuRequest, client_id)
, m_menu_id(menu_id)
, m_position(position)
- , m_top_anchored(top_anchored)
{
}
int menu_id() const { return m_menu_id; }
Point position() const { return m_position; }
- bool top_anchored() const { return m_top_anchored; }
private:
int m_menu_id;
Point m_position;
- bool m_top_anchored;
};
class WSAPIDismissMenuRequest : public WSAPIClientRequest {
diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp
index adb2873b78..e32ec7343f 100644
--- a/Servers/WindowServer/WSEventLoop.cpp
+++ b/Servers/WindowServer/WSEventLoop.cpp
@@ -158,7 +158,7 @@ bool WSEventLoop::on_receive_from_client(int client_id, const WSAPI_ClientMessag
post_event(client, make<WSAPICreateMenuRequest>(client_id, String(message.text, message.text_length)));
break;
case WSAPI_ClientMessage::Type::PopupMenu:
- post_event(client, make<WSAPIPopupMenuRequest>(client_id, message.menu.menu_id, message.menu.position, message.menu.top_anchored));
+ post_event(client, make<WSAPIPopupMenuRequest>(client_id, message.menu.menu_id, message.menu.position));
break;
case WSAPI_ClientMessage::Type::DismissMenu:
post_event(client, make<WSAPIDismissMenuRequest>(client_id, message.menu.menu_id));
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);
}
diff --git a/Servers/WindowServer/WSMenu.h b/Servers/WindowServer/WSMenu.h
index 43f66f838d..b9a9713256 100644
--- a/Servers/WindowServer/WSMenu.h
+++ b/Servers/WindowServer/WSMenu.h
@@ -74,7 +74,7 @@ public:
void close();
- void popup(const Point&, bool top_anchored);
+ void popup(const Point&);
private:
virtual void event(CEvent&) override;