WindowServer: Add unadjusted position members to Menu

Used to determine Menu relationships by proxy
This commit is contained in:
thankyouverycool 2022-09-07 07:43:34 -04:00 committed by Linus Groh
parent 7c9ad6cc2f
commit 6c35aac617
Notes: sideshowbarker 2024-07-17 07:20:23 +09:00
3 changed files with 6 additions and 1 deletions

View File

@ -635,7 +635,7 @@ void Menu::do_popup(Gfx::IntPoint const& position, bool make_input, bool as_subm
redraw_if_theme_changed();
constexpr auto margin = 10;
Gfx::IntPoint adjusted_pos = position;
Gfx::IntPoint adjusted_pos = m_unadjusted_position = 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.

View File

@ -74,6 +74,9 @@ public:
Gfx::IntRect rect_in_window_menubar() const { return m_rect_in_window_menubar; }
void set_rect_in_window_menubar(Gfx::IntRect const& rect) { m_rect_in_window_menubar = rect; }
Gfx::IntPoint unadjusted_position() const { return m_unadjusted_position; }
void set_unadjusted_position(Gfx::IntPoint const& position) { m_unadjusted_position = position; }
Window* menu_window() { return m_menu_window.ptr(); }
Window& ensure_menu_window(Gfx::IntPoint const&);
@ -150,6 +153,7 @@ private:
String m_name;
u32 m_alt_shortcut_character { 0 };
Gfx::IntRect m_rect_in_window_menubar;
Gfx::IntPoint m_unadjusted_position;
NonnullOwnPtrVector<MenuItem> m_items;
RefPtr<Window> m_menu_window;

View File

@ -892,6 +892,7 @@ void WindowFrame::open_menubar_menu(Menu& menu)
auto menubar_rect = this->menubar_rect();
MenuManager::the().close_everyone();
auto position = menu.rect_in_window_menubar().bottom_left().translated(rect().location()).translated(menubar_rect.location());
menu.set_unadjusted_position(position);
auto& window = menu.ensure_menu_window(position);
auto window_rect = window.rect();
auto& screen = Screen::closest_to_rect(window_rect);